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.

LiveLink geometry layout design

Please login with a confirmed email address before reporting spam

Hi,

I am using Matlab LiveLink and am trying to create a layout for optical reflectors. My Problem is the following: I am looking at about 2000 reflectors and want them to form a union so I don't have to click on every single one and set their properties seperatly every time I generate a new layout.
I have prepared a Codefragment that demonstrates my Problem:

import com.comsol.model.*;
import com.comsol.model.util.*;

model = ModelUtil.create('Model');
geom1 = model.geom.create('geom1',3);

wp1 = geom1.feature.create('wp1','WorkPlane');
wp1.set('planetype','quick');
wp1.set('quickplane','xy');

refl_union = wp1.geom.feature.create('refl_union', 'Union');

for i=1:10

refl_geom_name{i} = wp1.geom.feature.create(['r' num2str(i)], 'BezierPolygon');
refl_geom_name{i}.set('type', 'closed');
refl_geom_name{i}.set('p', [i i+0.5 i+0.5 i ; 0 0 2 2]);
wp1.geom.feature.create(['refl_csol' num2str(i)],'ConvertToSolid');
wp1.geom.feature(['refl_csol' num2str(i)]).selection('input').set(['r' num2str(i)]);

refl_union.selection('input').object('geom1');
refl_union.selection('input').set(['refl_csol' num2str(i)]);

end

ext1 = geom1.feature.create('ext1','Extrude');
ext1.selection('input').set({'wp1'});
ext1.set('distance',5);

geom1.run;
mphgeom(model,'geom1');

My Intention was to create one geometrical Object (refl_union) and one by one add the objects to it during each itteration of the for loop. However this does not seem to work. The Code works fine till I try to form a Union, what am I missing?

Thanks
Mark

5 Replies Last Post 8 juil. 2016, 05:22 UTC−4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 28 juin 2016, 05:21 UTC−4
Hi

There are many ways to solve your problem

1) Create your geometry without the union. Save the resulting model using mphsave to an MPH-file. Load the MPH-file into the Comsol Desktop. Make the union there. Save the model as an M-file and then you can see what commands you need in order to make the union. I.e. you create the union after you have extruded all your components.

...but I don't think you have to make the union at all

2) Look a the Extrude node (using Comsol Desktop). It has a section for "Selections of resulting entities". If you place a checkmark here you can use the selection name when settings things up later. A list of entities is much easier to handle than large, complicated geometries.

More ideas:
- Use the array transformation for making copies of your geometries in the work plane (if that makes sense for your reflectors).
- Use the selections tools on the Component->Definitions->Selections menu to create more complicated sets of selections if you need so


--
Lars Gregersen
Comsol Denmark
Hi There are many ways to solve your problem 1) Create your geometry without the union. Save the resulting model using mphsave to an MPH-file. Load the MPH-file into the Comsol Desktop. Make the union there. Save the model as an M-file and then you can see what commands you need in order to make the union. I.e. you create the union after you have extruded all your components. ...but I don't think you have to make the union at all 2) Look a the Extrude node (using Comsol Desktop). It has a section for "Selections of resulting entities". If you place a checkmark here you can use the selection name when settings things up later. A list of entities is much easier to handle than large, complicated geometries. More ideas: - Use the array transformation for making copies of your geometries in the work plane (if that makes sense for your reflectors). - Use the selections tools on the Component->Definitions->Selections menu to create more complicated sets of selections if you need so -- Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 28 juin 2016, 09:40 UTC−4
Thank you very much for your help! I have solved my problem thanks to you and your tipps helped me with some other issues as well.

Regards
Mark
Thank you very much for your help! I have solved my problem thanks to you and your tipps helped me with some other issues as well. Regards Mark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 5 juil. 2016, 05:16 UTC−4
Hi,

I have finished my program succesfully however I have stumbled upon another problem. I have programmed my layout to be created in 2D and 3D. In 3D I have done this by extrusion, since all extruded geometrys contribute to a list. In 2D this is not possible so I used the function 'contributeto'.
However this seems to be a very slow process since my 3D layout takes about 1,5 hours (including geom.run) to create and my 2D Layout takes about 9 hours. I do not understand this since 3D should take longer to create.
Here is an examplecode:

import com.comsol.model.*;
import com.comsol.model.util.*;

model = ModelUtil.create('Model');
geom1 = model.geom.create('geom1',2);

tic

model.geom('geom1').selection.create('csel1', 'CumulativeSelection');
model.geom('geom1').selection('csel1').label('Waveguide_union');

for i=1:300

refl_geom_name{i} = geom1.feature.create(['r' num2str(i)], 'BezierPolygon');
refl_geom_name{i}.set('type', 'closed');
refl_geom_name{i}.set('p', [i i+0.5 i+0.5 i ; 0 0 2 2]);
geom1.feature.create(['refl_csol' num2str(i)],'ConvertToSolid');
geom1.feature(['refl_csol' num2str(i)]).selection('input').set(['r' num2str(i)]);
%model.geom('geom1').feature(['r' num2str(i)]).set('contributeto', 'csel1');

end


toc

geom1.run;
figure;
mphgeom(model,'geom1');

If I run this once with and without the commented line in the for loop it takes twice as long with 'contributeto'! And this loop itterates to 300, whilst my programm goes to about 2000. Is there a faster way to solve this?

Regards, Mark
Hi, I have finished my program succesfully however I have stumbled upon another problem. I have programmed my layout to be created in 2D and 3D. In 3D I have done this by extrusion, since all extruded geometrys contribute to a list. In 2D this is not possible so I used the function 'contributeto'. However this seems to be a very slow process since my 3D layout takes about 1,5 hours (including geom.run) to create and my 2D Layout takes about 9 hours. I do not understand this since 3D should take longer to create. Here is an examplecode: import com.comsol.model.*; import com.comsol.model.util.*; model = ModelUtil.create('Model'); geom1 = model.geom.create('geom1',2); tic model.geom('geom1').selection.create('csel1', 'CumulativeSelection'); model.geom('geom1').selection('csel1').label('Waveguide_union'); for i=1:300 refl_geom_name{i} = geom1.feature.create(['r' num2str(i)], 'BezierPolygon'); refl_geom_name{i}.set('type', 'closed'); refl_geom_name{i}.set('p', [i i+0.5 i+0.5 i ; 0 0 2 2]); geom1.feature.create(['refl_csol' num2str(i)],'ConvertToSolid'); geom1.feature(['refl_csol' num2str(i)]).selection('input').set(['r' num2str(i)]); %model.geom('geom1').feature(['r' num2str(i)]).set('contributeto', 'csel1'); end toc geom1.run; figure; mphgeom(model,'geom1'); If I run this once with and without the commented line in the for loop it takes twice as long with 'contributeto'! And this loop itterates to 300, whilst my programm goes to about 2000. Is there a faster way to solve this? Regards, Mark

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 7 juil. 2016, 05:28 UTC−4
Hi Mark

In your case it seems as if the Cumulative Selections take an unreasonable time to create.

You are better off using a union (and adding a selection to that). The following code takes 43 seconds to run using Comsol 5.2a:

import com.comsol.model.*;
import com.comsol.model.util.*;

model = ModelUtil.create('Model');
model.hist.disable
geom1 = model.geom.create('geom1',2);

N = 2000
tic
rtags = cell(N,1);
for i=1:N
rtags{i} = ['r' num2str(i)];
gf = geom1.feature.create(rtags{i}, 'BezierPolygon');
gf.set('type', 'closed');
gf.set('p', [i i+0.5 i+0.5 i; 0 0 2 2]);
gf.set('type', 'solid');
end

model.geom('geom1').selection.create('csel1', 'CumulativeSelection');
model.geom('geom1').selection('csel1').label('Waveguide_union');
model.geom('geom1').create('uni1', 'Union');
model.geom('geom1').feature('uni1').selection('input').set(rtags);
model.geom('geom1').feature('uni1').set('contributeto', 'csel1');

geom1.run;

toc

mphgeom(model,'geom1')


--
Lars Gregersen
Comsol Denmark
Hi Mark In your case it seems as if the Cumulative Selections take an unreasonable time to create. You are better off using a union (and adding a selection to that). The following code takes 43 seconds to run using Comsol 5.2a: import com.comsol.model.*; import com.comsol.model.util.*; model = ModelUtil.create('Model'); model.hist.disable geom1 = model.geom.create('geom1',2); N = 2000 tic rtags = cell(N,1); for i=1:N rtags{i} = ['r' num2str(i)]; gf = geom1.feature.create(rtags{i}, 'BezierPolygon'); gf.set('type', 'closed'); gf.set('p', [i i+0.5 i+0.5 i; 0 0 2 2]); gf.set('type', 'solid'); end model.geom('geom1').selection.create('csel1', 'CumulativeSelection'); model.geom('geom1').selection('csel1').label('Waveguide_union'); model.geom('geom1').create('uni1', 'Union'); model.geom('geom1').feature('uni1').selection('input').set(rtags); model.geom('geom1').feature('uni1').set('contributeto', 'csel1'); geom1.run; toc mphgeom(model,'geom1') -- Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 8 juil. 2016, 05:22 UTC−4
Thank you once again for your help! Your solution works like a charm. My revised programm ran for about 1,5 hours but with your solution it now takes about 40 seconds!

Thank you once again for your help! Your solution works like a charm. My revised programm ran for about 1,5 hours but with your solution it now takes about 40 seconds!

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.