How to write a piecewise function with 3 subdomains?

Dear all,

I know how to write a piecewise function with 2 subdomains in fenics, for example if we want to write this:
q=\begin{cases} 3u+7 & \text{ if } \quad u>2 \\ 5 & \text{ if } \quad u \le 2 \end{cases}
we write:

from dolfin import *

V_u = VectorFunctionSpace(mesh, "CG", 1)
u = Function(V_u, name = "displacement")

q = conditional(gt(u, 2), 3*u+7, 5)

But if we want to write a piecewise function with 3 subdomains in fenics, like this one:
q=\begin{cases} 7u+8 & \text{ if } \quad u>10 \\ 5u^2-4 & \text{ if } \quad 2\le u \le 10 \\ 6 & \text{ if } \quad u<2 \end{cases}
I don’t know how to write it in fenics. Does anyone know how to do it? I appreciate any help. Thank you very much in advance.

Just nest another conditional in the second or third argument of the outer conditional you already have in q.

2 Likes

Got it. Thank you very much.