Absolute values in variational form

Dear all,

There is an absolute value in my variational form, for example: (....+|\frac{\partial u}{\partial x}|+....)dV, where u is a Function and x is the x axis. I write this variational form like this:

from dolfin import *
import numpy as np
V = VectorFunctionSpace(mesh, "CG", 1)
u = Function(V)
variational_form = (... + np.absolute(u.dx(0)) + ...)*dx

My first question is can we use np.absolute() in a variational form?

Besides, there is no doubt that we can use float as the argument of np.aboslute(), like this:

a=np.absolute(-3.2)
print(a)

But can we use the type of fenics (such as the u.dx(0) in my case) to be the argument of np.aboslute()? np.absolute() can recognize a float, but I don’t think np.aboslute() can recognize the types of fenics.

I appreciate any help.

I think you should be using abs(u.dx(0)).

This abs() is the Python built-in abs(), right? Initially, I thought it was a function defined in Fenics, but I didn’t find it in Fenics’s files.

ufl supports usage of the Python abs value (which calls my_python_function.__abs__), see for instance: Code search results · GitHub

Ok. Got it. Thank you very much.