From 2cbf79be8b3302adc808ebbcce8fd9a3a55b486d Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Mon, 7 Dec 2020 21:25:29 +0100 Subject: [PATCH] Option to export reference results For #669 --- teaser/data/output/aixlib_output.py | 27 ++++++++++++++++++++++ teaser/examples/e2_export_aixlib_models.py | 1 + teaser/project.py | 6 +++++ 3 files changed, 34 insertions(+) diff --git a/teaser/data/output/aixlib_output.py b/teaser/data/output/aixlib_output.py index 34ce22b45..3e9493d5a 100644 --- a/teaser/data/output/aixlib_output.py +++ b/teaser/data/output/aixlib_output.py @@ -189,11 +189,38 @@ def export_multizone(buildings, prj, path=None): extra=None) _copy_script_unit_tests(os.path.join(dir_scripts, "runUnitTests.py")) + _copy_reference_results(dir_resources, prj) print("Exports can be found here:") print(path) +def _copy_reference_results(dir_resources, prj): + """Copy reference results to modelica output. + + Parameters + ---------- + dir_resources : str + Resources directory of the modelica output + prj : teaser.project.Project + Project to be exported + """ + + if prj.dir_reference_results is not None: + dir_ref_out = os.path.join(dir_resources, "ReferenceResults") + if not os.path.exists(dir_ref_out): + os.mkdir(dir_ref_out) + dir_ref_out_dymola = os.path.join(dir_ref_out, "Dymola") + if not os.path.exists(dir_ref_out_dymola): + os.mkdir(dir_ref_out_dymola) + for filename in os.listdir(prj.dir_reference_results): + if filename.endswith(".txt"): + shutil.copy2( + os.path.join(prj.dir_reference_results, filename), + os.path.join(dir_ref_out_dymola, filename) + ) + + def _help_test_script(bldg, dir_dymola, test_script_template): """Create a test script for regression testing with BuildingsPy diff --git a/teaser/examples/e2_export_aixlib_models.py b/teaser/examples/e2_export_aixlib_models.py index d3d260563..46d477a56 100644 --- a/teaser/examples/e2_export_aixlib_models.py +++ b/teaser/examples/e2_export_aixlib_models.py @@ -20,6 +20,7 @@ def example_export_aixlib(): # buildings to get this Project we rerun this example prj = e1.example_generate_archetype() + prj.dir_reference_results = utilities.get_full_path("data/output/modelicatemplate") # To make sure the export is using the desired parameters you should # always set model settings in the Project. diff --git a/teaser/project.py b/teaser/project.py index eeadd7cd6..3074302de 100644 --- a/teaser/project.py +++ b/teaser/project.py @@ -86,6 +86,10 @@ class Project(object): IBPSA) used_library_calc : str used library (AixLib and IBPSA are supported) + dir_reference_results : str + Path to reference results in BuildingsPy format. If not None, the results + will be copied into the model output directories so that the exported + models can be regression tested against these results with BuildingsPy. """ def __init__(self, load_data=False): @@ -117,6 +121,8 @@ def __init__(self, load_data=False): else: self.data = None + self.dir_reference_results = None + @staticmethod def instantiate_data_class(): """Initialization of DataClass