Lars Gregersen
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
6 months ago
2025/07/31 8:42 GMT-4
Updated:
6 months ago
2025/07/31 8:43 GMT-4
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 months ago
2025/08/02 5:19 GMT-4
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:
6 months ago
2025/08/02 9:00 GMT-4
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.
Please login with a confirmed email address before reporting spam
Posted:
6 months ago
2025/08/02 14:26 GMT-4
I dont think that is possible its essentially the same solution as the one with MATLAB, even in JAVA if I create the vector element they cannot be used as parameters in the geometry of COMSOL model, its still going to JAVA and COMSOL model simulation and back and forth. I know the JAVA model builder is inside the COMSOL package but its not optimizing the COMSOL geometry using COMSOL optimization by changing the vectors as parameters for the geometry.
I dont think that is possible its essentially the same solution as the one with MATLAB, even in JAVA if I create the vector element they cannot be used as parameters in the geometry of COMSOL model, its still going to JAVA and COMSOL model simulation and back and forth. I know the JAVA model builder is inside the COMSOL package but its not optimizing the COMSOL geometry using COMSOL optimization by changing the vectors as parameters for the geometry.