flow360.report.Expression#

class Expression#

Bases: GenericOperation

Represents a mathematical expression to be evaluated on simulation result data.

This operation allows for defining and calculating custom expressions using variables extracted from simulation results. The results of the expression evaluation can be added as a new column to a dataframe for further analysis.

Example

expr = Expression(expr=”totalCD * area”) result = expr.calculate(data, case, cases, variables, new_variable_name)

Raises:
  • ValueError – If variables in the expression are missing from the dataframe or if the expression cannot be evaluated due to syntax or other issues.

  • NotImplementedError – If the data type is unsupported by the calculate method.

expr: str [Required]#

The mathematical expression to evaluate. It should be written in a syntax compatible with the numexpr library, using variable names that correspond to columns in the dataframe or user-defined variables.

type_name: Literal['Expression'] = 'Expression'#
classmethod get_variables(expr)#

Parses the given expression and returns a set of variable names used in it.

classmethod evaluate_expression(df, expr, variables, new_variable_name, case)#

Evaluates the given expression on the provided dataframe, using the specified variables. The result is added as a new column in the dataframe.

Parameters:

variables (List[Variable])

calculate(data, case, cases, variables, new_variable_name)#

Executes the expression evaluation for the given simulation data and returns the result.