Mesh-independent formulation of nonlinear problems


Hello everyone,

I am currently working on optimizing my structural mechanics code to enable remeshing during explicit dynamics simulations. I have been following the tutorials :

to make as many components as possible mesh-independent in my code, thereby reducing compilation/computation time when remeshing occurs.

However, I am stuck on whether it’s possible to abstract a nonlinear problem in this manner. Specifically, I believe there is no UFL equivalent to dolfinx.fem.Function - is this correct?
More specifically, the following code:

import ufl
import basix.ufl
import dolfinx
c_el = basix.ufl.element("Lagrange", "triangle", 1, shape=(2,))
domain = ufl.Mesh(c_el)
V = ufl.FunctionSpace(domain, c_el)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
F = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
u_func = dolfinx.fem.Function(V)

raises an error when creating the Function:


  File ~/Téléchargements/compile_form (1).py:12
    u_func = dolfinx.fem.Function(V)

  File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/function.py:319 in __init__
    V.element.dtype, np.dtype(dtype).type(0).real.dtype

AttributeError: 'FunctionSpace' object has no attribute 'element'

Is there a way to define a functional F(u) where u is a Function defined on an abstract vector space V created from a ufl.Mesh?

Any insights or suggestions would be greatly appreciated.

Thank you!

I believe ufl.Coefficient(V) is the analogue to fem.Function(V). Have you considered that?

Stein is correct, see for instance The UFL forms — FEniCS Workshop and/or dolfinx/python/test/unit/fem/test_assemble_mesh_independent_form.py at ff9ba439b0499c08665e9b3e146b82245c48dd88 · FEniCS/dolfinx · GitHub