Hi, I’m trying to solve a periodic problem with curl elements. I get the following error: “RuntimeError: Periodic conditions for vector valued spaces are not implemented”.
I’m using dolfinx_mpc v0.8.1 through the docker image provided by Jørgen.
I would be happy if it worked just for conformal mesh.
Here below is my MWE. I’m using dolfinx-complex-mode (i.e., source /usr/local/bin/dolfinx-complex-mode):
import dolfinx
import ufl
import dolfinx_mpc
import gmsh
from dolfinx.fem.petsc import LinearProblem
from dolfinx.io.gmshio import model_to_mesh
from petsc4py import PETSc
from mpi4py import MPI
import numpy as np
from dolfinx import fem, mesh, common
from basix.ufl import element
Lx = 0.1
Ly = 1
# Define region tags
air_tag = 1
port_1_tag = 2 #input port
port_2_tag = 3 #output port
left_tag = 4
right_tag = 5
# Generate mesh
gmsh.initialize()
gmsh.model.add("geometry")
r1 = gmsh.model.occ.addRectangle(-Lx/2, -Ly/2, 0, Lx, Ly)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(2, [1], tag=1, name="air")
gmsh.model.addPhysicalGroup(1, [1], tag=2, name="bottom")
gmsh.model.addPhysicalGroup(1, [2], tag=3, name="left")
gmsh.model.addPhysicalGroup(1, [3], tag=4, name="right")
gmsh.model.addPhysicalGroup(1, [4], tag=5, name="top")
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.01)
gmsh.model.mesh.generate(2)
gmsh.write("mesh.msh")
domain, cell_tags, facet_tags = model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=3)
gmsh.finalize()
k0 = dolfinx.fem.Constant(domain, PETSc.ScalarType(2 * np.pi / 0.8))
epsr = dolfinx.fem.Constant(domain, PETSc.ScalarType(1))
E0=ufl.as_vector((1, 0, 0))
#Define elements, spaces and measures
degree = 2
curl_el = element('N1curl', domain.basix_cell(), degree)
V = dolfinx.fem.functionspace(domain, curl_el)
dx = ufl.Measure("dx", domain, subdomain_data=cell_tags, metadata={'quadrature_degree': 4})
ds = ufl.Measure("exterior_facet", domain, subdomain_data=facet_tags,metadata={'quadrature_degree': 4})
E = ufl.TrialFunction(V)
testE = ufl.TestFunction(V)
n = ufl.FacetNormal(domain)
# Define problem
F = (- ufl.inner(ufl.curl(E), ufl.curl(testE)) * dx
+ epsr * k0**2 * ufl.inner(E, testE) * dx(air_tag)
+ 1j*k0 * ufl.inner(ufl.cross(E, n), ufl.cross(testE, n)) * ds((port_1_tag,port_2_tag))
- 2j*k0 * ufl.inner(ufl.cross(E0, n), ufl.cross(testE, n)) * ds(port_1_tag)
)
a, L = ufl.lhs(F), ufl.rhs(F)
# Periodic Boundary condition
bcs=[]
def periodic_relation(x):
out_x = np.zeros(x.shape)
out_x[0] = Lx-x[0]
out_x[1] = x[1]
out_x[2] = x[2]
return out_x
facets = facet_tags.find(right_tag)
arg_sort = np.argsort(facets)
mt = mesh.meshtags(domain, domain.topology.dim - 1, facets[arg_sort], np.full(len(facets), 2, dtype=np.int32))
with common.Timer("~~Periodic: Compute mpc condition"):
mpc = dolfinx_mpc.MultiPointConstraint(V)
mpc.create_periodic_constraint_topological(V, mt, 2, periodic_relation, bcs)
mpc.finalize()
# Solve problem
problem = dolfinx_mpc.LinearProblem(a, L, mpc, bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu","pc_factor_mat_solver_type": "mumps"})#
E=problem.solve()