Working with Geometry Sequences
This section shows how to create geometry sequences using the syntax outlined in The Geometry Sequence Syntax. This section has these examples:
For more information about geometry modeling, see the Geometry chapter in the COMSOL Multiphysics Reference Manual.
Creating a 1D Geometry
From the MATLAB command prompt, create a 1D geometry model by adding a geometry sequence and then adding geometry features. The last step is to run the sequence using the run method.
First create a model object:
model = ModelUtil.create('Model');
Then continue with the commands:
model.component.create('comp1',true);
 
geom1 = model.component('comp1').geom.create('geom1',1);
 
i1 = geom1.feature.create('i1','Interval');
i1.set('intervals','many');
i1.set('p','0,1,2');
 
geom1.run;
This creates a geometry sequence with a 1D solid object consisting of vertices at x  =  0, 1, and 2, and edges joining the vertices adjacent in the coordinate list.
Then enter:
p1 = geom1.feature.create('p1','Point');
p1.set('p',0.5);
 
geom1.run;
to add a point object located at x  =  0.5 to the geometry.
To plot the result, enter:
mphgeom(model,'geom1','vertexmode','on');
Code for Use with MATLAB®
model = ModelUtil.create('Model');
model.component.create('comp1',true);
geom1 = model.component('comp1').geom.create('geom1',1);
i1 = geom1.feature.create('i1','Interval');
i1.set('intervals','many');
i1.set('p','0,1,2');
geom1.run;
p1 = geom1.feature.create('p1','Point');
p1.set('p',0.5);
geom1.run;
mphgeom(model,'geom1','vertexmode','on')
Creating a 2D Geometry Using Primitive Geometry Objects
Creating Composite Objects
Use a model object with a 2D geometry. Enter:
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
geom2 = comp1.geom.create('geom2',2);
Continue by creating a rectangle with side length of 2 and centered at the origin:
sq1 = geom2.feature.create('sq1','Square');
sq1.set('size',2);
sq1.set('base','center');
The property size describes the side lengths of the rectangle and the property pos describes the positioning. The default is to position the rectangle about its lower-left corner. Use the property base to control the positioning.
Create a circular hole with a radius of 0.5 centered at (0, 0):
c1 = geom2.feature.create('c1','Circle');
c1.set('r',0.5);
c1.set('pos',[0 0]);
The property r describes the radius of the circle, and the property pos describes the positioning.
The property pos could have been excluded because the default position is the origin. The default is to position the circle about its center.
Drill a hole in the rectangle by subtracting the circle from it:
co1 = geom2.feature.create('co1','Compose');
co1.selection('input').set({'c1' 'sq1'});
co1.set('formula','sq1-c1');
A selection object is used to refer to the input object. The operators +, *, and - correspond to the set operations union, intersection, and difference, respectively.
The Compose operation allows you to work with a formula. Alternatively use the Difference operation instead of Compose. The following sequence of commands starts with disabling the Compose operation:
co1.active(false);
 
dif1 = geom2.feature.create('dif1','Difference');
dif1.selection('input').set({'sq1'});
dif1.selection('input2').set({'c1'});
Run the geometry sequence to create the geometry and plot the result:
geom2.run;
mphgeom(model,'geom2');
Trimming Solids
Continue with rounding the corners of the rectangle with the Fillet operation:
fil1 = geom2.feature.create('fil1','Fillet');
fil1.selection('point').set('dif1', [1 2 7 8]);
fil1.set('radius','0.5');
Run the sequence again:
geom2.run;
The geometry sequence is updated with rounded corners. To view the result, enter:
mphgeom(model,'geom2');
Code for use with MATLAB®
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
geom2 = comp1.geom.create('geom2',2);
sq1 = geom2.feature.create('sq1','Square');
sq1.set('size',2);
sq1.set('base','center');
c1 = geom2.feature.create('c1','Circle');
c1.set('r',0.5);
c1.set('pos',[0 0]);
co1 = geom2.feature.create('co1','Compose');
co1.selection('input').set({'c1' 'sq1'});
co1.set('formula','sq1-c1');
co1.active(false)
dif1 = geom2.feature.create('dif1','Difference');
dif1.selection('input').set({'sq1'});
dif1.selection('input2').set({'c1'});
geom2.run;
mphgeom(model,'geom2');
fil1 = geom2.feature.create('fil1','Fillet');
fil1.selection('point').set('dif1', [1 2 7 8]);
fil1.set('radius','0.5');
geom2.run;
mphgeom(model,'geom2');
Creating a 2D Geometry Using Boundary Modeling
Use the following commands to create six open curve segments that together form a closed curve:
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
g1 = comp1.geom.create('g1',2);
w=1/sqrt(2);
c1 = g1.feature.create('c1','BezierPolygon');
c1.set('type','open');
c1.set('degree',2);
c1.set('p',[-0.5 -1 -1;-0.5 -0.5 0]);
c1.set('w',[1 w 1]);
c2 = g1.feature.create('c2','BezierPolygon');
c2.set('type','open');
c2.set('degree',2);
c2.set('p',[-1 -1 -0.5;0 0.5 0.5]);
c2.set('w',[1 w 1]);
c3 = g1.feature.create('c3','BezierPolygon');
c3.set('type','open');
c3.set('degree',1);
c3.set('p',[-0.5 0.5; 0.5 0.5]);
c4 = g1.feature.create('c4','BezierPolygon');
c4.set('type','open');
c4.set('degree',2);
c4.set('p',[0.5 1 1; 0.5 0.5 0]);
c4.set('w',[1 w 1]);
c5 = g1.feature.create('c5','BezierPolygon');
c5.set('type','open');
c5.set('degree',2);
c5.set('p',[1 1 0.5; 0 -0.5 -0.5]);
c5.set('w',[1 w 1]);
c6 = g1.feature.create('c6','BezierPolygon');
c6.set('type','open');
c6.set('degree',1);
c6.set('p',[0.5 -0.5; -0.5 -0.5]);
The objects c1, c2, c3, c4, c5, and c6 are all curve2 objects. The vector [1 w 1] specifies the weights for a rational Bézier curve that is equivalent to a quarter-circle arc. The weights can be adjusted to create elliptical or circular arcs.
Convert the curve segments to a solid with the following conversion command:
csol1 = g1.feature.create('csol1','ConvertToSolid');
csol1.selection('input').set({'c1' 'c2' 'c3' 'c4' 'c5' 'c6'});
Then issue a final run command:
g1.run;
mphgeom(model,'g1');
Code for use with MATLAB®
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
g1 = comp1.geom.create('g1',2);
w=1/sqrt(2);
c1 = g1.feature.create('c1','BezierPolygon');
c1.set('type','open');
c1.set('degree',2);
c1.set('p',[-0.5 -1 -1;-0.5 -0.5 0]);
c1.set('w',[1 w 1]);
c2 = g1.feature.create('c2','BezierPolygon');
c2.set('type','open');
c2.set('degree',2);
c2.set('p',[-1 -1 -0.5;0 0.5 0.5]);
c2.set('w',[1 w 1]);
c3 = g1.feature.create('c3','BezierPolygon');
c3.set('type','open');
c3.set('degree',1);
c3.set('p',[-0.5 0.5; 0.5 0.5]);
c4 = g1.feature.create('c4','BezierPolygon');
c4.set('type','open');
c4.set('degree',2);
c4.set('p',[0.5 1 1; 0.5 0.5 0]);
c4.set('w',[1 w 1]);
c5 = g1.feature.create('c5','BezierPolygon');
c5.set('type','open');
c5.set('degree',2);
c5.set('p',[1 1 0.5; 0 -0.5 -0.5]);
c5.set('w',[1 w 1]);
c6 = g1.feature.create('c6','BezierPolygon');
c6.set('type','open');
c6.set('degree',1);
c6.set('p',[0.5 -0.5; -0.5 -0.5]);
csol1 = g1.feature.create('csol1','ConvertToSolid');
csol1.selection('input').set({'c1' 'c2' 'c3' 'c4' 'c5' 'c6'});
g1.run;
mphgeom(model,'g1');
Creating a 3D Geometry Using Solid Modeling
This section shows how to create 3D solids using work planes and Boolean operations.
Create a 3D geometry with an xy work plane at = 0:
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
 
geom1 = comp1.geom.create('geom1', 3);
 
wp1 = geom1.feature.create('wp1', 'WorkPlane');
wp1.set('planetype', 'quick');
wp1.set('quickplane', 'xy');
Add a rectangle to the work plane, then add fillet to its corners:
r1 = wp1.geom.feature.create('r1', 'Rectangle');
r1.set('size',[1 2]);
 
geom1.run;
 
fil1 = wp1.geom.feature.create('fil1', 'Fillet');
fil1.selection('point').set('r1', [1 2 3 4]);
fil1.set('radius', '0.125');
 
geom1.runCurrent;
 
ext1 = geom1.feature.create('ext1', 'Extrude');
ext1.set('distance', '0.1');
Add another yz work plane, at = 0.5:
wp2 = geom1.feature.create('wp2', 'WorkPlane');
wp2.set('planetype', 'quick');
wp2.set('quickplane', 'yz');
wp2.set('quickx', '0.5');
 
b1 = wp2.geom.feature.create('b1', 'BezierPolygon');
b1.set('type', 'open');
b1.set('degree', [1 1 1 1]);
b1.set('p', {'0.75','1','1','0.8','0.75';'0.1','0.1','0.05','0.05','0.1'});
b1.set('w', {'1','1','1','1','1','1','1','1'});
 
wp2.geom.feature.create('csol1', 'ConvertToSolid');
wp2.geom.feature('csol1').selection('input').set({'b1'});
Revolve the triangle from the yz work plane:
rev1 = geom1.feature.create('rev1', 'Revolve');
rev1.selection('input').set({'wp2'});
rev1.setIndex('pos', '1', 0);
Add the difference operation that computes the final 3D geometry:
dif1 = geom1.feature.create('dif1', 'Difference');
dif1.selection('input').set({'ext1'});
dif1.selection('input2').set({'rev1'});
To run the sequence, enter:
geom1.run;
To view the geometry enter:
mphgeom(model);
Code for use with MATLAB®
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1',true);
geom1 = comp1.geom.create('geom1', 3);
wp1 = geom1.feature.create('wp1', 'WorkPlane');
wp1.set('planetype', 'quick');
wp1.set('quickplane', 'xy');
r1 = wp1.geom.feature.create('r1', 'Rectangle');
r1.set('size',[1 2]);
geom1.run
fil1 = wp1.geom.feature.create('fil1', 'Fillet');
fil1.selection('point').set('r1', [1 2 3 4]);
fil1.set('radius', '0.125');
geom1.runCurrent;
ext1 = geom1.feature.create('ext1', 'Extrude');
ext1.set('distance', '0.1');
wp2 = geom1.feature.create('wp2', 'WorkPlane');
wp2.set('planetype', 'quick');
wp2.set('quickplane', 'yz');
wp2.set('quickx', '0.5');
b1 = wp2.geom.feature.create('b1', 'BezierPolygon');
b1.set('type', 'open');
b1.set('degree', [1 1 1 1]);
b1.set('p', {'0.75','1','1','0.8','0.75';'0.1','0.1','0.05','0.05','0.1'});
b1.set('w', {'1','1','1','1','1','1','1','1'});
wp2.geom.feature.create('csol1', 'ConvertToSolid');
wp2.geom.feature('csol1').selection('input').set({'b1'});
rev1 = geom1.feature.create('rev1', 'Revolve');
rev1.selection('input').set({'wp2'});
rev1.setIndex('pos', '1', 0);
dif1 = geom1.feature.create('dif1', 'Difference');
dif1.selection('input').set({'ext1'});
dif1.selection('input2').set({'rev1'});
geom1.run;
mphgeom(model);