This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Laplacian of an Expression

+1 vote

Dear all

I have an expression as below and I want the Laplacian of this. Is there an easy way to get it ?

Thanks

from scipy.special import j0, j1
from math import atan2
class psiinit(Expression):
   def eval(self,values,x):
       k  = 3.83170597020751 # first zero of J1
       c  = 2.0/(k*j0(k))
       r2 = x[0]**2 + x[1]**2
       r  = sqrt(r2)
       t  = atan2(x[1],x[0])
       if r < 1:
           values[0] = c*j1(k*r)*cos(t)
       else:
           values[0] = (r - 1/r)*cos(t)
asked Apr 10, 2017 by praveen FEniCS User (2,760 points)

1 Answer

+1 vote
 
Best answer

You need to create the ufl expression and then project it to some space. I will use the following:

V = FunctionSpace(mesh, 'CG', 1)

Now, use the following:

f = psiinit( element = FiniteElement('CG', mesh.ufl_cell(), 3))
lap = div(grad(f))

lap would be enough to create a form. If you need to plot it or evaluate it, projection would be required:

Plap = project(lap, V)

Note that I used degree = 3 in f, because derivation is done at the discrete level, so less than 2 will give a null laplacian.

Best regards!

answered Apr 11, 2017 by nabarnaf FEniCS User (2,940 points)
selected Apr 11, 2017 by praveen
...