Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new example added #127 #128

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/e2_fmu_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def main(
for sizing in sizings:
parameters.append({"heaCap.C": hea_cap_c * sizing})

# Additional information: Dynamic exchange of parameter values has the same syntax when using DymolaAPI,
# instead of FMU_API.

# ######################### Inputs ##########################
# Let's also change the input of the simulation:
print("Inputs names are:", fmu_api.inputs)
Expand Down
109 changes: 109 additions & 0 deletions examples/e5_modifier_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
Goals of this part of the examples:
1. Learn how to use the `DymolaAPI`
2. Learn how to dynamically modify parameters in the model
"""
# Start by importing all relevant packages
import pathlib
# Imports from ebcpy
from ebcpy import DymolaAPI


def main(
aixlib_mo,
ibpsa_mo,
besmod_mo,
ext_model_name,
working_directory=None,
n_cpu=1,
with_plot=True
):
"""
Arguments of this example:
:param str aixlib_mo:
Path to the package.mo of the AixLib.
This example was tested for AixLib version 1.3.2.
:param str ibpsa_mo:
Path to the package.mo of the IBSPA.
This example was tested for IBSPA version 3.0.0.
:param str besmod_mo:
Path to the package.mo of the BESMod.
This example was tested for BESMod version 0.4.0.
:param list 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.
"""

# General settings
if working_directory is None:
working_directory = pathlib.Path(__file__).parent.joinpath("results")

# ######################### Simulation API Instantiation ##########################
# %% Setup the Dymola-API:
dym_api = DymolaAPI(
model_name=ext_model_name,
working_directory=working_directory,
n_cpu=n_cpu,
packages=[aixlib_mo, ibpsa_mo, besmod_mo],
show_window=False,
# Only necessary if you need a specific dymola version
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))

# ######################### Settings ##########################
simulation_setup = {"start_time": 0,
"stop_time": 3600,
"output_interval": 100}
dym_api.set_sim_setup(sim_setup=simulation_setup)

# ######################### Simulation options ##########################
# Look at the doc of simulate() in the website or previous examples
result_sp_2 = dym_api.simulate(
return_option="time_series"
)
print(result_sp_2)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the following code as well, showing that simulating multiple model_names works, as well? It should work, if not, please give me a note


    # You can also simulate a list of different `model_names` (or modified versions of the same model) 
    # by passing a list to the `simulate` function in `DymolaAPI`:
    model_names_to_simulate = [
        "BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))",
        "BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=5))",
        "BESMod.Examples.DesignOptimization.BES",
    ]
    results = dym_api.simulate(
        return_option="time_series",
        model_names=model_names
    )
    print(results)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @FWuellhorst ! Example script is updated und pushed to the issue branch #127

# You can also simulate a list of different `model_names` (or modified versions of the same model)
# by passing a list to the `simulate` function in `DymolaAPI`:
model_names_to_simulate = [
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))",
"BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=5))",
"BESMod.Examples.DesignOptimization.BES",
]
results = dym_api.simulate(
return_option="time_series",
model_names=model_names_to_simulate
)
print(results)

# ######################### Closing ##########################
# Close Dymola. If you forget to do so,
# we call this function at the exit of your script.
dym_api.close()


if __name__ == '__main__':
# TODO-User: Change the AixLib and BESMod path!

# call function main
# - External libraries AixLib, IBSPA and BESMod will be loaded
# - Model ext_model_name will be called. Subsystem for controller will be exchanged from NoControl to DHWSuperheating.
# Additional to the new subsystem, the parameter dTDHW will be set from 5 K to 10 K.
# Furthermore, inside the main function, a method for simulating multiple models at one call is shown.
main(
aixlib_mo=r"D:\900_repository\000_general\AixLib-1.3.2\AixLib\package.mo",
ibpsa_mo=r"D:\900_repository\000_general\modelica-ibpsa-master\IBPSA\package.mo",
besmod_mo=r"D:\900_repository\000_general\BESMod\BESMod\package.mo",
ext_model_name='BESMod.Examples.GasBoilerBuildingOnly(redeclare BESMod.Systems.Control.DHWSuperheating control(dTDHW=10))'
)