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.
If else condition syntax in comsol multiphysics 4.2
Posted 09.11.2011, 01:33 GMT-5 Version 4.4, Version 5.1 14 Replies
Please login with a confirmed email address before reporting spam
well i would like to impliment a function which is having different values at different ranges. Can any one provide me syntax of if else condition in comsol. Even any example of Implimentation can serve my purpose :)....
Krishna Chaitanya S
Please login with a confirmed email address before reporting spam
For a simple rule of 2 variables x and y: if x<a then y=c1 else y=c2
In Comsol: y= if(x<a,c1,c2)
Furthermore, i don't know how to link 2 rules with 3 variables x,y,z:
if x<a then y=c1
else if z<b then y=c2
else y=c3
I will appreciate if anyone know the solution.
Best regards,
Dinh An
Please login with a confirmed email address before reporting spam
you can also try something like for a < b
c1*(x<a)+c2*(x>=a)*(x<b)+c3*(x>=b)
but you should perhaps consider step functions to smoothen the jumps, as your solver might get caught in such Dirac step functions
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
Thanks for your response. I have one more question if you can help me.
c1*(x<a)+c2*(x>=a)*(x<b)+c3*(x>=b)
If we use a step function in this case, and if i change a little bit this expression such as:
c1*(x<a)+c2*(x>=a)*(y<b)+c3*(y>=b) so y is the second variable vs time.
I know the step function can separately solve : c1*(x<a)+c2*(x>=a) and c2*(y<b)+c3*(y>=b)
If i would like to link these 2 steps in one expression at the same time, do you think this is possible ?
Thanks once more time
Dinh An
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
Furthermore, i don't know how to link 2 rules with 3 variables x,y,z:
if x<a then y=c1
else if z<b then y=c2
else y=c3
Hi,
The if operator can be nested, hence y=if(x<a,c1,if(z<b,c2,c3)) is a valid expression.
Regards,
Andrzej
Please login with a confirmed email address before reporting spam
Do you have any idea if we use step1() function to represent this conditions ?
Because as said in the user's guide :"Use smoothing to improve the behavior of the model by avoiding discontinuities that are difficult to handle numerically. "
Regards,
Dinh An
Please login with a confirmed email address before reporting spam
y=((c3-c2)*step1(z-b)+c2-c1)*step2(x-a)+c1.
Parameters of both step functions: Location 0, From 0 To 1. Size of transition zone can be different.
Regards,
Andrzej
Please login with a confirmed email address before reporting spam
I really appreciate your response. It works well. I can now add more conditions in this serie.
Many thanks to you and thanks to the Comsol forum.
Best regards,
Dinh An
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
How if I want to make these logic with if function?:
Q1: if t<4 [d] then Q=0.5, else Q1=0
Q2: if 4[d]<= t <8[d] then Q2=0.5, else Q2=0
Q3: if 8[d]<= t <12[d] then Q3=0.5, else Q3 = 0
Q4: if t>= 12[d] then Q4 = 0.5, else Q4 = 0
Thank for your help
Please login with a confirmed email address before reporting spam
Hi,
How if I want to make these logic with if function?:
Q1: if t<4 [d] then Q=0.5, else Q1=0
Q2: if 4[d]<= t <8[d] then Q2=0.5, else Q2=0
Q3: if 8[d]<= t <12[d] then Q3=0.5, else Q3 = 0
Q4: if t>= 12[d] then Q4 = 0.5, else Q4 = 0
Thank for your help
Just define them separately in the variable section.
Q1 : if( t < 4 [d], 0.5 , 0)
and so on.
Please login with a confirmed email address before reporting spam
Just define them separately in the variable section.
Q1 : if( t < 4 [d], 0.5 , 0)
and so on.
Thank you for your response.
I tried that way, but the singularity error appeared.
Then I used piecewise function and it worked.
Please login with a confirmed email address before reporting spam
If this question is about applying a loading that changes instantaneously in time, then you may also be interested in reviewing these articles:
www.comsol.com/blogs/modeling-a-periodic-heat-load/
www.comsol.com/blogs/implementing-a-thermostat-with-the-events-interface/
Please login with a confirmed email address before reporting spam
Hello,
If this question is about applying a loading that changes instantaneously in time, then you may also be interested in reviewing these articles:
www.comsol.com/blogs/modeling-a-periodic-heat-load/
www.comsol.com/blogs/implementing-a-thermostat-with-the-events-interface/
Hello Walter, thank you for your information.
I found it useful to enhance my current solution.
I have another question.
I'm modeling a 2D Heat Transfer in Porous Media module (time-dependent).
There's a boundary (outflow boundary) which activated / deactivated by time function.
For instance:
Outflow boundary active at time 0-4 day
Outflow boundary not active at time 4-8 day.
However, for this outflow boundary, there is no text-field where I can state a function.
So this outflow boundary is like a "non modifiable" boundary.
Could you please kindly suggest me how to deal with this problem?
Thank you
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.
Suggested Content
- BLOG COMSOL Multiphysics v4.2 New Features Video
- KNOWLEDGE BASE My Flux Calculation Seems Wrong
- FORUM multiphysics coupling
- FORUM Temperature multiphysics field analysis
- KNOWLEDGE BASE Avoiding Negative Concentrations