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

Exponential of a Function gives negative values.

+2 votes

Hi,

I have a Function variable u on a FunctionSpace V ("Lagrange",1).

If I construct f, where

f = project(exp(u),V)

or

f = project(2.7182818284**u,V)

all values of f are greater than zero.

However, if I construct

f = project(exp(u/Constant(0.1)),V)

or

f = project(2.7182818284**(u/Constant(0.1)),V)

f will be less then zero at certain points.

I don't see how this could be. Has this happened to anyone else?

Unfortunately it's proving difficult constructing a toy model to reproduce the error.

Thanks

[edit] - Here is a toy script that gives the strange result

from dolfin import *

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh,"Lagrange",1)

q = project(Expression("10*sin(x[0]*6)"),V)
f = project(exp(q),V)

print min(f.vector())

I am solving a nonlinear poisson equation and it seems this error really messes with the result.

asked Sep 8, 2014 by sixtysymbols FEniCS User (2,280 points)
edited Sep 8, 2014 by sixtysymbols

Can you use interpolate instead of project ?

This worked! Thanks

1 Answer

+1 vote
 
Best answer

chris_richardson's suggestion worked.

Here is how I managed to implement interpolate in the toy script.

from dolfin import *

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh,"Lagrange",1)

q = interpolate(Expression("10*sin(x[0]*6)"),V)

f = interpolate(Expression("exp(f)",f=q),V)

print min(f.vector())
answered Sep 10, 2014 by sixtysymbols FEniCS User (2,280 points)
selected Sep 10, 2014 by sixtysymbols
...