Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Create geometry from a matrix

Please login with a confirmed email address before reporting spam

Hi everyone,

I am trying to create a geometry with Comsol 4.3 with Matlab 2012.
The geometry I want to create is very complex.
The geometry is defined by a matrix (the value 1 corresponding to the material and the 0 corresponding to outside the material).

I have no clue how to get started with that, and I didn't find any tutorial helping me.

Therefore my question is simple ? Do you know any way to create a geometry from a matrix file ?

Thank you so much.

4 Replies Last Post 27 mai 2013, 21:16 UTC−4
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 17 janv. 2013, 15:04 UTC−5
Hi

probably you should use matlab and Comsol commands and not SolidWorks ;)

One way is to divide your volume into small squares/cubes and map the matrix to the material. You wil get many internal surfaces too, but I'm not sure that is so more heavy to use than if you start to write agorithms to group similar adjacent material and remove the internal boundaries, because your mesh wil anyhow also be helped by the regular subdivision pattern

But in 3D you wil get very many DoF hence nee quite some RAM

--
Good luck
Ivar
Hi probably you should use matlab and Comsol commands and not SolidWorks ;) One way is to divide your volume into small squares/cubes and map the matrix to the material. You wil get many internal surfaces too, but I'm not sure that is so more heavy to use than if you start to write agorithms to group similar adjacent material and remove the internal boundaries, because your mesh wil anyhow also be helped by the regular subdivision pattern But in 3D you wil get very many DoF hence nee quite some RAM -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18 janv. 2013, 09:46 UTC−5
Thank you for your answer.

I work in 2D only. I already divided my matrix (=surface) into small square, but I am a very beginner with Comsol and I don't know how to 'map' the matrix to the material.
Which commands could be useful ?
Thank you for your answer. I work in 2D only. I already divided my matrix (=surface) into small square, but I am a very beginner with Comsol and I don't know how to 'map' the matrix to the material. Which commands could be useful ?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 27 mai 2013, 21:16 UTC−4
HI

I have an answer for your questions. So just see the followed sample I offer. it is a .m file.

import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('C:\Users\Administrator\Desktop');
model.modelNode.create('mod1');
model.geom.create('geom1', 3);
model.mesh.create('mesh1', 'geom1');
model.physics.create('ec', 'ConductiveMedia', 'geom1');
model.study.create('std1');
model.study('std1').feature.create('stat', 'Stationary');
model.geom('geom1').run;
model.geom('geom1').run;
model.param.set('e_l',0.01);
coord_mid=[
0.0050 0.0050 0.0050 1.0000
0.0050 0.0150 0.0050 1.0000
0.0050 0.0250 0.0050 1.0000
0.0050 0.0350 0.0050 1.0000
0.0050 0.0050 0.0150 1.0000
0.0050 0.0150 0.0150 1.0000
0.0050 0.0250 0.0150 1.0000
0.0050 0.0350 0.0150 1.0000
0.0050 0.0050 0.0250 1.0000
0.0050 0.0150 0.0250 1.0000
0.0050 0.0250 0.0250 1.0000
0.0050 0.0350 0.0250 1.0000];
%建立几何模型
%for i = 1:BB(1)
for i = 1:12

str=sprintf('model.geom(''geom1'').feature.create(''blk%d'', ''Block'');',i);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 0);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 1);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 2);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 0);',i,coord_mid(i,1));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 1);',i,coord_mid(i,2));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 2);',i,coord_mid(i,3));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').set(''base'', ''center'');',i);
eval(str);
str=sprintf('model.geom(''geom1'').run(''blk%d'');',i);
eval(str);
end
model.geom('geom1').run
model.geom('geom1').run('fin');
hope it is usefull to you.
HI I have an answer for your questions. So just see the followed sample I offer. it is a .m file. import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('C:\Users\Administrator\Desktop'); model.modelNode.create('mod1'); model.geom.create('geom1', 3); model.mesh.create('mesh1', 'geom1'); model.physics.create('ec', 'ConductiveMedia', 'geom1'); model.study.create('std1'); model.study('std1').feature.create('stat', 'Stationary'); model.geom('geom1').run; model.geom('geom1').run; model.param.set('e_l',0.01); coord_mid=[ 0.0050 0.0050 0.0050 1.0000 0.0050 0.0150 0.0050 1.0000 0.0050 0.0250 0.0050 1.0000 0.0050 0.0350 0.0050 1.0000 0.0050 0.0050 0.0150 1.0000 0.0050 0.0150 0.0150 1.0000 0.0050 0.0250 0.0150 1.0000 0.0050 0.0350 0.0150 1.0000 0.0050 0.0050 0.0250 1.0000 0.0050 0.0150 0.0250 1.0000 0.0050 0.0250 0.0250 1.0000 0.0050 0.0350 0.0250 1.0000]; %建立几何模型 %for i = 1:BB(1) for i = 1:12 str=sprintf('model.geom(''geom1'').feature.create(''blk%d'', ''Block'');',i); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 0);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 1);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 2);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 0);',i,coord_mid(i,1)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 1);',i,coord_mid(i,2)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 2);',i,coord_mid(i,3)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').set(''base'', ''center'');',i); eval(str); str=sprintf('model.geom(''geom1'').run(''blk%d'');',i); eval(str); end model.geom('geom1').run model.geom('geom1').run('fin'); hope it is usefull to you.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 27 mai 2013, 21:16 UTC−4
HI

I have an answer for your questions. So just see the followed sample I offer. it is a .m file.

import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelPath('C:\Users\Administrator\Desktop');
model.modelNode.create('mod1');
model.geom.create('geom1', 3);
model.mesh.create('mesh1', 'geom1');
model.physics.create('ec', 'ConductiveMedia', 'geom1');
model.study.create('std1');
model.study('std1').feature.create('stat', 'Stationary');
model.geom('geom1').run;
model.geom('geom1').run;
model.param.set('e_l',0.01);
coord_mid=[
0.0050 0.0050 0.0050 1.0000
0.0050 0.0150 0.0050 1.0000
0.0050 0.0250 0.0050 1.0000
0.0050 0.0350 0.0050 1.0000
0.0050 0.0050 0.0150 1.0000
0.0050 0.0150 0.0150 1.0000
0.0050 0.0250 0.0150 1.0000
0.0050 0.0350 0.0150 1.0000
0.0050 0.0050 0.0250 1.0000
0.0050 0.0150 0.0250 1.0000
0.0050 0.0250 0.0250 1.0000
0.0050 0.0350 0.0250 1.0000];
%建立几何模型
%for i = 1:BB(1)
for i = 1:12

str=sprintf('model.geom(''geom1'').feature.create(''blk%d'', ''Block'');',i);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 0);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 1);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 2);',i,0.01);
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 0);',i,coord_mid(i,1));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 1);',i,coord_mid(i,2));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 2);',i,coord_mid(i,3));
eval(str);
str=sprintf('model.geom(''geom1'').feature(''blk%d'').set(''base'', ''center'');',i);
eval(str);
str=sprintf('model.geom(''geom1'').run(''blk%d'');',i);
eval(str);
end
model.geom('geom1').run
model.geom('geom1').run('fin');
hope it is usefull to you.
HI I have an answer for your questions. So just see the followed sample I offer. it is a .m file. import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('C:\Users\Administrator\Desktop'); model.modelNode.create('mod1'); model.geom.create('geom1', 3); model.mesh.create('mesh1', 'geom1'); model.physics.create('ec', 'ConductiveMedia', 'geom1'); model.study.create('std1'); model.study('std1').feature.create('stat', 'Stationary'); model.geom('geom1').run; model.geom('geom1').run; model.param.set('e_l',0.01); coord_mid=[ 0.0050 0.0050 0.0050 1.0000 0.0050 0.0150 0.0050 1.0000 0.0050 0.0250 0.0050 1.0000 0.0050 0.0350 0.0050 1.0000 0.0050 0.0050 0.0150 1.0000 0.0050 0.0150 0.0150 1.0000 0.0050 0.0250 0.0150 1.0000 0.0050 0.0350 0.0150 1.0000 0.0050 0.0050 0.0250 1.0000 0.0050 0.0150 0.0250 1.0000 0.0050 0.0250 0.0250 1.0000 0.0050 0.0350 0.0250 1.0000]; %建立几何模型 %for i = 1:BB(1) for i = 1:12 str=sprintf('model.geom(''geom1'').feature.create(''blk%d'', ''Block'');',i); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 0);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 1);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''size'', ''%f'', 2);',i,0.01); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 0);',i,coord_mid(i,1)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 1);',i,coord_mid(i,2)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').setIndex(''pos'', ''%f'', 2);',i,coord_mid(i,3)); eval(str); str=sprintf('model.geom(''geom1'').feature(''blk%d'').set(''base'', ''center'');',i); eval(str); str=sprintf('model.geom(''geom1'').run(''blk%d'');',i); eval(str); end model.geom('geom1').run model.geom('geom1').run('fin'); hope it is usefull to you.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.