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

24
views
-1
9 weeks ago by
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 = 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)
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