Ejemplo n.º 1
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 = Epm.from_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)
def generate_outputs():
    for eplus_version in TESTED_EPLUS_VERSIONS:
        # iter simulation cases
        for simulation_case in to_simulate:

            # building_dir_name
            building_dir_name = simulation_case["dir_name"]

            # prepare base dir
            building_path = getattr(Resources.SimulationsOutputs,
                                    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(get_eplus_base_dir_path(eplus_version),
                                    "ExampleFiles",
                                    f"{simulation_case['idf']}.idf")
            epw_path = os.path.join(get_eplus_base_dir_path(eplus_version),
                                    "WeatherData",
                                    f"{simulation_case['epw']}.epw")

            # prepare idf if needed
            pre_process = simulation_case.get("pre_process")
            if pre_process is not None:
                idf = Epm.load(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):
                if get_resource_ref(
                        file_name) not in simulation_case["keep_resources"]:
                    os.remove(os.path.join(dir_path, file_name))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def check():
    """
    Tested under EPlus 8.1.0 on Windows (Geoffroy).
    """
    # !! CAN BE VERY LONG
    epw_path = os.path.join(
        CONF.eplus_base_dir_path, "WeatherData",
        "USA_VA_Sterling-Washington.Dulles.Intl.AP.724030_TMY3.epw")
    idf_dir_path = os.path.join(CONF.eplus_base_dir_path, "ExampleFiles")
    test_num = 0
    for file_num, file_name in enumerate(os.listdir(idf_dir_path)):
        if file_num < START_FILE_NUM:
            continue
        base, ext = os.path.splitext(file_name)
        if ext == ".idf":
            with tempfile.TemporaryDirectory() as simulation_dir_path:
                s = simulate(
                    os.path.join(idf_dir_path, file_name), epw_path,
                    simulation_dir_path
                    if DEBUG_SIMUL_DIR_PATH is None else DEBUG_SIMUL_DIR_PATH)
                if s.exists("eio"):
                    eio = Eio(s.get_file_path("eio"))  # raise error if problem
                    test_num += 1
        if test_num == MAX_TESTS_NB:
            break
Ejemplo n.º 5
0
 def test_summary_table(self):
     for eplus_version in iter_eplus_versions(self):
         base_dir_path = get_eplus_base_dir_path(eplus_version)
         idf_path = os.path.join(base_dir_path, "ExampleFiles", "4ZoneWithShading_Simple_1.idf")
         epw_path = os.path.join(base_dir_path, "WeatherData", "USA_CO_Golden-NREL.724666_TMY3.epw")
         with tempfile.TemporaryDirectory() as temp_dir_path:
             idf = Epm.load(idf_path)
             idf.OutputControl_Table_Style.add({0: "Comma", 1: "JtoKWH"})
             idf.Output_Table_SummaryReports.add({0: "AllSummary"})
             s = simulate(idf, epw_path, temp_dir_path)
             self.assertIsNotNone(s.get_out_summary_table())
Ejemplo n.º 6
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 = Epm.from_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.get_data()
                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
Ejemplo n.º 7
0
    def test_simulate(self):
        for eplus_version in iter_eplus_versions(self):
            # prepare paths
            idf_path = os.path.join(get_eplus_base_dir_path(eplus_version),
                                    "ExampleFiles", "1ZoneEvapCooler.idf")
            epw_path = os.path.join(
                get_eplus_base_dir_path(eplus_version), "WeatherData",
                "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")

            # prepare a quick simulation
            idf = Epm.load(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
            all_messages = []

            def print_fct(message):
                all_messages.append(message)

            # simulate
            with tempfile.TemporaryDirectory() as dir_path:

                s = simulate(idf,
                             epw_path,
                             dir_path,
                             print_function=print_fct,
                             beat_freq=0.1)

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

            # aggregate messages
            complete_message = "\n".join(all_messages)

            # check subprocess is still running
            self.assertIn("subprocess is still running", complete_message)

            # check stdout
            without_subprocess_message = complete_message.replace(
                "subprocess is still running\n", "")
            self.assertGreater(len(without_subprocess_message.split("\n")),
                               15)  # check that more than 15 lines
Ejemplo n.º 8
0
      len(epm.Building.select(lambda x: x.terrain == "Suburbs")))  # not ok
print("doesn't retain, lowercase: ",
      len(epm.Building.select(lambda x: x.terrain == "suburbs")))  # ok

## ---------------------------------------------------------------------------------------------------------------------
## ---------------------------------------------- simulation -----------------------------------------------------------
## ---------------------------------------------------------------------------------------------------------------------
#@ ## simulation
#@
## ----------------------------------------------- simulate ------------------------------------------------------------
#@ ### simulate
simulation_dir = os.path.join(work_dir_path, "simulation")
if not os.path.isdir(simulation_dir):
    os.mkdir(simulation_dir)
s = op.simulate(epm,
                os.path.join(op.CONF.eplus_base_dir_path, "WeatherData",
                             "USA_CO_Golden-NREL.724666_TMY3.epw"),
                base_dir_path=simulation_dir)

## -------------------------------------------- standard output --------------------------------------------------------
#@ ### standard output
# explore output
print("info: \n", s.eso.get_info(), "\n")

# explore environements
print("environments: ", s.eso.get_environments(), "\n")

# explore variables
print(f"variables: {s.eso.get_variables()}\n")

# tuple instants dataframe
df = s.eso.get_data()
Ejemplo n.º 9
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