This module handles the Expression class in Python.
The Expression class needs special handling and is not mapped directly by SWIG from the C++ interface. Instead, a new Expression class is created which inherits both from the DOLFIN C++ Expression class and the ufl Coefficient class.
The resulting Expression class may thus act both as a variable in a UFL form expression and as a DOLFIN C++ Expression.
This module make heavy use of creation of Expression classes and instantiation of these dynamically at runtime.
The whole logic behind this somewhat magic behaviour is handle by:
- function __new__ in the Expression class
- meta class ExpressionMetaClass
- function compile_expressions from the compiledmodule/expression module
- functions create_compiled_expression_class and create_python_derived_expression_class
The __new__ method in the Expression class take cares of the logic when the class Expression is used to create an instance of Expression, see use cases 1-4 in the docstring of Expression.
The meta class ExpressionMetaClass take care of the logic when a user subclasses Expression to create a user-defined Expression, see use cases 3 in the docstring of Expression.
The function compile_expression is a JIT compiler. It compiles and returns different kinds of cpp.Expression classes, depending on the arguments. These classes are sent to the create_compiled_expression_class.