I am little confused how to fix the issue in the function H(x). The minimal example is given below.
from fenics import *
q_s = 75 # Column saturation moisture content
# Create mesh and define function space
nx = ny = 10
mesh = RectangleMesh( Point(0, 0), Point(5120, 6400), nx, ny)
# Define function space for velocity
W = VectorFunctionSpace(mesh, 'P', 2)
#Define function space for system of equations
P1 = FiniteElement('P', triangle, 1)
element = MixedElement( [P1, P1] )
V = FunctionSpace ( mesh, element)
# Define test functions
v_1, v_2= TestFunctions(V)
# Define functions for velocity and PDE
u = Function(V)
# Split system functions to access components
u_1, u_2 = split(u)
# Define expressions used in variational forms
q_s = Constant(q_s)
#Define Latent heat source
from ufl.algebra import Sum
def P(u_1):
return ( alpha*(u_1-q_c) * H(u_1 - q_c) )
# Define Heaviside function H
def H(x):
if ( x>0):
return(1)
else :
return (0)
# Define variational problem
F = P(u_1)*v_1*dx
The following error occurred.
File "exp.py", line 105, in <module>
+ P(u_1)*v_1*dx + Q(u_1)*v_1*dx - M1*K(u_1, u_2)*u_1*v_1*dx \
File "exp.py", line 75, in P
return ( alpha*(u_1-q_c) * H(u_1 - q_c) )
File "exp.py", line 96, in H
if ( x>0):
File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/conditional.py", line 46, in __bool__
error("UFL conditions cannot be evaluated as bool in a Python context.")
File "/Users/kapilchawla/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/log.py", line 172, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: UFL conditions cannot be evaluated as bool in a Python context.
I did not find the name of the operator in ufl package.