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.



1 Reply Last Post 31 lug 2025, 14:42 CEST
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 21 hours ago 31 lug 2025, 14:42 CEST
Updated: 21 hours ago 31 lug 2025, 14:43 CEST

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

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.