### (Deleted) Eigenfunctions of the Laplacian with Neumann Boundary Conditions

24

views

-1

I would like to compute Eigenfunctions of the Laplacian with Neumann Boundary Conditions, first on simple domains, later on more complicated ones. Why does this on not work?

```
from dolfin import *
mesh = UnitSquareMesh(64, 64)
V = FunctionSpace(mesh, "Lagrange", 3)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v))*dx
A = PETScMatrix()
assemble(a, tensor=A)
eigensolver = SLEPcEigenSolver(A)
eigensolver.solve()
r, c, rx, cx = eigensolver.get_eigenpair(0)
print "Largest eigenvalue: ", r
u = Function(V)
u.vector()[:] = rx
import matplotlib.pyplot as plt
plot(u)
plt.show()
```

Later I tried this:

```
from dolfin import *
# Define mesh, function space
mesh = UnitSquareMesh(64, 64)
V = FunctionSpace(mesh, "Lagrange", 1)
# Define basis and bilinear forms
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v))*dx
b = u*v*dx
# Assemble stiffness forms
A = PETScMatrix()
B = PETScMatrix()
assemble(a,tensor=A)
assemble(b,tensor=B)
# Create eigensolver
eigensolver = SLEPcEigenSolver(A, B)
eigensolver.parameters["spectrum"]="smallest magnitude"
# Compute all eigenvalues of A x = \lambda x
print("Computing eigenvalues. This can take a minute.")
eigensolver.solve()
# Extract eigenpair
r, c, rx, cx = eigensolver.get_eigenpair(1)
print("eigenvalue = ", r)
# Initialize function and assign eigenvector
u = Function(V)
u.vector()[:] = rx
# Plot eigenfunction
import matplotlib.pyplot as plt
plot(u)
plt.show()
```

Community: FEniCS Project

Please login to add an answer/comment or follow this question.

The thread is closed. No new answer/comment may be added.