I know this sounds peculiar, but I'm wondering if there's a way to do this. I'm solving a problem in which the source term depends on the gradient of a function defined over the entire mesh. This function, h, is computed as a Python expression. Most often this expression uses a FEniCS object defined over the mesh as an argument, and so grad
knows the domain that it's working with. However, I'd like to have the flexibility to allow for this function, h, to be a constant. I can include a conditional statement to achieve the desired behavior, but I was curious if there is a more elegant approach.
To make my question more concrete, here is a simple example:
from dolfin import *
from mshr import *
N = 32
mesh = generate_mesh( Rectangle( dolfin.Point( 0., 0. ),
dolfin.Point( 1., 1. ) ), N )
g = Expression("x[0] + x[1]*x[1]", domain=mesh)
h = 10.
f = dot( grad(g), grad(h) )
This results in an error with grad
, and returns
ufl.log.UFLException: Cannot get geometric dimension from an expression with no domains!
On the other hand, if my function is h = 10.*g
, everything works as expected.