Hi:
I’m new to FeniCS and still experimenting. As a toy problem, I am trying to solve a simple eigenvalue problem, with nonzero Dirichlet BCs. The program finds solutions, but they all have zero BCs (and I’m trying to find them with BC = 1). I am for sure doing something wrong but I can’t find what. Thank you!
Here’s my code:
#define mesh and function space
mesh = IntervalMesh(100, -5, 5)
V = FunctionSpace(mesh, ‘Lagrange’, 3)
#define boundary
def boundary(x, on_boundary):
return on_boundary
#apply essential boundary conditions
bc = DirichletBC(V, Constant(1.0), boundary)
#define functions
u = TrialFunction(V)
v = TestFunction(V)
x2 = Expression(‘x[0]*x[0]’, element = V.ufl_element())
#define problem
a = (inner(grad(u), grad(v)) + x2uv)*dx
m = u * v * dx
L_dummy = Constant(0)vdx
A = PETScMatrix()
M = PETScMatrix()
assemble_system(a, L_dummy, bc, A_tensor=A)
assemble_system(m, L_dummy, bc, A_tensor=M)
bc.apply(A)
bc.zero(M)
#create eigensolver
eigensolver = SLEPcEigenSolver(A,M)
eigensolver.parameters[‘spectrum’] = ‘smallest magnitude’
eigensolver.parameters[‘solver’] = ‘lapack’
eigensolver.parameters[‘tolerance’] = 1.e-10
#solve for eigenvalues
eigensolver.solve()