Skip to content

Commit

Permalink
Merge pull request #809 from RWTH-EBC/808-bug-in-custom-export-path
Browse files Browse the repository at this point in the history
fix custom paths
  • Loading branch information
FelixStege authored Jan 29, 2025
2 parents 60bef83 + 181f237 commit e51040e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion teaser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
import os

__version__ = "1.1.3"
__version__ = "1.1.4"


new_path = os.path.join(os.path.expanduser('~'), ("TEASEROutput"))
Expand Down
20 changes: 9 additions & 11 deletions teaser/data/output/aixlib_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def export_multizone(
Template for MultiZone model
"""

if path is None:
path = utilities.get_full_path("")

lookup = TemplateLookup(directories=[utilities.get_full_path(
os.path.join('data', 'output', 'modelicatemplate'))])
zone_template_1 = Template(
Expand Down Expand Up @@ -126,10 +129,8 @@ def export_multizone(
assert bldg.used_library_calc == 'AixLib', ass_error

bldg_path = os.path.join(path, bldg.name)
utilities.create_path(utilities.get_full_path(bldg_path))
utilities.create_path(utilities.get_full_path(
os.path.join(bldg_path,
bldg.name + "_DataBase")))
utilities.create_path(bldg_path)
utilities.create_path(os.path.join(bldg_path, bldg.name + "_DataBase"))
bldg.library_attr.modelica_set_temp(path=bldg_path)
bldg.library_attr.modelica_set_temp_cool(path=bldg_path)
bldg.library_attr.modelica_AHU_boundary(
Expand All @@ -154,8 +155,7 @@ def export_multizone(
"number of the building in "
"the project list.")
bldg.building_id = i
with open(utilities.get_full_path(
os.path.join(bldg_path, bldg.name + ".mo")), 'w') as out_file:
with open(os.path.join(bldg_path, bldg.name + ".mo"), 'w') as out_file:

out_file.write(model_template.render_unicode(
bldg=bldg,
Expand All @@ -172,9 +172,8 @@ def export_multizone(

for zone in bldg.thermal_zones:

with open(utilities.get_full_path(os.path.join(
zone_path,
bldg.name + '_' + zone.name + '.mo')), 'w') as out_file:
with open(os.path.join(zone_path, bldg.name + '_' + zone.name + '.mo'),
'w') as out_file:
if type(zone.model_attr).__name__ == "OneElement":
out_file.write(zone_template_1.render_unicode(zone=zone))
elif type(zone.model_attr).__name__ == "TwoElement":
Expand Down Expand Up @@ -250,8 +249,7 @@ def _help_test_script(bldg, dir_dymola, test_script_template):
dir_building = os.path.join(dir_dymola, bldg.name)
if not os.path.exists(dir_building):
os.mkdir(dir_building)
with open(utilities.get_full_path(os.path.join(
dir_building, bldg.name + ".mos")), 'w') as out_file:
with open(os.path.join(dir_building, bldg.name + ".mos"), 'w') as out_file:

names_variables = []
for i, zone in enumerate(bldg.thermal_zones):
Expand Down
14 changes: 8 additions & 6 deletions teaser/data/output/besmod_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def export_besmod(
if examples is None:
examples = []

if path is None:
path = utilities.get_full_path("")

if not isinstance(examples, list):
examples = [examples]

Expand Down Expand Up @@ -176,15 +179,14 @@ def export_besmod(
utilities.create_path(os.path.join(bldg_path, bldg.name + "_DataBase"))
bldg.library_attr.modelica_gains_boundary(path=bldg_path)

with open(utilities.get_full_path(
os.path.join(bldg_path, bldg.name + ".mo")), 'w') as out_file:
with open(os.path.join(bldg_path, bldg.name + ".mo"), 'w') as out_file:
out_file.write(building_template.render_unicode(
bldg=bldg))
out_file.close()

def write_example_mo(example_template, example):
with open(utilities.get_full_path(
os.path.join(bldg_path, example + bldg.name + ".mo")), 'w') as model_file:
with open(os.path.join(bldg_path, example + bldg.name + ".mo"),
'w') as model_file:
model_file.write(example_template.render_unicode(
bldg=bldg,
project=prj,
Expand Down Expand Up @@ -239,9 +241,9 @@ def write_example_mo(example_template, example):

for zone in bldg.thermal_zones:
zone.use_conditions.with_heating = False
with open(utilities.get_full_path(os.path.join(
with open(os.path.join(
zone_path,
bldg.name + '_' + zone.name + '.mo')), 'w') as out_file:
bldg.name + '_' + zone.name + '.mo'), 'w') as out_file:
if type(zone.model_attr).__name__ == "FourElement":
out_file.write(zone_template_4.render_unicode(zone=zone))
else:
Expand Down
12 changes: 7 additions & 5 deletions teaser/data/output/ibpsa_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def export_ibpsa(
library + '(version="' + prj.buildings[-1].library_attr.version[
library] + '")']

if path is None:
path = utilities.get_full_path("")

lookup = TemplateLookup(directories=[utilities.get_full_path(
os.path.join('data', 'output', 'modelicatemplate'))])
model_template_1 = Template(
Expand Down Expand Up @@ -112,9 +115,8 @@ def export_ibpsa(

bldg_path = os.path.join(path, bldg.name)

utilities.create_path(utilities.get_full_path(bldg_path))
utilities.create_path(utilities.get_full_path(
os.path.join(bldg_path, bldg.name + "_Models")))
utilities.create_path(bldg_path)
utilities.create_path(os.path.join(bldg_path, bldg.name + "_Models"))

modelica_output.create_package(
path=bldg_path,
Expand All @@ -138,8 +140,8 @@ def export_ibpsa(
zone=zone,
path=zone_path)

with open(utilities.get_full_path(os.path.join(
zone_path, bldg.name + '_' + zone.name + '.mo')), 'w') as out_file:
with open(os.path.join(
zone_path, bldg.name + '_' + zone.name + '.mo'), 'w') as out_file:

if type(zone.model_attr).__name__ == "OneElement":
out_file.write(model_template_1.render_unicode(zone=zone,
Expand Down
6 changes: 2 additions & 4 deletions teaser/data/output/modelica_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def create_package(path, name, uses=None, within=None):

package_template = Template(filename=utilities.get_full_path(
"data/output/modelicatemplate/package"))
with open(utilities.get_full_path(os.path.join(
path, "package.mo")), 'w') as out_file:
with open(os.path.join(path, "package.mo"), 'w') as out_file:

out_file.write(package_template.render_unicode(
name=name,
Expand Down Expand Up @@ -60,8 +59,7 @@ def create_package_order(path, package_list, addition=None, extra=None):

order_template = Template(filename=utilities.get_full_path(
"data/output/modelicatemplate/package_order"))
with open(utilities.get_full_path(
path + "/" + "package" + ".order"), 'w') as out_file:
with open(path + "/" + "package" + ".order", 'w') as out_file:

out_file.write(order_template.render_unicode
(list=package_list, addition=addition, extra=extra))
Expand Down

0 comments on commit e51040e

Please sign in to comment.