Skip to content

Commit

Permalink
update test to use pyenergyplus dataset for reference models
Browse files Browse the repository at this point in the history
  • Loading branch information
Taoning Wang committed Oct 24, 2023
1 parent be449f7 commit da33376
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
62 changes: 30 additions & 32 deletions test/test_eplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,86 @@

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"

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")
Expand Down
7 changes: 3 additions & 4 deletions test/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import frads as fr
import numpy as np
import pytest
from pyenergyplus.dataset import ref_models, weather_files


@pytest.fixture
Expand Down Expand Up @@ -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(
Expand All @@ -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}
Expand Down

0 comments on commit da33376

Please sign in to comment.