Hi, I am using dolfinx_mpc and I am trying to create a MultiPointConstraint. I am trying to apply the create_general_constraint
to a Vector Function Space within a Mixed Function Space. I get the following error: “RuntimeError: Multiple slaves found at same point. You should use sub-space locators.” But I am already using the sub-space locators for accessing the Vector Function Space within my Mixed Function Space. Is there a work around? Thank you very much!
Here below is my MWE.
import numpy as np
from mpi4py import MPI
from dolfinx import mesh, fem
from ufl import VectorElement, FiniteElement, MixedElement, TestFunctions, inner, grad, dx
from dolfinx.mesh import locate_entities_boundary
from dolfinx_mpc import MultiPointConstraint
Lx, Ly, Lz = 1.0, 1.0, 1.0
nx, ny, nz = 3, 3, 3
domain = mesh.create_box(MPI.COMM_WORLD, [[0.0, 0.0, 0.0], [Lx, Ly, Lz]], [nx, ny, nz])
fdim = domain.topology.dim - 1
V_element = VectorElement("CG", domain.ufl_cell(), 2)
Q_element = FiniteElement("CG", domain.ufl_cell(), 1)
W = fem.FunctionSpace(domain, MixedElement([V_element, Q_element]))
slave_facets = locate_entities_boundary(domain, dim=2, marker=lambda x: np.isclose(x[0], 0.0))
master_facets = locate_entities_boundary(domain, dim=2, marker=lambda x: np.isclose(x[0], Lx))
ZS_v = fem.FunctionSpace(domain, FiniteElement("CG", domain.ufl_cell(), 2))
ZS_q = fem.FunctionSpace(domain, FiniteElement("CG", domain.ufl_cell(), 1))
slave_dofs_velocity = fem.locate_dofs_topological(ZS_v, 2, slave_facets)
master_dofs_velocity = fem.locate_dofs_topological(ZS_v, 2, master_facets)
slave_dofs_pressure = fem.locate_dofs_topological(ZS_q, 2, slave_facets)
master_dofs_pressure = fem.locate_dofs_topological(ZS_q, 2, master_facets)
def create_slave_master_dict(slave_coords, master_coords):
slave_master_dict = {}
for i, slave_coord in enumerate(slave_coords):
master_index = np.argmin(np.linalg.norm(master_coords - slave_coord, axis=1))
master_coord = master_coords[master_index]
slave_master_dict[slave_coord.tobytes()] = {master_coord.tobytes(): 1.0}
return slave_master_dict
dof_coords_velocity = ZS_v.tabulate_dof_coordinates()
slave_coords_velocity = dof_coords_velocity[slave_dofs_velocity]
master_coords_velocity = dof_coords_velocity[master_dofs_velocity]
dof_coords_pressure = ZS_q.tabulate_dof_coordinates()
slave_coords_pressure = dof_coords_pressure[slave_dofs_pressure]
master_coords_pressure = dof_coords_pressure[master_dofs_pressure]
slave_master_dict_velocity = create_slave_master_dict(slave_coords_velocity, master_coords_velocity)
slave_master_dict_pressure = create_slave_master_dict(slave_coords_pressure, master_coords_pressure)
mpc = MultiPointConstraint(W)
mpc.create_general_constraint(
slave_master_dict=slave_master_dict_velocity,
subspace_slave=0,
subspace_master=0
)
mpc.create_general_constraint(
slave_master_dict=slave_master_dict_pressure,
subspace_slave=1,
subspace_master=1
)