NumericHandler

class simu.NumericHandler

This class implements the function object describing the top level model.

__init__(
model: ModelProxy,
port_properties: bool = True,
)

The option port_properties determines whether the properties of connected materials are also reported from a child model’s perspective by the name of their ports.

property function: QFunction

Create a Function object based on currently available argument and result structures.

vector_arg_names(key: str) Sequence[str]

Return the names for the argument vector of given key

vector_res_names(key: str) Sequence[str]

Return the names for the result vector of given key

property arguments: Mapping[str, Quantity]

The function arguments as numerical values. A DataFlowError is thrown, if not all numerical values are known. A deepcopy of the structure is provided, so the returned data can be altered without side effects.

export_state() NestedMutMap[str]

Export the internal state of the model in a hierarchical structure, whereas all thermodynamic states are given in \(T, p, n\).

As by the philosophy of the chosen approach, only the thermodynamic models know how to obtain their internal state from any \(T, p, n\) specification.

The returned structure is meant to be easy to store for instance in yaml or json format, and easy to edit. One can use parse_quantities_in_struct() to convert the values of the data structure into Quantity objects for programmatic processing.

import_state(
state: NestedMap[str],
allow_missing: bool = False,
allow_extra: bool = False,
) NestedMap[str]

Imports the state data in terms of \(T, p, n\) as exported by export_state().

Parameters:
  • state – A nested mapping as returned by export_state(), containing the two first-level keys thermo (for thermodynamic states) and non-canonical for non-canonical states.

  • allow_missing – If true, throw a ValueError if there are model states in the model that are not defined in the given state structure.

  • allow_extra – If false, throw a ValueError if there are states in the given state structure that are not present in the model.

Returns:

A nested mapping of same structure as state, but containing states that are not present in the model (value = extra) and states that were not given as part of state (value = missing)

retain_state(
state: Sequence[float],
parameters: NestedMap[Quantity],
)

Given a numeric state vector and the current set of parameters as a nested mapping of quantities, store the values for temperature, pressure and molar quantities back into the internal representations of the initial thermodynamic states.

extract_parameters(
key: str,
definition: NestedMap[str],
) Quantity

collect the parameter symbols addressed by the definition argument, which defines the unit of measurement for each parameter - as the numerical parameter vector elements must be considered dimensionless.

Note

Unfortunately, we cannot easily allow unit conversion (even compatible units) at this point, as the parameters are already independent variables used to build up the symbolic graph. Well, it can be done by first building the original function, and then call the function as f(c(x)), where c(x) is the unit conversion.

These parameter symbols and values are then removed from the original argument structure and instead added to the vector entry as dimensionless entities.

Parameters:
  • key – The name to be used for the parameter set

  • definition – The parameters to be extracted

collect_properties(
key: str,
definition: NestedMap[str],
) Quantity

Collect the property symbols addressed by the definition argument, which defines the unit of measurement for each property to be scaled with - as the numerical property vector elements must be dimensionless.