Skip to content

Commit

Permalink
Merge pull request #789 from RWTH-EBC/771-add-besmod-export
Browse files Browse the repository at this point in the history
771 add besmod export
  • Loading branch information
HvanderStok authored Dec 17, 2024
2 parents 1a24adf + cf64878 commit f2b4be6
Show file tree
Hide file tree
Showing 67 changed files with 1,970 additions and 252 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Efficient Buildings and Indoor
Climate](https://www.ebc.eonerc.rwth-aachen.de/cms/~dmzz/E-ON-ERC-EBC/?lidx=1).

* [AixLib](https://github.com/RWTH-EBC/AixLib)
* [BESMod](https://github.com/RWTH-EBC/BESMod)
* [Buildings](https://github.com/lbl-srg/modelica-buildings)
* [BuildingSystems](https://github.com/UdK-VPT/BuildingSystems)
* [IDEAS](https://github.com/open-ideas/IDEAS).
Expand Down Expand Up @@ -67,7 +68,7 @@ If you just want to read the example on github, check them here: docs/examples.

### Dependencies

TEASER is currently tested against Python 3.6 and 3.7. Older versions of Python may
TEASER is currently tested against Python 3.7 up to 3.11. Older versions of Python may
still work, but are no longer actively supported.
Using a Python distribution is recommended as they already contain (or easily
support installation of) many Python packages (e.g. SciPy, NumPy, pip, PyQT,
Expand Down
213 changes: 213 additions & 0 deletions docs/jupyter_notebooks/e11_export_besmod_models.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "# Example 11: Export Modelica models for BESMod library using TEASER API\nThis module demonstrates how to export building models from a TEASER project\nto ready-to-run simulation models for the Modelica BESMod library.\nBESMod enables seamless integration with state-of-the-art energy systems,\nsuch as heat pumps and photovoltaic systems. These systems can be utilized\nto generate primary energy demand curves (e.g., for electricity or gas) or\nto conduct in-depth analyses of building energy systems. In contrast,\nAixLib focuses on ideal heat demand calculation, and IBPSA on\nfree floating temperature without an ideal heater.\nYou can execute this example using\n[jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "import teaser.examples.e1_generate_archetype as e1\nimport teaser.logic.utilities as utilities\nimport os\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "## Standard export\nIn e1_generate_archetype we created a Project with three archetype\nbuildings to get this Project we rerun this example\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "prj = e1.example_generate_archetype()\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Configure project settings to ensure compatibility with BESMod. The BESMod\nlibrary uses the AixLib.ThermalZones.ReducedOrder.ThermalZone.ThermalZone model\nwith 4 elements for the demand building model. Other numbers of elements are possible,\nbut compatability with ARoof for PV and AFloor for UFH systems must be checked first.\nSet these parameters in the project:\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "prj.used_library_calc = 'AixLib'\nprj.number_of_elements_calc = 4\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "BESMod allows building models to be included in predefined example energy systems:\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "examples = [\n \"TEASERHeatLoadCalculation\", # Ideal electric heater for heat load calculations\n \"HeatPumpMonoenergetic\", # Heat pump with radiators, buffer and DHW storage, and PV\n \"GasBoilerBuildingOnly\" # Gas boiler with radiators\n]\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "For the hydraulic systems, you have to specify a nominal supply temperature\nfor heat transfer, e.g. in radiators.\nMultiple options are available:\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Option 1: Set a single value for all buildings and zones.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "THydSup_nominal = 55 + 273.15\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Option 2: Set values for each building or thermal zone.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "THydSup_nominal = {\"ResidentialBuilding\": 328.15,\n \"OfficeBuilding\": 328.15,\n \"InstituteBuilding\": {\"Office\": 343.15,\n \"Floor\": 343.15,\n \"Storage\": 343.15,\n \"Meeting\": 343.15,\n \"Restroom\": 343.15,\n \"ICT\": 343.15,\n \"Laboratory\": 328.15},\n \"InstituteBuildingMoisture\": 343.15,\n \"ResidentialBuildingTabula\": 328.15,\n \"ResidentialBuildingTabulaMulti\": 328.15}\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Option 3: Specify values based on construction year.\nHere, the value of the next higher specified year is set to the building.\nThe classification here is taken from:\nhttps://www.ffe.de/projekte/waermepumpen-fahrplan-finanzielle-kipppunkte-zur-modernisierung-mit-waermepumpen-im-wohngebaeudebestand/\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "THydSup_nominal = {\n 1950: 90 + 273.15,\n 1980: 70 + 273.15,\n 2010: 55 + 273.15,\n 2024: 35 + 273.15\n}\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "In the examples, the parameters for BESMod.Systems.UserProfiles.TEASERProfiles are configured,\nincluding internal gains and heating profiles for each zone.\nBESMod requires 24-hour heating profiles, which are used\nto define the parameters of the `setBakTSetZone` Pulse block.\nBy default, the TEASER profiles are applied, but these can be customized if needed.\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Additionally, location-specific parameters must be set, which can be achieved using the following function.\nThe default values provided here correspond to Mannheim.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "weather_file_path = utilities.get_full_path(\n os.path.join(\n \"data\",\n \"input\",\n \"inputdata\",\n \"weatherdata\",\n \"DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos\"))\n\nprj.set_location_parameters(t_outside=262.65,\n t_ground=286.15,\n weather_file_path=weather_file_path,\n calc_all_buildings=True)\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "To make sure the parameters are calculated correctly we recommend to\nrun prj.calc_all_buildings() function which is here already done in the set_location_parameters function.\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Export all buildings to BESMod and include them in predefined example systems.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "path = prj.export_besmod(\n THydSup_nominal=THydSup_nominal,\n path=None,\n examples=examples\n)\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "## Partial retrofit export\nThe partial retrofit option of the energy system in BESMod can also be utilized.\nFor more information on this see BESMod.UsersGuide.GettingStarted.Parameterization.\nTo enable this here, the nominal heat flow of each zone in the building must be extracted prior to the retrofit.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "QBuiOld_flow_design = {\n bldg.name: {\n tz.name: tz.model_attr.heat_load for tz in bldg.thermal_zones\n }\n for bldg in prj.buildings\n}\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Retrofit project buildings and recalculate parameters.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "prj.name = \"ArchetypeExample_partial_retrofit\"\nprj.retrofit_all_buildings(\n year_of_retrofit=2015,\n type_of_retrofit=\"adv_retrofit\",\n window_type='Alu- oder Stahlfenster, Isolierverglasung',\n material='EPS_perimeter_insulation_top_layer'\n)\nprj.calc_all_buildings()\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "By default, radiator transfer systems are not retrofitted when the\nQBuiOld_flow_design parameter is provided and differs from the new nominal heat flow.\nAdditionally, new THydSup_nominal temperatures can be specified alongside\nTHydSupOld_design values, which are used for radiator sizing but not for control settings.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "path = prj.export_besmod(\n THydSup_nominal=THydSup_nominal,\n QBuiOld_flow_design=QBuiOld_flow_design,\n path=None,\n examples=examples\n)\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "## Custom export\nAdditionally, we have the flexibility to define custom templates for including buildings in specific setups.\nFor instance, a custom template is defined here to include the building in the\nModelicaConferencePaper example from BESMod, which features an integrated battery system.\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Custom template\n```\n< %namespace file = \"/modelica_language/\" import=\"get_list\" / >\nwithin ${bldg.parent.name}.${bldg.name};\nmodel ModelicaConferencePaper${bldg.name}\n extends BESMod.Examples.ModelicaConferencePaper.PartialModelicaConferenceUseCase(\n redeclare ${bldg.name} building,\n redeclare BESMod.Systems.UserProfiles.TEASERProfiles\n userProfiles(fileNameIntGains=Modelica.Utilities.Files.loadResource(\n \"modelica://${bldg.parent.name}/${bldg.name}/InternalGains_${bldg.name}.txt\"),\n setBakTSetZone(amplitude=${get_list(setBakTSetZone_amplitude)},\n width =${get_list(setBakTSetZone_width)},\n startTime =${get_list(setBakTSetZone_startTime)})),\n systemParameters(nZones=${len(bldg.thermal_zones)},\n QBui_flow_nominal = building.QRec_flow_nominal,\n TOda_nominal =${TOda_nominal},\n TSetZone_nominal =${get_list(TSetZone_nominal)},\n THydSup_nominal =${THydSup_nominal},\n QBuiOld_flow_design =${QBuiOld_flow_design},\n THydSupOld_design =${THydSupOld_design},\n filNamWea = Modelica.Utilities.Files.loadResource(\n \"modelica://${bldg.parent.name}/Resources/${bldg.parent.weather_file_name}\")));\n\n extends Modelica.Icons.Example;\n\n annotation(experiment(StopTime=172800,\n Interval=600,\n Tolerance=1e-06),\n __Dymola_Commands(file=\n \"Resources/Scripts/Dymola/${bldg.name}/ModelicaConferencePaper${bldg.name}.mos\"\n \"Simulate and plot\"));\nend\nModelicaConferencePaper${bldg.name};\n```\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "prj.name = \"ArchetypeExample_custom\"\n\ncustom_template_path = os.path.join(\n os.path.dirname(__file__), \"examplefiles\", \"custom_besmod_templates\"\n)\ncustom_example_template = {\"ModelicaConferencePaper\": os.path.join(custom_template_path, \"custom_template.txt\")}\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "The template also includes a .mos script as part of its annotation.\nBy default, the provided examples export a basic \"simulate and plot\" script,\nwhich is incorporated into their annotation, as shown in the custom example.\nAdditionally, you have the flexibility to modify the template for existing examples\nand define custom scripts for your tailored examples.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "custom_script = {\"HeatPumpMonoenergetic\": os.path.join(custom_template_path, \"custom_script_hp_mono.txt\"),\n \"ModelicaConferencePaper\": os.path.join(custom_template_path, \"custom_script.txt\")}\n\npath = prj.export_besmod(\n THydSup_nominal=THydSup_nominal,\n path=None,\n examples=examples,\n custom_examples=custom_example_template,\n custom_script=custom_script\n)\n"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
7 changes: 1 addition & 6 deletions docs/jupyter_notebooks/e2_export_aixlib_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# Example 2: Export Modelica models for AixLib library using TEASER API\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "This module contains an example how to export buildings from a TEASER\nproject to ready-to-run simulation models for Modelica library AixLib. These\nmodels will only simulate using Dymola, the reason for this are state\nmachines that are used in one AixLib specific AHU model.\nYou can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)\n"
"source": "# Example 2: Export Modelica models for AixLib library using TEASER API\nThis module contains an example how to export buildings from a TEASER\nproject to ready-to-run simulation models for Modelica library AixLib.\nAixLib focuses on ideal hat demand calculation. In contrast,\nIBPSA focuses on the free floating temperature and has no ideal heater,\nand BESMod on the coupling to state-of-the-art energy systems.\nThese models will only simulate using Dymola, the reason for this are state\nmachines that are used in one AixLib specific AHU model.\nYou can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)\n"
},
{
"cell_type": "code",
Expand Down
2 changes: 1 addition & 1 deletion docs/jupyter_notebooks/e3_export_ibpsa_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# Example 3: Export Modelica models for IBPSA library using TEASER API\nThis module contains an example how to export buildings from a TEASER\nproject to ready-to-run simulation models for Modelica library IBPSA. These\nmodels should simulate in Dymola, OpenModelica and JModelica.\nYou can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)\n"
"source": "# Example 3: Export Modelica models for IBPSA library using TEASER API\nThis module contains an example how to export buildings from a TEASER\nproject to ready-to-run simulation models for Modelica library IBPSA.\nIBPSA focuses on free floating temperature without an ideal heater.\nIn contrast, AixLib focuses on ideal heat demand calculation, and\nBESMod on the coupling to state-of-the-art energy systems.\nThese models should simulate in Dymola, OpenModelica and JModelica.\nYou can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks)\n"
},
{
"cell_type": "code",
Expand Down
2 changes: 1 addition & 1 deletion docs/jupyter_notebooks/e6_generate_building.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "from teaser.logic.buildingobjects.thermalzone import ThermalZone\n\ntz = ThermalZone(parent=bldg)\ntz.name = \"LivingRoom\"\ntz.area = 140.0\ntz.volume = tz.area * bldg.number_of_floors * bldg.height_of_floors\ntz.infiltration_rate = 0.5\n"
"source": "from teaser.logic.buildingobjects.thermalzone import ThermalZone\n\ntz = ThermalZone(parent=bldg)\ntz.name = \"LivingRoom\"\ntz.area = 140.0\ntz.volume = tz.area * bldg.number_of_floors * bldg.height_of_floors\n"
},
{
"cell_type": "markdown",
Expand Down
Loading

0 comments on commit f2b4be6

Please sign in to comment.