pyrc.core.network#

class RCNetwork(save_to_pickle: bool = True, load_from_pickle: bool = True, load_solution: bool = True, num_cores_jacobian: int = 1, settings: ~pyrc.core.settings.Settings = <pyrc.core.settings.Settings object>, rc_objects: ~pyrc.core.components.templates.RCObjects = <pyrc.core.components.templates.RCObjects object>, rc_solution: ~pyrc.core.components.templates.RCSolution = <pyrc.core.components.templates.RCSolution object>, continue_canceled: bool = True, skip_infinity_check: bool = False)#

Bases: object

Parameters:
  • save_to_pickle

  • load_from_pickle

  • load_solution

  • num_cores_jacobian

  • settings

  • rc_objects

  • rc_solution

  • continue_canceled (bool, default=True) – If True, continue canceled simulations. Overwrites load_solution

  • skip_infinity_check (bool, default=False) – If True the infinity check of the created matrices is skipped. This is recommended for complicated dynamic (time-dependent) systems.

__init__(save_to_pickle: bool = True, load_from_pickle: bool = True, load_solution: bool = True, num_cores_jacobian: int = 1, settings: ~pyrc.core.settings.Settings = <pyrc.core.settings.Settings object>, rc_objects: ~pyrc.core.components.templates.RCObjects = <pyrc.core.components.templates.RCObjects object>, rc_solution: ~pyrc.core.components.templates.RCSolution = <pyrc.core.components.templates.RCSolution object>, continue_canceled: bool = True, skip_infinity_check: bool = False)#
Parameters:
  • save_to_pickle

  • load_from_pickle

  • load_solution

  • num_cores_jacobian

  • settings

  • rc_objects

  • rc_solution

  • continue_canceled (bool, default=True) – If True, continue canceled simulations. Overwrites load_solution

  • skip_infinity_check (bool, default=False) – If True the infinity check of the created matrices is skipped. This is recommended for complicated dynamic (time-dependent) systems.

property all_objects: list#
change_static_dynamic(calculate_static: bool | str)#
check_courant(time_step: float)#

Calculates the Courant number for the whole network and raises an error if its larger than 1.

Parameters:

time_step (float) – The maximum time step in seconds.

Raises:

HighCourantNumberError : – If the courant number is greater than 1 the network will calculate shit.

copy_dict()#
create_network(*args, **kwargs)#
determine_max_step() float | None#
get_node_by_id(_id: str | int)#

Returns the node with the given id.

Parameters:

_id (str | int) – The id of the node.

Return type:

TemperatureNode | InternalHeatSource

get_symbols_and_values() tuple[list, list]#

Return two lists of first: all symbols and second: all associated values of all rc objects.

Return type:

tuple[list, list]

property hash#

Compute a deterministic hash for the RCNetwork where node identity (class name + obj.id) and topology matter.

For Capacitor instances, an optional internal_heat_source (identified by its id) is encoded as a node attribute.

For Cell subclass instances, position and delta arrays are encoded.

Returns:

SHA-256 hex digest of the canonical edge and node representation.

Return type:

str

property inhomogeneous_system: bool#

Returns True if inputs are existing and the network is inhomogeneous. False otherwise.

Returns:

True if inputs are existing and the network is inhomogeneous. False otherwise.

Return type:

bool

property input_matrix: SparseMatrix | ImmutableSparseMatrix | spmatrix | sparray#
property input_matrix_function: Callable#
property input_matrix_symbol: MutableSparseMatrix | ImmutableSparseMatrix#
property input_vector: ndarray#
property input_vector_symbol: ndarray#
property inputs: list[EquationItemInput]#
load_initial_values(return_bool: bool = False, pickle_path_single_solution: str = None) None | bool#

Loads the last time step solution (temperature vector) and sets it as initial values.

load_matrices()#
make_system_matrices()#

Creates the Jacobian matrices of the RC Network.

If self.load_from_pickle the whole network will be loaded from pickle file if it exists to prevent heavy calculations.

Returns:

The system matrix as sympy expression.

Return type:

sympy expression

matrix_to_latex_diag()#
no_infinity(sp_matrix: SparseMatrix | spmatrix | sparray) bool#

Checks the given sparse matrix for infinity entries and symbolic singularities.

Notes

Saves a dict, which maps each free sympy symbol to a set of values at which at least one symbolic entry diverges. Empty if no symbolic entries exist.

Parameters:

sp_matrix (SparseMatrix | spmatrix | sparray) – A sparse matrix/vector to check, may contain numeric values or sympy expressions.

Returns:

bool : True if no numeric infinity was found.

Return type:

tuple[bool, dict]

property nodes#
property pickle_path: str#
pickle_path_result(t_span, name_add_on=None)#
property pickle_path_single_solution: str#
pickle_path_solution(t_span, name_add_on=None) str#
remap_symbol_function(symbols: Iterable[Symbol] | Symbol, function: Callable, wanted_order: Iterable[Symbol] | Symbol = None) Callable#

Remap the functions return so that it maps self.get_time_dependent_symbols(). The symbols iterable shows the order of the current return.

Parameters:
  • symbols (Iterable[Symbol] | Symbol) – The order of the current return of the function.

  • function (Callable) – The function that calculates the values for the symbols in the symbols iterable.

  • wanted_order (Iterable[Symbol] | Symbol, optional) – A list with the expected order of the function output. If None, self.get_time_dependent_symbols() is used.

Returns:

The function which return was reordered.

Return type:

Callable

reset_properties()#
property resistors_filtered_equivalent: list[Resistor]#

Get all resistor objects which equivalent resistor symbols are unique in defined order.

In other words: If two Capacitors are connected over multiple Resistors (parallel or serial) only one of these is returned.

The order is kept like in self.rc_objects.resistors, except all objects that are filtered out.

Returns:

All resistor objects without doubled equivalent symbols.

Return type:

list[Resistor]

property save_folder_path#
save_last_step_solution(pickle_path_single_solution: str = None)#

Saves the last time step solution.

save_matrices()#
solve_network(t_span: tuple, print_progress=False, name_add_on: str = '', check_courant: bool = True, time_dependent_tuple: tuple[Iterable, Callable] | None = None, time_dependent_tuple_input: tuple[Iterable, Callable] | None = None, hook_function: Callable = None, expected_solution_size_mb=5000, **kwargs: dict[str, int | Any])#

Solves the network at the given times.

If time_vector is None, one second is calculated.

Parameters:
  • t_span (tuple | Any) – Interval of integration (t0, tf). The solver starts with t=t0 and integrates until it reaches t=tf. Both t0 and tf must be floats or values interpretable by the float conversion function.

  • print_progress (bool, default=False) – If True, some print-outs are made during solving to get the time step that is currently simulated.

  • name_add_on (str, default="") – Optional add-on to the name of in-between saves that is placed after the hash value (separated by “_”). Example save name: 42395d3d9f07f06ce9c9cb609b406aa54fc2dc5e8c4d9cc75987d9a02541ad2f_nameAddOn_zw_000001080_h.pickle

  • check_courant (bool, default=True) – If True, self.check_courant(0.4) is run before simulating.

  • time_dependent_tuple (tuple[Iterable, Callable] | None, optional) – A ordered list with the time dependent symbols and the function that calculates their values. The list represents the order of the output of the function. The function calculates the value of the time dependent symbols in the order of the list. It gets passed the time step, temperature vector and input vector (last one only if existing): value1, value2, … = my_function(time_step, temperature_vector, input_vector)

  • time_dependent_tuple_input (tuple[Iterable, Callable] | None, optional) –

    A ordered list with the time dependent input vector symbols and the function that calculates their values. The list represents the order of the output of the function. A function that calculates all time dependent variables within the time step and returns them in the same order as RCNetwork.variable_input_vector_symbols. It gets parameters like this:

    time_dependent_function(time, temperature_vector)

    This function is required if time dependent symbols exist in the input vector. It must return an iterable (e.g. list).

  • hook_function (Callable, optional) – A function that is run before the network is solved using solve_ivp. Can be used to catch the time before the solving actually starts (e.g. used in PerformanceTest).

  • expected_solution_size_mb (int | float, default=5000) – The expected solution size in Megabytes. Is used for RAM-Management in SystemHandler.solve(). The solution size depends on the size of the RC network and number of saved time steps.

  • kwargs (dict[str: int | Any], optional) – Passed to SystemHandler.

solve_stationary(time_step: float | int = 0)#

Determines the analytic solution of the network (if it exists). It works for symbolic and numeric matrices.

Parameters:

time_step (float | int, default=0) – The time step as which the solution is saved in the rc_solution object. This parameter has no effect if the network is symbolic.

Returns:

Stationary symbolic temperature vector of shape (n, 1) (only if result is symbolic, otherwise nothing is returned and the result is written to the rc_solution object using time_step).

Return type:

sp.Matrix | MutableDenseMatrix or None

property system_handler_type#

Returns the SystemHandler type depending on which system (in/homogeneous) is needed.

Returns:

The system handler type.

Return type:

type

property system_matrix: SparseMatrix | ImmutableSparseMatrix | spmatrix | sparray#
property system_matrix_function: Callable#
property system_matrix_symbol: MutableSparseMatrix | ImmutableSparseMatrix#
property system_objects_unique: list[Resistor | Capacitor]#

Returns all Resistor and Capacitor objects that are needed for system and B-matrix (using resistors_filtered_equivalent instead of all resistors).

Returns:

All (equivalent representative) Resistors and Capacitor objects in the network.

Return type:

list[Resistor|Capacitor]

property system_symbols: list#

Returns a list with all R and C symbols for A- and B-matrix.

Returns:

All R and C symbols for A- and B-matrix.

Return type:

list

property system_values: list#

Returns a list with all R and C values for A- and B-matrix.

Returns:

All R and C values for A- and B-matrix (might be sympy Expressions).

Return type:

list

property temperature_vector: ndarray#
property temperature_vector_symbol: list#
property time_dependent_input_symbols#

A list with all time dependent input symbols of the system (u vector).

Return type:

list

property time_dependent_system_symbols: list#

A list with all time dependent symbols of the system (A-matrix).

Returns:

The time dependent symbols of the system (appearing in system (A) matrix).

Return type:

list

property time_steps: list#

Returns a list with all time steps.

Returns:

The time steps.

Return type:

list

property variable_input_vector_symbols: list#

A list of all symbols in the input vector.

Returns:

The symbols in the input vector.

Return type:

list