Salabim Classes
This are overwritten salabim classes and self created classes mainly used to run the simulation and set correct parameters for the simulation. The salabim environment class is based on the sim.Environment class and is used to run the simulation. It contains the required stores and data storage for each simulation run. It also provides methods that can be used to let the simulation interact with the weather module. The Component class adds some additional monitoring functionality in order to store results correctly. The SimulationEnvironment class is used to store the current run experiment, it contains a salabim environment which is overwritten at each run (to reset all resources and the clock to 0).
- class logsim.classes_salabim.SalabimEnvironment(experiment, trace, *args, **kwargs)
Salabim environment is created every simulation run. It is instantiated with the experiment class and the necessary stores and resources. It also contains the shared data dictionary, which is used to share data between the different components of the simulation. Components will register themselves with the environment, so that they can be accessed by other components. The
SimulationEnvironmentincludes methods that will set the weather sample variable in this class, which is used to determine the weather conditions for the simulation.- Parameters:
experiment – Experiment class that contains the experiment parameters
trace – Boolean that determines whether the simulation should be traced
args – sim.Environment arguments
kwargs – sim.Environment keyword arguments
- get_next_window(window_size: int | float, hm0_limit: float, tp_limit: float, start_time_check: float | None = None) float
Get waiting time until next window of weather data is available. Calls the
logsim.weather.get_next_window()function of the weather module.- Parameters:
window_size – The size of the window
hm0_limit – The limit for the wave height
tp_limit – The limit for the wave period
start_time_check – The time from which the waiting time should be calculated
- Returns:
The waiting time until the next window of weather data is available in hours
- static get_store_length(store: Store) array
Return store length by stacking time and length of store in numpy array
- class logsim.classes_salabim.SimulationEnvironment
Simulation Environment is the main environment used to run all simulations. It is used to hold the environment that is currently run and contains the unit registry. If multiple experiments need to be run in parallel for each of them a SimulationEnvironment is created that will on its turn create a SalabimEnvironment for every run.
- create_salabim_env(trace: bool = False, *args, **kwargs)
Every run this function is called to create a new SalabimEnvironment that is used to run the simulation. Old SalabimEnvironment is overwritten. Will be saved as within the main run function:
logsim.classes.Experiment.run_experiment()thelogsim.classes.Experiment.save_sample_results()is called.- Parameters:
trace – Boolean that indicates if the simulation should be traced
args – Arguments that are passed to the SalabimEnvironment
kwargs – Keyword arguments that are passed to the SalabimEnvironment
- set_experiment(experiment: Experiment)
Set experiment and set the quantities that are used in the experiment. Transform all quantities to the correct units by using the
logsim.classes.SimulationEnvironment.set_quantity()function that creates ureg quantity objects.- Parameters:
experiment – Experiment class that contains the experiment parameters
- set_quantity(value: float, unit: str) float
Function to set a quantity in the correct unit. Will return the quantity in hours if the dimension is time. This is because in the simulation hours as the base unit for time is used. All other units are converted to the base unit.
- Parameters:
value – Float that contains the value of the quantity
unit – String that contains the unit of the quantity
- Returns:
Float that contains the value of the quantity in the correct unit (h if time, base unit otherwise)
- set_weather_sample(sample_no: int)
Called when weather is used and a new weather sample is needed. Sets the weather sample in the SalabimEnvironment. Each environment has its own weather sample.
- Parameters:
sample_no – Integer that indicates the weather sample number
- class logsim.classes_salabim.Component(*args, **kwargs)
Base class for all components. Contains some manual monitors, like mode (as sim.Monitor) and location (as sim.State). Manually implemented these to allow for correct typing and enforce usage of ‘int8’ type for storing the modes/states. This saves a lot of memory.
- from_store_item() Component
Function to retrieve store item. Overwritten to enforce correct typing and enforce never returns None.
- Return sim.Component:
Component that is retrieved from the store
- from_store_mode(store: Store, mode: int) Component
Function to retrieve store item with integer mode (based on
logsim.enumerations.Modes) from store.- Parameters:
store – Store that is used to retrieve the item from
mode (int (
logsim.enumerations.Modes)) – Integer that indicates the mode of the component
- Return sim.Component:
Component that is retrieved from the store
- get_location_data() array
Returns a numpy array with the location data from simulation objects
- Return np.ndarray:
Numpy array with location data in form of ‘time’, ‘location value’
- get_mode_data() array
Returns a numpy array with the mode data from simulation objects
- Return np.ndarray:
Numpy array with mode data in form of ‘time’, ‘mode value’
- hold_mode(duration: float | int, mode: int) None
Function to hold component with integer mode (based on
logsim.enumerations.Modes) for a certain duration.- Parameters:
duration – Duration that the component is held
mode (int (
logsim.enumerations.Modes)) – Integer that indicates the mode of the component
- passivate_mode(mode: int) None
Function to passivate component with integer mode (based on
logsim.enumerations.Modes).- Parameters:
mode (int (
logsim.enumerations.Modes)) – Integer that indicates the mode of the component
- request_mode(resource: Resource, mode: int) None
Function to request resource with integer mode (based on
logsim.enumerations.Modes) for a certain duration.- Parameters:
resource – Resource that is requested
mode (int (
logsim.enumerations.Modes)) – Integer that indicates the mode of the component
- set_mode(mode: int | None = None) None
Function to set mode of component without any other action (mode based on
logsim.enumerations.Modes).- Parameters:
mode (int (
logsim.enumerations.Modes)) – Integer that indicates the mode of the component