# Eigenvalue Problem not satisfying BCs

**URL:** <https://fenicsproject.discourse.group/t/eigenvalue-problem-not-satisfying-bcs/1690>\
**Category:** Uncategorized\
**Created:** [October 8, 2019, 2:06am UTC](https://fenicsproject.discourse.group/t/eigenvalue-problem-not-satisfying-bcs/1690 "2019-10-08T02:06:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![javi](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@javi](https://fenicsproject.discourse.group/u/javi)\
**Post date:** [October 8, 2019, 2:06am UTC](https://fenicsproject.discourse.group/t/eigenvalue-problem-not-satisfying-bcs/1690/1 "2019-10-08T02:06:29Z")

</div>

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)) + x2_u_v)\*dx  
m = u \* v \* dx  
L\_dummy = Constant(0)_v_dx

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()

---

<div class="post-metadata">

**Author:** ![bleyerj](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bleyerj/32/6020_2.png) [@bleyerj](https://fenicsproject.discourse.group/u/bleyerj)\
**Post date:** [October 8, 2019, 10:21am UTC](https://fenicsproject.discourse.group/t/eigenvalue-problem-not-satisfying-bcs/1690/2 "2019-10-08T10:21:54Z")

</div>

Hello,  
first it does not make any sense to compute eigenmodes with non-zero DirichletBC. Second, considering row number i of the eigenvalue system with i corresponding to a DirichletBC dof, you are replacing  
A\_{ij}u\_j = \lambda M\_{ij}u\_j with u\_i=0  
since `bc.apply` replaces row i with a row of zeros and a 1 on the diagonal and `bc.zero` replaces row i with a full row of zeros. It is then normal to find a solution with zero DirichletBC.
