I’m trying to implement this Dolfin waveguide example in DolfinX.
The implementation below calculates only one eigenpair. If I set solver to SLEPc.EPS.Type.LAPACK
, it calculats about a 2500 eigenpairs.
What settings should I use to get a number of eigenpairs requested by eps.setDimensions
?
import dolfinx
import dolfinx.io
import ufl
from mpi4py import MPI
from slepc4py import SLEPc
import numpy as np
c0 = 299792458
mesh = dolfinx.RectangleMesh(
MPI.COMM_WORLD,
[np.array([0, 0, 0]), np.array([1, 0.5, 0])], [30, 30],
cell_type=dolfinx.cpp.mesh.CellType.triangle)
mesh.topology.create_connectivity(mesh.topology.dim-1, mesh.topology.dim)
N1curl = ufl.FiniteElement("N1curl", mesh.ufl_cell(), 2)
V = dolfinx.FunctionSpace(mesh, N1curl)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a = ufl.inner(ufl.curl(v), ufl.curl(u)) * ufl.dx
b = ufl.inner(v, u) * ufl.dx
bc_facets = np.where(np.array(dolfinx.cpp.mesh.compute_boundary_facets(mesh.topology)) == 1)[0]
bc_dofs = dolfinx.fem.locate_dofs_topological(V, mesh.topology.dim-1, bc_facets)
u_bc = dolfinx.Function(V)
with u_bc.vector.localForm() as loc:
loc.set(0)
bc = dolfinx.DirichletBC(u_bc, bc_dofs)
A = dolfinx.fem.assemble_matrix(a, bcs=[bc])
A.assemble()
B = dolfinx.fem.assemble_matrix(b, bcs=[bc])
B.assemble()
eps = SLEPc.EPS().create(MPI.COMM_WORLD)
eps.setOperators(A, B)
eps.setType(SLEPc.EPS.Type.KRYLOVSCHUR)
eps.setProblemType(SLEPc.EPS.ProblemType.GHEP)
eps.setWhichEigenpairs(SLEPc.EPS.Which.SMALLEST_REAL)
# eps.setWhichEigenpairs(SLEPc.EPS.Which.TARGET_REAL)
# eps.setTarget(10)
eps.setDimensions(42)
eps.solve()
solution = dolfinx.Function(V)
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "out.xdmf", "w") as xdmf:
xdmf.write_mesh(mesh)
for i in range(eps.getConverged()):
print(eps.getEigenpair(i, solution.vector))
solution.name = f"f-{i}"
xdmf.write_function(solution)