-
Notifications
You must be signed in to change notification settings - Fork 2
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
tosch4
merged 3 commits into
master
from
127-add-new-example-for-parameter-modifications
May 7, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
# 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))' | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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