pymor.analyticalproblems.expressions
¶
This module contains a basic symbolic expression library.
The library is used by ExpressionFunction
and ExpressionParameterFunctional
by calling parse_expression
, which parses str
expressions by replacing
the names in the string with objects from this module. The result is an
Expression
object, which can be converted to a NumPy
-vectorized function
using Expression.to_numpy
. In the future, more conversion routines will
be added to make the same Expression
usable for pymor.discretizers
that use external PDE solvers. Further advantages of using this expression library:
meaningful error messages are generated at parse time of the
str
expression, instead of hard-to-debug errors in lambda functions at evaluation time,expressions are automatically correctly vectorized. In particular, there is no longer a need to add
...
to indexing expressions,the shape of the resulting expressions is automatically determined.
In the future, we will also provide support for symbolic differentiation of the
given Expression
.
Every Expression
is built from the following atoms:
a
Constant
, which is a fixed value of arbitrary shape,a
Parameter
, which is a variable of a fixed one-dimensional shape.
Note that both Parameters
and input variables are treated as a Parameter
in the expression. Only when calling, e.g., to_numpy
, it is
determined which Parameter
belongs to the resulting function’s Parameters
and which Parameter
is treated as an input variable.
More complex expressions can be built using:
For binary operations of Expressions
of different shape,
the usual broadcasting rules apply.
Module Contents¶
- class pymor.analyticalproblems.expressions.Array(array)[source]¶
Bases:
Expression
An array of scalar-valued
Expressions
.
- class pymor.analyticalproblems.expressions.BaseConstant[source]¶
Bases:
Expression
A constant value.
- class pymor.analyticalproblems.expressions.BinaryOp(first, second)[source]¶
Bases:
Expression
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Constant(value)[source]¶
Bases:
BaseConstant
A constant value given by a
NumPy
array.Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.Diff(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Div(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.E[source]¶
Bases:
BaseConstant
A constant value.
- class pymor.analyticalproblems.expressions.Expression[source]¶
Bases:
pymor.parameters.base.ParametricObject
A symbolic math expression.
- to_numpy(variables)[source]¶
Convert expression to a
NumPy
-vectorized callable.Parameters
- variables
List of names of
~Parameters
in the expression which shall be treated as input variables.
- class pymor.analyticalproblems.expressions.GE(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.GT(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Indexed(base, index)[source]¶
Bases:
Expression
Indexed
Expression
.
- class pymor.analyticalproblems.expressions.LE(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.LT(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Mod(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Neg(operand)[source]¶
Bases:
Expression
Negated
Expression
.
- class pymor.analyticalproblems.expressions.Parameter(name, dim)[source]¶
Bases:
Expression
A free parameter in an
Expression
.Parameters represent both pyMOR
Parameters
as well as input variables. Each parameter is a vector of shape(dim,)
.Parameters
- name
The name of the parameter.
- dim
The dimension of the parameter.
- class pymor.analyticalproblems.expressions.Pi[source]¶
Bases:
BaseConstant
A constant value.
- class pymor.analyticalproblems.expressions.Pow(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Prod(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.Sum(first, second)[source]¶
Bases:
BinaryOp
Compound
Expression
of a binary operator acting on two sub-expressions.
- class pymor.analyticalproblems.expressions.TransformChainedComparison[source]¶
Bases:
ast.NodeTransformer
Transformer for chained comparisons.
Methods
- class pymor.analyticalproblems.expressions.TransformLiterals[source]¶
Bases:
ast.NodeTransformer
Transformer for literals.
- class pymor.analyticalproblems.expressions.UnaryFunctionCall(arg, *args)[source]¶
Bases:
Expression
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.UnaryReductionCall(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.abs(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.angle(arg)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.arccos(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arccosh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.arcsin(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arcsinh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.arctan(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.arctanh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.cos(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.cosh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.exp(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.exp2(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.log(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.log10(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.log2(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.max(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.min(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.norm(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
Methods
Called by
to_fenics
.
- class pymor.analyticalproblems.expressions.prod(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.sign(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sin(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sinh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sqrt(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.sum(arg, *args)[source]¶
Bases:
UnaryReductionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied to the entire vector/matrix/tensor the sub-expression evaluates to, returning a single number.
- class pymor.analyticalproblems.expressions.tan(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.
- class pymor.analyticalproblems.expressions.tanh(arg, *args)[source]¶
Bases:
UnaryFunctionCall
Compound
Expression
of an unary function applied to a sub-expression.The function is applied component-wise.