What does it take to create a Primitive ufl operator in 1d that returns the function
$$\int_0^x{u(t)dt}$$
that is similar to other ufl operator and can be used in forms?
I tried
class Primitive(ufl.Coefficient, dolfin.cpp.Expression):
def __init__(self,f,mesh,element,constant= 0.0, **kwargs):
dolfin.cpp.Expression.__init__(self)
self._f = f
self._mesh = mesh
self._constant = constant
subdomains = CellFunction('size_t',mesh)
self._subdomains = subdomains
dx = Measure('dx',domain=mesh)[subdomains]
self._dx=dx
self._F = Form(f*dx(1))
ufl.Coefficient.__init__(self, element, count=self.id())
def eval(self, values, x):
inside_function = lambda y: y<=x[0]
domain = AutoSubDomain(inside_function=inside_function)
self._subdomains.set_all(0)
domain.mark(self._subdomains,1)
F = self._F
values[0] = assemble(F) + self._constant
def eval_cell(self, values, x, cell):
self.eval(values,x)
def ufl_evaluate(self,x, component, derivatives):
values = np.zeros(1,dtype='d')
self.eval(values,x)
return values[0]
I can then do
mesh = UnitInterval(100)
V = FunctionSpace(mesh,'CG',1)
u = Expression("x[0]")
Pu = Primitive(u,mesh, V.ufl_element())
plot(Pu,mesh=mesh)
My question: is this enough to make Pu behave like other ufl operators [ exp(u), ln(u) ...] in forms?