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)#
Bases:
object- Parameters:
save_to_pickle
load_from_pickle
load_solution
num_cores_jacobian
settings
rc_objects
rc_solution
continue_canceled (bool, optional) – If True, continue canceled simulations. Overwrites load_solution
- __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)#
- Parameters:
save_to_pickle
load_from_pickle
load_solution
num_cores_jacobian
settings
rc_objects
rc_solution
continue_canceled (bool, optional) – If True, continue canceled simulations. Overwrites load_solution
- 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)#
- 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:
- get_symbols()#
Returns a list with all symbols, except time dependent symbols.
- Returns:
All symbols, except time dependent symbols.
- Return type:
list
- 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]
- get_time_dependent_symbols() list#
A list with all time dependent symbols but each of it is only added once.
- Returns:
The time dependent symbols.
- Return type:
list
- get_values()#
Returns a list with all values, except of time dependent symbols.
- Returns:
All values, except of time dependent symbols.
- Return type:
list
- property hash#
Compute a deterministic hash for the
RCNetworkwhere 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.
- 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) 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 objects_with_identical_symbols: list#
Get all objects with symbols that are relevant for the system matrix.
You cannot just use every object, because some (e.g. Resistors) can be summarized in local groups with one symbol representing the whole group, like the equivalent resistance of multiple connected Resistors.
No
InternalHeatSources are returned, because their symbol is already represented in the corresponding Node.- Returns:
All network objects without the ones that are already taken into account by the symbols of another. The list has the same order every time it is created.
- Return type:
list
- 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#
- reset_properties()#
- 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 | ~typing.Any = None, print_progress=False, name_add_on: str = '', check_courant: bool = True, time_dependent_function: ~typing.Callable = None, hook_function: ~typing.Callable = None, expected_solution_size_mb=5000, **kwargs: dict[slice(<class 'str'>, int | typing.Any, None)])#
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, optional) – If True, some print outs are made during solving to get the time step that is currently simulated.
name_add_on (str, optional) –
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, optional) – If True, self.check_courant(0.4) is run before simulating.
time_dependent_function (Callable) – A function returning the values for all time dependent symbols that are in the matrices in the same order as self.get_time_dependent_symbols(). This function is required if time dependent symbols exist. 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, optional) – 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.
- Returns:
The solution of the network (time and temperatures of all nodes). See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html#solve-ivp
- Return type:
scipy.integrate._ivp.ivp.OdeResult
- 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 temperature_vector: ndarray#
- property temperature_vector_symbol: list#
- property time_steps: list#
Returns a list with all time steps.
- Returns:
The time steps.
- Return type:
list