From da33376b27ca350635e5647ac93c3fbf0a3dcc83 Mon Sep 17 00:00:00 2001 From: Taoning Wang Date: Tue, 24 Oct 2023 14:35:16 -0700 Subject: [PATCH] update test to use pyenergyplus dataset for reference models --- test/test_eplus.py | 62 +++++++++++++++++++++----------------------- test/test_methods.py | 7 +++-- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/test/test_eplus.py b/test/test_eplus.py index 73ff0f1..b72fe8e 100644 --- a/test/test_eplus.py +++ b/test/test_eplus.py @@ -3,6 +3,8 @@ from frads.eplus import EnergyPlusModel, EnergyPlusSetup, load_energyplus_model from frads.window import GlazingSystem, create_glazing_system +from pyenergyplus.dataset import ref_models +import pytest test_dir = Path(__file__).resolve().parent resource_dir = test_dir / "Resources" @@ -10,81 +12,77 @@ idf_path = resource_dir / "RefBldgMediumOfficeNew2004_southzone.idf" glazing_path = resource_dir / "igsdb_product_7406.json" +@pytest.fixture +def medium_office(): + return load_energyplus_model(ref_models["medium_office"]) -def test_add_glazingsystem(): - epmodel = load_energyplus_model(idf_path) +def test_add_glazingsystem(medium_office): gs = create_glazing_system( name="test", layers=[glazing_path], ) - epmodel.add_glazing_system(gs) - assert epmodel.construction_complex_fenestration_state != {} - assert isinstance(epmodel.construction_complex_fenestration_state, dict) - assert isinstance(epmodel.matrix_two_dimension, dict) - assert isinstance(epmodel.window_material_glazing, dict) - assert isinstance(epmodel.window_thermal_model_params, dict) + medium_office.add_glazing_system(gs) + assert medium_office.construction_complex_fenestration_state != {} + assert isinstance(medium_office.construction_complex_fenestration_state, dict) + assert isinstance(medium_office.matrix_two_dimension, dict) + assert isinstance(medium_office.window_material_glazing, dict) + assert isinstance(medium_office.window_thermal_model_params, dict) -def test_add_lighting(): - epmodel = load_energyplus_model(idf_path) +def test_add_lighting(medium_office): try: - epmodel.add_lighting("z1") # zone does not exist + medium_office.add_lighting("z1") # zone does not exist assert False except ValueError: pass -def test_add_lighting1(): - epmodel = load_energyplus_model(idf_path) +def test_add_lighting1(medium_office): try: - epmodel.add_lighting("Perimeter_bot_ZN_1") # zone already has lighting + medium_office.add_lighting("Perimeter_bot_ZN_1") # zone already has lighting assert False except ValueError: pass -def test_add_lighting2(): - epmodel = load_energyplus_model(idf_path) - epmodel.add_lighting("Perimeter_bot_ZN_1", replace=True) +def test_add_lighting2(medium_office): + medium_office.add_lighting("Perimeter_bot_ZN_1", replace=True) - assert isinstance(epmodel.lights, dict) - assert isinstance(epmodel.schedule_constant, dict) - assert isinstance(epmodel.schedule_type_limits, dict) + assert isinstance(medium_office.lights, dict) + assert isinstance(medium_office.schedule_constant, dict) + assert isinstance(medium_office.schedule_type_limits, dict) -def test_output_variable(): +def test_output_variable(medium_office): """Test adding output variable to an EnergyPlusModel.""" - epmodel = load_energyplus_model(idf_path) - epmodel.add_output(output_name="Zone Mean Air Temperature", output_type="variable") + medium_office.add_output(output_name="Zone Mean Air Temperature", output_type="variable") assert "Zone Mean Air Temperature" in [ - i.variable_name for i in epmodel.output_variable.values() + i.variable_name for i in medium_office.output_variable.values() ] -def test_output_meter(): +def test_output_meter(medium_office): """Test adding output meter to an EnergyPlusModel.""" - epmodel = load_energyplus_model(idf_path) - epmodel.add_output( + medium_office.add_output( output_name="CO2:Facility", output_type="meter", reporting_frequency="Hourly", ) assert "CO2:Facility" in [ - i.key_name for i in epmodel.output_meter.values() + i.key_name for i in medium_office.output_meter.values() ] assert "Hourly" in [ - i.reporting_frequency.value for i in epmodel.output_meter.values() + i.reporting_frequency.value for i in medium_office.output_meter.values() ] -def test_energyplussetup(): +def test_energyplussetup(medium_office): """Test running EnergyPlusSetup.""" - epmodel = load_energyplus_model(idf_path) # file with Design Day - ep = EnergyPlusSetup(epmodel) + ep = EnergyPlusSetup(medium_office) ep.run(design_day=True) assert Path("eplusout.csv").exists() os.remove("eplus.json") diff --git a/test/test_methods.py b/test/test_methods.py index c253b53..013fb7a 100644 --- a/test/test_methods.py +++ b/test/test_methods.py @@ -8,6 +8,7 @@ import frads as fr import numpy as np import pytest +from pyenergyplus.dataset import ref_models, weather_files @pytest.fixture @@ -102,15 +103,13 @@ def test_eprad_threephase(resources_dir): """ Integration test for ThreePhaseMethod using EnergyPlusModel and GlazingSystem """ - idf_path = resources_dir / "RefBldgMediumOfficeNew2004_Chicago.idf" view_path = resources_dir / "view1.vf" - epw_path = resources_dir / "USA_CA_Oakland.Intl.AP.724930_TMY3.epw" clear_glass_path = resources_dir / "CLEAR_3.DAT" product_7406_path = resources_dir / "igsdb_product_7406.json" shade_path = resources_dir / "ec60.rad" shade_bsdf_path = resources_dir / "ec60.xml" - epmodel = load_energyplus_model(idf_path) + epmodel = load_energyplus_model(ref_models["medium_office"]) os.remove("eplusout.err") os.remove("eplusout.end") gs_ec60 = create_glazing_system( @@ -119,7 +118,7 @@ def test_eprad_threephase(resources_dir): gaps=[Gap([Gas("air", 0.1), Gas("argon", 0.9)], 0.0127)], ) epmodel.add_glazing_system(gs_ec60) - rad_models = epmodel_to_radmodel(epmodel, epw_file=epw_path) + rad_models = epmodel_to_radmodel(epmodel, epw_file=weather_files["usa_ca_san_francisco"]) zone = "Perimeter_bot_ZN_1" zone_dict = rad_models[zone] zone_dict["model"]["views"]["view1"] = {"file": view_path, "xres": 16, "yres": 16}