Simulator
The Simulator class forms the framework for all HiSim simulations.
It iterates over all components in each timestep until convergence and loops over all time steps.
- class simulator.Simulator(module_directory: str, module_filename: str, my_simulation_parameters: SimulationParameters | None, setup_function: str = 'setup_function', my_module_config: str | None = None)
Bases:
objectCore class of HiSim: Runs the main loop.
- add_component(component: Component, is_cachable: bool = False, connect_automatically: bool = False) None
Adds component to simulator and wraps it up the output in the register.
- connect_all_components() None
Connects the inputs from every component to the corresponding outputs.
- connect_everything_automatically(source_component_list: List[Component] | List[DynamicComponent], target_component: Component | DynamicComponent) None
Connect chosen target component in the sytem setups automatically based on its default connections.
- get_simulation_parameters() SimulationParameters
Returns the simulation parameters for exporting them to JSON.
- get_std_results(results_data_frame: DataFrame) Tuple[DataFrame, DataFrame, DataFrame, DataFrame]
Converts results into a pretty dataframe for post processing.
- prepare_calculation() None
Connects the inputs from every component to the corresponding outputs.
- prepare_post_processing(all_result_lines, start_counter)
Assembles simulation results into a DataFrame and prepares data for post-processing.
Builds a pandas DataFrame from simulation outputs, assigns a datetime index based on simulation start/end dates and timestep size, and optionally computes monthly, daily, hourly, and cumulative aggregations. Returns a PostProcessingDataTransfer object containing all results and metadata.
- Args:
all_result_lines: List of result arrays, one per timestep. start_counter: High-resolution time from before simulation started, used to compute execution time.
- Returns:
PostProcessingDataTransfer: Object bundling results, outputs, parameters, and timing for post-processing.
- prepare_simulation_directory()
Prepares the simulation directory. Determines the filename if nothing is set.
- process_one_timestep(timestep: int, previous_stsv: SingleTimeStepValues) Tuple[SingleTimeStepValues, int, bool]
Executes one simulation timestep.
Some components can be connected in a circle. To solve the circular dependency, all components have their states restored and simulated until their values converge.
Firstly, their previously converged state is saved as the current timestep state. Following up, all components have their states restored and simulated respectively. Convergence is dependent on the i_restore and i_simulate of the components and how they are connected to each other.
- run_all_timesteps() None
Performs all the timesteps of the simulation and saves the results in the attribute results.
- set_simulation_parameters(my_simulation_parameters: SimulationParameters) None
Sets the simulation parameters and the logging level at the same time.
- show_progress(starttime: datetime, step: int, total_iteration_tries: int, last_step: int, force_covergence: bool) datetime
Makes the pretty progress messages with time estimate.