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

taking an exponential of a float and interpolation.

0 votes

I have a little problem.

As indicated in subject I am having a problem getting the exponential of a product of a float and interpolation. Below is just a construction for my problem.

             from dolfin import *
             import numpy

             mesh = IntervalMesh(20, 0, 2)
             V = FunctionSpace(mesh, 'CG', 2)

             theta_k = interpolate(Constant(0.0), V)

            def fun(y):
                alpha = 0.01
                return numpy.exp(-alpha*y)

            # I have to call this fun for theta_k.
             fun(theta_k) # Attribute error : exp

I know why I am getting this error, since I am trying to multiply alpha with theta_k(which is not float). How can I achieve this multiplication and then the exponential of the product.

Any help would be greatly appreciated.

asked Oct 1, 2014 by Orange FEniCS Novice (470 points)

1 Answer

+1 vote
 
Best answer

You can't directly apply numpy methods to fenics functions. You have to either modify the coefficient vector y.vector().array(), or use fenics expressions, for example

e_theta = interpolate(Expression('exp(alpha*theta)',alpha=alpha,theta=theta_k) 
answered Oct 7, 2014 by clason FEniCS Novice (880 points)
selected Sep 5, 2015 by Orange
...