The magic behind dolfin.functions.expression.Expression
is essentially to convert a cpp_code string to a ufl.Coefficient
that can be used to create forms. What if instead of the cpp_code string you have a dolfin.cpp.function.Expression
class. How do you wrap it so it behaves like a proper ufl.Coefficient
? The way I have been doing it is like this.
Let's say I have a custom class MyChildCppExpression
that inherits from Expression in c++ and MyChildCppExpression
is exposed in python. I can do
class MyPythonExpression(ufl.Coefficient, MyChildCppExpression):
def __init__(self, function_space):
MyChildCppExpression.__init__(self)
ufl.Coefficient.__init__(self, function_space,
count=self.id())
This will compile in the JIT compiler but I am afraid I am missing something. For example this construct tends to compile everytime I simulate the same problem. I wonder if I should be using the function create_compiled_expression_class
or if I should redefine Expression.__new__
to use MyChildCppExpression
instead of a cpp_code string.