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.

if condition in variable definitions

Please login with a confirmed email address before reporting spam

Hi,

I was wondering how to implement if conditions in variable definitions?

For example, if I wanted to define a variable a, and it is based on a condition of b, which has been defined as another variable.

a = 1 if b>0
a = 3 if b<=0

I was wondering how to implement this?

And another situation is, I have already defined a variable M, then another variable depends on M:
c = M^2 + 5 when M<0.5
c = 2*M/(M+1)^2 when M>=0.5

Could anyone please help with this? Thanks a lot in advance!


6 Replies Last Post 2011年4月19日 GMT-4 10:42

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月12日 GMT-4 10:46
Hi,

you can multiply boolean expressions:

3*(b<=0) + 1*(b>0) behaves as desired for a.

The expression for c would then be:

(M^2 + 5)*(M<0.5) + (2*M/(M+1)^2)*(M>=0.5)

Cheers
Edgar
Hi, you can multiply boolean expressions: 3*(b0) behaves as desired for a. The expression for c would then be: (M^2 + 5)*(M=0.5) Cheers Edgar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月15日 GMT-4 06:32
Hi ,

I have a question in connection with this.

I wish to add a boolien expression, which should use time variable. I want to know, how the time is accessed? What is the variable name?
Hi , I have a question in connection with this. I wish to add a boolien expression, which should use time variable. I want to know, how the time is accessed? What is the variable name?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月15日 GMT-4 06:39
Hi,

I think the time variable is always "t".

Cheers
Edgar
Hi, I think the time variable is always "t". Cheers Edgar

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 2011年4月16日 GMT-4 02:45
Hi

The time in COMSOL is "t" (in seconds) but it is not formally declared before you call a transient solver, therefore when you mix stationary followed by a time series and you want to debug such a solution with variables depending on "t" these might flag an error.

To avoid this, add a "Parameter" t = 0[s], this will be overwritten by COMSOL once the time solver comes up
Sometimes it is better to use a value slightly different from "0" to avoid all =0 in your variables, this is all model and case dependent ;)

--
Good luck
Ivar
Hi The time in COMSOL is "t" (in seconds) but it is not formally declared before you call a transient solver, therefore when you mix stationary followed by a time series and you want to debug such a solution with variables depending on "t" these might flag an error. To avoid this, add a "Parameter" t = 0[s], this will be overwritten by COMSOL once the time solver comes up Sometimes it is better to use a value slightly different from "0" to avoid all =0 in your variables, this is all model and case dependent ;) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月19日 GMT-4 00:55
Hi,

Thanks to both of you!

Dhanashri.
Hi, Thanks to both of you! Dhanashri.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月19日 GMT-4 10:42
Thank you so much!
Thank you so much!

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.