Best differentiable approximation of L1 norm in Fenics?

Hi, I have an objective f(b) + |\nabla b| where b is the control variable which is defined in DG0 function space. Is there a function in fenics adjoint which is a smooth approximation of the TV norm such that the gradients w.r.t. b can also be tracked.

For example, consider this:

’’’

n = 250
mesh = UnitSquareMesh(n, n)
A = FunctionSpace(mesh, "CG", 1)  # function space for control
P = FunctionSpace(mesh, "CG", 1)  # function space for solution
.......
J = assemble(f * T * dx + alpha * inner(grad(a), grad(a)) * dx)
m = Control(a)
Jhat = ReducedFunctional(J, m, eval_cb_post=eval_cb)

What should I use in place of : inner(grad(a), grad(a))

To me this seems like a general mathematical question rather than a dolfin-adjoint question.
You are asking what is the best substitute for \int_\Omega \sqrt{(\nabla b \cdot \nabla b)}~\mathrm{d}x for an unspecified optimization problem, which I believe is covered in S. Bartels paper: https://doi.org/10.1137/11083277X,
and in: Total Generalized Variation with Finite Elements for Imaging and Shape Optimization by @Baumi

Hello,

as described by @dokken, it is not possible to compute a real gradient, because our objective is not differentiable. There are specialized algorithms to solve such non-smooth problems. Some of them require generalized gradients of the objective, which could be computed using dolfin-adjoint.

One problem you might face (and this might be you actual question) is that you represent the euclidean norm, a Lipschitz continious function, by a composition using sqrt, which is not Lipschitz. This can lead to instablility in the numerical computation. I think you could fix this by adding the euclidean norm as a custom function. Then you can specify the derivative you want to use at 0.