Exemple #1
0
    def setUpClass(cls):
        cls.epms_d = {}

        for eplus_version in TESTED_EPLUS_VERSIONS:
            CONF.eplus_version = eplus_version
            cls.epms_d[eplus_version] = Epm.from_idf(os.path.join(
                CONF.eplus_base_dir_path,
                "ExampleFiles",
                "1ZoneEvapCooler.idf")
            )
Exemple #2
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)
Exemple #3
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
Exemple #4
0
def run_eplus(epm_or_idf_path,
              weather_data_or_epw_path,
              simulation_dir_path,
              stdout=None,
              stderr=None,
              beat_freq=None):
    """
    Parameters
    ----------
    epm_or_idf_path:
    weather_data_or_epw_path
    simulation_dir_path
    stdout: default sys.stdout
    stderr: default sys.stderr
    beat_freq: if not none, stdout will be used at least every beat_freq (in seconds)
    """
    # work with absolute paths
    simulation_dir_path = os.path.abspath(simulation_dir_path)

    # check dir path
    if not os.path.isdir(simulation_dir_path):
        raise NotADirectoryError("Simulation directory does not exist: '%s'." %
                                 simulation_dir_path)

    # epm
    if not isinstance(epm_or_idf_path, Epm):
        # we don't copy file directly because we want to manage it's external files
        # could be optimized (use _copy_without_read_only)
        epm = Epm.from_idf(epm_or_idf_path)
    else:
        epm = epm_or_idf_path
    # gather external files
    simulation_idf_path = os.path.join(simulation_dir_path,
                                       CONF.simulation_base_name + ".idf")
    epm.gather_external_files(get_external_files_dir_path(simulation_idf_path))
    epm.to_idf(simulation_idf_path)

    # weather data
    simulation_epw_path = os.path.join(simulation_dir_path,
                                       CONF.simulation_base_name + ".epw")
    if isinstance(weather_data_or_epw_path, WeatherData):
        weather_data_or_epw_path.to_epw(simulation_epw_path)
    else:
        # no need to load: we copy directly
        _copy_without_read_only(weather_data_or_epw_path, simulation_epw_path)

    # copy epw if needed (depends on os/eplus version)
    temp_epw_path = get_simulated_epw_path()
    if temp_epw_path is not None:
        _copy_without_read_only(simulation_epw_path, temp_epw_path)

    # prepare command
    eplus_relative_cmd = get_simulation_base_command()
    eplus_cmd = os.path.join(CONF.eplus_base_dir_path, eplus_relative_cmd)

    # idf
    idf_command_style = get_simulation_input_command_style("idf")
    if idf_command_style == SIMULATION_INPUT_COMMAND_STYLES.simu_dir:
        idf_file_cmd = os.path.join(simulation_dir_path,
                                    CONF.simulation_base_name)
    elif idf_command_style == SIMULATION_INPUT_COMMAND_STYLES.file_path:
        idf_file_cmd = simulation_idf_path
    else:
        raise AssertionError("should not be here")

    # epw
    epw_command_style = get_simulation_input_command_style("epw")
    if epw_command_style == SIMULATION_INPUT_COMMAND_STYLES.simu_dir:
        epw_file_cmd = os.path.join(simulation_dir_path,
                                    CONF.simulation_base_name)
    elif epw_command_style == SIMULATION_INPUT_COMMAND_STYLES.file_path:
        epw_file_cmd = simulation_epw_path
    else:
        raise AssertionError("should not be here")

    # command list
    simulation_command_style = get_simulation_command_style()
    if simulation_command_style == SIMULATION_COMMAND_STYLES.args:
        cmd_l = [eplus_cmd, idf_file_cmd, epw_file_cmd]
    elif simulation_command_style == SIMULATION_COMMAND_STYLES.kwargs:
        cmd_l = [eplus_cmd, "-w", epw_file_cmd, "-r", idf_file_cmd]
    else:
        raise RuntimeError("should not be here")

    # launch calculation
    run_subprocess(cmd_l,
                   cwd=simulation_dir_path,
                   stdout=stdout,
                   stderr=stderr,
                   beat_freq=beat_freq)

    # if needed, we delete temp weather data (only on Windows, see above)
    if (temp_epw_path is not None) and os.path.isfile(temp_epw_path):
        os.remove(os.path.join(temp_epw_path))