Set Up and Run a Simulation
What files are needed for a simulation?
Scenario script
Start the simulators, build the models, create the connections and start mosaik.
Exemplary scripts for building, grid etc. can be found in the examples
folder.
Model data file
Information on number of models and their parameterization.
1{
2 "ems": [
3 {
4 "strategy": "HEMS_default",
5 "cs_strategy": "balanced"
6 }
7 ],
8 "HouseholdCSV": [
9 {
10 "p_rated": 4500,
11 "p_rated_profile": 4000,
12 "cos_phi": 1.0,
13 "datafile": "examples/data/load/4_persons_profile/load_34.csv",
14 "date_format": "YYYY-MM-DD HH:mm:ss",
15 "header_rows": 2,
16 "start_time": "2014-01-01 00:00:00"
17 }
18 ],
19...
Model connections
Connections between grid buses and the ems models (or directly the devices)
Connections between ems and the devices
1{
2 "0-load_1_1": {
3 "ems": "HEMS_default_0",
4 "load": [
5 "HouseholdCSV_0"
6 ],
7 "household_thermal": [],
8 "pv": [],
9 "bss": [],
10 "hp": [],
11 "cs": [
12 "ChargingStation_0"
13 ],
14 "ev": [
15 "EV_0"
16 ]
17 },
18 "0-load_1_2": {
19 "ems": "HEMS_default_1",
20 "load": [
21 "HouseholdCSV_1"
22 ],
23...
Grid file
In .json
format (possibly created via pandapower)
1{
2 "_module": "pandapower.auxiliary",
3 "_class": "pandapowerNet",
4 "_object": {
5 "bus": {
6 "_module": "pandas.core.frame",
7 "_class": "DataFrame",
8 "_object": "{\"columns\":[\"name\",\"vn_kv\",\"type\",\"zone\",\"in_service\"],\"index\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],\"data\":[[\"Trafostation_OS\",10.0,\"b\",null,true],[\"main_busbar\",0.4,\"b\",null,true],[\"MUF_1_1\",0.4,\"n\",null,true],[\"loadbus_1_1\",0.4,\"b\",null,true],[\"KV_1_2\",0.4,\"b\",null,true],[\"loadbus_1_2\",0.4,\"b\",null,true],[\"MUF_1_3\",0.4,\"n\",null,true],[\"loadbus_1_3\",0.4,\"b\",null,true],[\"KV_1_4\",0.4,\"b\",null,true],[\"loadbus_1_4\",0.4,\"b\",null,true],[\"MUF_1_5\",0.4,\"n\",null,true],[\"loadbus_1_5\",0.4,\"b\",null,true],[\"KV_1_6\",0.4,\"b\",null,true],[\"loadbus_1_6\",0.4,\"b\",null,true],[\"MUF_2_1\",0.4,\"n\",null,true],[\"loadbus_2_1\",0.4,\"b\",null,true],[\"KV_2_2\",0.4,\"b\",null,true],[\"loadbus_2_2\",0.4,\"b\",null,true]]}",
9 "orient": "split",
10 "dtype": {
11 "name": "object",
12 "vn_kv": "float64",
13 "type": "object",
14 "zone": "object",
15 "in_service": "bool"
16 }
17 },
18...
Tip
All files can be created (more easily) with a Scenario Configurator
(.ipynb
) via an excel file. Or use existing files and adapt the parameterization.
Configuration of a Scenario Script
Note
All of these code-blocks derive from examples/test_scenario_building.py
as of (01/24)
if not stated otherwise.
Setup
8import os
9import json
10import mosaik
11import mosaik.util
12import eelib.utils.simulation_helper as sim_help
13from eelib.model_connections.connections import get_default_connections
14from eelib.utils.logging_helpers import set_console_logger
15import arrow
16import logging
27# define paths and filenames
28DIR = sim_help.get_default_dirs(
29 os.path.realpath(os.path.dirname(__file__)), scenario="building", grid=None, format_db="hdf5"
30)
37# Sim config.: Simulators and their used model types with the properties to store into DB
38SIM_CONFIG = {
39 # used database, will be left out for model creation and connections
40 "DBSim": {"python": "eelib.data.database.hdf5:Hdf5Database"},
41 # all the used simulators and their models for this simulation
42 "EMSSim": {
43 "python": "eelib.core.control.EMS.EMS_simulator:Sim",
44 "models": {"ems": ["p_balance", "q_balance", "p_th_balance", "p_th_dem"]},
45 },
46 "CSVSim": {
47 "python": "eelib.data.csv_reader.csv_reader_simulator:Sim",
48 "models": {
49 "HouseholdCSV": ["p", "q"],
50 "PvCSV": ["p", "q"],
51 "ChargingStationCSV": ["p", "q"],
52 "HeatpumpCSV": ["p_el", "q_el"],
53 "HouseholdThermalCSV": ["p_th_room", "p_th_water"],
54 },
55 },
56 ...
82# Configuration of scenario: time and granularity
83START = "2020-01-01 00:00:00"
84END = "2020-01-04 00:00:00"
85STEP_SIZE_IN_SECONDS = 900 # 1=sec-steps, 3600=hour-steps, 900=15min-steps, 600=10min-steps
86N_SECONDS = int(
87 (
88 arrow.get(END, "YYYY-MM-DD HH:mm:ss") - arrow.get(START, "YYYY-MM-DD HH:mm:ss")
89 ).total_seconds()
90)
91N_STEPS = int(N_SECONDS / STEP_SIZE_IN_SECONDS)
92scenario_config = {
93 "start": START, # time of beginning for simulation
94 "end": END, # time of ending
95 "step_size": STEP_SIZE_IN_SECONDS,
96 "n_steps": N_STEPS,
97 "bool_plot": False,
98}
99
100# Read Scenario file with data for model entities
101with open(DIR["MODEL_DATA"]) as f:
102 model_data = json.load(f)
103
104# Read configuration file with data for connections between prosumer devices
105model_connect_config = get_default_connections()
106
107# Create world
108world = mosaik.World(SIM_CONFIG, debug=True)
Start Simulators
120# start all simulators/model factories with mosaik for data given in SIM_CONFIG
121dict_simulators = sim_help.start_simulators(
122 sim_config=SIM_CONFIG, world=world, scenario_config=scenario_config
123)
Initiate Models
133# create all models based on given SIM_CONFIG
134dict_entities = sim_help.create_entities(
135 sim_config=SIM_CONFIG, model_data=model_data, dict_simulators=dict_simulators
136)
Connect Entities
143# connect all models to each other
144sim_help.connect_entities(
145 world=world,
146 dict_entities=dict_entities,
147 model_connect_config=model_connect_config,
148 dict_simulators=dict_simulators,
149)
Run Simulation
161world.run(until=scenario_config["n_steps"], print_progress=True)
Running a simulation
- You can run one of the
test_scenario
s in theexamples
folder building
: Just one single building to see the operation of devices inside the household.grid
: Simple low voltage grid (2 feeders with six resp. two household connection points) to get an estimation of the impact of different operating strategies on the local grid.multi_fam_house
: TBDresidential_district
: TBD
- You can run one of the
Adapting the parameterization in the simulation files can yield quite different results.
Running one of the simulations will create a
.hdf5
results data file in the folder/examples/results
.You can view the information of this file via the H5Web Extension in Microsoft VSC and plot the profiles (stored under Series and the name of the corresponding simulator) of the used devices.
Create your own simulation
Copy one of the test scenarios and delete all of the redundant simulators/devices/connections.
Set up corresponding model (and grid) data as well as a model configuration file.