Hi,
while changing my code from mixed_element
to MixedFunctionSpace
(see the previous post here), I ran into convergence problems (solver produces NaN), which I think stem from the bc set up.
This was before:
import numpy as np
from mpi4py import MPI
from dolfinx import fem, mesh
import basix
from dolfinx.fem import locate_dofs_geometrical
from basix.ufl import mixed_element
p = 1
domain = mesh.create_box(MPI.COMM_WORLD, [[0.0, 0.0, 0.0], [1, 1, 1]], [1, 1, 1], mesh.CellType.hexahedron)
Ue = basix.ufl.element("P", domain.basix_cell(), p, shape=(domain.geometry.dim,))
He = basix.ufl.quadrature_element(domain.basix_cell(), value_shape=(), degree=p)
Te = basix.ufl.blocked_element(He, shape=(domain.geometry.dim, domain.geometry.dim), symmetry=True)
V_el = mixed_element([Ue, Te, He, Te])
V = fem.functionspace(domain, V_el)
Uf = fem.functionspace(domain, Ue)
Tf = fem.functionspace(domain, Te)
Hf = fem.functionspace(domain, He)
V0, _ = V.sub(0).collapse()
u_L = fem.Function(V0)
u_L.x.array[:] = 0.
dofs_L = locate_dofs_geometrical((V.sub(0), V0), lambda x: np.isclose(x[0], 0))
bc_L = fem.dirichletbc(u_L, dofs_L, V.sub(0))
print(dofs_L)
And this is my attempt with MixedFunctionSpace
, which results in a different dof vector:
import numpy as np
import ufl
from mpi4py import MPI
from dolfinx import fem, mesh
import basix
from dolfinx import default_scalar_type
p = 1
domain = mesh.create_box(MPI.COMM_WORLD, [[0.0, 0.0, 0.0], [1, 1, 1]], [1, 1, 1], mesh.CellType.hexahedron)
Ue = basix.ufl.element("P", domain.basix_cell(), p, shape=(domain.geometry.dim,))
He = basix.ufl.quadrature_element(domain.basix_cell(), value_shape=(), degree=p)
Te = basix.ufl.blocked_element(He, shape=(domain.geometry.dim, domain.geometry.dim), symmetry=True)
Uf = fem.functionspace(domain, Ue)
Tf = fem.functionspace(domain, Te)
Hf = fem.functionspace(domain, He)
V = ufl.MixedFunctionSpace(Uf, Tf, Hf, Tf)
def left(x):
return np.isclose(x[0], 0)
dofs_L = fem.locate_dofs_geometrical(Uf, lambda x: np.isclose(x[0], 0))
u_bc = np.array((0,) * domain.geometry.dim, dtype=default_scalar_type)
bc_L = fem.dirichletbc(u_bc, dofs_L, Uf)
print(dofs_L)
I am using Fenicx 0.9 on WSL Ubuntu / Windows. Many thanks!