I have two functions, u1 and u2, and I am trying to apply a Dirichlet boundary condition to just u1. I define the function space and functions as follows:
from mpi4py import MPI
from dolfinx import fem, io, nls, log, mesh, plot
import numpy as np
import ufl
from petsc4py.PETSc import ScalarType
domain = mesh.create_interval(MPI.COMM_WORLD, 100, [0, L])
P1 = ufl.FiniteElement('CG', domain.ufl_cell(), 1)
element = ufl.MixedElement([P1, P1])
V = fem.FunctionSpace(domain, element)
# test functions
v1, v2 = ufl.TestFunctions(V)
# fields to solve for
u = fem.Function(V)
u1, u2 = u.split()
And then I apply the boundary condition:
# function determining if a node is on the tray top
def on_top_boundary(x):
return(np.isclose(x[0], L))
# determine boundary DOFs
boundary_dofs = fem.locate_dofs_geometrical(V.sub(0), on_top_boundary)
# apply dirichlet BC to boundary DOFs
bc = fem.dirichletbc(ScalarType(C_0), boundary_dofs, V.sub(0))
But this returns the error:
RuntimeError: Cannot tabulate coordinates for a FunctionSpace that is a subspace.
So instead I use the mixed space instead of a subspace:
# function determining if a node is on the tray top
def on_top_boundary(x):
return(np.isclose(x[0], L))
# determine boundary DOFs
boundary_dofs = fem.locate_dofs_geometrical(V, on_top_boundary)
# apply dirichlet BC to boundary DOFs
bc = fem.dirichletbc(ScalarType(C_0), boundary_dofs, V)
But this returns: RuntimeError: Cannot locate dofs geometrically for mixed space. Use subspaces.
It seems like I’m being sent in circles. Any thoughts on what to try next?