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.

How to add a conditional statement?

Please login with a confirmed email address before reporting spam

Total time for my simulation is 4.2 sec. I have to add a conditional source term which are as follows, For, 0< t <= 0.1 sec, Q=Q_1 0.1< t <= 2.1 sec, Q=0 2.1< t <= 2.2 sec , Q=Q_2 2.2< t <= 4.2 sec, Q=0 Where t is the time and Q is the source term.I have already defined Q_1 and Q_2 in definition. How can I add these conditions in the heat source section in comsol multiphysics?


2 Replies Last Post 12.01.2022, 08:10 GMT-5

Please login with a confirmed email address before reporting spam

Posted: 3 years ago 06.01.2022, 04:07 GMT-5

You could define a function with nested if statements as shown in the attached image. Note that you will need to add the appropriate units for the function and the argument as shown in the highlighted fields in the attached image. (your argument unit would be s, and your function unit would be whatever the unit of Q are... Joules from memory).

I am not sure how well Comsol will handle instantaneous changes in source values, as it seems to me this would be highly non-linear and would not converge. In which case you could create a function using the rectangular function to introduce smooth transitions between values. Your final analytical function would then just sum the contributing rectangular functions. You would need to ensure your time step in your study can resolve the transition zones sufficiently.

In the attached image I have set Q1= 0.75 and Q2 =1.3 within the global parameters.

The core of the function is

if((x>lowerlimit)*(x<=upperlimit),valueiftrue,valueiffalse)

the value if false is then a second if statement of the same form, and so on. The "*" in the formula is equivilent to the AND statement.

However, for model stability I suspect you will need to use a sequence of rectangular functions with smoothing, which themselves could contain IF statements to meet your needs.

You could define a function with nested if statements as shown in the attached image. Note that you will need to add the appropriate units for the function and the argument as shown in the highlighted fields in the attached image. (your argument unit would be s, and your function unit would be whatever the unit of Q are... Joules from memory). I am not sure how well Comsol will handle instantaneous changes in source values, as it seems to me this would be highly non-linear and would not converge. In which case you could create a function using the rectangular function to introduce smooth transitions between values. Your final analytical function would then just sum the contributing rectangular functions. You would need to ensure your time step in your study can resolve the transition zones sufficiently. In the attached image I have set Q1= 0.75 and Q2 =1.3 within the global parameters. The core of the function is *if((x>lowerlimit)\*(x


Please login with a confirmed email address before reporting spam

Posted: 2 years ago 12.01.2022, 08:10 GMT-5

sir, how can I define this, if Q_1 and Q_2 are polynomial functions of temperature?

sir, how can I define this, if Q_1 and Q_2 are polynomial functions of temperature?

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.