Evaluate expression at a specific value

I want to use FEniCS to evaluate an expression (f below) at a particular argument value. The below works (2018.1) but is ugly, and I think I’m missing something.

from fenics import *
from ufl import replace

mesh = RectangleMesh(Point(0,0), Point(1,1) ,10,10)
P = FiniteElement("Lagrange", mesh.ufl_cell(),1)

c = Function(FunctionSpace(mesh,P))

f = c**2
f_at_1 = replace(f,{c:1})
print(f_at_1(0))

returns ‘1’ as expected.

Hi Mike,

check tests for UFL evaluation here, https://github.com/FEniCS/ufl/blob/master/test/test_evaluate.py, especially testCoefficient() for evaluation of expression containing a Function (Coefficient in UFL terms).