UFL - conditional for Tensor


I am trying to define UFL to use in the variational formulation.

PM = FunctionSpace(mesh, ‘DG’, 0)
TM = TensorFunctionSpace(mesh, ‘DG’, 0)

u = Function(U)

phi0 = Function(PM)
k0 = Function™

def strain(u):
return sym(grad(u))

def vol_strain(u):
return tr(strain(u))

def perm_newton(vol_strain(u),phi0,k0):
perm_min = 1e-20
perm_min_tensor = Constant(((perm_min, 0.), (0., perm_min)))
k = k0*pow(1.0+vs/phi0,3.0)/(1.0+vs)
return conditional(ge(k,perm_min_tensor),k,perm_min_tensor)

The idea is to use this perm_newton in the variational formulation to solve the non-linear problem. Since pow(1.0+vs/phi0,3.0)/(1.0+vs) can be negative, perm_min_tensor is built to prevent perm_newton(vol_strain(u),phi0,k0) becomes less than zero. However, ‘ge(a,b)’ requires ‘ufl.log.UFLException: Expecting scalar arguments.’. Does anyone have any recommendations?

Thank you!


I had the same kind of problem.
See this post : Integer part of UFL tensor

Thank you very much for your help!