pyrc.core.components.templates#

class Cell(position: ndarray | tuple, delta: ndarray | tuple = None)#

Bases: Geometric

Extends the Geometric class to a cell with length, height and depth.

Parameters:
  • position (np.ndarray) – The position of the node in 2D/3D space. If 2D, a zero is added for the z coordinate.

  • delta (np.ndarray | tuple, optional) – Delta vector [delta_x, delta_y, delta_z].

__init__(position: ndarray | tuple, delta: ndarray | tuple = None)#

Extends the Geometric class to a cell with length, height and depth.

Parameters:
  • position (np.ndarray) – The position of the node in 2D/3D space. If 2D, a zero is added for the z coordinate.

  • delta (np.ndarray | tuple, optional) – Delta vector [delta_x, delta_y, delta_z].

property boundaries: list#

Returns the boundaries of the cell.

The format looks like: [-x, x, -y, y, -z, z]

Returns:

The boundaries.

Return type:

list

create_adjacent(alignment, **kwargs)#

Create and place new cell of same type adjacent to self.

Parameters:
  • alignment (str) –

    Face alignment specification with optional pairing override. Format: Space-separated or consecutive axis specifications. Each specification: [self_dir][other_dir]axis where self_dir and other_dir are ‘+’ or ‘-‘. Default pairing: opposite faces (‘+x’ pairs with ‘-x’ of other) Examples:

    x (default opposite), xy (both default opposite),

    +-x (explicit opposite), ++x (same face),

    -y (self -y with other +y), +-x -+y (multiple axes with space)

  • **kwargs – Arguments passed to constructor (delta etc.)

Returns:

New Cell of same type as self placed adjacent to self

Return type:

Cell or subclass

classmethod create_grid(grid_size, delta: ndarray | tuple = None, center_position=None, **kwargs) ndarray#

Create a 3D grid of cells.

Parameters:
  • grid_size (tuple of int) – Number of cells (nx, ny, nz).

  • delta (float) – Total dimensions in one vector. If single delta-values are given, too, the delta vector is used.

  • delta – Total length in x,y,z direction.

  • center_position (np.ndarray, optional) – Center position of the grid. Defaults to origin.

  • **kwargs – Additional arguments passed to constructor.

Returns:

3D array of shape (nx, ny, nz) containing Cell instances.

Return type:

np.ndarray

create_grid_aligned(alignment, grid_size, total_delta, position=None, **kwargs) ndarray[Cell]#

Create a 3D grid of cells aligned to self.

Parameters:
  • alignment (str) – Face alignment specification. See _apply_alignment for format.

  • grid_size (tuple of int) – Number of cells (nx, ny, nz).

  • total_delta (float) – Total length in x,y,z direction.

  • position (np.ndarray, optional) – Base position, updated by alignment. Defaults to origin.

  • **kwargs – Additional arguments passed to constructor.

Returns:

3D array of shape (nx, ny, nz) containing Cell instances.

Return type:

np.ndarray

property delta#

Returns the delta vector.

Returns:

The delta vector.

Return type:

np.ndarray

property delta_x#
property delta_y#
property delta_z#
property depth#
property height#
property length#
place_adjacent(other_cell, alignment)#

Place other_cell adjacent to self aligned at specified face(s).

Parameters:
  • other_cell (Cell) – Cell to be placed adjacent to self

  • alignment (str) –

    Face alignment specification with optional pairing override. Format: Space-separated or consecutive axis specifications. Each specification: [self_dir][other_dir]axis where self_dir and other_dir are ‘+’ or ‘-‘. Default pairing: opposite faces (‘+x’ pairs with ‘-x’ of other) Examples: ‘x’ (default opposite), ‘xy’ (both default opposite),

    ’+-x’ (explicit opposite), ‘++x’ (same face), ‘-y’ (self -y with other +y), ‘+-x -+y’ (multiple axes with space)

property position: ndarray#
update_color(temperature: float, t_min: float = 263.15, t_max: float = 413.15, colormap='managua') None#

Update the color of the vbox for visualization.

Parameters:
  • temperature (float) – The temperature in Kelvin to set.

  • t_min (float | int, optional) – The minimal temperature for the color code.

  • t_max (float | int, optional) – The maximal temperature for the color code.

  • colormap (str, optional) – The colormap to use. See pyrc.core.visualization.color.color.py or the txt files in there respectively.

update_vbox_geometry() None#

Update position/size (geometry) of the vbox (visualization). Call only if geometry changes.

property vbox#
class CompositeMaterialFluid(*args, **kwargs)#

Bases: Fluid

Combine multiple fluid materials using ratios.

Parameters:
  • args

  • kin_viscosity (float | int | np.number) – The kinematic viscosity of the material in m^2/s.

  • prandtl_number (float | int | np.number) – The Prandtl number of the material without unit.

  • grashof_number (float | int | np.number) – The Grashof number of the material without unit.

  • kwargs

class CompositeMaterialSolid(*args, **kwargs)#

Bases: Solid

Combine multiple materials using ratios.

Container to hold all material properties.

Parameters:
  • name (str) – The name/identifier of the material.

  • density (float | int | np.number) – The density of the material in kg/m^3.

  • heat_capacity (float | int | np.number) – The heat capacity of the material in J/kg/K.

  • thermal_conductivity (float | int | np.number) – The thermal conductivity of the material in W/m/K.

class ConnectedFlowObject#

Bases: object

abstract property balance#
abstractmethod check_balance() bool#
property guess_volume_flow#
property sinks: list#
property sources: list#
property volume_flow#
class EquationItem#

Bases: SymbolMixin, ABC

item_counter = 1501#
classmethod reset_counter()#
class EquationItemInput(settings: ~pyrc.core.settings.Settings = <pyrc.core.settings.Settings object>)#

Bases: Input, EquationItem, ABC

Super class for all inputs.

Mainly used for calculation boundary conditions both time-independent and time-dependent.

The simplest way of using this class would be to just return one static value, no matter which solving time, temperature or input_vector is given. Because the __call__method is run every solver iteration it should be as performant as possible. Therefor, for constant Inputs it’s recommended to use the ConstantInput class.

class Fluid(*args, **kwargs)#

Bases: Material

Parameters:
  • args

  • kin_viscosity (float | int | np.number) – The kinematic viscosity of the material in m^2/s.

  • prandtl_number (float | int | np.number) – The Prandtl number of the material without unit.

  • grashof_number (float | int | np.number) – The Grashof number of the material without unit.

  • kwargs

property Gr#
property Pr#
__init__(*args, kin_viscosity: float | int | number = nan, prandtl_number: float | int | number = nan, grashof_number: float | int | number = nan, **kwargs)#
Parameters:
  • args

  • kin_viscosity (float | int | np.number) – The kinematic viscosity of the material in m^2/s.

  • prandtl_number (float | int | np.number) – The Prandtl number of the material without unit.

  • grashof_number (float | int | np.number) – The Grashof number of the material without unit.

  • kwargs

property grashof_number#
property kin_viscosity#
property prandtl_number#
property rayleigh_number#
class Geometric(position: ndarray | tuple, fixed_position: bool = False, fixed_z: bool = False, fixed_xy: bool = False)#

Bases: object

Skeleton for a geometric object that only contains the position in 3D space.

Defines getter and setter for X, Y and Z coordinates. If a 2D vector is given, the Z coordinate is set to 0.

Parameters:
  • position (np.ndarray) – Either 2D or 3D position of the object as array.

  • fixed_position (bool) – If True, the position cannot be changed. Overwrites both fixed_z and fixed_xy parameters.

  • fixed_z (bool) – If True, the z coordinate cannot be changed.

  • fixed_xy (bool) – If True, the x and y coordinates cannot be changed.

property position: ndarray#
property x#
property y#
property z#
class Material(*args, **kwargs)#

Bases: object

Container to hold all material properties.

Parameters:
  • name (str) – The name/identifier of the material.

  • density (float | int | np.number) – The density of the material in kg/m^3.

  • heat_capacity (float | int | np.number) – The heat capacity of the material in J/kg/K.

  • thermal_conductivity (float | int | np.number) – The thermal conductivity of the material in W/m/K.

__init__(name, density: float | int | number = nan, heat_capacity: float | int | number = nan, thermal_conductivity: float | int | number = nan)#

Container to hold all material properties.

Parameters:
  • name (str) – The name/identifier of the material.

  • density (float | int | np.number) – The density of the material in kg/m^3.

  • heat_capacity (float | int | np.number) – The heat capacity of the material in J/kg/K.

  • thermal_conductivity (float | int | np.number) – The thermal conductivity of the material in W/m/K.

static __new__(cls, *args, **kwargs)#

This blocks the creation of instances from this class because it should only be used the children of self.

Parameters:
  • args

  • kwargs

property density#
property heat_capacity#
property name#
property thermal_conductivity#
class ObjectWithPorts#

Bases: object

__iter__()#

Iterate over self.neighbours.

Returns:

The neighbours.

Return type:

ObjectWithPorts

connect(neighbour, direction: tuple | list | ndarray | Any = None, node_direction_points_to=None)#

Add the given object/neighbour to the self.neighbours list.

The neighbour itself will connect self to its neighbours list. E.g.: If node2 should be connected to node1, node2’s neighbours list appends self.

The direction is a possibility to set the direction between two connected nodes manually. It is used for connected BoundaryCondition s and Node s. The direction is set for the neighbour. The

Parameters:
  • neighbour (ObjectWithPorts) – The neighbour to connect to. It will connect self to itself. This is the Node the manual direction is set on!

  • direction (tuple | list | np.ndarray, optional) – If not None, a direction is set manually to node_direction_points_at. Either none or both node_direction_points_at and direction must be passed.

  • node_direction_points_to (TemperatureNode, optional) – If not None, this is the node to which the direction points at (looking from neighbour). Either none or both node_direction_points_at and direction must be passed. Must be a TemperatureNode.

double_connect(neighbour1, neighbour2)#
property neighbours#
property ports#

Alias for self.neighbours.

class RCObjects(nodes: list = None, resistors: list = None, boundaries: list = None)#

Bases: object

property all: list[TemperatureNode | Resistor]#

Returns all TemperatureNodes and Resistors (network objects, that are linked together).

InternalHeatSource s are not returned!

Returns:

Capacitors, BoundaryConditions and Resistors

Return type:

list[TemperatureNode | Resistor]

property all_equation_objects: list[EquationItem]#
property boundaries: list#
get_all_objects(variant: type) list#

Returns a list with tuples with all objects in the network with requested variant/type.

Parameters:

variant (type) – The type of the objects that will be returned. Will be used for the isinstance() match.

Returns:

The list with all objects in the network with requested variant.

Return type:

list

property inputs: list[EquationItemInput]#
property internal_heat_sources: list[InternalHeatSource]#
property mass_flow_nodes#
property nodes: list#
property other_equation_objects: list[EquationItem]#

Like RCObjects.all but not the connected RC objects were returned but all other EquationItem s.

This is mainly used for InternalHeatSource s and in the future for other input items.

Returns:

All other EquationItem s. Until now, it’s just all InternalHeatSource items.

Return type:

list[InternalHeatSource]

property raw_data: tuple#
property resistors: list[Resistor]#
set_lists(capacitors: list = None, resistors: list = None, boundaries: list = None)#
set_loaded_data(loaded_objects: RCObjects)#

Replaces all attributes with the ones of the loaded RCObjects.

Parameters:

loaded_objects (RCObjects) – The loaded RCObjects that should “replace” self / should be used to overwrite self.

wipe_all()#

Deletes every raw data.

class RCSolution(rc_objects: ~pyrc.core.components.templates.RCObjects = <pyrc.core.components.templates.RCObjects object>)#

Bases: object

append_to_input(new_input_vector: ndarray)#
property dataframe#
delete_last_input()#
delete_solution_except_first()#

Deletes every solution except for the time_step == 0.

delete_solutions(confirm=False)#

Use with care! Deletes all data if it’s confirm=True.

property exist: bool#
property input_exists: bool#
property input_vectors: ndarray | Any#
property inputs#
last_value_input(index)#
load_solution(path_with_name_and_ending: str, save_combined_solution: bool = True, last_time_step=None)#

Loads a pickled solution. If the file is not found it searches for incremental solutions and loads them.

This method forces the load. That the hash matches the current network is the responsibility of the user.

The search for an incremental solution is done by using the hash as the start followed by a “_” and everything after the hash is used as add-on to the name, except “_result”. So if the requested file is:

fcd7d8e0f79c611c05db6e80457b8c3f0f2a696acb5e213cc0516bed468e9497_normal_static_result.pickle

it searches for:

fcd7d8e0f79c611c05db6e80457b8c3f0f2a696acb5e213cc0516bed468e9497_normal_static_0000100_*.pickle

The number is the time step and after the time step everything can follow (“.*”).

Parameters:
  • path_with_name_and_ending (str) – The path where the solution is stored with name and ending.

  • save_combined_solution (bool, optional) – If True, the solution is saved in a pickle file if it was concatenated from incremental solutions.

  • last_time_step (int | float, optional) – The last time step which defines the complete solution. If given, it is checked if the whole solution was loaded or just a part out of it. Used, to continue canceled simulations.

property nodes#
property raw_data#
raw_data_last(starting_index)#

Like raw_data but only returns the values starting from starting_index.

Parameters:

starting_index (int) – The index where to start getting the data from.

Returns:

A list with all raw data starting from starting_index.

Return type:

list

property result_vectors: ndarray | Any#
save_last_step(file_path)#

Saves a vector with the solution of the last time step.

The saved data can be set as initial values using RCNetwork.load_initial_values

Parameters:

file_path (str | Any) – The file path with name and ending.

save_new_solution(path_with_name_and_ending: str)#

Like save_solution, but it only saves the new solution data instead of everything.

New data is defined as all data that is saved in a time step greater than self.last_saved_timestep.

Parameters:

path_with_name_and_ending (str) – Where to save the solution.

save_solution(path_with_name_and_ending: str)#
save_to_file_only(t: ndarray, y: ndarray, path_with_name_and_ending: str)#

Only save the passed solution to file and delete the input vector except the last value.

The t and y values are not saved into the solution object to prevent high RAM usage. The input vector is deleted for the same reason. Only the last value of the input vector is kept to use it for further solving.

Parameters:
  • t (np.ndarray) – The time step array of the solution.

  • y (np.ndarray) – The result array/matrix of the solution.

  • path_with_name_and_ending (str) – Where to save the solution.

property t#
property temperature_vectors: ndarray#

Like temperature_vectors_pandas, but returns a numpy array.

This value is not cached.

Returns:

The solution. Each column represents the solution of one node. Each row the time step.

Return type:

np.ndarray

property temperature_vectors_pandas: DataFrame#

Returns the solution with all node results in one column within a pd.DataFrame.

The DataFrame is cached. To reset it, set self.result_vectors = None .

Returns:

The solution. Each column represents the solution of one node. Each row the time step. The index of the DataFrame are the time steps.

Return type:

pd.DataFrame

property time_steps_count#
write_paraview_data(folder: str, increment: int = None, number_of_saved_steps: int = None, time_increment: int | float | Any = None, use_degrees_celsius: bool = True)#

Parsing the result data to vtu files that can be used to visualize the result in paraview.

It is recommended to not generate more than several thousand resolution steps. If no increment is given, about 2000 result steps are created.

Parameters:
  • folder (str) – The folder to save the paraview data in.

  • increment (int, optional) – If specified, only the incremental part of the result is parsed (to shorten the write time). If None, the increment is calculated so that a maximum of 2000 results are created.

  • number_of_saved_steps (int, optional) – Works like increment but instead of walking a fixed step width it calculates the increment using the given number to get the number of steps. Or: Say, how many steps should be saved (+-1). Overwrites the increment parameter.

  • time_increment (int | float | Any, optional) –

    The x’th time that should be saved in seconds. If given, the increment parameter is not used. Example usage: time_increment = 120

    The result files are created for results every 120 seconds.

  • use_degrees_celsius (bool, optional) – If True, the temperatures are saved as degree Celsius. In Kelvin otherwise.

property y#
class Solid(*args, **kwargs)#

Bases: Material

Container to hold all material properties.

Parameters:
  • name (str) – The name/identifier of the material.

  • density (float | int | np.number) – The density of the material in kg/m^3.

  • heat_capacity (float | int | np.number) – The heat capacity of the material in J/kg/K.

  • thermal_conductivity (float | int | np.number) – The thermal conductivity of the material in W/m/K.

class SymbolMixin#

Bases: object

abstract property symbols: list#

Returns a list of all sympy.symbols of the object, except time dependent symbols.

Must be in the same order as self.values.

Returns:

The list of sympy.symbols.

Return type:

list

property time_dependent_symbols: list#

Returns a list of all symbols that are needed to calculate self.value.

The list is sorted by the name of the symbols for deterministic reasons.

Returns:

All symbols that are needed to calculate self.value (symbols that are time dependent and will be calculated between time steps).

Return type:

list

abstract property values: list#

Returns a list of all values of all object symbols, except of time dependent symbols.

Must be in the same order as self.symbols.

Returns:

The list of sympy.symbols.

Return type:

list

calculate_balance_for_resistors(node, resistors: list[MassTransport])#