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.

Question about "if" function

Please login with a confirmed email address before reporting spam

Hello,

I want to add a volume force to NS equation with a special condition.
The volume force is like this: H/Re
Re is reynolds number.
u2 is calculated from convection-diffusion equation and I want to limit the values of u2 like this.

if (u2>=0 or u2<=1) then H=u2
if (u2>1) set it to 1 and then H=u2
if (u2<0) set it to 0 and then H=u2


Would you please help me?
Thanks,
Hooman

4 Replies Last Post 8 mai 2013, 14:19 UTC−4
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 6 mai 2013, 12:02 UTC−4
Hi

I'm not fully sure how to fix that and get the transition to be "smooth", be also aware that the "cell Reynolds numner of COMSOL is not exactly the clasical fluid Reynolds number as the latter depends on a characterisitic length COMSOL cannot gues, so it uses its mesh average size "h"

But if you define a variable Reynolds with your fomula you can make it as a field, and then you can try with Bolean or better some combination of smoothing functions (step, rect ...)

--
Good luck
Ivar
Hi I'm not fully sure how to fix that and get the transition to be "smooth", be also aware that the "cell Reynolds numner of COMSOL is not exactly the clasical fluid Reynolds number as the latter depends on a characterisitic length COMSOL cannot gues, so it uses its mesh average size "h" But if you define a variable Reynolds with your fomula you can make it as a field, and then you can try with Bolean or better some combination of smoothing functions (step, rect ...) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 6 mai 2013, 12:12 UTC−4
Ivar,
Thank you for the answer.
I defined a variable like Re and set to a number. So I guess it is a constant and fixed number.
for the other part I try something like this

I omit "H" variable and just work with u2 and Fr instead of Re.(Fr is a constant number)

(-u2*1/(Fr^2))*(u2>=0 && u2<=1)+(floor(u2)/-(Fr^2))*(u2>1 && u2<2)+((floor(u2)+1)/-(Fr^2))*(u2<0 && u2>=-1)+((floor(u2)-1)/-(Fr^2))*(u2>=2 && u2<3)+((floor(u2)+2)/-(Fr^2))*(u2<-1 && u2>=-2)+((floor(u2)-2)/-(Fr^2))*(u2>=3 && u2<4)+((floor(u2)+3)/-(Fr^2))*(u2<-2 && u2>=-3)+((floor(u2)-3)/-(Fr^2))*(u2>=4 && u2<5)+((floor(u2)+4)/-(Fr^2))*(u2<-3 && u2>=-4)+((floor(u2)-4)/-(Fr^2))*(u2>=5 && u2<6)+((floor(u2)+5)/-(Fr^2))*(u2<-4 && u2>=-5)+((floor(u2)-5)/-(Fr^2))*(u2>=6 && u2<7)+((floor(u2)+6)/-(Fr^2))*(u2<-5 && u2>=-6)
By this way I can run the simulation,but as you see I can not extend to formula to infinity!
I mean I can not set u2 by that way to 1 if u2 is for instance 98 or -105.
I need a general way

Can we use for loop in variable definition part?

Thanks,
Hooman
Ivar, Thank you for the answer. I defined a variable like Re and set to a number. So I guess it is a constant and fixed number. for the other part I try something like this I omit "H" variable and just work with u2 and Fr instead of Re.(Fr is a constant number) (-u2*1/(Fr^2))*(u2>=0 && u21 && u2=2 && u2=3 && u2=4 && u2=5 && u2=6 && u2

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 mai 2013, 13:05 UTC−4
I have found something new and I guess it works.

Just need to add max(min(u2,1),0) to have u2 between 0 and 1.

I have found something new and I guess it works. Just need to add max(min(u2,1),0) to have u2 between 0 and 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 8 mai 2013, 14:19 UTC−4
Hi

indeed, but remains that oyur function is rather spiky oe of sharp angles from what I imagine, this might give some difficulties for the solver as it cannot easily determine the derivatives for the next step estimations, but with the complexity of your function, it's worth a try :)

--
Good luck
Ivar
Hi indeed, but remains that oyur function is rather spiky oe of sharp angles from what I imagine, this might give some difficulties for the solver as it cannot easily determine the derivatives for the next step estimations, but with the complexity of your function, it's worth a try :) -- Good luck Ivar

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.