Commit 63ab5d0a authored by Eric Duminil's avatar Eric Duminil
Browse files

Cooling too

parent 842bf1e8
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_345" class="java.beans.XMLDecoder">
<object class="eu.simstadt.workflowsteps.MonthlyEnergyBalanceStep">
<void property="calculationMode">
<object class="java.lang.Enum" method="valueOf">
<class>de.hft.stuttgart.simstadt2.buildingenergymodels.MonthlyBalanceDIN18599$CalculationMode</class>
<string>HEATING_AND_COOLING</string>
</object>
</void>
<void property="name">
<string>Base</string>
</void>
......
from pathlib import Path
import shutil
from xml.etree import ElementTree as et
import logging
import pandas as pd
import re
from run_simstadt_workflow import find_simstadt, SCRIPT_DIR, run_workflow
# logging.getLogger().setLevel(logging.WARN)
import logging
logging.getLogger().setLevel(logging.WARN)
#######################################################################
# User params
SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/'
REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository'
PROJECT_NAME = 'Gruenbuehl'
CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml']
SURFACES = ['outWalls', 'pitchedRoof']
WINDOW_RATIOS = [0, 0.5, 1]
# Heat demand, with custom BuildingPhysics
TEMPLATE_NAME = '99_HeatDemand'
#######################################################################
#######################################################################
XML_LIB_URL = 'http://www.simstadt.eu/BuildingPhysicsLibraries'
NAMESPACE = {'': XML_LIB_URL}
PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj'
PARAMS = 'params.xml'
BUILDING_PHYSICS_LIBRARY = 'GermanBuildingTypologyLibrary_IWU.xml'
#######################################################################
WINDOW_RATIOS = [0, 0.5, 1]
TEMPLATE_NAME = '99_HeatDemand'
template = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics
def copy_workflow_from_template(template_name, project_path):
template = SCRIPT_DIR / 'Template' / f'{template_name}.flow'
workflow_path = project_path / f'{template_name}.flow'
workflow_path = PROJECT_PATH / f'{TEMPLATE_NAME}.flow'
shutil.copytree(template, workflow_path, dirs_exist_ok=True)
shutil.copytree(template, workflow_path, dirs_exist_ok=True)
print(workflow_path)
physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step'
return workflow_path, physics_processor_step
physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step'
def set_custom_library(physics_processor_step):
custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
############# Specify custom lib #########################
custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
physics_processor_params = physics_processor_step / PARAMS
physics_processor_params = physics_processor_step / PARAMS
param_tree = et.parse(physics_processor_params)
root = param_tree.getroot()
param_tree = et.parse(physics_processor_params)
root = param_tree.getroot()
lib_node = root.find(
".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string")
lib_node.text = str(custom_library_path)
param_tree.write(physics_processor_params)
return custom_library_path
lib_node = root.find(".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string")
lib_node.text = str(custom_library_path)
param_tree.write(physics_processor_params)
##########################################################
def parse_library(library_path: Path) -> et.ElementTree:
et.register_namespace('', XML_LIB_URL)
return et.parse(library_path)
lib_tree = parse_library(custom_library_path)
def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, export_path: Path):
root = tree.getroot()
......@@ -65,36 +71,33 @@ def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, expo
window_ratio_node.text = str(window_ratio)
tree.write(export_path)
for window_ratio in WINDOW_RATIOS:
#################### Update lib with custom values ############################
def parse_results(window_ratio, heat_demand_csv):
df = pd.read_csv(heat_demand_csv,
skiprows=list(range(19)) + [20],
sep=';',
decimal=','
)
heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000
cool_demand_MWh = df['Yearly Cooling demand'].sum() / 1000
print(f"Window Ratio : {window_ratio * 100} %")
print(f"Total heating demand : {heat_demand_MWh:.0f} MWh / a")
print(f"Total cooling demand : {cool_demand_MWh:.0f} MWh / a")
set_custom_window_ratio(lib_tree, window_ratio, custom_library_path)
# new_content = re.sub(r"<name>[\w ]+</name>",
# f"<name>Custom Physics Library with Window Ratio : {window_ratio}</name>",
# content, 1)
# # FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
# new_content = re.sub(r"<windowRatio>[\d\.]+</windowRatio>",
# f"<windowRatio>{window_ratio}</windowRatio>",
# new_content)
workflow_path, physics_processor_step = copy_workflow_from_template(TEMPLATE_NAME, PROJECT_PATH)
custom_library_path = set_custom_library(physics_processor_step)
lib_tree = parse_library(custom_library_path)
# with open(custom_library_path, 'w') as library_file:
# library_file.write(new_content)
#################################################################################
for window_ratio in WINDOW_RATIOS:
# TODO: Status quo too
set_custom_window_ratio(lib_tree, window_ratio, custom_library_path)
output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS)
heat_demand_csv = next(file for file in output_files if 'HEATING.csv' in file.name)
heat_demand_csv = next(file for file in output_files if 'HEATING_AND_COOLING.csv' in file.name)
################### Parse heat demand ########################
df = pd.read_csv(heat_demand_csv,
skiprows=list(range(19)) + [20],
sep=';',
decimal=','
)
heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000
print(f"Window Ratio : {window_ratio * 100} %")
print(f"Total heat demand : {heat_demand_MWh:.0f} MWh / a")
parse_results(window_ratio, heat_demand_csv)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment