pyrc.core.simulation#
- class Parameterization(parameters_tuples: list[tuple], pre_calculation_seconds=36000, initial_settings_dict: dict = <pyrc.core.settings.Settings object>, max_core_number=0, t_span=None)#
Bases:
SimulationClass to handle
RCNetworkcalculations that are quite similar but differ in one settings parameter.All calculations are run in parallel.
- Parameters:
parameters_tuples (list[tuple]) – Defining the parameters for each simulation: for parameters in parameters_tuples: network_type: type = parameters[0] settings_dict = parameters[1] network_parameters = parameters[2] t_span = parameters[3] name_add_on = parameters[4]
pre_calculation_seconds (int | float, default=36000) – How long the static calculation before the dynamic calculation should be.
initial_settings_dict (dict, default=i_settings) – The initial settings to use for the calculations. If not given, the initial ones from
core.settingsis used.max_core_number (int, default=0) – An optional limit how many cores can be used for the calculations. 0 for no limit.
- __init__(parameters_tuples: list[tuple], pre_calculation_seconds=36000, initial_settings_dict: dict = <pyrc.core.settings.Settings object>, max_core_number=0, t_span=None)#
- Parameters:
parameters_tuples (list[tuple]) – Defining the parameters for each simulation: for parameters in parameters_tuples: network_type: type = parameters[0] settings_dict = parameters[1] network_parameters = parameters[2] t_span = parameters[3] name_add_on = parameters[4]
pre_calculation_seconds (int | float, default=36000) – How long the static calculation before the dynamic calculation should be.
initial_settings_dict (dict, default=i_settings) – The initial settings to use for the calculations. If not given, the initial ones from
core.settingsis used.max_core_number (int, default=0) – An optional limit how many cores can be used for the calculations. 0 for no limit.
- get_parameters(parameters: tuple)#
Returns the first few parameters for the worker method.
- Parameters:
parameters (tuple) – The tuple out of self.parameters_tuples
- Returns:
The parameters as tuple.
- Return type:
tuple
- pre_create_jacobians()#
Pre-creates the jacobian matrices of all RCNetworks if not already found in pickle file.
This is useful to quickly generate all jacobian matrices outside the workers so that they only need to load the matrices and lambdify them.
- run()#
Run the simulation including pre-simulation with the passed network type.
- Parameters:
network_class (type[RCNetwork] | None, optional) – The RCNetwork that is created for the simulation.
network_keyword_arguments (dict[str, Any] | None, optional) – The keyword arguments for the RCNetwork object that is created.
t_span (tuple | None, optional) – The t_span for the simulation: (start, end) in seconds. It should start at 0 (otherwise it can work but it’s not tested).
name_add_on (str, optional) – An add-on for the name to identify the name to the worker. If None, a random five digits integer is used (with leading zeros).
settings (Settings | None, optional) – The settings for the network and simulation. If None, the initial settings dict from the network is used.
pre_calculation_settings (Settings | None, optional) – The settings for the pre-calculation. Should only vary in the weather data start date. If None, the initial settings dict from the network is used, but with static calculation.
print_progress (bool | None, optional) – Whether to print some progress information during the simulation.
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)
- class Simulation(network_class: type[RCNetwork] | None = None, network_keyword_arguments: dict[str, Any] | None = None, pre_calculation_seconds: int | float = 36000, t_span: tuple | None = None, name_add_on: str = '', settings: Settings = None, pre_calculation_settings: Settings = None, print_progress: bool = True, time_dependent_tuple: tuple[Iterable, Callable] | None = None, time_dependent_tuple_input: tuple[Iterable, Callable] | None = None)#
Bases:
objectHandle one RC network simulation including pre-simulation.
The pre-simulation determines correct initial values for the network by calculating a time range before the real simulation. The pre-simulation can be done with varying weather data or just static simulation of the initial boundary conditions of the network. However, because of the dynamic values of all capacities it is recommended to use the option with varying (realistic) boundary data.
The pre-simulation is saved as single initial values that can be loaded in. It is executed only once and then loaded in from file.
All parameters can be also set in the run method. However, when you don’t want to pass them in each run() call you can initialize them directly and they will be used (if not overwritten).
- Parameters:
network_class (type[RCNetwork] | None, optional) – The RCNetwork class that is used to create an object of it and run the simulation. This is needed because when using parallelization the RCNetwork cannot be pickled to other CPU cores (on Windows). Instead, first the network is build on each core.
network_keyword_arguments (dict[str, Any] | None, optional) – The keyword arguments for the RCNetwork object that is created.
pre_calculation_seconds (int | float, default=36000) – The length of the pre-simulation in seconds.
t_span (tuple | None, optional) – The simulation start and end time tuple for the scipy.solve_ivp() in seconds.
name_add_on (str, default="")
settings
pre_calculation_settings
print_progress (bool, default=True)
time_dependent_tuple (tuple[Iterable | Callable] | None) – 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)
- __init__(network_class: type[RCNetwork] | None = None, network_keyword_arguments: dict[str, Any] | None = None, pre_calculation_seconds: int | float = 36000, t_span: tuple | None = None, name_add_on: str = '', settings: Settings = None, pre_calculation_settings: Settings = None, print_progress: bool = True, time_dependent_tuple: tuple[Iterable, Callable] | None = None, time_dependent_tuple_input: tuple[Iterable, Callable] | None = None) None#
Handle one RC network simulation including pre-simulation.
The pre-simulation determines correct initial values for the network by calculating a time range before the real simulation. The pre-simulation can be done with varying weather data or just static simulation of the initial boundary conditions of the network. However, because of the dynamic values of all capacities it is recommended to use the option with varying (realistic) boundary data.
The pre-simulation is saved as single initial values that can be loaded in. It is executed only once and then loaded in from file.
All parameters can be also set in the run method. However, when you don’t want to pass them in each run() call you can initialize them directly and they will be used (if not overwritten).
- Parameters:
network_class (type[RCNetwork] | None, optional) – The RCNetwork class that is used to create an object of it and run the simulation. This is needed because when using parallelization the RCNetwork cannot be pickled to other CPU cores (on Windows). Instead, first the network is build on each core.
network_keyword_arguments (dict[str, Any] | None, optional) – The keyword arguments for the RCNetwork object that is created.
pre_calculation_seconds (int | float, default=36000) – The length of the pre-simulation in seconds.
t_span (tuple | None, optional) – The simulation start and end time tuple for the scipy.solve_ivp() in seconds.
name_add_on (str, default="")
settings
pre_calculation_settings
print_progress (bool, default=True)
time_dependent_tuple (tuple[Iterable | Callable] | None) – 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)
- run(network_class: type[RCNetwork] | None = None, network_keyword_arguments: dict[str, Any] | None = None, t_span: tuple | None = None, name_add_on: str = '', settings: Settings | None = None, pre_calculation_settings: Settings | None = None, print_progress: bool | None = None, time_dependent_tuple: tuple[Iterable, Callable] | None = None, time_dependent_tuple_input: tuple[Iterable, Callable] | None = None)#
Run the simulation including pre-simulation with the passed network type.
- Parameters:
network_class (type[RCNetwork] | None, optional) – The RCNetwork that is created for the simulation.
network_keyword_arguments (dict[str, Any] | None, optional) – The keyword arguments for the RCNetwork object that is created.
t_span (tuple | None, optional) – The t_span for the simulation: (start, end) in seconds. It should start at 0 (otherwise it can work but it’s not tested).
name_add_on (str, optional) – An add-on for the name to identify the name to the worker. If None, a random five digits integer is used (with leading zeros).
settings (Settings | None, optional) – The settings for the network and simulation. If None, the initial settings dict from the network is used.
pre_calculation_settings (Settings | None, optional) – The settings for the pre-calculation. Should only vary in the weather data start date. If None, the initial settings dict from the network is used, but with static calculation.
print_progress (bool | None, optional) – Whether to print some progress information during the simulation.
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)