How to create non-uniform geometry array in COMSOL

Please login with a confirmed email address before reporting spam

I want to create an array of ellipses ( i.e. a Nanobeam Cavity ) with each of them having major and minor radii and spacing defined by a function. I already tried Comsol with MATLAB, but that creates the ellipses but not parameterized, i want the parameters to be an comsol array which i can change to get the parameters of each ellipse in the and they will also change accordingly. For reference I have attached my scripts of MATLAB, but these dont parameterize the geometry instead each of the geometry is just separate entity and I cannot optimize them. My idea is to use a COMSOL vector as the the parameter for radii and lattice constant of the photonic crystal cavity and use the vectors indexing as a parameters for creating the array of geometries, but COMSOL only allow diplacement to be a vector not the geomtery parameters like radius and there is no for loop in COMSOL geomtery creation to get the indexing of vector and generating geometry array. Even using MATLAB I dont get how all the geometry of the array can be parameterize with just one vector.



3 Replies Last Post 02.08.2025, 15:00 MESZ
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 days ago 31.07.2025, 14:42 MESZ
Updated: 2 days ago 31.07.2025, 14:43 MESZ

Hi Aakif

Geometries have to be defined using numerical values or parameters/function that are constants. Comsol's parameters are scalar so unless you create as many parameters as you have ellipses you cannot do what you are describing.

If the number of ellipses remains constant and you just want to adjust their parameters then I suggest you do something like this:

1) Create your geometry using dummy parameters with the correct number of ellipses. 2) Create a matrix, Evalues, with the values you want to use for the model 3) Create a function along these lines (untested)

function v=ellipsesmodel(model, Evalues)

for i=1:size(Evalues,1)
    tag = ['ellipse_px' num2str(i)];
    ellipses = model.geom('geom3').feature('wp1').geom.feature(tag)
    ellipses.set('pos', Evalues(i,1:2) )
    ellipses.set('semiaxes', Evalues(i,3:4) )
end

% solve the model
% extract data from the model and put them in the variable v, that is returned from this function
-------------------
Lars Gregersen
Comsol Denmark
Hi Aakif Geometries have to be defined using numerical values or parameters/function that are constants. Comsol's parameters are scalar so unless you create as many parameters as you have ellipses you cannot do what you are describing. If the number of ellipses remains constant and you just want to adjust their parameters then I suggest you do something like this: 1) Create your geometry using dummy parameters with the correct number of ellipses. 2) Create a matrix, Evalues, with the values you want to use for the model 3) Create a function along these lines (untested) function v=ellipsesmodel(model, Evalues) for i=1:size(Evalues,1) tag = ['ellipse_px' num2str(i)]; ellipses = model.geom('geom3').feature('wp1').geom.feature(tag) ellipses.set('pos', Evalues(i,1:2) ) ellipses.set('semiaxes', Evalues(i,3:4) ) end % solve the model % extract data from the model and put them in the variable v, that is returned from this function

Please login with a confirmed email address before reporting spam

Posted: 6 hours ago 02.08.2025, 11:19 MESZ

Yeah I already thought about this solution, but then the geometry optimization will be a pain I have to keep switching back and forth between COMSOL and MATLAB functions. I wanted to use the geomtery optimzation inside COMSOL. What you suggested I have already tried and while it works for geomtery creation but optimization of geometry in COMSOL I cannot think of any solution for that.

Yeah I already thought about this solution, but then the geometry optimization will be a pain I have to keep switching back and forth between COMSOL and MATLAB functions. I wanted to use the geomtery optimzation inside COMSOL. What you suggested I have already tried and while it works for geomtery creation but optimization of geometry in COMSOL I cannot think of any solution for that.

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 2 hours ago 02.08.2025, 15:00 MESZ

You can consider to do this in a JAVA method inside COMSOL. This allows you to set up a convenient interface to input the vector elements.

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
You can consider to do this in a JAVA method inside COMSOL. This allows you to set up a convenient interface to input the vector elements.

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.