pyoomph.expressions.cb module

class pyoomph.expressions.cb.CustomMathExpression[source]

Bases: CustomMathExpression

A custom math expression class.

This class allows to provide custom expressions programmed in python. After creating, you can call the object with Expression arguments to obtain the symbolical function call. This can be then used as normal Expression. When the C code is generated, we will call back the eval method to obtain the numerical result.

By default, finite difference derivatives are calculated. If you can provide a symbolic derivative, you can override the derivative method.

fd_epsilon

The finite difference epsilon value for numerical differentiation.

Type:

float

derivative(index)[source]

Calculate the derivative of the expression with respect to a given index. Override it specifically, if you can provide a symbolical derivative of the eval function with respect to the argument at index i.

Parameters:

index (int) – The index of the variable with respect to which the derivative is calculated.

Returns:

The derivative of the expression.

Return type:

CustomMathExpression

abstract eval(arg_array)[source]

Evaluate the expression with the given array of arguments. This function must be implemented in the derived class to specify the functionality of the CustomMathExpression.

Parameters:

arg_array (NPFloatArray) – The array of arguments to evaluate the expression.

Returns:

The evaluated expression result.

Return type:

float

Raises:

RuntimeError – If the eval function is not implemented.

get_argument_unit(index)[source]

Get the expected unit of the argument at the given index. Before eval is called, the arguments are divided by this units to make them dimensionless.

Parameters:

index (int) – index of the argument for which we want to get the unit

Returns:

Unit of the argument at the given index

Return type:

Expression

get_id_name()[source]

Get the name of the expression class.

Returns:

The name of the expression class.

Return type:

str

get_result_unit()[source]

Get the result unit. After eval is called, the result will be multiplied by this unit.

Returns:

Result unit

Return type:

Expression

outer_derivative(x, index)[source]

Calculate the outer derivative of the expression with respect to a given index.

Parameters:
  • x (Expression) – The expression with respect to which the derivative is calculated.

  • index (int) – The index of the variable with respect to which the derivative is calculated.

Returns:

The outer derivative of the expression.

Return type:

Expression