Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Define Length as a Variable?

Please login with a confirmed email address before reporting spam

Hello,

Is there a way to define an object's length as a variable in COMSOL so when I change the value of the variable, the object automatically changes lengths?

I have noticed that making the length a "constant" does not work. When I change the value of the constant, the object does not automatically change lengths. (It is necessary to re-enter the constant in the objects' dimensions.)

It would be very helpful if I could define an object's dimensions using variables when I have many instances of the same object scattered throughout the design.

If it is relevant, I am using COMSOL 3.5a.

Thank you,
Kevin

13 Replies Last Post Feb 3, 2011, 5:27 a.m. EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2011, 2:09 a.m. EST

Hello,

Is there a way to define an object's length as a variable in COMSOL so when I change the value of the variable, the object automatically changes lengths?

I have noticed that making the length a "constant" does not work. When I change the value of the constant, the object does not automatically change lengths. (It is necessary to re-enter the constant in the objects' dimensions.)

It would be very helpful if I could define an object's dimensions using variables when I have many instances of the same object scattered throughout the design.

If it is relevant, I am using COMSOL 3.5a.

Thank you,
Kevin


I don't think it is possible in Comsol 3.5a, but it is in Comsol 4. The workaround is to use matlab and comsol, and run all the code in matlab.


--
Comsol 4.1
Ubuntu 10.04.1
[QUOTE] Hello, Is there a way to define an object's length as a variable in COMSOL so when I change the value of the variable, the object automatically changes lengths? I have noticed that making the length a "constant" does not work. When I change the value of the constant, the object does not automatically change lengths. (It is necessary to re-enter the constant in the objects' dimensions.) It would be very helpful if I could define an object's dimensions using variables when I have many instances of the same object scattered throughout the design. If it is relevant, I am using COMSOL 3.5a. Thank you, Kevin [/QUOTE] I don't think it is possible in Comsol 3.5a, but it is in Comsol 4. The workaround is to use matlab and comsol, and run all the code in matlab. -- Comsol 4.1 Ubuntu 10.04.1

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2011, 4:42 a.m. EST
Hi

if you are talking about geometrial objects, you cannot give them a variable name in 3.5a, (in v4 yes).
But you can give them a constant name.
However, in contrary to 4.1, there is NO "big loop around the geometry" in 3.5a. The idea, I believe, was that one used matlab for that.

--
Good luck
Ivar
Hi if you are talking about geometrial objects, you cannot give them a variable name in 3.5a, (in v4 yes). But you can give them a constant name. However, in contrary to 4.1, there is NO "big loop around the geometry" in 3.5a. The idea, I believe, was that one used matlab for that. -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 17, 2011, 3:37 a.m. EST
Hi,

Just to clarify, are you saying that there is a way to define an object's position and dimensions in Matlab and then import them into COMSOL? Is that what you mean?

If so, would you be able to direct me to some documentation of how to do that?

Thanks,
Kevin

Hi, Just to clarify, are you saying that there is a way to define an object's position and dimensions in Matlab and then import them into COMSOL? Is that what you mean? If so, would you be able to direct me to some documentation of how to do that? Thanks, Kevin

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 17, 2011, 7:22 a.m. EST
Hi

I understand you are in v3.5a, if so, you can have COMSOL to save a ".history" file (see the presferences), while programming the GUI, by studying this file and cross checking with the command.pdf you should be able to find out how the commands for geometrical components are set-up (I assume you need the Length in a geometrical object for your model).

Today you can define constants (parameters in v4) and use these in 3.5a for the definition of your geometrical shapes, but not variables.

The thing is that you need to loop around the geometry + mesh + physics to update a geometrical size dependent shape and the normal parametrical sweep is NOT looping arounf the geometry and remesh function

--
Good luck
Ivar
Hi I understand you are in v3.5a, if so, you can have COMSOL to save a ".history" file (see the presferences), while programming the GUI, by studying this file and cross checking with the command.pdf you should be able to find out how the commands for geometrical components are set-up (I assume you need the Length in a geometrical object for your model). Today you can define constants (parameters in v4) and use these in 3.5a for the definition of your geometrical shapes, but not variables. The thing is that you need to loop around the geometry + mesh + physics to update a geometrical size dependent shape and the normal parametrical sweep is NOT looping arounf the geometry and remesh function -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 4:23 a.m. EST
Hi Ivar,

Thanks for your reply. I found the The command.pdf, and it is very helpful and detailed.

However what is a .history file, and how do I save a .history file? Is it a format when exporting a geometry object? I don't see a .history option when I go to File - Export - Geometry Objects to File.

Also is there a way to generate a ".m Matlab" file from a design in the GUI? It would be helpful to see an example ".m Matlab" file for my simple geometry. (I'm not certain if this is what you are talking about with the .history file or not.)

I very much appreciate your continued help with my attempt to learn different aspects of COMSOL.

Thanks again,
Kevin
Hi Ivar, Thanks for your reply. I found the The command.pdf, and it is very helpful and detailed. However what is a .history file, and how do I save a .history file? Is it a format when exporting a geometry object? I don't see a .history option when I go to File - Export - Geometry Objects to File. Also is there a way to generate a ".m Matlab" file from a design in the GUI? It would be helpful to see an example ".m Matlab" file for my simple geometry. (I'm not certain if this is what you are talking about with the .history file or not.) I very much appreciate your continued help with my attempt to learn different aspects of COMSOL. Thanks again, Kevin

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 6:47 a.m. EST
Ok I figured out how to export geometry objects to MATLAB and then import them back into COMSOL. I needed to connect to MATLAB from within COMSOL before I was allowed to do that. :)

However is there a way to specify the boundary conditions in MATLAB for these objects and then import the boundary conditions into COMSOL? My final design is going to have a ton of objects, so it would be nice if I didn't have to click on each line manually in COMSOL to set the boundary conditions.

Thanks,
Kevin

Ok I figured out how to export geometry objects to MATLAB and then import them back into COMSOL. I needed to connect to MATLAB from within COMSOL before I was allowed to do that. :) However is there a way to specify the boundary conditions in MATLAB for these objects and then import the boundary conditions into COMSOL? My final design is going to have a ton of objects, so it would be nice if I didn't have to click on each line manually in COMSOL to set the boundary conditions. Thanks, Kevin

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 7:19 a.m. EST
Hello Kevin,

Me and some other users had the same problem in the past. It is possible to set and solve the complete model in Matlab, without seeing one pixel of the Comsol GUI. There are codes in this forum exists to find the right boundaries of your objects and apply boundary conditions to them. You can check "Numbering of the boundaries in *.m file"

/Onur
Hello Kevin, Me and some other users had the same problem in the past. It is possible to set and solve the complete model in Matlab, without seeing one pixel of the Comsol GUI. There are codes in this forum exists to find the right boundaries of your objects and apply boundary conditions to them. You can check "Numbering of the boundaries in *.m file" /Onur

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 1:45 p.m. EST
Hi Onur,

Thanks for your response. However, to be honest with you, I don't fully understand every aspect of COMSOL, so I would prefer to be able to just import the geometry objects (which I know how to do now) and the boundary conditions from MATLAB rather that specify and solve the entire model in MATLAB.

How to specify the entire model in MATLAB would be arduous and lengthy task to learn. Ideally after I import the geometry objects and boundary conditions from MATLAB, I would then solve the problem in the COMSOL GUI. (There is some surface and contour plots on the GUI I would like to look at for my design to.)

Do you know if it is possible to import the boundary conditions without worrying about specifying and solving the entire model in COMSOL?

Thank you,
Kevin
Hi Onur, Thanks for your response. However, to be honest with you, I don't fully understand every aspect of COMSOL, so I would prefer to be able to just import the geometry objects (which I know how to do now) and the boundary conditions from MATLAB rather that specify and solve the entire model in MATLAB. How to specify the entire model in MATLAB would be arduous and lengthy task to learn. Ideally after I import the geometry objects and boundary conditions from MATLAB, I would then solve the problem in the COMSOL GUI. (There is some surface and contour plots on the GUI I would like to look at for my design to.) Do you know if it is possible to import the boundary conditions without worrying about specifying and solving the entire model in COMSOL? Thank you, Kevin

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 2:12 p.m. EST
You should seriously consider upgrading to 4.1. What you want to do is trivial there.
Jeff
You should seriously consider upgrading to 4.1. What you want to do is trivial there. Jeff

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 20, 2011, 2:32 p.m. EST
Unfortunately my school doesn't have the 4.1 version, so that's not an option. Do you know how I can import boundary conditions from MATLAB to COMSOL using the 3.5a version?

Thanks,
Kevin
Unfortunately my school doesn't have the 4.1 version, so that's not an option. Do you know how I can import boundary conditions from MATLAB to COMSOL using the 3.5a version? Thanks, Kevin

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 2, 2011, 7:26 a.m. EST
Hello!

I've got similar request to Kevin's.
I'm training myself to be professional user of COMSOL (4.1).
The thing I would like to do is to solve a problem (i.e. finding all mode profiles in an optical fibre), sweeping it against a geometrical parameter (i.e. the radius of the fibre's core).
I tried to experiment with defining parameters and variables and it didn't work. However, I'm sure there must be a way to go as it sounds so much like a standard problem.

I would be extremely grateful for any hints.
Kind Regards
Oleg
Hello! I've got similar request to Kevin's. I'm training myself to be professional user of COMSOL (4.1). The thing I would like to do is to solve a problem (i.e. finding all mode profiles in an optical fibre), sweeping it against a geometrical parameter (i.e. the radius of the fibre's core). I tried to experiment with defining parameters and variables and it didn't work. However, I'm sure there must be a way to go as it sounds so much like a standard problem. I would be extremely grateful for any hints. Kind Regards Oleg

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 2, 2011, 9:35 a.m. EST
Hi

in v4 define a parameter as radius = 100[um] or whatever size, use the "radius" to define your circle radius
set up a parametric Sweep solver node, define parameter and gie it a range, then add an eigenfrequency scan (for yu mode analysis) set the required parametrs frequency ... And (normally) off you go that should be it.

You have a few examples of step index fibres in the library

--
Good luck
Ivar
Hi in v4 define a parameter as radius = 100[um] or whatever size, use the "radius" to define your circle radius set up a parametric Sweep solver node, define parameter and gie it a range, then add an eigenfrequency scan (for yu mode analysis) set the required parametrs frequency ... And (normally) off you go that should be it. You have a few examples of step index fibres in the library -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 3, 2011, 5:27 a.m. EST
Dear Ivar,

I think I've succeeded for now. Thank you very much for help!

Kind Regards
Oleg
Dear Ivar, I think I've succeeded for now. Thank you very much for help! Kind Regards Oleg

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.