Hello,
I am trying to implement periodic boundary conditions for 3D TGV using dolfinx_mpc. But, I am having some type errors.
My dolfinx and dolfinx_mpc versions are as following:
The code I am using is as following:
from mpi4py import MPI
import numpy as np
import dolfinx
from dolfinx.mesh import create_box
from dolfinx.fem import functionspace
from dolfinx_mpc import MultiPointConstraint
# 1. Create a simple mesh and function space
mesh = create_box(MPI.COMM_WORLD, [[0,0,0], [1,1,1]], [8,8,8])
V = functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))
# 2. Define the domain boundaries
L_min = [0.0, 0.0, 0.0]
L_max = [1.0, 1.0, 1.0]
tol = 1e-6
# 3. Define the correct periodic functions for all 3 dimensions
def periodic_boundary(x):
return np.isclose(x[0], L_min[0], atol=tol) | np.isclose(x[1], L_min[1], atol=tol) | np.isclose(x[2], L_min[2], atol=tol)
def periodic_relation(x):
out_x = x.copy()
mask_x = np.isclose(x[0], L_min[0], atol=tol)
mask_y = np.isclose(x[1], L_min[1], atol=tol)
mask_z = np.isclose(x[2], L_min[2], atol=tol)
out_x[0, mask_x] = L_max[0]
out_x[1, mask_y] = L_max[1]
out_x[2, mask_z] = L_max[2]
return out_x
# 4. Attempt to create the MultiPointConstraint
try:
print("Attempting to create MultiPointConstraint...")
mpc = MultiPointConstraint(V)
mpc.create_periodic_constraint_geometrical(
V, periodic_boundary, periodic_relation, bcs=[], scale=1.0
)
mpc.finalize()
print("SUCCESS: MultiPointConstraint created and finalized without error.")
except TypeError as e:
print("\nERROR: The minimal test script failed with the same TypeError.")
print("This strongly suggests an issue with the software environment, not the code logic.")
print("\nFull Error Message:")
# We print the error message itself to confirm it's the same one
print(e)
except Exception as e:
print(f"\nAn unexpected error occurred: {e}")
The below is the error message:
Does anyone have similar issues?
Thanks,