diff --git a/.gitmodules b/.gitmodules index 65cebe61446bfe6b4df0ca501c46df58ca0ae2a5..81b42f9c2efc80247e036b3fc77669134f41be48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,4 +6,7 @@ url = https://github.com/RWTH-EBC/BESMod.git [submodule "BuildingSim/FrostingModels"] path = BuildingSim/FrostingModels - url = https://git-ce.rwth-aachen.de/ebc/projects/ebc0932_bmwk_elosdeutschland_kap/frostingmodelicamodels \ No newline at end of file + url = https://git-ce.rwth-aachen.de/ebc/projects/ebc0932_bmwk_elosdeutschland_kap/frostingmodelicamodels +[submodule "BuildingSim/EvalAndPlot"] + path = BuildingSim/EvalAndPlot + url = git@git-ce.rwth-aachen.de:ebc/projects/ebc0606_bmwi_digitalerzwillingwp_ges/evalandplot.git diff --git a/BuildingSim/.idea/workspace.xml b/BuildingSim/.idea/workspace.xml index b3d98f4326810514d1d4e65939b75824a5b595da..00e93f7af9977dc3e533d56531fd48fde0b53d4a 100644 --- a/BuildingSim/.idea/workspace.xml +++ b/BuildingSim/.idea/workspace.xml @@ -5,6 +5,7 @@ </component> <component name="ChangeListManager"> <list default="true" id="2bc32c04-dd44-4e01-9ff9-c09263eca269" name="Changes" comment=""> + <change afterPath="$PROJECT_DIR$/EvalAndPlot" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../.gitmodules" beforeDir="false" afterPath="$PROJECT_DIR$/../.gitmodules" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/BESMod/installed_dependencies/IBPSA/.github/workflows/formatting.yml" beforeDir="false" /> @@ -5441,36 +5442,7 @@ <change beforePath="$PROJECT_DIR$/BESMod/installed_dependencies/IBPSA/bin/convertBuildingsToAnnex60.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/BESMod/installed_dependencies/IBPSA/bin/runUnitTests.py" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/BESMod/installed_dependencies/IBPSA/bin/verifyFiles.py" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Components/CreateFrostingMapEN14511.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Components/CreateFrostingMapEN14511.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Components/Frosting/RoccatelloCOPCorrection.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Components/Frosting/RoccatelloCOPCorrection.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/DesignOptimization/BaseAPI.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/DesignOptimization/BaseAPI.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/DesignOptimization/ExamplesInModelica/OptiHorst2D.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/DesignOptimization/ExamplesInModelica/OptiHorst2D.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/HybridPlanning/ExamplesWithoutAPI/AfterStorage.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/HybridPlanning/ExamplesWithoutAPI/AfterStorage.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/HybridPlanning/ExamplesWithoutAPI/Parallel.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/HybridPlanning/ExamplesWithoutAPI/Parallel.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/OptiHorst2D.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/OptiHorst2D.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/OptiHorst2DFromVCLibPy.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/OptiHorst2DFromVCLibPy.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/RealDevices/HeatPumps/VitoCal250A04.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/RealDevices/HeatPumps/VitoCal250A04.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/EN_MEN412_EN412.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/EN_MEN412_EN412.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/EN_MEN412_Linear.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/EN_MEN412_Linear.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/MEN.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/MEN.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/MEN_MEN_ENTests.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4D/MEN_MEN_ENTests.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/EN_MEN412_EN412.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/EN_MEN412_EN412.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/EN_MEN412_Linear.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/EN_MEN412_Linear.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/VitoCal250.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy4DDeltaT/VitoCal250.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_EN412.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_EN412.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_Linear.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_Linear.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_Reg.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/EN_MEN412_Reg.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/MEN_MEN_EN412.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/RecordsCollection/VCLibPy5D/MEN_MEN_EN412.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/Defrost/PartialDefrostValidation.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/Defrost/PartialDefrostValidation.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/PartialValidation.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/PartialValidation.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VCLibPy/PartialValidation.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VCLibPy/PartialValidation.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VCLibPy5D/PartialValidation.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VCLibPy5D/PartialValidation.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VitoCal250Validation.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/Validation/VitoCal250Validation.mo" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/FrostingModels/BESRules/package.mo" beforeDir="false" afterPath="$PROJECT_DIR$/FrostingModels/BESRules/package.mo" afterDir="false" /> <change beforePath="$PROJECT_DIR$/working_dir/DymolaAPI.log" beforeDir="false" afterPath="$PROJECT_DIR$/working_dir/DymolaAPI.log" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/working_dir/dsin.txt" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/../evalandplot" beforeDir="false" afterPath="$PROJECT_DIR$/EvalAndPlot" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -5499,8 +5471,10 @@ <component name="PropertiesComponent"><![CDATA[{ "keyToString": { "Python tests.Python tests in test_ebcpy.py.executor": "Run", - "Python.eval_plot.executor": "Debug", + "Python.eval_and_plot.executor": "Run", + "Python.eval_plot.executor": "Run", "Python.list_parameters.executor": "Run", + "Python.simple_eval_plot.executor": "Run", "Python.simulate.executor": "Run", "Python.simulate_param_sweep.executor": "Run", "Python.simulate_with_different_heatpump.executor": "Run", @@ -5516,8 +5490,8 @@ "vue.rearranger.settings.migration": "true" } }]]></component> - <component name="RunManager" selected="Python.eval_plot"> - <configuration name="eval_plot" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> + <component name="RunManager" selected="Python.eval_and_plot"> + <configuration name="eval_and_plot" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <module name="BuildingSim" /> <option name="ENV_FILES" value="" /> <option name="INTERPRETER_OPTIONS" value="" /> @@ -5531,7 +5505,7 @@ <option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> - <option name="SCRIPT_NAME" value="$PROJECT_DIR$/working_dir/eval_plot.py" /> + <option name="SCRIPT_NAME" value="$PROJECT_DIR$/working_dir/eval_and_plot.py" /> <option name="PARAMETERS" value="" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="false" /> @@ -5540,7 +5514,7 @@ <option name="INPUT_FILE" value="" /> <method v="2" /> </configuration> - <configuration name="simulate" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> + <configuration name="simple_eval_plot" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <module name="BuildingSim" /> <option name="ENV_FILES" value="" /> <option name="INTERPRETER_OPTIONS" value="" /> @@ -5554,7 +5528,7 @@ <option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> - <option name="SCRIPT_NAME" value="$PROJECT_DIR$/working_dir/simulate.py" /> + <option name="SCRIPT_NAME" value="C:\Users\mbc\Documents\Git-Repos\RollOut\BuildingSim\working_dir\simple_eval_plot.py" /> <option name="PARAMETERS" value="" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="false" /> @@ -5634,11 +5608,11 @@ </configuration> <recent_temporary> <list> - <item itemvalue="Python.eval_plot" /> + <item itemvalue="Python.eval_and_plot" /> + <item itemvalue="Python.simple_eval_plot" /> <item itemvalue="Python.simulate_param_sweep" /> <item itemvalue="Python.simulate_with_dymola_api" /> <item itemvalue="Python.simulate_with_different_heatpump" /> - <item itemvalue="Python.simulate" /> </list> </recent_temporary> </component> @@ -5660,7 +5634,6 @@ <updated>1742207574701</updated> <workItem from="1742207576975" duration="4000" /> <workItem from="1743083402015" duration="23379000" /> - <workItem from="1743844796307" duration="4070000" /> </task> <servers /> </component> @@ -5691,58 +5664,34 @@ <option name="timeStamp" value="51" /> </line-breakpoint> <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/working_dir/eval_plot.py</url> - <line>152</line> - <option name="timeStamp" value="52" /> + <url>file://$PROJECT_DIR$/working_dir/simple_eval_plot.py</url> + <line>163</line> + <option name="timeStamp" value="65" /> </line-breakpoint> <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>129</line> - <option name="timeStamp" value="53" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>127</line> - <option name="timeStamp" value="54" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>123</line> - <option name="timeStamp" value="55" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/working_dir/eval_plot.py</url> - <line>159</line> - <option name="timeStamp" value="59" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>124</line> - <option name="timeStamp" value="61" /> - </line-breakpoint> - <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> - <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>125</line> - <option name="timeStamp" value="62" /> + <url>file://$PROJECT_DIR$/working_dir/simple_eval_plot.py</url> + <line>166</line> + <option name="timeStamp" value="66" /> </line-breakpoint> <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>106</line> - <option name="timeStamp" value="63" /> + <line>204</line> + <option name="timeStamp" value="68" /> </line-breakpoint> <line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <url>file://$PROJECT_DIR$/EvalAndPlot/EvalAndPlot/utils/Evaluator.py</url> - <line>108</line> - <option name="timeStamp" value="64" /> + <line>203</line> + <option name="timeStamp" value="69" /> </line-breakpoint> </breakpoints> </breakpoint-manager> </component> <component name="com.intellij.coverage.CoverageDataManagerImpl"> <SUITE FILE_PATH="coverage/createBuildings_py$simulate_param_sweep.coverage" NAME="simulate_param_sweep Coverage Results" MODIFIED="1743846910010" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> - <SUITE FILE_PATH="coverage/createBuildings_py$eval_plot.coverage" NAME="eval_plot Coverage Results" MODIFIED="1743847837203" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> + <SUITE FILE_PATH="coverage/createBuildings_py$eval_plot.coverage" NAME="simple_eval_plot Coverage Results" MODIFIED="1743854116822" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> <SUITE FILE_PATH="coverage/createBuildings_py$simulate.coverage" NAME="simulate Coverage Results" MODIFIED="1743514607347" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> <SUITE FILE_PATH="coverage/createBuildings_py$simulate_with_different_heatpump.coverage" NAME="simulate_with_different_heatpump Coverage Results" MODIFIED="1743519044431" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> + <SUITE FILE_PATH="coverage/createBuildings_py$eval_and_plot.coverage" NAME="eval_and_plot Coverage Results" MODIFIED="1743854129818" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> <SUITE FILE_PATH="coverage/createBuildings_py$.coverage" NAME=" Coverage Results" MODIFIED="1743084204374" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> <SUITE FILE_PATH="coverage/createBuildings_py$list_parameters.coverage" NAME="list_parameters Coverage Results" MODIFIED="1743089291565" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> <SUITE FILE_PATH="coverage/createBuildings_py$simulate_with_dymola_api.coverage" NAME="simulate_with_dymola_api Coverage Results" MODIFIED="1743679974051" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/working_dir" /> diff --git a/BuildingSim/EvalAndPlot b/BuildingSim/EvalAndPlot new file mode 160000 index 0000000000000000000000000000000000000000..f96aba68ae97aafc858e71a36e2c6264d654c530 --- /dev/null +++ b/BuildingSim/EvalAndPlot @@ -0,0 +1 @@ +Subproject commit f96aba68ae97aafc858e71a36e2c6264d654c530 diff --git a/BuildingSim/working_dir/DymolaAPI.log b/BuildingSim/working_dir/DymolaAPI.log index e4803e4e31165935ec6de40c78590de27507ee87..3156f25528d7c3b95ac27a187b4437018d931eca 100644 --- a/BuildingSim/working_dir/DymolaAPI.log +++ b/BuildingSim/working_dir/DymolaAPI.log @@ -1508,8 +1508,3 @@ Error: Class or component 'defCtrl' not found in HeatPumpAndElectricHeater gener 03.04.2025-13:38:23 INFO DymolaAPI: Finished 1 simulations on 1 processes in 0:00:42 03.04.2025-13:39:48 INFO DymolaAPI: Closing Dymola 03.04.2025-13:39:50 INFO DymolaAPI: Successfully closed Dymola -05.04.2025-11:55:19 INFO DymolaAPI: -------------------------Initializing class DymolaAPI------------------------- -05.04.2025-11:55:19 INFO DymolaAPI: Using dymola installation at C:\Program Files\Dymola 2023x -05.04.2025-11:55:19 INFO DymolaAPI: Using dymola.exe: C:\Program Files\Dymola 2023x\bin64\Dymola.exe -05.04.2025-11:55:19 INFO DymolaAPI: Using dymola interface: C:\Program Files\Dymola 2023x\Modelica\Library\python_interface\dymola.egg -05.04.2025-11:55:24 INFO DymolaAPI: Executing given mos_script_pre prior to loading packages. diff --git a/BuildingSim/working_dir/eval_and_plot.py b/BuildingSim/working_dir/eval_and_plot.py new file mode 100644 index 0000000000000000000000000000000000000000..e7e0e04de4655878b38e9a8b54bcb58312426e62 --- /dev/null +++ b/BuildingSim/working_dir/eval_and_plot.py @@ -0,0 +1,336 @@ +# heat_pump_analysis_evalandplot.py +import os +import pathlib +import pandas as pd +import numpy as np +import json +import matplotlib.pyplot as plt + +# Korrekte Imports von EvalAndPlot +from EvalAndPlot.EvalAndPlot.utils.Evaluator import Evaluator, KPI, Symbol +from EvalAndPlot.EvalAndPlot.utils.Plotter import PlotOptions, Plotter, SubPlot + + +def main(): + # Arbeitsverzeichnis + working_directory = pathlib.Path.cwd() + + # Pfade zu den Verzeichnissen + results_dir = os.path.join(working_directory, "results") + plots_dir = os.path.join(working_directory, "plots") + + # Erstelle Ordner, falls sie nicht existieren + os.makedirs(plots_dir, exist_ok=True) + os.makedirs(results_dir, exist_ok=True) + + # Pfad zur Simulationsinfo-Datei + simulation_info_files = [f for f in os.listdir(results_dir) if + f.startswith("simulation_info_") and f.endswith(".json")] + + if not simulation_info_files: + print("Keine Simulationsinfo-Dateien gefunden!") + return + + # Nehme die neueste Simulationsinfo-Datei + latest_sim_info = sorted(simulation_info_files)[-1] + simulation_info_path = os.path.join(results_dir, latest_sim_info) + + print(f"Verwende Simulationsinfo-Datei: {latest_sim_info}") + + # Lade die Simulationsinfo + with open(simulation_info_path, 'r') as f: + simulation_info = json.load(f) + + # Die Spalten-Mapping-Definitionen + variable_map = { + "hp_power": "outputs.hydraulic.gen.PEleHeaPum.value", + "hp_energy": "outputs.hydraulic.gen.PEleHeaPum.integral", + "eh_power": "outputs.hydraulic.gen.PEleEleHea.value", + "eh_energy": "outputs.hydraulic.gen.PEleEleHea.integral", + "simulation_time": "Variables" + } + + # Erfolgreiche Modelle + successful_models = [model for model in simulation_info["models"] if model.get("success", True)] + + if not successful_models: + print("Keine erfolgreichen Simulationen gefunden!") + return + + print("\nVorbereite und konvertiere Simulationsdaten für EvalAndPlot...") + + # Vorverarbeite jede CSV-Datei und speichere eine bereinigte Version + processed_files = {} + + for model in successful_models: + model_name = model["name"] + result_file = model["result_file"] + result_path = os.path.join(results_dir, result_file) + + print(f"\nVerarbeite Daten für {model_name} aus {result_file}") + + try: + # Lade die CSV-Datei + df = pd.read_csv(result_path) + + # Anzeigen der ersten Zeilen zur Überprüfung + print("Erste Zeilen der Daten:") + print(df.head(3)) + + # Überprüfen der Spalten + print(f"Verfügbare Spalten: {df.columns.tolist()}") + + # Entferne Zeilen, die nur NaN-Werte enthalten + df = df.dropna(how='all') + + # Überprüfe, ob die benötigten Spalten vorhanden sind + required_cols = [ + variable_map["hp_power"], + variable_map["hp_energy"], + variable_map["eh_power"], + variable_map["eh_energy"] + ] + + missing_cols = [col for col in required_cols if col not in df.columns] + if missing_cols: + print(f"Warnung: Folgende Spalten fehlen: {missing_cols}") + continue + + # Konvertiere alle Spalten außer time zu numerischen Werten + for col in df.columns: + if col != 'time': + df[col] = pd.to_numeric(df[col], errors='coerce') + + # Erstelle eine numerische Zeitspalte für EvalAndPlot + # EvalAndPlot benötigt eine numerische Zeit, die als Sekunden interpretiert werden kann + df['time_seconds'] = np.arange(len(df)) * 60 # Annahme: 60-Sekunden-Intervalle + + # Speichere die vorverarbeitete Datei + processed_path = os.path.join(results_dir, f"processed_{result_file}") + df.to_csv(processed_path, index=False) + + processed_files[model_name] = processed_path + print(f"Vorverarbeitete Daten gespeichert in {processed_path}") + + except Exception as e: + print(f"Fehler bei der Vorverarbeitung von {model_name}: {e}") + import traceback + traceback.print_exc() + + if not processed_files: + print("Keine Daten konnten erfolgreich vorverarbeitet werden!") + return + + print(f"\nErfolgreich vorverarbeitete Modelle: {list(processed_files.keys())}") + + # Definiere Symbole für EvalAndPlot + time = Symbol(name='time', + og_name='time_seconds', + plt_opts=PlotOptions(color='black')) + + hp_power = Symbol(name='hp_power', + og_name=variable_map["hp_power"], + factor=0.001, # W zu kW + plt_opts=PlotOptions(color='red', label='Wärmepumpe')) + + hp_energy = Symbol(name='hp_energy', + og_name=variable_map["hp_energy"], + factor=1 / (3600 * 1000), # J zu kWh + plt_opts=PlotOptions(color='red', label='Wärmepumpe')) + + eh_power = Symbol(name='eh_power', + og_name=variable_map["eh_power"], + factor=0.001, # W zu kW + plt_opts=PlotOptions(color='blue', label='Heizstab')) + + eh_energy = Symbol(name='eh_energy', + og_name=variable_map["eh_energy"], + factor=1 / (3600 * 1000), # J zu kWh + plt_opts=PlotOptions(color='blue', label='Heizstab')) + + symbols = [time, hp_power, hp_energy, eh_power, eh_energy] + + # KPIs definieren + n_days = KPI( + name='Anzahl der Tage', + calculation_rule=lambda time: (time.iloc[-1] - time.iloc[0]) / (24 * 3600), + calc_vars=['time'] + ) + + total_hp_energy = KPI( + name='Gesamtenergie Wärmepumpe [kWh]', + calculation_rule=lambda hp_energy: hp_energy.iloc[-1] - hp_energy.iloc[0], + calc_vars=['hp_energy'] + ) + + total_eh_energy = KPI( + name='Gesamtenergie Heizstab [kWh]', + calculation_rule=lambda eh_energy: eh_energy.iloc[-1] - eh_energy.iloc[0], + calc_vars=['eh_energy'] + ) + + total_energy = KPI( + name='Gesamtenergie [kWh]', + calculation_rule=lambda hp_energy, eh_energy: + (hp_energy.iloc[-1] - hp_energy.iloc[0]) + (eh_energy.iloc[-1] - eh_energy.iloc[0]), + calc_vars=['hp_energy', 'eh_energy'] + ) + + daily_energy = KPI( + name='Täglicher Energieverbrauch [kWh/d]', + calculation_rule=lambda hp_energy, eh_energy, time: + ((hp_energy.iloc[-1] - hp_energy.iloc[0]) + (eh_energy.iloc[-1] - eh_energy.iloc[0])) / + ((time.iloc[-1] - time.iloc[0]) / (24 * 3600)), + calc_vars=['hp_energy', 'eh_energy', 'time'] + ) + + kpis = [n_days, total_hp_energy, total_eh_energy, total_energy, daily_energy] + + # Erstelle Evaluator + evaluator = Evaluator(kpis=kpis) + + # Lade die vorverarbeiteten Daten in den Evaluator + for model_name, processed_path in processed_files.items(): + print(f"\nLade vorverarbeitete Daten für {model_name}...") + + try: + # Datenkonfiguration für den Evaluator - verwende die neue time_seconds-Spalte + data_config = { + "format": "csv", + "time": { + "og_name": "time_seconds" + } + } + + # Lade Daten in den Evaluator + evaluator.load_data( + name=model_name, + path=processed_path, + data_config=data_config, + symbols=symbols + ) + print(f"Daten für {model_name} erfolgreich in EvalAndPlot geladen.") + + # Überprüfe, ob die Daten korrekt geladen wurden + data_df = evaluator.get_data_df(data_names=[model_name])[0] + print(f"Verfügbare Spalten in EvalAndPlot für {model_name}: {data_df.columns.tolist()}") + print(f"Anzahl Zeilen in EvalAndPlot für {model_name}: {len(data_df)}") + + except Exception as e: + print(f"Fehler beim Laden von {model_name} in EvalAndPlot: {e}") + import traceback + traceback.print_exc() + + if not evaluator.get_all_names(): + print("Keine Daten konnten in EvalAndPlot geladen werden!") + return + + print(f"\nErfolgreich in EvalAndPlot geladene Modelle: {evaluator.get_all_names()}") + + # Berechne KPIs mit EvalAndPlot + try: + evaluator.calc_kpis() + print("KPIs berechnet mit EvalAndPlot.") + + # Ausgabe der KPI-Zusammenfassung + print("\nZusammenfassung der KPIs (aus EvalAndPlot):") + + for kpi in kpis: + try: + kpi_name, values = evaluator.get_kpi(kpi) + print(f"\n{kpi_name}:") + + for i, model_name in enumerate(evaluator.get_all_names()): + if i < len(values): + print(f" {model_name}: {values[i]:.2f}") + except Exception as e: + print(f"Fehler bei der Ausgabe des KPIs {kpi.name}: {e}") + + # Speichere KPI-Zusammenfassung in CSV + models = evaluator.get_all_names() + kpi_table = [] + + for model in models: + row = {'Modell': model} + for kpi in kpis: + try: + kpi_name, values = evaluator.get_kpi(kpi, data_names=[model]) + row[kpi_name] = values[0] + except Exception as e: + print(f"Fehler bei KPI {kpi.name} für Modell {model}: {e}") + row[kpi.name] = np.nan + kpi_table.append(row) + + kpi_df = pd.DataFrame(kpi_table) + kpi_csv_path = os.path.join(results_dir, "kpi_zusammenfassung_evalandplot.csv") + kpi_df.to_csv(kpi_csv_path, index=False) + print(f"\nKPI-Zusammenfassung aus EvalAndPlot gespeichert in: {kpi_csv_path}") + + except Exception as e: + print(f"Fehler bei der Berechnung der KPIs mit EvalAndPlot: {e}") + import traceback + traceback.print_exc() + + # Erstelle Plots mit EvalAndPlot + try: + print("\nErstelle Plots mit EvalAndPlot...") + plotter = Plotter() + + # Erstelle Zeitreihenplots für jedes Modell + for model_name in evaluator.get_all_names(): + print(f"\nErstelle Zeitreihenplot für {model_name}...") + + try: + # Hole Daten für dieses Modell + data_df = evaluator.get_data_df(data_names=[model_name])[0] + + # Erstelle Unterplots für Wärmepumpe und Heizstab + plotter.multiple_timeseries( + subplots=[ + SubPlot(symbols=[hp_power], ylabel='Leistung [kW]', legend=True), + SubPlot(symbols=[eh_power], ylabel='Leistung [kW]', legend=True) + ], + data=data_df, + title=f'Leistungsverläufe - {model_name}' + ) + + plt.savefig(os.path.join(plots_dir, f"evalplot_leistung_{model_name.replace(' ', '_')}.png")) + plt.close() + + print(f"Zeitreihenplot für {model_name} erstellt.") + + except Exception as e: + print(f"Fehler bei der Erstellung des Zeitreihenplots für {model_name}: {e}") + import traceback + traceback.print_exc() + + # Erstelle Balkendiagramm für die Gesamtenergie + try: + total_energy_name, total_energy_values = evaluator.get_kpi(total_energy) + + plotter.bar_plot( + var=(total_energy_name, total_energy_values), + names_plot=evaluator.get_all_names(), + title="Gesamtenergieverbrauch im Vergleich" + ) + + plt.savefig(os.path.join(plots_dir, "evalplot_gesamtenergie_vergleich.png")) + plt.close() + + print("\nBalkendiagramm für Gesamtenergie erstellt.") + except Exception as e: + print(f"Fehler bei der Erstellung des Balkendiagramms: {e}") + import traceback + traceback.print_exc() + + except Exception as e: + print(f"Fehler bei der Verwendung des EvalAndPlot Plotters: {e}") + import traceback + traceback.print_exc() + + print("\nAnalyse mit EvalAndPlot abgeschlossen!") + print(f"Alle Dateien wurden im Verzeichnis '{results_dir}' und '{plots_dir}' gespeichert.") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/BuildingSim/working_dir/simple_eval_plot.py b/BuildingSim/working_dir/simple_eval_plot.py new file mode 100644 index 0000000000000000000000000000000000000000..10a633a869ea4a178f6b7561048694984a680c9b --- /dev/null +++ b/BuildingSim/working_dir/simple_eval_plot.py @@ -0,0 +1,300 @@ +# heat_pump_analysis.py +import os +import pathlib +import pandas as pd +import numpy as np +import json +import matplotlib.pyplot as plt +from datetime import datetime + + +def main(): + # Arbeitsverzeichnis + working_directory = pathlib.Path.cwd() + + # Pfade zu den Verzeichnissen + results_dir = os.path.join(working_directory, "results") + plots_dir = os.path.join(working_directory, "plots") + + # Erstelle Ordner, falls sie nicht existieren + os.makedirs(plots_dir, exist_ok=True) + os.makedirs(results_dir, exist_ok=True) + + # Pfad zur Simulationsinfo-Datei + simulation_info_files = [f for f in os.listdir(results_dir) if + f.startswith("simulation_info_") and f.endswith(".json")] + + if not simulation_info_files: + print("Keine Simulationsinfo-Dateien gefunden!") + return + + # Nehme die neueste Simulationsinfo-Datei + latest_sim_info = sorted(simulation_info_files)[-1] + simulation_info_path = os.path.join(results_dir, latest_sim_info) + + print(f"Verwende Simulationsinfo-Datei: {latest_sim_info}") + + # Lade die Simulationsinfo + with open(simulation_info_path, 'r') as f: + simulation_info = json.load(f) + + # Die Spalten-Mapping-Definitionen + variable_map = { + "hp_power": "outputs.hydraulic.gen.PEleHeaPum.value", + "hp_energy": "outputs.hydraulic.gen.PEleHeaPum.integral", + "eh_power": "outputs.hydraulic.gen.PEleEleHea.value", + "eh_energy": "outputs.hydraulic.gen.PEleEleHea.integral", + "simulation_time": "Variables" + } + + # Erfolgreiche Modelle + successful_models = [model for model in simulation_info["models"] if model.get("success", True)] + + if not successful_models: + print("Keine erfolgreichen Simulationen gefunden!") + return + + print("\nLade und verarbeite Simulationsdaten...") + + # Dictionary zum Speichern der verarbeiteten Daten und KPIs + processed_data = {} + kpi_results = {} + + # Lade und verarbeite jede CSV-Datei + for model in successful_models: + model_name = model["name"] + result_file = model["result_file"] + result_path = os.path.join(results_dir, result_file) + + print(f"\nLade Daten für {model_name} aus {result_file}") + + try: + # Lade die CSV-Datei + df = pd.read_csv(result_path) + + # Anzeigen der ersten Zeilen zur Überprüfung + print("Erste Zeilen der Daten:") + print(df.head(3)) + + # Überprüfen der Spalten + print(f"Verfügbare Spalten: {df.columns.tolist()}") + + # Entferne Zeilen, die nur NaN-Werte enthalten + df = df.dropna(how='all') + + # Überprüfe, ob die benötigten Spalten vorhanden sind + required_cols = [ + variable_map["hp_power"], + variable_map["hp_energy"], + variable_map["eh_power"], + variable_map["eh_energy"] + ] + + missing_cols = [col for col in required_cols if col not in df.columns] + if missing_cols: + print(f"Warnung: Folgende Spalten fehlen: {missing_cols}") + continue + + # Konvertiere die Spalten zu numerischen Werten, ignoriere nicht-numerische Werte + for col in df.columns: + if col != 'time': + df[col] = pd.to_numeric(df[col], errors='coerce') + + # Entferne Zeilen mit NaN in wichtigen Spalten + df = df.dropna(subset=required_cols) + + # Überprüfe, ob überhaupt noch Daten übrig sind + if len(df) == 0: + print(f"Keine gültigen Daten für {model_name} nach der Filterung.") + continue + + # Speichere die verarbeiteten Daten + processed_data[model_name] = df + + # Berechne KPIs für dieses Modell + kpi_results[model_name] = {} + + # Simulationszeit (in Sekunden) + time_col = variable_map["simulation_time"] + if time_col in df.columns: + sim_time = df[time_col] + if not pd.api.types.is_numeric_dtype(sim_time): + print(f"Warnung: Simulationszeit ist nicht numerisch. Verwende Zeilenindizes.") + sim_time = pd.Series(range(len(df))) + else: + print(f"Simulationszeit-Spalte '{time_col}' nicht gefunden. Verwende Zeilenindizes.") + sim_time = pd.Series(range(len(df))) + + # Dauer in Tagen + sim_duration_seconds = sim_time.iloc[-1] - sim_time.iloc[0] + days = sim_duration_seconds / (24 * 3600) + kpi_results[model_name]["Anzahl der Tage"] = days + + # Wärmepumpen-Energie in kWh + hp_energy_col = variable_map["hp_energy"] + hp_energy_j = df[hp_energy_col].iloc[-1] - df[hp_energy_col].iloc[0] + hp_energy_kwh = hp_energy_j / (3600 * 1000) # Joule zu kWh + kpi_results[model_name]["Gesamtenergie Wärmepumpe [kWh]"] = hp_energy_kwh + + # Heizstab-Energie in kWh + eh_energy_col = variable_map["eh_energy"] + eh_energy_j = df[eh_energy_col].iloc[-1] - df[eh_energy_col].iloc[0] + eh_energy_kwh = eh_energy_j / (3600 * 1000) # Joule zu kWh + kpi_results[model_name]["Gesamtenergie Heizstab [kWh]"] = eh_energy_kwh + + # Gesamtenergie + total_energy_kwh = hp_energy_kwh + eh_energy_kwh + kpi_results[model_name]["Gesamtenergie [kWh]"] = total_energy_kwh + + # Täglicher Energieverbrauch + daily_energy = total_energy_kwh / days if days > 0 else 0 + kpi_results[model_name]["Täglicher Energieverbrauch [kWh/d]"] = daily_energy + + print(f"KPIs für {model_name} erfolgreich berechnet.") + + except Exception as e: + print(f"Fehler bei der Verarbeitung von {model_name}: {e}") + import traceback + traceback.print_exc() + + if not processed_data: + print("Keine Daten konnten erfolgreich verarbeitet werden!") + return + + print(f"\nErfolgreich verarbeitete Modelle: {list(processed_data.keys())}") + + # Ausgabe der KPI-Zusammenfassung + print("\nZusammenfassung der KPIs:") + + for model_name, kpis in kpi_results.items(): + print(f"\n{model_name}:") + for kpi_name, value in kpis.items(): + print(f" {kpi_name}: {value:.2f}") + + # Speichere KPI-Zusammenfassung in CSV + kpi_table = [] + for model_name, kpis in kpi_results.items(): + row = {'Modell': model_name} + row.update(kpis) + kpi_table.append(row) + + kpi_df = pd.DataFrame(kpi_table) + kpi_csv_path = os.path.join(results_dir, "kpi_zusammenfassung.csv") + kpi_df.to_csv(kpi_csv_path, index=False) + print(f"\nKPI-Zusammenfassung gespeichert in: {kpi_csv_path}") + + # Erstelle Plots für jedes Modell + for model_name, df in processed_data.items(): + try: + print(f"\nErstelle Plot für {model_name}...") + + # Plot der Wärmepumpen- und Heizstapleistung + plt.figure(figsize=(12, 8)) + + # Wärmepumpenleistung + plt.subplot(2, 1, 1) + hp_power_col = variable_map["hp_power"] + plt.plot(range(len(df)), df[hp_power_col] / 1000, # Konvertieren von W zu kW + label='Wärmepumpe', color='red') + plt.title(f'Wärmepumpenleistung - {model_name}') + plt.ylabel('Leistung [kW]') + plt.grid(True) + plt.legend() + + # Heizstapleistung + plt.subplot(2, 1, 2) + eh_power_col = variable_map["eh_power"] + plt.plot(range(len(df)), df[eh_power_col] / 1000, # Konvertieren von W zu kW + label='Heizstab', color='blue') + plt.title(f'Heizstapleistung - {model_name}') + plt.xlabel('Zeitschritt') + plt.ylabel('Leistung [kW]') + plt.grid(True) + plt.legend() + + plt.tight_layout() + plt.savefig(os.path.join(plots_dir, f"leistungsverlauf_{model_name.replace(' ', '_')}.png")) + plt.close() + + # Kreisdiagramm für Energieanteile + plt.figure(figsize=(8, 8)) + hp_energy = kpi_results[model_name]["Gesamtenergie Wärmepumpe [kWh]"] + eh_energy = kpi_results[model_name]["Gesamtenergie Heizstab [kWh]"] + + # Stelle sicher, dass mindestens einer der Werte positiv ist + if hp_energy > 0 or eh_energy > 0: + plt.pie([hp_energy, eh_energy], + labels=['Wärmepumpe', 'Heizstab'], + autopct='%1.1f%%', + colors=['red', 'blue'], + startangle=90) + plt.title(f'Energieanteile - {model_name}') + plt.savefig(os.path.join(plots_dir, f"energieanteile_{model_name.replace(' ', '_')}.png")) + plt.close() + else: + print(f"Keine positiven Energiewerte für {model_name}, überspringe Kreisdiagramm.") + + print(f"Plots für {model_name} erstellt.") + except Exception as e: + print(f"Fehler bei der Erstellung der Plots für {model_name}: {e}") + import traceback + traceback.print_exc() + + # Vergleichende Balkendiagramme für alle Modelle + try: + # Balkendiagramm der Gesamtenergie + plt.figure(figsize=(12, 6)) + models = list(kpi_results.keys()) + total_energies = [kpi_results[model]["Gesamtenergie [kWh]"] for model in models] + + bars = plt.bar(models, total_energies, color='red') + + # Beschriftungen hinzufügen + for bar in bars: + height = bar.get_height() + plt.text(bar.get_x() + bar.get_width() / 2., height + 0.1, + f'{height:.1f}', ha='center', va='bottom') + + plt.title('Gesamtenergieverbrauch im Vergleich') + plt.xlabel('Modell') + plt.ylabel('Gesamtenergie [kWh]') + plt.xticks(rotation=45, ha='right') + plt.tight_layout() + + plt.savefig(os.path.join(plots_dir, "gesamtenergie_vergleich.png")) + plt.close() + + # Balkendiagramm des täglichen Energieverbrauchs + plt.figure(figsize=(12, 6)) + daily_energies = [kpi_results[model]["Täglicher Energieverbrauch [kWh/d]"] for model in models] + + bars = plt.bar(models, daily_energies, color='blue') + + # Beschriftungen hinzufügen + for bar in bars: + height = bar.get_height() + plt.text(bar.get_x() + bar.get_width() / 2., height + 0.1, + f'{height:.1f}', ha='center', va='bottom') + + plt.title('Täglicher Energieverbrauch im Vergleich') + plt.xlabel('Modell') + plt.ylabel('Energieverbrauch pro Tag [kWh/d]') + plt.xticks(rotation=45, ha='right') + plt.tight_layout() + + plt.savefig(os.path.join(plots_dir, "taeglicher_energieverbrauch_vergleich.png")) + plt.close() + + print("\nVergleichende Balkendiagramme erstellt.") + except Exception as e: + print(f"Fehler bei der Erstellung der vergleichenden Balkendiagramme: {e}") + import traceback + traceback.print_exc() + + print("\nAnalyse abgeschlossen!") + print(f"Alle Dateien wurden im Verzeichnis '{results_dir}' und '{plots_dir}' gespeichert.") + + +if __name__ == "__main__": + main() + plt.show() \ No newline at end of file diff --git a/BuildingSim/working_dir/simulate_param_sweep.py b/BuildingSim/working_dir/simulate_param_sweep.py new file mode 100644 index 0000000000000000000000000000000000000000..c5a380cf5db0b516f5e8db91176e9e166a34c5fe --- /dev/null +++ b/BuildingSim/working_dir/simulate_param_sweep.py @@ -0,0 +1,277 @@ +# simulate_param_sweep.py +import os +import pathlib +import pandas as pd +import numpy as np +from ebcpy import DymolaAPI, TimeSeriesData +from datetime import datetime + + +def main(): + # Arbeitsverzeichnis (aktuelles Verzeichnis) + working_directory = pathlib.Path.cwd() + + # Erstelle Ordner für Ergebnisse und Logs mit relativen Pfaden + results_dir = os.path.join(working_directory, "results") + logs_dir = os.path.join(working_directory, "logs") + + # Erstelle Ordner, falls sie nicht existieren + os.makedirs(results_dir, exist_ok=True) + os.makedirs(logs_dir, exist_ok=True) + + # Exakte Pfade (diese sollten relativ sein, wenn möglich) + rollout_mo_path = os.path.join(working_directory, "Modelica_RollOut", "RollOut.mo") + mos_script_path = os.path.join(working_directory, "startModelica.mos") + + # Fallback auf absolute Pfade, wenn die obigen nicht existieren + if not os.path.isfile(rollout_mo_path): + # Fallback auf den ursprünglichen absoluten Pfad + rollout_mo_path = "C:\\Users\\mbc\\Documents\\Git-Repos\\RollOut\\BuildingSim\\working_dir\\Modelica_RollOut\\RollOut.mo" + + if not os.path.isfile(mos_script_path): + # Fallback auf den ursprünglichen absoluten Pfad + mos_script_path = "C:\\Users\\mbc\\Documents\\Git-Repos\\RollOut\\BuildingSim\\startModelica.mos" + + print(f"RollOut.mo-Pfad: {rollout_mo_path}") + print(f".mos-Script-Pfad: {mos_script_path}") + + # Überprüfen, ob die Dateien existieren + if not os.path.isfile(rollout_mo_path): + print(f"WARNUNG: Die Datei {rollout_mo_path} wurde nicht gefunden!") + if not os.path.isfile(mos_script_path): + print(f"WARNUNG: Die Datei {mos_script_path} wurde nicht gefunden!") + + try: + # Basis-Modellpfad + base_model_path = "RollOut.HeatPumpMonoenergeticResidentialBuilding" + + print(f"Verwende Basis-Modellpfad: {base_model_path}") + print("Starte Dymola und lade Bibliotheken...") + + # Liste der Wärmepumpentypen + heat_pump_types = [ + { + "name": "Vitocal 350 AWI 114", + "model": "AixLib.Fluid.HeatPumps.ModularReversible.Data.TableData2D.EN255.Vitocal350AWI114" + }, + { + "name": "Nibe Fighter 1140-15", + "model": "AixLib.Fluid.HeatPumps.ModularReversible.Data.TableData2D.EN255.NibeFighter1140_15" + }, + { + "name": "Alpha Innotec SW170I", + "model": "AixLib.Fluid.HeatPumps.ModularReversible.Data.TableData2D.EN255.AlphaInnotec_SW170I" + } + ] + + # Liste der Wetterdaten + weather_files = [ + { + "name": "Aachen", + "file": "modelica://BESMod/Resources/WeatherData/TRY2015_507931060546_Jahr_City_Aachen_Normal.mos" + }, + { + "name": "Potsdam", + "file": "modelica://BESMod/Resources/WeatherData/TRY2015_522361130393_Jahr_City_Potsdam.mos" + } + ] + + # Erstelle Modellpfade für alle Kombinationen von Wärmepumpen und Wetterdaten + model_combinations = [] + + for hp in heat_pump_types: + for weather in weather_files: + model_path = f"{base_model_path}(hydraulic(generation(heatPump(refCyc(refCycHeaPumHea(redeclare {hp['model']} datTab))))), systemParameters(filNamWea=Modelica.Utilities.Files.loadResource(\"{weather['file']}\")))" + model_combinations.append({ + "name": f"{hp['name']} - {weather['name']}", + "path": model_path, + "hp_name": hp['name'], + "weather_name": weather['name'] + }) + + # Initialisiere DymolaAPI mit dem Modell + dym_api = DymolaAPI( + model_name=base_model_path, + working_directory=working_directory, + show_window=True, + n_restart=-1, + mos_script_pre=mos_script_path + ) + + # Zeige Modellstatistik + print(f"Anzahl der Variablen: {len(dym_api.variables)}") + print(f"Anzahl der Ausgänge: {len(dym_api.outputs)}") + print(f"Anzahl der Eingänge: {len(dym_api.inputs)}") + print(f"Anzahl der Parameter: {len(dym_api.parameters)}") + print(f"Anzahl der Zustände: {len(dym_api.states)}") + + # Simulationseinstellungen + print("\nKonfiguriere Simulationseinstellungen...") + simulation_setup = { + "start_time": 0, + "stop_time": 7 * 24 * 3600, # 1 Woche + "output_interval": 60, # 1 Minute + "tolerance": 1e-4, + "solver": "Dassl" + } + dym_api.set_sim_setup(sim_setup=simulation_setup) + + # Zu speichernde Ergebnisvariablen + # Wärmepumpe und elektrischer Heizer + variable_names = { + "hp_power": "outputs.hydraulic.gen.PEleHeaPum.value", + "hp_energy": "outputs.hydraulic.gen.PEleHeaPum.integral", + "eh_power": "outputs.hydraulic.gen.PEleEleHea.value", + "eh_energy": "outputs.hydraulic.gen.PEleEleHea.integral" + } + + # Zu speichernde Ergebnisse + dym_api.result_names = list(variable_names.values()) + + # Simulation info speichern + simulation_info = { + "timestamp": datetime.now().strftime('%Y%m%d_%H%M%S'), + "models": [] + } + + # Simuliere die Modelle einzeln + print("\nSimuliere Modelle für verschiedene Kombinationen von Wärmepumpentypen und Wetterdaten...") + + for model in model_combinations: + model_name = model["name"] + model_path = model["path"] + hp_name = model["hp_name"] + weather_name = model["weather_name"] + + filename = f"{hp_name.replace(' ', '_')}_{weather_name.replace(' ', '_')}" + result_file_name = os.path.join(results_dir, filename) + + print(f"\nSimuliere {model_name}...") + + try: + # Simuliere das Modell + result = dym_api.simulate( + return_option="time_series", + model_names=[model_path], + result_file_name=result_file_name + ) + + if isinstance(result, list) and len(result) > 0: + result = result[0] + + # Konvertiere zu TimeSeriesData wenn nötig + if not isinstance(result, TimeSeriesData): + print(f"Konvertiere Ergebnis für {model_name} zu TimeSeriesData") + result = TimeSeriesData(result) + + # Überprüfe, ob die Variablen im Ergebnis existieren + missing_vars = [var for var_name, var in variable_names.items() if var not in result.columns] + + if not missing_vars: + print(f"Alle Variablen gefunden für {model_name}!") + + # Speichere das Ergebnis als CSV + csv_path = os.path.join(results_dir, f"{filename}.csv") + result.to_csv(csv_path) + print(f"Ergebnis gespeichert in: {csv_path}") + + # Speichere Information zur Simulation + simulation_info["models"].append({ + "name": model_name, + "hp_name": hp_name, + "weather_name": weather_name, + "result_file": f"{filename}.csv", + "success": True + }) + else: + print( + f"Warnung: Folgende Variablen nicht in den Ergebnissen für {model_name} gefunden: {', '.join(missing_vars)}") + + # Speichere trotzdem was wir haben + csv_path = os.path.join(results_dir, f"{filename}_incomplete.csv") + result.to_csv(csv_path) + print(f"Unvollständiges Ergebnis gespeichert in: {csv_path}") + + # Fehlende Variablen im Simulationsinfo-Eintrag vermerken + simulation_info["models"].append({ + "name": model_name, + "hp_name": hp_name, + "weather_name": weather_name, + "result_file": f"{filename}_incomplete.csv", + "success": False, + "missing_variables": missing_vars + }) + + except Exception as e: + print(f"Fehler bei der Simulation von {model_name}: {e}") + error_log = dym_api.dymola.getLastError() + print(f"Dymola-Fehler für {model_name}:") + print(error_log) + + # Speichere den Fehler in einer Log-Datei + error_log_path = os.path.join(logs_dir, f"error_{filename}.log") + with open(error_log_path, "w") as f: + f.write(f"Fehler bei der Simulation von {model_name}: {e}\n\n") + f.write(f"Dymola-Fehler:\n{error_log}") + + # Fehler im Simulationsinfo-Eintrag vermerken + simulation_info["models"].append({ + "name": model_name, + "hp_name": hp_name, + "weather_name": weather_name, + "result_file": None, + "success": False, + "error": str(e), + "error_log": f"error_{filename}.log" + }) + + # Speichere die Simulationsinformationen + import json + with open(os.path.join(results_dir, f"simulation_info_{simulation_info['timestamp']}.json"), "w") as f: + json.dump(simulation_info, f, indent=4) + + # Speichere auch ein Mapping für einfache Auswertung + with open(os.path.join(results_dir, "variable_mapping.json"), "w") as f: + json.dump(variable_names, f, indent=4) + + # Speichere die Simulation für spätere Reproduktion + try: + from ebcpy.utils import reproduction + reproduction_archive = os.path.join(logs_dir, "simulation_reproduction.zip") + reproduction.save_reproduction_archive(title="WärmepumpenSimulation", path=reproduction_archive) + print(f"\nSimulation wurde für spätere Reproduktion in {reproduction_archive} gespeichert.") + except Exception as e: + print(f"Fehler beim Speichern für Reproduktion: {e}") + + # Alternative Methode über DymolaAPI + try: + zip_file = dym_api.save_for_reproduction( + title="WärmepumpenSimulation", + log_message="Simulation verschiedener Wärmepumpentypen und Wetterdaten", + path=os.path.join(logs_dir, "dymola_reproduction.zip") + ) + print(f"Simulation wurde in {zip_file} für spätere Reproduktion gespeichert.") + except Exception as e2: + print(f"Auch die alternative Methode zur Speicherung ist fehlgeschlagen: {e2}") + + # Dymola-Instanz schließen + dym_api.close() + print("\nDymola-Instanz geschlossen.") + print(f"Simulation beendet am: {datetime.now()}") + + except Exception as e: + print(f"Fehler bei der Simulation: {e}") + import traceback + traceback.print_exc() + + # Versuche, Dymola zu schließen + try: + if 'dym_api' in locals(): + dym_api.close() + print("Dymola-Instanz geschlossen nach Fehler.") + except: + pass + + +if __name__ == "__main__": + main() \ No newline at end of file