Lars Gregersen
                                                                                                                                                    COMSOL Employee
                                                         
                            
                                                                                                                                                
                         
                                                
    
        Please login with a confirmed email address before reporting spam
     
    
 
                                                Posted:
                            
                                9 years ago                            
                            
                                2016/06/28 5:21 GMT-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:
                            
                                9 years ago                            
                            
                                2016/06/28 9:40 GMT-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:
                            
                                9 years ago                            
                            
                                2016/07/05 5:16 GMT-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:
                            
                                9 years ago                            
                            
                                2016/07/07 5:28 GMT-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:
                            
                                9 years ago                            
                            
                                2016/07/08 5:22 GMT-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!