"""
Goals of this part of the examples:
1. Learn how to use the `DymolaAPI`
2. Learn how to dynamically modify parameters in the model
"""
import pathlib
from ebcpy import DymolaAPI
def main(
besmod_startup_mos,
ext_model_name,
working_directory=None,
n_cpu=1
):
"""
Arguments of this example:
:param str besmod_startup_mos:
Path to the startup.mos of the BESMod.
This example was tested for BESMod version 0.4.0.
This example was tested for IBSPA version 3.0.0.
This example was tested for AixLib version 1.3.2.
:param str ext_model_name:
Executable model name with redeclared subsystems and modifiers.
:param str working_directory:
Path in which to store the output.
Default is the examples\results folder
:param int n_cpu:
Number of processes to use
:param bool with_plot:
Show the plot at the end of the script. Default is True.
"""
if working_directory is None:
working_directory = pathlib.Path(__file__).parent.joinpath("results")
dym_api = DymolaAPI(
model_name=ext_model_name,
working_directory=working_directory,
n_cpu=n_cpu,
mos_script_pre=besmod_startup_mos,
show_window=False,
dymola_path=r"C:\Program Files\Dymola 2023x",
)
print("Number of variables:", len(dym_api.variables))
print("Number of outputs:", len(dym_api.outputs))
print("Number of inputs:", len(dym_api.inputs))
print("Number of parameters:", len(dym_api.parameters))
print("Number of states:", len(dym_api.states))
simulation_setup = {"start_time": 0,
"stop_time": 3600,
"output_interval": 100}
dym_api.set_sim_setup(sim_setup=simulation_setup)
result_sp_2 = dym_api.simulate(
return_option="time_series"
)
print(result_sp_2)
model_names_to_simulate = [
"BESMod.Examples.DesignOptimization.BES",
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))",
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=5))",
]
results = dym_api.simulate(
return_option="time_series",
model_names=model_names_to_simulate
)
print(results)
dym_api.save_for_reproduction(
title="FMUTest",
log_message="This is just an example."
)
dym_api.close()
if __name__ == '__main__':
main(
besmod_startup_mos=r"D:\04_git\BESMod\startup.mos",
ext_model_name='BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))'
)