Hi!
I am struggling to adapt an old fenicsx code to version 10. The code aims at computing stationary points of a nonlinear functional that depends on a scalar-valued function phi and vector-valued function u that are both defined on a 2D domain. In the old code, we used ufl.MixedElement like this:
import dolfinx
import basix.ufl
import ufl
from mpi4py import MPI
import numpy as np
# Create domain
my_domain = dolfinx.mesh.create_rectangle(MPI.COMM_WORLD, [np.array([0.0, 0.0]), np.array([1, 1])], [40,40], cell_type=dolfinx.mesh.CellType.triangle)
# Define mixed element and functionspace
u_el = ufl.VectorElement('Lagrange', my_domain.ufl_cell(), degree=1, dim=2)
phi_el = ufl.FiniteElement('Lagrange', my_domain.ufl_cell(), degree=1)
mixed_el = ufl.MixedElement([u_el, phi_el]) # mixed element
V = dolfinx.fem.FunctionSpace(my_domain, mixed_el)
#Define functions u and phi
u_gen = fem.Function(V)
u, phi = ufl.split(u_gen)
and then we define the nonlinear functional in terms of ulf.cos like this
I = ufl.Identity(my_domain.topology.dim)
F = I + ufl.grad(u)
E = ufl.variable(1/2*(F.T * F-I))
psi = 1/(ufl.cos(phi)**2)*ufl.tr(E) ** 2
dx = Measure("dx", my_domain)
potential_energy = psi * dx
in version 10, I transform the first paragraph like this, using ufl.MixedFunctionSpace instead of ufl.MixedElement:
# Define mixed functionspace
u_el = dolfinx.fem.functionspace(my_domain, basix.ufl.element("Lagrange", "triangle", degree=1, shape=(2,)))
phi_el = dolfinx.fem.functionspace(my_domain, basix.ufl.element("Lagrange", "triangle", degree=1, shape=(1,)))
V = ufl.MixedFunctionSpace(u_el, phi_el)
#Define the functions u and phi
dtype = dolfinx.default_scalar_type
u = dolfinx.fem.Function(u_el, dtype = dtype)
phi = dolfinx.fem.Function(phi_el, dtype = dtype)
but then the command ufl.cos(phi) yields the following error:
ValueError: Expecting scalar argument.
Many thanks in advance for your help!
kind regards,
Claire