Exemple #1
0
 def test_summary_table(self):
     with tempfile.TemporaryDirectory() as temp_dir_path:
         idf = Idf(self.idf_path)
         idf.add('''OutputControl:Table:Style,Comma,JtoKWH;''')
         idf.add('''Output:Table:SummaryReports,AllSummary;''')
         s = simulate(idf, self.epw_path, temp_dir_path)
         self.assertIsNotNone(s.summary_table)
Exemple #2
0
 def setUpClass(cls):
     cls.idf_managers_d = {}
     for eplus_version in TESTED_EPLUS_VERSIONS:
         CONF.eplus_version = eplus_version
         cls.idf_managers_d[eplus_version] = Idf(
             os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                          "1ZoneEvapCooler.idf"))._
Exemple #3
0
 def test_multiple_branch_links(self):
     for _ in iter_eplus_versions(self):
         idf = Idf(
             os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                          "5ZoneAirCooled.idf"))
         bl = idf["BranchList"].one(
             lambda x: x["Name"] == "heating supply side branches")
         b3 = idf["Branch"].one(
             lambda x: x["Name"] == "heating supply bypass branch")
         self.assertEqual(bl[3], b3)
Exemple #4
0
def generate_outputs():
    for eplus_version in TESTED_EPLUS_VERSIONS:
        # set eplus version
        CONF.eplus_version = eplus_version

        # iter simulation cases
        for simulation_case in to_simulate:

            # building_dir_name
            building_dir_name = simulation_case["dir_name"]

            # prepare base dir
            building_path = os.path.realpath(
                os.path.join(os.path.dirname(__file__), "..",
                             "simulations-outputs", building_dir_name))
            if not os.path.isdir(building_path):
                os.mkdir(building_path)

            # prepare directory name (or skip if exists)
            eplus_version_str = "-".join([str(v) for v in eplus_version])
            dir_path = os.path.join(building_path, eplus_version_str)
            if os.path.isdir(dir_path):
                continue
            os.mkdir(dir_path)

            # set paths
            idf_path = os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                                    f"{simulation_case['idf']}.idf")
            epw_path = os.path.join(CONF.eplus_base_dir_path, "WeatherData",
                                    f"{simulation_case['epw']}.epw")

            # prepare idf if needed
            pre_process = simulation_case.get("pre_process")
            if pre_process is not None:
                idf = Idf(idf_path)
                pre_process(idf)
            else:
                idf = idf_path

            # inform user
            print(eplus_version)
            print(idf_path)
            print(epw_path)
            print("---")

            # simulate
            simulate(idf, epw_path, dir_path)

            # remove unwanted extensions
            for file_name in os.listdir(dir_path):
                file_path = os.path.join(dir_path, file_name)
                _, ext = os.path.splitext(file_path)
                if ext[1:] not in simulation_case["extensions"]:
                    os.remove(file_path)
Exemple #5
0
    def test_simulate(self):
        for eplus_version in iter_eplus_versions(self):
            # prepare paths
            idf_path = os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                                    "1ZoneEvapCooler.idf")
            epw_path = os.path.join(
                CONF.eplus_base_dir_path, "WeatherData",
                "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")

            # prepare a quick simulation
            idf = Idf(idf_path)
            sc = idf["SimulationControl"].one()
            sc["Run Simulation for Sizing Periods"] = "No"
            rp = idf["RunPeriod"].one()
            rp["End Month"] = 1
            rp["End Day of Month"] = 1

            # prepare outputs
            out_f = io.StringIO()
            err_f = io.StringIO()

            # simulate
            with tempfile.TemporaryDirectory() as dir_path:
                s = simulate(idf,
                             epw_path,
                             dir_path,
                             stdout=out_f,
                             stderr=err_f,
                             beat_freq=0.1)

                # check one day output
                eso_df = s.eso.df()
                self.assertEqual(24, len(eso_df))

            # check err (manage differences between eplus versions)
            err_out = err_f.getvalue()
            self.assertTrue(
                (err_out == "")
                or ("EnergyPlus Completed Successfully.\n" in err_out))
            # check beat
            out_str = out_f.getvalue()
            self.assertIn("subprocess is still running", out_str)

            # check stdout
            out_str = out_str.replace("subprocess is still running\n", "")
            self.assertGreater(len(out_str.split("\n")),
                               15)  # check that more than 15 lines
Exemple #6
0
    def test_simulate_with_custom_idd(self):
        for eplus_version in iter_eplus_versions(self):
            default_idd_path = Idd.get_idd_path()
            dirname, basename = os.path.split(default_idd_path)

            with tempfile.TemporaryDirectory() as dir_path:
                # path
                new_idd_path = os.path.join(dir_path, f"~{basename}")

                # create empty file
                open(new_idd_path, "w").close()
                self.assertTrue(os.path.isfile(new_idd_path))

                # prepare idf and epw paths
                idf_path = os.path.join(CONF.eplus_base_dir_path,
                                        "ExampleFiles", "1ZoneEvapCooler.idf")
                epw_path = os.path.join(
                    CONF.eplus_base_dir_path, "WeatherData",
                    "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")

                # prepare a quick simulation
                idf = Idf(idf_path)
                sc = idf["SimulationControl"].one()
                sc["Run Simulation for Sizing Periods"] = "No"
                rp = idf["RunPeriod"].one()
                rp["End Month"] = 1
                rp["End Day of Month"] = 1

                # prepare outputs
                out_f = io.StringIO()
                err_f = io.StringIO()

                # simulate with empty idd -> must raise
                s = simulate(idf,
                             epw_path,
                             dir_path,
                             stdout=out_f,
                             stderr=err_f,
                             beat_freq=0.1,
                             idd_or_path_or_key=new_idd_path)
                with self.assertRaises(AssertionError):
                    # check one day output
                    s.eso.df()
                err_out = err_f.getvalue()
                self.assertTrue((err_out == "") or (
                    "Program terminated: EnergyPlus Terminated--Error(s) Detected.\n"
                    in err_out))

                # simulate with good idd -> check that works
                s = simulate(idf,
                             epw_path,
                             dir_path,
                             stdout=out_f,
                             stderr=err_f,
                             beat_freq=0.1,
                             idd_or_path_or_key=default_idd_path)

                # check one day output
                eso_df = s.eso.df()
                self.assertEqual(24, len(eso_df))

                # check err (manage differences between eplus versions)
                err_out = err_f.getvalue()
                self.assertTrue(
                    (err_out == "")
                    or ("EnergyPlus Completed Successfully.\n" in err_out))
                # check beat
                out_str = out_f.getvalue()
                self.assertIn("subprocess is still running", out_str)

                # check stdout
                out_str = out_str.replace("subprocess is still running\n", "")
                self.assertGreater(len(out_str.split("\n")),
                                   15)  # check that more than 15 lines
Exemple #7
0
 def get_idf_manager():
     return Idf(
         os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                      "1ZoneEvapCooler.idf"))._
Exemple #8
0
 def test_simple_read(self):
     for _ in iter_eplus_versions(self):
         for idf_name in ("4ZoneWithShading_Simple_1", ):
             Idf(
                 os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                              f"{idf_name}.idf"))
Exemple #9
0
import os
import tempfile

from oplus.configuration import CONF
from oplus import Idf

idf = Idf(
    os.path.join(CONF.eplus_base_dir_path, "ExampleFiles",
                 "1ZoneEvapCooler.idf"))
zone = idf["Zone"].one(lambda x: x["name"] == "Main Zone")
building = idf["Building"].one(lambda x: x["name"] == "Bldg")

# check info
if True:
    print(idf.info(sort_by_group=False, detailed=True))

if True:
    print(zone.info(detailed=False))

# check to_str
if True:
    zone.head_comment = "Hello\n\n\nhello!!"
    zone.tail_comment = "Here is my tail comment\nwritten on several lines..."
    zone.field_comment(
        0,
        zone.field_comment(0) + " **modified with\nline\nbreaks**")
    print(zone.to_str(style="console"))  # idf, console

# check save_as
if True:
    # modify idf comment