This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Multiple (or nested) conditionals

0 votes

Hello, I'm trying to solve a 2D advection-diffusion-reaction problem with a strong non-linear source term that is piecewise defined with dependence from the value of a difference of temperature:

$$ q = a\;f(x,y)^{0.566} \Delta T^{0.461}\quad \text{for }\Delta T > 300 $$
$$ q = 1.87\times 10^{-5} \Delta T^{5.55}\quad \text{for } 0 <\Delta T < 300 $$

What I tried so far is:

 u = Function(Q)
# [...]
# Non-integer exponent of negative basis gives NaN
# And since the problem is non-linear during Newton iterations
# It can happen that we get a Delta T that is negative
dt = conditional(ge(u - T0), 0), u-T0, 0)  
q = conditional(ge(dt), 300), f1, f2)

where f1 and f2 are the two expressions I wrote before. This does not seem to work since I'm getting NaN... If I use just one conditional I get some results. Any suggestion on how to implement this?

asked May 11, 2017 by RdB FEniCS Novice (220 points)
edited May 12, 2017 by RdB

1 Answer

0 votes
 
Best answer

When you use expressions with exponents you have to remember Newton's method uses the derivative of the forms (which in this case includes your sources). What is the derivative of deltaT^0.461 evaluated at deltaT=0?

To get around this you can either do: deltaT => deltaT + (small number, i.e. 1.0e-12) which is never 0, or you can change your initial conditions so that at the first time step deltaT is not 0.

You can use the first option to quickly check if this is actually what's causing the problem but the second option will give you a numerically 'exact' solution

The problem with the last option is that you need a proper guess for the initial condition or Newton's method might diverge depending on the problem. You can try a temperature value such that you get a small non-zero value for deltaT.

answered May 12, 2017 by alexmm FEniCS User (4,240 points)
selected May 13, 2017 by RdB

Thanks,

It was as you said. I imposed a different, non-zero, profile for the temperature and now I'm not experience NaN crash anymore. Thanks,

...