I have written a complicated expression as a subclass-expression with changeable parameters following examples found on the forum. Unfortunately, the approach is prohibitively slow. In the reference on expressions it is stated that writing a JIT-compiled expression on the form
code = '''class MyFunc : public Expression {
};'''
cell_data = CellFunction('uint', V.mesh())
f = Expression(code)
f.cell_data = cell_data
is much faster. However, in the documentation there are no examples of how to actually write a user-defined JIT-compiled Expressions with changeable parameters. Does anyone know how to write a JIT-compiled expression in the above form of the simple subclass defined expression given below ?
class MyExpression(Expression):
def __init__(self, a, b,element):
self.a = a
self.b = b
self._ufl_element = element
def eval(self, value, x):
dx = x[0] - self.a
dy = x[1] - self.b
value[0] = exp(-(dx*dx + dy*dy)/0.02)
value[1] = exp(-(dx*dx + dy*dy)/0.02)
def value_shape(self):
return (2,)
mesh = UnitCircle(20)
V = FunctionSpace(mesh, "BDM", 1)
f = MyExpression(a=0.5,b=0.5,element=V.ufl_element())