conditional parameter

David David Betancourth

Please login with a confirmed email address before reporting spam

Hello COMSOL Community,

I am working on a COMSOL model that involves multiple geometric components, and I want to create a flexible simulation where users can choose which components to include or exclude before running the model. My goal is to allow users to control these options via the Application Builder interface.

Specifically, I have three geometric components in my model, and I want users to have the option to:

Include all components. Include any combination of the components. Exclude all components except the ones they select. I would like detailed guidance on how to:

Set up conditional statements for geometric components in the model. Link user input from the Application Builder to control these components. Ensure the model updates correctly based on these inputs. What are the best practices for defining these conditional parameters and incorporating them into both the model and the Application Builder interface?

Any detailed advice or examples would be greatly appreciated!

Thank you in advance for your help.

David


2 Replies Last Post May 24, 2024, 4:39 p.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 6 months ago May 23, 2024, 9:52 a.m. EDT
Updated: 6 months ago May 23, 2024, 9:53 a.m. EDT

You can use programmatic "if" statements in the geometry tree to enumerate a parameter and determine if a geometric entity gets created.

So, for simplicaity, you could have a cylinder and a cube as possible geometric entities to model.

In your parameters, you can have a parameter called "cylinder" and a parameter called "cube".

Your "if" settings window would have a statement like cylinder==1, to determine (parametrically) if your cylider is created or not. See attached simple example.

You can extend this to an Application by having the user select which geometric entities they wish to include.

You can use programmatic "if" statements in the geometry tree to enumerate a parameter and determine if a geometric entity gets created. So, for simplicaity, you could have a cylinder and a cube as possible geometric entities to model. In your parameters, you can have a parameter called "cylinder" and a parameter called "cube". Your "if" settings window would have a statement like cylinder==1, to determine (parametrically) if your cylider is created or not. See attached simple example. You can extend this to an Application by having the user select which geometric entities they wish to include.


Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 months ago May 24, 2024, 4:39 p.m. EDT
Updated: 5 months ago May 24, 2024, 5:39 p.m. EDT

Hello David,

You could use if statements, like Mark mentioned above. An example can be found here.

Another approach is to use the concept of selections, along the lines of what is done in this blog post.

If it was me, I would probably take the easy way out and go a third route:

With only 3 components, there are "only" 8 possible cases (empty set, A, B, C, A+B, B+C, A+C, A+B+C) to deal with. I would create 8 separate Components, each dealing with one of those cases. I'll grant you that it's not an elegant solution, but it's going to be easy to set up, debug and maintain over time. Otherwise, depending on the specifics of your problem, you are going to have to deal with changing numbers of boundaries, changing numbers of domains/overlaps between objects, even possibly changing physics, etc based on which case you're in, and that may get messy.

Best,

Jeff

-------------------
Jeff Hiller
Hello David, You could use if statements, like Mark mentioned above. An example can be found [here](https://www.comsol.com/blogs/why-do-tennis-rackets-tumble-the-dzhanibekov-effect-explained). Another approach is to use the concept of selections, along the lines of what is done in [this blog post](https://www.comsol.com/blogs/how-to-create-an-app-with-cad-import-and-selections). If it was me, I would probably take the easy way out and go a third route: With only 3 components, there are "only" 8 possible cases (empty set, A, B, C, A+B, B+C, A+C, A+B+C) to deal with. I would create 8 separate Components, each dealing with one of those cases. I'll grant you that it's not an elegant solution, but it's going to be easy to set up, debug and maintain over time. Otherwise, depending on the specifics of your problem, you are going to have to deal with changing numbers of boundaries, changing numbers of domains/overlaps between objects, even possibly changing physics, etc based on which case you're in, and that may get messy. Best, Jeff

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.