Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RWTH-EBC
GitHub Repository: RWTH-EBC/ebcpy
Path: blob/master/examples/e5_modifier_example.py
505 views
1
"""
2
Goals of this part of the examples:
3
1. Learn how to use the `DymolaAPI`
4
2. Learn how to dynamically modify parameters in the model
5
"""
6
# Start by importing all relevant packages
7
import pathlib
8
# Imports from ebcpy
9
from ebcpy import DymolaAPI
10
11
12
def main(
13
besmod_startup_mos,
14
ext_model_name,
15
working_directory=None,
16
n_cpu=1
17
):
18
"""
19
Arguments of this example:
20
21
:param str besmod_startup_mos:
22
Path to the startup.mos of the BESMod.
23
This example was tested for BESMod version 0.4.0.
24
This example was tested for IBSPA version 3.0.0.
25
This example was tested for AixLib version 1.3.2.
26
:param str ext_model_name:
27
Executable model name with redeclared subsystems and modifiers.
28
:param str working_directory:
29
Path in which to store the output.
30
Default is the examples\results folder
31
:param int n_cpu:
32
Number of processes to use
33
:param bool with_plot:
34
Show the plot at the end of the script. Default is True.
35
"""
36
37
# General settings
38
if working_directory is None:
39
working_directory = pathlib.Path(__file__).parent.joinpath("results")
40
41
# ######################### Simulation API Instantiation ##########################
42
# %% Setup the Dymola-API:
43
dym_api = DymolaAPI(
44
model_name=ext_model_name,
45
working_directory=working_directory,
46
n_cpu=n_cpu,
47
mos_script_pre=besmod_startup_mos,
48
show_window=False,
49
# Only necessary if you need a specific dymola version
50
dymola_path=r"C:\Program Files\Dymola 2023x",
51
)
52
print("Number of variables:", len(dym_api.variables))
53
print("Number of outputs:", len(dym_api.outputs))
54
print("Number of inputs:", len(dym_api.inputs))
55
print("Number of parameters:", len(dym_api.parameters))
56
print("Number of states:", len(dym_api.states))
57
58
# ######################### Settings ##########################
59
simulation_setup = {"start_time": 0,
60
"stop_time": 3600,
61
"output_interval": 100}
62
dym_api.set_sim_setup(sim_setup=simulation_setup)
63
64
# ######################### Simulation options ##########################
65
# Look at the doc of simulate() in the website or previous examples
66
result_sp_2 = dym_api.simulate(
67
return_option="time_series"
68
)
69
print(result_sp_2)
70
71
# You can also simulate a list of different `model_names` (or modified versions of the same model)
72
# by passing a list to the `simulate` function in `DymolaAPI`:
73
model_names_to_simulate = [
74
"BESMod.Examples.DesignOptimization.BES",
75
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))",
76
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=5))",
77
]
78
results = dym_api.simulate(
79
return_option="time_series",
80
model_names=model_names_to_simulate
81
)
82
print(results)
83
dym_api.save_for_reproduction(
84
title="FMUTest",
85
log_message="This is just an example."
86
)
87
# ######################### Closing ##########################
88
# Close Dymola. If you forget to do so,
89
# we call this function at the exit of your script.
90
dym_api.close()
91
92
93
if __name__ == '__main__':
94
# TODO-User: Change the BESMod path!
95
# call function main
96
# - External libraries AixLib, IBSPA and BESMod will be loaded
97
# - Model ext_model_name will be called. Subsystem for controller will be exchanged from NoControl to DHWSuperheating.
98
# Additional to the new subsystem, the parameter dTDHW will be set from 5 K to 10 K.
99
# Furthermore, inside the main function, a method for simulating multiple models at one call is shown.
100
main(
101
besmod_startup_mos=r"D:\04_git\BESMod\startup.mos",
102
ext_model_name='BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))'
103
)
104
105