Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Please, how can I output global displacement (U) in Comsol?
Posted 24.07.2017, 19:44 GMT-4 1 Reply
Please login with a confirmed email address before reporting spam
Please, how can I output global displacement (U) in Comsol? I want to calculate the compliance of my model. (Please, see the attached Comsol code).
compliance = U transpose x Global stiffness matrix x U
I have used these lines of code to obtain the global stiffness matrix (Kf).
MA = mphmatrix(model, 'sol1', 'out', {'K','E'})
K = MA.K; % stiffness vector
Kf = full(K);
.....................................................................
This is my complete code
%....................................................................
function [Kf,compliance] = examplestudy
%
% examplestudy.m
%
% Model exported on Jul 24 2017, 18:50 by COMSOL 5.2.1.152.
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('C:\Users\sayinde\Dropbox\Comsol stuffs new');
model.label('examplestudy.mph');
model.comments(['Untitled\n\n']);
model.modelNode.create('comp1');
model.geom.create('geom1', 2);
model.mesh.create('mesh1', 'geom1');
model.geom('geom1').create('b1', 'BezierPolygon');
model.geom('geom1').feature('b1').set('p', {'-0.7' '-0.7' '0.05' '0.05' '0.5' '0.5' '-0.7'; ...
'-0.3' '0.3' '0.3' '0.6' '0.6' '-0.3' '-0.3'});
model.geom('geom1').feature('b1').set('w', {'1' '1' '1' '1' '1' '1' '1' '1' '1' '1' ...
'1' '1'});
model.geom('geom1').feature('b1').set('degree', {'1' '1' '1' '1' '1' '1'});
model.geom('geom1').run;
model.material.create('mat1', 'Common', 'comp1');
model.material('mat1').propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');
model.physics.create('solid', 'SolidMechanics', 'geom1');
model.physics('solid').create('fix1', 'Fixed', 1);
model.physics('solid').feature('fix1').selection.set([1]);
model.physics('solid').create('disp1', 'Displacement0', 0);
model.physics('solid').create('disp2', 'Displacement0', 0);
model.physics('solid').feature('disp2').selection.set([5]);
model.mesh('mesh1').create('fq1', 'FreeQuad');
model.view('view1').axis.set('ymax', '1.7435424327850342');
model.view('view1').axis.set('xmax', '1.561381220817566');
model.view('view1').axis.set('ymin', '-1.7435424327850342');
model.view('view1').axis.set('xmin', '-1.561381220817566');
model.material('mat1').label('solid material 1');
model.material('mat1').propertyGroup('Enu').set('youngsmodulus', '1');
model.material('mat1').propertyGroup('Enu').set('poissonsratio', '0.3');
model.physics('solid').feature('disp1').set('Direction', {'1'; '1'; '0'});
model.physics('solid').feature('disp1').set('U0', {'-12.44'; '-3.45'; '0'});
model.physics('solid').feature('disp2').set('Direction', {'1'; '1'; '0'});
model.physics('solid').feature('disp2').set('U0', {'14.257'; '3.457'; '0'});
model.mesh('mesh1').run;
model.study.create('std1');
model.study('std1').create('stat', 'Stationary');
model.sol.create('sol1');
model.sol('sol1').study('std1');
model.sol('sol1').attach('std1');
model.sol('sol1').create('st1', 'StudyStep');
model.sol('sol1').create('v1', 'Variables');
model.sol('sol1').create('s1', 'Stationary');
model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled');
model.sol('sol1').feature('s1').feature.remove('fcDef');
model.result.create('pg1', 'PlotGroup2D');
model.result.create('pg2', 'PlotGroup2D');
model.result('pg1').create('surf2', 'Surface');
model.result('pg2').create('surf1', 'Surface');
model.sol('sol1').attach('std1');
model.sol('sol1').runAll;
model.result('pg1').label('Stress (solid)');
model.result('pg1').feature('surf2').set('resolution', 'normal');
model.result('pg2').label('total disp');
model.result('pg2').feature('surf1').label('total displacement');
model.result('pg2').feature('surf1').set('resolution', 'normal');
MA = mphmatrix(model, 'sol1', 'out', {'K','E'})
K = MA.K; % stiffness vector
Kf = full(K);
% How can I output the global displacement in comsol
compliance = u'*Kf*u; % u is the global displacement I want to use to compute the compliance
out = model;
Thank you.
compliance = U transpose x Global stiffness matrix x U
I have used these lines of code to obtain the global stiffness matrix (Kf).
MA = mphmatrix(model, 'sol1', 'out', {'K','E'})
K = MA.K; % stiffness vector
Kf = full(K);
.....................................................................
This is my complete code
%....................................................................
function [Kf,compliance] = examplestudy
%
% examplestudy.m
%
% Model exported on Jul 24 2017, 18:50 by COMSOL 5.2.1.152.
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('C:\Users\sayinde\Dropbox\Comsol stuffs new');
model.label('examplestudy.mph');
model.comments(['Untitled\n\n']);
model.modelNode.create('comp1');
model.geom.create('geom1', 2);
model.mesh.create('mesh1', 'geom1');
model.geom('geom1').create('b1', 'BezierPolygon');
model.geom('geom1').feature('b1').set('p', {'-0.7' '-0.7' '0.05' '0.05' '0.5' '0.5' '-0.7'; ...
'-0.3' '0.3' '0.3' '0.6' '0.6' '-0.3' '-0.3'});
model.geom('geom1').feature('b1').set('w', {'1' '1' '1' '1' '1' '1' '1' '1' '1' '1' ...
'1' '1'});
model.geom('geom1').feature('b1').set('degree', {'1' '1' '1' '1' '1' '1'});
model.geom('geom1').run;
model.material.create('mat1', 'Common', 'comp1');
model.material('mat1').propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');
model.physics.create('solid', 'SolidMechanics', 'geom1');
model.physics('solid').create('fix1', 'Fixed', 1);
model.physics('solid').feature('fix1').selection.set([1]);
model.physics('solid').create('disp1', 'Displacement0', 0);
model.physics('solid').create('disp2', 'Displacement0', 0);
model.physics('solid').feature('disp2').selection.set([5]);
model.mesh('mesh1').create('fq1', 'FreeQuad');
model.view('view1').axis.set('ymax', '1.7435424327850342');
model.view('view1').axis.set('xmax', '1.561381220817566');
model.view('view1').axis.set('ymin', '-1.7435424327850342');
model.view('view1').axis.set('xmin', '-1.561381220817566');
model.material('mat1').label('solid material 1');
model.material('mat1').propertyGroup('Enu').set('youngsmodulus', '1');
model.material('mat1').propertyGroup('Enu').set('poissonsratio', '0.3');
model.physics('solid').feature('disp1').set('Direction', {'1'; '1'; '0'});
model.physics('solid').feature('disp1').set('U0', {'-12.44'; '-3.45'; '0'});
model.physics('solid').feature('disp2').set('Direction', {'1'; '1'; '0'});
model.physics('solid').feature('disp2').set('U0', {'14.257'; '3.457'; '0'});
model.mesh('mesh1').run;
model.study.create('std1');
model.study('std1').create('stat', 'Stationary');
model.sol.create('sol1');
model.sol('sol1').study('std1');
model.sol('sol1').attach('std1');
model.sol('sol1').create('st1', 'StudyStep');
model.sol('sol1').create('v1', 'Variables');
model.sol('sol1').create('s1', 'Stationary');
model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled');
model.sol('sol1').feature('s1').feature.remove('fcDef');
model.result.create('pg1', 'PlotGroup2D');
model.result.create('pg2', 'PlotGroup2D');
model.result('pg1').create('surf2', 'Surface');
model.result('pg2').create('surf1', 'Surface');
model.sol('sol1').attach('std1');
model.sol('sol1').runAll;
model.result('pg1').label('Stress (solid)');
model.result('pg1').feature('surf2').set('resolution', 'normal');
model.result('pg2').label('total disp');
model.result('pg2').feature('surf1').label('total displacement');
model.result('pg2').feature('surf1').set('resolution', 'normal');
MA = mphmatrix(model, 'sol1', 'out', {'K','E'})
K = MA.K; % stiffness vector
Kf = full(K);
% How can I output the global displacement in comsol
compliance = u'*Kf*u; % u is the global displacement I want to use to compute the compliance
out = model;
Thank you.
1 Reply Last Post 25.07.2017, 18:35 GMT-4