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 Apr 19, 2011, 10:42 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 12, 2011, 10:46 a.m. EDT
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 Apr 15, 2011, 6:32 a.m. EDT
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 Apr 15, 2011, 6:39 a.m. EDT
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 Apr 16, 2011, 2:45 a.m. EDT
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 Apr 19, 2011, 12:55 a.m. EDT
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 Apr 19, 2011, 10:42 a.m. EDT
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.