I’m trying to write a script to solve a basic Hermitian eigenproblem, ∇^2u = Eu, on a 2D square, using the new dolfinx module. I think I can follow the documentation once the problem is solved (extracting eigenvalues, plotting etc), but I am struggling with defining the problem. Here is what I have so far
from mpi4py import MPI
import numpy as np
import ufl
from dolfinx import fem, io, mesh, plot
from dolfinx.fem.petsc import LinearProblem, assemble_matrix
from ufl import ds, dx, grad, inner
msh = mesh.create_rectangle(
comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (1.0, 1.0)),
n=(32, 32),
cell_type=mesh.CellType.triangle
)
V = fem.functionspace(msh, ("Lagrange", 1))
# Set Dirichlet boundary conditions
def bc_checker(x):
return np.logical_or(
np.logical_or(np.isclose(x[0], 0.0), np.isclose(x[0], 1.0)),
np.logical_or(np.isclose(x[1], 0.0), np.isclose(x[1], 1.0))
)
facets = mesh.locate_entities_boundary(
msh,
dim=(msh.topology.dim - 1),
marker=bc_checker
)
dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)
bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)
# Define problem
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a = inner(grad(u), grad(v)) * dx
A = assemble_matrix(a, bcs=[bc])
A.assemble()
solver = SLEPc.EPS().create(MPI.COMM_WORLD)
solver.setOperators(A)
solver.solve()
![img1|551x500](upload://sxJyQT10x2ZCqDX3CXPNUey2jWt.jpeg)
It fails at assemble_matrix. “AttributeError: ‘Form’ object has no attribute ‘_cpp_object’”. I remember doing something similar above to hande the variational representation of the problem with the old dolfin module. Perhaps this is no longer the right procedure.
[edit] - For more info: This is the general form I am trying to reproduce