how to run code faster

3 months ago by
Let me start with the code I have so far (this has been a product of a lot of help from this community so thanks in advance)

from pylab import *
from fenics import *
import dolfin
from mshr import *
import matplotlib.pyplot as plt
import sympy as sp

n = 2
#Define 3D geometry
sphere1 = Sphere(Point(0, 0, 0), 1.0)
sphere2 = Sphere(Point(0, 0, 0), 0.5)
g3d = sphere1 - sphere2
mesh = generate_mesh(g3d,10)


V = FunctionSpace(mesh,"CG", 3)
n = FacetNormal(mesh)

# Define basis and bilinear form
u = TrialFunction(V)
v = TestFunction(V)


a = dot(grad(u), grad(v))*dx + beta*dot(grad(u)-dot(grad(u),n)*n, grad(v)-dot(grad(v),n)*n)*ds
m = u*v*ds

#Containers for stiffnes and mass matrices
A = PETScMatrix()
M = PETScMatrix()
#L = PETScMatrix()

#Global assembly of Stiffness and mass matrices
A = assemble(a, tensor=A)
M = assemble(m, tensor=M)
#L = assemble(l, tensor=L)

eigensolver = SLEPcEigenSolver(A,M) # create solver for Kx = lambda Mx
eigensolver.parameters['solver'] = 'lapack' # solve with LAPACK
eigensolver.parameters['spectrum']= 'smallest real'
eigensolver.parameters['tolerance'] = 1.e-15

print('computing eigenvalues')
#r,c,rv,cv = eigensolver.get_eigenpair(0,None,None)
#print r,c,rv,cv

for i in range(2):
eval = eigensolver.get_eigenvalue(i)
print eval

print "number of iterations", eigensolver.get_iteration_number()

plot(mesh, interactive=True)

As the code suggests, I am trying to find the eigevanlues of the Wentzell problem. Anyways, I want to run my code with this line 

mesh = generate_mesh(g3d,40)

Instead of 
mesh = generate_mesh(g3d,10)

However, if I use 40 instead of 10 it takes forever to complete the execution is there any way to make the execution more efficient? 

Also, Can somebody tell me what that number means?, I searched  documentation for the function generate_mesh() and I didn't find anything. 

The reason why I want to increase this value is because it seems that when it is bigger than 10 my eigevanlue converge to the value a I am looking for, so I just want to run some tests to see if that it is the case.


Community: FEniCS Project
I believe LAPACK uses QR factorization, perhaps you can use one of SLEPc's Krylov solvers?
written 3 months ago by pf4d  
LAPACK is a dense solver too if I recall correctly. Anything with more than 4,000 DoFs will be horrific to solve. Krylov-schur or Arnoldi iteration via SLEPc is the way to go like pf4d says. Even then, this looks like a nasty problem. At a quick glace, the FEM formulation looks Hermitian, you can make large gains in performance by telling the solver this. You also get the attractive feature that your solutions will be orthonormal with respect to the mass matrix.
written 3 months ago by Nate  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »