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.

Geometry construction

Flavison de Almada Vieira

Please login with a confirmed email address before reporting spam

Hi!

I'm trying to solve a geometry problem for my model using Matlab Livelink Comsol.
There is a "loop" using "for" to create multiples lines (BezierPolygon), but the program returns
just the last line I have created. Here is the code inside the loop:

model.param.set('a',j);
model.param.set('b',iv);
model.geom('geom1').feature.create(model.param().descr('nome'), 'BezierPolygon');
model.geom('geom1').feature(model.param().descr('nome')).set('p', {'(a-1)*0.001' '(a-1)*0.001'; 'b*0.001' '(b-1)*0.001'});

I suppose that the program is creating just the last line because all lines are define by 'a' and 'b'. So,
'a' and 'b' are changing according to j' and 'iv' (variables from matlab) in each single loop and, in the finalized geometry, all lines will have the same values for the coordinates.

So, my question is: there is a way to creating lines with evaluated coordinates? I mean making Comsol
understands that this line of code:

model.geom('geom1').feature(model.param().descr('nome')).set('p', {'(a-1)*0.001' '(a-1)*0.001'; 'b*0.001' '(b-1)*0.001'});

Should be read, for example making a = 2 and b = 2:

model.geom('geom1').feature(model.param().descr('nome')).set('p', {'(2-1)*0.001' '(2-1)*0.001'; '2*0.001' '(2-1)*0.001'});

Best regards, Flavi.

1 Reply Last Post 11.06.2015, 13:16 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 11.06.2015, 13:16 GMT-4
Flavison,

I'm also interested in this situation for automating the construction of geometries using a 'for'-loop in MATLAB. I'd like to create a periodic structure using Bezier Polygon just by looping through a single variable or index. Something to this affect:

DC = 0.85;
L = 2.0e-6;
imax = 5;

for i = 1:imax;
model.param.set('m', i);
tag = model.geom('geom1').feature().uniquetag('b');
model.geom('geom1').create(tag, 'BezierPolygon');
model.geom('geom1').feature(tag).set('degree', {'1' '1' '1'});
model.geom('geom1').feature(tag).set('p', {'0' 't' 't' '0'; 'm*L' 'm*L' 'm*L + DC*L' 'm*L + DC*L'});
model.geom('geom1').feature(tag).set('w', {'1' '1' '1' '1' '1' '1'});
mphgeom(model, 'geom1')
pause(0.3)
tag
% update command??
end

As you mentioned, it doesn't seem to be saving each iteration, but almost overwriting the previous geometric component with the next value of the index. Maybe there is a command to either keep each component in a "geometric array" or update the model after every iteration. Let me know what you think.

Thanks,
Ethan
Flavison, I'm also interested in this situation for automating the construction of geometries using a 'for'-loop in MATLAB. I'd like to create a periodic structure using Bezier Polygon just by looping through a single variable or index. Something to this affect: DC = 0.85; L = 2.0e-6; imax = 5; for i = 1:imax; model.param.set('m', i); tag = model.geom('geom1').feature().uniquetag('b'); model.geom('geom1').create(tag, 'BezierPolygon'); model.geom('geom1').feature(tag).set('degree', {'1' '1' '1'}); model.geom('geom1').feature(tag).set('p', {'0' 't' 't' '0'; 'm*L' 'm*L' 'm*L + DC*L' 'm*L + DC*L'}); model.geom('geom1').feature(tag).set('w', {'1' '1' '1' '1' '1' '1'}); mphgeom(model, 'geom1') pause(0.3) tag % update command?? end As you mentioned, it doesn't seem to be saving each iteration, but almost overwriting the previous geometric component with the next value of the index. Maybe there is a command to either keep each component in a "geometric array" or update the model after every iteration. Let me know what you think. Thanks, Ethan

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.