pytrnsys_process.deck package#

Submodules#

pytrnsys_process.deck.extractor module#

pytrnsys_process.deck.extractor.parse_deck_for_constant_expressions(deck_as_string: str, logger: ~logging.Logger = <Logger default_pytrnsys_process (WARNING)>) dict[str, float | int][source]#

Evaluate constant expressions in a TRNSYS deck file and return their values.

This function parses a TRNSYS deck file string, identifies constant expressions, and evaluates them to their numerical values. It handles mathematical operations, functions, and variable references.

Parameters:
  • deck_as_string (A string containing the contents of a TRNSYS deck file.)

  • logger (provide your own logger. to for example log per simulation)

Returns:

variable_values – A dictionary mapping variable names to their evaluated values (float or int). The original case of variable names is preserved in the returned dictionary. Expressions that could not be evaluated are not included in the returned dictionary.

Return type:

dict

class pytrnsys_process.deck.extractor.EquationsCollectorVisitor[source]#

Bases: Visitor

This visitor is given the whole deck as a tree. For each equation the equation() method is called and it appends it to a list of equations

__init__()[source]#
equation(tree)[source]#
class OutputOfTrnsysTypeDetector[source]#

Bases: Visitor_Recursive

Detects if equation is an output: equation_name = [15,1]

__init__()[source]#
output(_)[source]#
class pytrnsys_process.deck.extractor.EquationsTransformer(evaluated_variables: Mapping[str, float | int])[source]#

Bases: Transformer

__init__(evaluated_variables: Mapping[str, float | int])[source]#
number(items)[source]#
negate(items)[source]#
plus(items)[source]#
minus(items)[source]#
divided_by(items)[source]#
times(items)[source]#
to_power_of(items)[source]#
default_visibility_var(items) float[source]#
func_call(meta, items)[source]#

Mathematical function behaviour is described in pages 20 and 21 of trnsys doc 6 TRNedit

explicit_var(items)[source]#
exception pytrnsys_process.deck.extractor.MathFuncNotFoundError(message, meta)[source]#

Bases: Exception

This error is raised if the parsed ‘func_call’ is not supported.

__init__(message, meta)[source]#
exception pytrnsys_process.deck.extractor.ReferencedVariableNotEvaluatedError[source]#

Bases: Exception

Raised if an equation could not be found in the dictionary of resolved equations.

pytrnsys_process.deck.parser module#

pytrnsys_process.deck.parser.parse_dck(ddck_content: str) Tree[source]#

pytrnsys_process.deck.visitor_helpers module#

pytrnsys_process.deck.visitor_helpers.get_child_token_value(token_type: str, tree: Tree, conversion_function: Callable[[str], _T]) _T[source]#
pytrnsys_process.deck.visitor_helpers.get_child_token_value_or_none(token_type: str, tree: Tree, conversion_function: Callable[[str], _T]) _T | None[source]#
pytrnsys_process.deck.visitor_helpers.get_child_token_or_none(token_type: str, tree: Tree) Token | None[source]#
pytrnsys_process.deck.visitor_helpers.get_child_token_values_or_empty_sequence(token_type: str, tree: Tree) Sequence[str][source]#
pytrnsys_process.deck.visitor_helpers.get_child_token(token_type: str, tree: Tree) Token[source]#
pytrnsys_process.deck.visitor_helpers.get_child_tokens_or_empty_sequence(token_type: str, tree: Tree) Sequence[Token][source]#

Module contents#

pytrnsys_process.deck.parse_deck_for_constant_expressions(deck_as_string: str, logger: ~logging.Logger = <Logger default_pytrnsys_process (WARNING)>) dict[str, float | int][source]#

Evaluate constant expressions in a TRNSYS deck file and return their values.

This function parses a TRNSYS deck file string, identifies constant expressions, and evaluates them to their numerical values. It handles mathematical operations, functions, and variable references.

Parameters:
  • deck_as_string (A string containing the contents of a TRNSYS deck file.)

  • logger (provide your own logger. to for example log per simulation)

Returns:

variable_values – A dictionary mapping variable names to their evaluated values (float or int). The original case of variable names is preserved in the returned dictionary. Expressions that could not be evaluated are not included in the returned dictionary.

Return type:

dict