示例#1
0
def test_makeductbranch():
    """py.test for makeductbranch"""
    tdata = (
        (
            "d_branch",
            [
                "BRANCH",
                "d_branch",
                "0",
                "",
                "duct",
                "d_branch_duct",
                "d_branch_duct_inlet",
                "d_branch_duct_outlet",
                "Bypass",
            ],
            ["DUCT", "d_branch_duct", "d_branch_duct_inlet", "d_branch_duct_outlet"],
        ),  # db_name, branch_obj, duct_obj
    )
    for db_name, branch_obj, duct_obj in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        result = hvacbuilder.makeductbranch(idf, db_name)
        assert result.obj == branch_obj
        theduct = idf.getobject("DUCT", result.Component_1_Name)
        assert theduct.obj == duct_obj
示例#2
0
    def test_save_copy(self):
        """Test savecopy with a new filename.

        IDF.savecopy(fname) doesn't change the filename. The next save should
        save with the original name.
        
        Fails if on a following save, the copy is changed.

        """
        idf = IDF(self.startfile)
        idf.savecopy(self.copyfile)
        setversion(idf, '7.5')
        idf.save()
        idf2 = IDF(self.copyfile)

        result = getversion(idf2)
        expected = '7.3'  # unchanged since version was changed after savecopy
        
        assert result == expected
        
        idf3 = IDF(self.startfile)
        result = getversion(idf3)
        expected = '7.5' # should be changed in the original file

        assert result == expected
示例#3
0
def test_replacebranch():
    """py.test for replacebranch"""
    tdata = (
        (
            "p_loop", ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4'],
            ['db0', ['db1', 'db2', 'db3'], 'db4'],
            'sb0',
            [
                ("Chiller:Electric".upper(), 'Central_Chiller',
                 'Chilled_Water_'),
                ("PIPE:ADIABATIC", 'np1', None),
                ("PIPE:ADIABATIC", 'np2', None)
            ],
            'Water',
            [
                'BRANCH', 'sb0', '0', '', 'CHILLER:ELECTRIC', 'Central_Chiller',
                'p_loop Supply Inlet', 'Central_Chiller_np1_node', '',
                'PIPE:ADIABATIC',
                'np1', 'Central_Chiller_np1_node', 'np1_np2_node', '',
                'PIPE:ADIABATIC',
                'np2', 'np1_np2_node', 'np2_Outlet_Node_Name', ''
            ]
        ), # loopname, sloop, dloop, branchname, componenttuple, fluid, outbranch
    )
    for (loopname, sloop, dloop, branchname,
         componenttuple, fluid, outbranch) in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        loop = hvacbuilder.makeplantloop(idf, loopname, sloop, dloop)
        components_thisnodes = [(idf.newidfobject(key, nm), thisnode)
                                for key, nm, thisnode in componenttuple]
        branch = idf.getobject('BRANCH', branchname)
        newbr = hvacbuilder.replacebranch(idf, loop, branch,
                                          components_thisnodes, fluid=fluid)
        assert newbr.obj == outbranch
示例#4
0
def test_makepipebranch():
    """py.test for makepipebranch"""
    tdata = (
        (
            "p_branch",
            [
                "BRANCH",
                "p_branch",
                "0",
                "",
                "Pipe:Adiabatic",
                "p_branch_pipe",
                "p_branch_pipe_inlet",
                "p_branch_pipe_outlet",
                "Bypass",
            ],
            ["PIPE:ADIABATIC", "p_branch_pipe", "p_branch_pipe_inlet", "p_branch_pipe_outlet"],
        ),  # pb_name, branch_obj, pipe_obj
    )
    for pb_name, branch_obj, pipe_obj in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        result = hvacbuilder.makepipebranch(idf, pb_name)
        assert result.obj == branch_obj
        thepipe = idf.getobject("PIPE:ADIABATIC", result.Component_1_Name)
        assert thepipe.obj == pipe_obj
示例#5
0
def test_new():
    """py.test for IDF.new()"""
    idf = IDF()
    idf.new()
    # assert idf.idfobjects['building'.upper()] == Idf_MSequence()
    assert idf.idfobjects['building'.upper()].list1 == []
    assert idf.idfobjects['building'.upper()].list2 == []
示例#6
0
def test_initinletoutlet():
    """py.test for initinletoutlet"""
    tdata = (
        ("PIPE:ADIABATIC", "apipe", None, True, ["apipe_Inlet_Node_Name"], ["apipe_Outlet_Node_Name"]),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
        ("PIPE:ADIABATIC", "apipe", None, False, ["Gumby"], ["apipe_Outlet_Node_Name"]),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
        (
            "Coil:Cooling:Water".upper(),
            "acoil",
            "Water_",
            True,
            ["acoil_Water_Inlet_Node_Name", ""],
            ["acoil_Water_Outlet_Node_Name", ""],
        ),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
    )
    fhandle = StringIO("")
    idf = IDF(fhandle)
    for idfobjectkey, idfobjname, thisnode, force, inlets, outlets in tdata:
        idfobject = idf.newidfobject(idfobjectkey, idfobjname)
        inodefields = hvacbuilder.getfieldnamesendswith(idfobject, "Inlet_Node_Name")
        idfobject[inodefields[0]] = "Gumby"
        hvacbuilder.initinletoutlet(idf, idfobject, thisnode, force=force)
        inodefields = hvacbuilder.getfieldnamesendswith(idfobject, "Inlet_Node_Name")
        for nodefield, inlet in zip(inodefields, inlets):
            result = idfobject[nodefield]
            assert result == inlet
        onodefields = hvacbuilder.getfieldnamesendswith(idfobject, "Outlet_Node_Name")
        for nodefield, outlet in zip(onodefields, outlets):
            result = idfobject[nodefield]
            assert result == outlet
示例#7
0
def test_reproduce_run_issue():
    """This is for use as a debugging tool.

    Add the files used in the run as reported/provided by a user.
    Make any additional changes required for reproducing/diagnosing the issue.
    """
    # update the following four lines if necessary
    ep_version = "8-9-0"
    idffile = "V8_9/smallfile.idf"
    iddfile = "Energy+V8_9_0.idd"
    epwfile = "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"

    _, eplus_home = paths_from_version(ep_version)
    idfname = os.path.join(IDF_FILES, idffile)
    iddfile = os.path.join(IDD_FILES, iddfile)
    epwfile = os.path.join(eplus_home, "WeatherData", epwfile)
    modeleditor.IDF.setiddname(iddfile, testing=True)
    idf = IDF(idfname, epwfile)
    # make any changes to the IDF here
    try:
        # Add any additional `run` kwargs here
        # `ep_version` kwarg is required due to buggy test isolation
        idf.run(output_directory="test_dir", ep_version=ep_version)
        # Add any tests for expected/unexpected outputs here
    except Exception:
        # Add any tests for expected/unexpected exceptions here
        raise
    finally:
        shutil.rmtree("test_dir", ignore_errors=True)
示例#8
0
def test_makeductbranch():
    """py.test for makeductbranch"""
    tdata = ((
        'd_branch',
        [
            'BRANCH',
            'd_branch',
            '0',
            '',
            'duct',
            'd_branch_duct',
            'd_branch_duct_inlet',
            'd_branch_duct_outlet',
            'Bypass'],
        [
            'DUCT',
            'd_branch_duct',
            'd_branch_duct_inlet',
            'd_branch_duct_outlet']), # db_name, branch_obj, duct_obj
            )
    for db_name, branch_obj, duct_obj in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        result = hvacbuilder.makeductbranch(idf, db_name)
        assert result.obj == branch_obj
        theduct = idf.getobject('DUCT', result.Component_1_Name)
        assert theduct.obj == duct_obj
示例#9
0
def test_makepipebranch():
    """py.test for makepipebranch"""
    tdata = ((
        "p_branch",
        ['BRANCH',
         'p_branch',
         '0',
         '',
         'Pipe:Adiabatic',
         'p_branch_pipe',
         'p_branch_pipe_inlet',
         'p_branch_pipe_outlet',
         'Bypass'],
        [
            'PIPE:ADIABATIC',
            'p_branch_pipe',
            'p_branch_pipe_inlet',
            'p_branch_pipe_outlet']
        ), # pb_name, branch_obj, pipe_obj
            )
    for pb_name, branch_obj, pipe_obj in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        result = hvacbuilder.makepipebranch(idf, pb_name)
        assert result.obj == branch_obj
        thepipe = idf.getobject('PIPE:ADIABATIC', result.Component_1_Name)
        assert thepipe.obj == pipe_obj
示例#10
0
def getidfkeyswithnodes():
    """return a list of keys of idfobjects that hve 'None Name' fields"""
    idf = IDF(StringIO(""))
    keys = idfobjectkeys(idf)
    keysfieldnames = ((key, idf.newidfobject(key.upper()).fieldnames) 
                for key in keys)
    keysnodefdnames = ((key,  (name for name in fdnames 
                                if (name.endswith('Node_Name')))) 
                            for key, fdnames in keysfieldnames)
    nodekeys = [key for key, fdnames in keysnodefdnames if list(fdnames)]
    return nodekeys
示例#11
0
def test_IDF():
    """py.test for class IDF"""
    stored_idd = IDF.iddname
    IDF.iddname = None
    assert IDF.iddname == None
    IDF.setiddname("gumby", testing=True)
    assert IDF.iddname == "gumby"
    IDF.setiddname("karamba", testing=True)
    assert IDF.iddname != "karamba"
    assert IDF.iddname == "gumby"
    IDF.iddname = stored_idd
示例#12
0
def test_getiddgroupdict():
    """py.test for IDF.getiddgroupdict()"""
    data = ((
    {
        None: ['Lead Input', 'Simulation Data']
    },
    ),  # gdict,
    )
    for gdict, in data:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        result = idf.getiddgroupdict()
        assert result[None] == gdict[None]
示例#13
0
def get_idf(idf_file: str = config.files.get('idf'),
            idd_file: str = config.files.get('idd'),
            output_directory=config.out_dir) -> IDF:
    """Uses eppy to read an idf file and generate the corresponding idf object"""
    # Trying to change the idd file inside a program will cause an error
    IDF.setiddname(idd_file)
    # TODO: Fix this rather than hiding it.
    # calling IDF causes a warning to appear, currently redirect_stdout hides this.
    with contextlib.redirect_stdout(None):
        idf = IDF(idf_file)
        # override the output location so I stop messing up
        idf.run = partial(idf.run, output_directory=output_directory)
        return idf
示例#14
0
def read_idf(fname, iddfile="lib/V8-5-0-Energy+.idd"):
    IDF.setiddname(iddfile)
    idf = IDF(fname)

    zones = {}

    for zone in idf.idfobjects["ZONE"]:
        zone_obj = Zone(zone.Name, "Zone", zone.Floor_Area)
        zone_obj.equipmentLoad = 0.0
        zone_obj.occupancy = 0.0
        zone_obj.lightingLoad = 0.0
        zone_obj.wallClasses = []
        zones[zone.Name] = zone_obj
示例#15
0
def test_replacebranch():
    """py.test for replacebranch"""
    tdata = (
        (
            "p_loop",
            ["sb0", ["sb1", "sb2", "sb3"], "sb4"],
            ["db0", ["db1", "db2", "db3"], "db4"],
            "sb0",
            [
                ("Chiller:Electric", "Central_Chiller", "Chilled_Water_"),
                ("PIPE:ADIABATIC", "np1", None),
                ("PIPE:ADIABATIC", "np2", None),
            ],
            "Water",
            [
                "BRANCH",
                "sb0",
                0.0,
                "",
                "CHILLER:ELECTRIC",
                "Central_Chiller",
                "p_loop Supply Inlet",
                "Central_Chiller_np1_node",
                "",
                "PIPE:ADIABATIC",
                "np1",
                "Central_Chiller_np1_node",
                "np1_np2_node",
                "",
                "PIPE:ADIABATIC",
                "np2",
                "np1_np2_node",
                "np2_Outlet_Node_Name",
                "",
            ],
        ),  # loopname, sloop, dloop, branchname, componenttuple, fluid, outbranch
    )
    for (loopname, sloop, dloop, branchname, componenttuple, fluid,
         outbranch) in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        loop = hvacbuilder.makeplantloop(idf, loopname, sloop, dloop)
        components_thisnodes = [(idf.newidfobject(key, Name=nm), thisnode)
                                for key, nm, thisnode in componenttuple]
        branch = idf.getobject("BRANCH", branchname)
        newbr = hvacbuilder.replacebranch(idf,
                                          loop,
                                          branch,
                                          components_thisnodes,
                                          fluid=fluid)
        assert newbr.obj == outbranch
示例#16
0
def test_initinletoutlet():
    """py.test for initinletoutlet"""
    tdata = (
        (
            'PIPE:ADIABATIC',
            'apipe',
            None,
            True,
            ["apipe_Inlet_Node_Name"],
            ["apipe_Outlet_Node_Name"]
        ),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
        (
            'PIPE:ADIABATIC',
            'apipe',
            None,
            False,
            ["Gumby"],
            ["apipe_Outlet_Node_Name"]
        ),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
        (
            'Coil:Cooling:Water',
            'acoil',
            'Water_',
            True,
            ["acoil_Water_Inlet_Node_Name", ""],
            ["acoil_Water_Outlet_Node_Name", ""]
        ),
        # idfobjectkey, idfobjname, thisnode, force, inlets, outlets
    )
    fhandle = StringIO("")
    idf = IDF(fhandle)
    for idfobjectkey, idfobjname, thisnode, force, inlets, outlets in tdata:
        idfobject = idf.newidfobject(idfobjectkey, Name=idfobjname)
        inodefields = hvacbuilder.getfieldnamesendswith(
            idfobject,
            "Inlet_Node_Name")
        idfobject[inodefields[0]] = "Gumby"
        hvacbuilder.initinletoutlet(idf, idfobject, thisnode, force=force)
        inodefields = hvacbuilder.getfieldnamesendswith(idfobject,
                                                        "Inlet_Node_Name")
        for nodefield, inlet in zip(inodefields, inlets):
            result = idfobject[nodefield]
            assert result == inlet
        onodefields = hvacbuilder.getfieldnamesendswith(
            idfobject,
            "Outlet_Node_Name")
        for nodefield, outlet in zip(onodefields, outlets):
            result = idfobject[nodefield]
            assert result == outlet
示例#17
0
def test_save():
    """
    Test the IDF.save() function using a filehandle to avoid external effects.
    """
    file_text = "Material,TestMaterial,  !- Name"
    idf = IDF(StringIO(file_text))
    # test save with just a filehandle
    file_handle = StringIO()
    idf.save(file_handle)
    expected = "TestMaterial"
    file_handle.seek(0)
    result = file_handle.read()
    # minimal test that TestMaterial is being written to the file handle
    assert expected in result
def test_simulations_basic_settings(ureg, res_folder):
    expected_file_path = os.path.dirname(__file__) / Path(
        "./expected_results/idf_expected_simulation_basics.idf")

    os.makedirs(res_folder, exist_ok=True)
    aux_files_handler = RelativeAuxiliaryFilesHandler()
    aux_files_handler.set_destination(res_folder, "profiles")

    idf_file_path = res_folder / Path("idf_simulation_basics.idf")
    my_idf_writer = CesarIDFWriter(idf_file_path, ureg, aux_files_handler)
    idf = IDF(str(idf_file_path))
    my_idf_writer.add_basic_simulation_settings(idf, SiteGroundTemperatureFactory(ureg).get_ground_temperatures())
    idf.save()
    assert are_files_equal(idf_file_path, expected_file_path, ignore_line_nrs=[1]) == True
示例#19
0
def test_componentsintobranch():
    """py.test for componentsintobranch"""
    tdata = (
    ("""BRANCH,
         sb0,
         0,
         ,
         Pipe:Adiabatic,
         sb0_pipe,
         p_loop Supply Inlet,
         sb0_pipe_outlet,
         Bypass;
    """, 
    [("PIPE:ADIABATIC", "pipe1"), ("PIPE:ADIABATIC", "pipe2")],
    '',
    ['PIPE:ADIABATIC', 'pipe1', 'pipe1_Inlet_Node_Name', 
    'pipe1_Outlet_Node_Name', '', 'PIPE:ADIABATIC', 'pipe2', 
    'pipe2_Inlet_Node_Name', 'pipe2_Outlet_Node_Name', '']
    ), 
    # idftxt, complst, fluid, branchcomps
    
    ("""BRANCH,
         sb0,
         0,
         ,
         Pipe:Adiabatic,
         sb0_pipe,
         p_loop Supply Inlet,
         sb0_pipe_outlet,
         Bypass;
    """, 
    [("PIPE:ADIABATIC", "pipe1"), ('CHILLER:ELECTRIC', "chiller")],
    '',
    ['PIPE:ADIABATIC', 'pipe1', 'pipe1_Inlet_Node_Name', 
    'pipe1_Outlet_Node_Name', '', 'CHILLER:ELECTRIC', 'chiller', 
    'chiller_Chilled_Water_Inlet_Node_Name', 
    'chiller_Chilled_Water_Outlet_Node_Name', '']
    ), 
    # idftxt, complst, fluid, branchcomps
    )                                                    
    for idftxt, complst, fluid, branchcomps in tdata:
        fhandle = StringIO(idftxt)
        idf = IDF(fhandle)
        components = [idf.newidfobject(key, nm) for key, nm in complst]
        fnc = hvacbuilder.initinletoutlet
        components = [fnc(idf, cp) for cp in components]
        branch = idf.idfobjects['BRANCH'][0]
        branch = hvacbuilder.componentsintobranch(idf, branch, components, 
                                                                    fluid)
        assert branch.obj[4:] == branchcomps
示例#20
0
def test_save():
    """
    Test the IDF.save() function using a filehandle to avoid external effects.
    """
    file_text = "Material,TestMaterial,  !- Name"
    idf = IDF(StringIO(file_text))
    # test save with just a filehandle
    file_handle = StringIO()
    idf.save(file_handle)
    expected = "TestMaterial"
    file_handle.seek(0)
    result = file_handle.read()
    # minimal test that TestMaterial is being written to the file handle
    assert expected in result
示例#21
0
def test_idfobjectindices():
    """py.test for idfobjectindices"""
    idf = IDF(StringIO.StringIO(""))
    data = (
        ('ZONE', 1, 0),  # objkey, num_makes, obj_id
        ('ZONELIST', 3, 2),  # objkey, num_makes, obj_id
        ('BRANCH', 13, 12),  # objkey, num_makes, obj_id
    )
    for objkey, num_makes, obj_id in data:
        key_id = idf_helpers.idfobjectkeys(idf).index(objkey.upper())
        for i in range(num_makes):
            idfobj = idf.newidfobject(objkey.upper(), Name="obj%s" % (i, ))
        result = eppystuff.idfobjectindices(idf, idfobj)
        assert result == (key_id, obj_id)
示例#22
0
    def test_save_copy(self):
        """Test savecopy with a new filename.

        IDF.savecopy(fname) doesn't change the filename. The next save should
        save with the original name.

        Fails if on a following save, the copy is changed.

        """
        idf = IDF(self.startfile)
        idf.savecopy(self.copyfile)
        setversion(idf, "7.5")
        idf.save()
        idf2 = IDF(self.copyfile)

        result = getversion(idf2)
        expected = "7.3"  # unchanged since version was changed after savecopy

        assert result == expected

        idf3 = IDF(self.startfile)
        result = getversion(idf3)
        expected = "7.5"  # should be changed in the original file

        assert result == expected
示例#23
0
    def setup(self):
        """Set the IDD and file paths, and make a copy of the original file."""
        iddfile = os.path.join(IDD_FILES, "Energy+V7_2_0.idd")
        IDF.setiddname(iddfile, testing=True)

        self.origfile = os.path.join(INTEGRATION_FILES, "origfile.idf")

        # set tempfile names
        self.startfile = os.path.join(INTEGRATION_FILES, "startfile.idf")
        self.saveasfile = os.path.join(INTEGRATION_FILES, "saveas.idf")
        self.copyfile = os.path.join(INTEGRATION_FILES, "savecopy.idf")

        # make a copy of test file
        shutil.copy(self.origfile, self.startfile)
示例#24
0
    def write_to_idf(self, edited_schedule, idf_file, new_file):
        """
        method to write schedule to IDF
        :param edited_schedule: str -> schedule that is edited
        :param idf_file: original IDF from which base schedule is extracted
        :param new_file: name of new file to which the schedule is written
        """

        idf_0 = IDF(idfname=idf_file)
        idf_0.saveas(new_file)

        with open(new_file, "a") as file:
            file.write("\n\n")
            file.write(edited_schedule)

        idf = IDF(idfname=new_file)
        # IDF.setiddname(self.idd_file)
        DualSetpoints = idf.idfobjects["ThermostatSetpoint:DualSetpoint"]

        if self.schedule_type == "CLGSETP":
            for DualSetpoint in DualSetpoints:
                DualSetpoint[
                    "Cooling_Setpoint_Temperature_Schedule_Name"] = self.schedule_name_edited
        elif self.schedule_type == "HTGSETP":
            for DualSetpoint in DualSetpoints:
                DualSetpoint[
                    "Heating_Setpoint_Temperature_Schedule_Name"] = self.schedule_name_edited
        else:
            print("Enter Valid SETP")

        idf.saveas(new_file)

        return None
示例#25
0
def test_name2idfobject():
    """py.test for name2idfobject"""
    idf = IDF(StringIO(""))
    plantloopname = "plantloopname"
    branchname = "branchname"
    pumpname = "pumpname"
    zonename = "zonename"
    plantloop = idf.newidfobject('PlantLoop'.upper(), 
                    Name=plantloopname,
                    Plant_Side_Inlet_Node_Name='CW Supply Inlet Node')
    branch = idf.newidfobject('Branch'.upper(), 
                    Name=branchname,
                    Component_1_Inlet_Node_Name='CW Supply Inlet Node')
    pump = idf.newidfobject('Pump:VariableSpeed'.upper(), 
                    Name=pumpname,
                    Inlet_Node_Name='CW Supply Inlet Node')
    zone = idf.newidfobject('zone'.upper(), Name=zonename)
    simulation = idf.newidfobject('SimulationControl'.upper()) 
    # - test
    names = [plantloopname, branchname, pumpname, zonename]
    idfobjs = [plantloop, branch, pump, zone]
    for name, idfobj in zip(names, idfobjs):
        result = idf_helpers.name2idfobject(idf, Name=name)
        assert result == idfobj
    # test when objkeys!=None
    objkey = 'ZoneHVAC:EquipmentConnections'.upper()
    equipconnections = idf.newidfobject(objkey,
                        Zone_Name=zonename)
    result = idf_helpers.name2idfobject(idf, Zone_Name=zonename, 
                    objkeys=[objkey, ])
    assert result == equipconnections
示例#26
0
def test_componentsintobranch():
    """py.test for componentsintobranch"""
    tdata = (
        ("""BRANCH,
             sb0,
             0,
             ,
             Pipe:Adiabatic,
             sb0_pipe,
             p_loop Supply Inlet,
             sb0_pipe_outlet,
             Bypass;
             """, [("PIPE:ADIABATIC", "pipe1", None),
                   ("PIPE:ADIABATIC", "pipe2", None)], '', [
                       'PIPE:ADIABATIC', 'pipe1', 'pipe1_Inlet_Node_Name',
                       'pipe1_Outlet_Node_Name', '', 'PIPE:ADIABATIC', 'pipe2',
                       'pipe2_Inlet_Node_Name', 'pipe2_Outlet_Node_Name', ''
                   ]),
        # idftxt, complst, fluid, branchcomps
        ("""BRANCH,
            sb0,
            0,
            ,
            Pipe:Adiabatic,
            sb0_pipe,
            p_loop Supply Inlet,
            sb0_pipe_outlet,
            Bypass;
            """, [("PIPE:ADIABATIC", "pipe1", None),
                  ('CHILLER:ELECTRIC', "chiller", "Chilled_Water_")], '', [
                      'PIPE:ADIABATIC', 'pipe1', 'pipe1_Inlet_Node_Name',
                      'pipe1_Outlet_Node_Name', '', 'CHILLER:ELECTRIC',
                      'chiller', 'chiller_Chilled_Water_Inlet_Node_Name',
                      'chiller_Chilled_Water_Outlet_Node_Name', ''
                  ]),
        # idftxt, complst, fluid, branchcomps
    )
    for ii, (idftxt, complst, fluid, branchcomps) in enumerate(tdata):
        fhandle = StringIO(idftxt)
        idf = IDF(fhandle)
        components_thisnodes = [(idf.newidfobject(key, nm), thisnode)
                                for key, nm, thisnode in complst]
        fnc = hvacbuilder.initinletoutlet
        components_thisnodes = [(fnc(idf, cp, thisnode), thisnode)
                                for cp, thisnode in components_thisnodes]
        branch = idf.idfobjects['BRANCH'][0]
        branch = hvacbuilder.componentsintobranch(idf, branch,
                                                  components_thisnodes, fluid)
        assert branch.obj[4:] == branchcomps
示例#27
0
 def setup(self):
     """Set the IDD and file paths, and make a copy of the original file.
     """
     iddfile = os.path.join(IDD_FILES, "Energy+V7_2_0.idd")
     IDF.setiddname(iddfile, testing=True)
     
     self.origfile = os.path.join(INTEGRATION_FILES, "origfile.idf")
     
     #set tempfile names
     self.startfile = os.path.join(INTEGRATION_FILES, "startfile.idf")
     self.saveasfile = os.path.join(INTEGRATION_FILES, "saveas.idf")
     self.copyfile = os.path.join(INTEGRATION_FILES, "savecopy.idf")
 
     # make a copy of test file
     shutil.copy(self.origfile, self.startfile)
示例#28
0
    def test_save(self):
        """Test save with a changed version number.

        Fails if the version number has not been changed.

        """
        idf = IDF(self.startfile)
        setversion(idf, "7.4")
        idf.save()
        idf2 = IDF(self.startfile)
        assert idf is not idf2  # be sure we don't just have an in-memory copy

        result = getversion(idf2)
        expected = "7.4"

        assert result == expected
def add_detailed_construction(idf: IDF,
                              construction: LayeredConstructionProtocol,
                              ureg: pint.UnitRegistry,
                              is_window=False) -> str:
    """
    Adds a construction to the idf.

    Note that in cesarp.model each layer of a construction or window construction is modelled with a separate
    Layer object having a thickness and material, whereas in the IDF definition a material object has a specific
    thickness, thus a construction has directly materials assigned without an intermediate layer object.
    """
    idf_obj_name = construction.name
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.construction, idf_obj_name):
        # assert construction.external_layer_index == 0, \
        #    "external/outside layer of a construction is expected as layer 0. Either change your initialization " \
        #    "of the construction or add some code handling reverse layer order in idf_writer_construction"
        idf_constr = idf.newidfobject(idf_strings.IDFObjects.construction)
        idf_constr.Name = idf_obj_name
        idf_constr.Outside_Layer = add_layer(idf=idf,
                                             layer=construction.layers[0],
                                             ureg=ureg,
                                             is_window_layer=is_window)
        for idx in range(1, len(construction.layers)):
            mat_idf_name = add_layer(idf=idf,
                                     layer=construction.layers[idx],
                                     ureg=ureg,
                                     is_window_layer=is_window)
            idf_constr[f"Layer_{idx+1}"] = mat_idf_name

    return idf_obj_name
def test_surfacefilter():
    """py.test for surfacefilter"""
    idftxt = IdfData.idftxt
    wallnames = set(
        ['South_Wall', 'North_Wall', 'Roof_Wall', 'East_Wall', 'West_Wall'])
    floornames = set(['Floor_Outdoor'])
    roofnames = set(['Roof_Roof'])
    fhandle = io.StringIO(idftxt)
    idf = IDF(fhandle)

    result = setallconstructions.surfacefilter(idf, 'walls')
    resultnames = set([surface.Name for surface in result])
    assert resultnames == wallnames

    result = setallconstructions.surfacefilter(idf, 'floors')
    resultnames = set([surface.Name for surface in result])
    assert resultnames == floornames

    result = setallconstructions.surfacefilter(idf, 'roofs')
    resultnames = set([surface.Name for surface in result])
    assert resultnames == roofnames

    result = setallconstructions.surfacefilter(idf, 'all')
    resultnames = {
        key: set([val.Name for val in value])
        for key, value in result.items()
    }
    assert resultnames == dict(roofs=roofnames,
                               walls=wallnames,
                               floors=floornames)
def add_window_glazing_material(idf: IDF, idf_obj_name: str,
                                mat_def: TransparentMaterial,
                                thickness: pint.Quantity,
                                ureg: pint.UnitRegistry) -> None:

    idf_obj_type = idf_strings.IDFObjects.win_material_glazing
    if not idf_writing_helpers.exists_in_idf(idf, idf_obj_type, idf_obj_name):
        win_glazing = idf.newidfobject(idf_obj_type)
        win_glazing.Name = idf_obj_name
        win_glazing.Thickness = thickness.to(ureg.m).m
        win_glazing.Optical_Data_Type = idf_strings.WindowMatGlazing.optical_data_type
        win_glazing.Solar_Transmittance_at_Normal_Incidence = mat_def.solar_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Solar_Reflectance_at_Normal_Incidence = mat_def.front_side_solar_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Solar_Reflectance_at_Normal_Incidence = mat_def.back_side_solar_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Visible_Transmittance_at_Normal_Incidence = mat_def.visible_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Visible_Reflectance_at_Normal_Incidence = mat_def.front_side_visible_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Visible_Reflectance_at_Normal_Incidence = mat_def.back_side_visible_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Infrared_Transmittance_at_Normal_Incidence = mat_def.infrared_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Infrared_Hemispherical_Emissivity = mat_def.front_side_infrared_hemispherical_emissivity.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Infrared_Hemispherical_Emissivity = mat_def.back_side_infrared_hemispherical_emissivity.to(
            ureg.dimensionless).m
        win_glazing.Conductivity = mat_def.conductivity.to(ureg.W /
                                                           (ureg.m * ureg.K)).m
        win_glazing.Dirt_Correction_Factor_for_Solar_and_Visible_Transmittance = mat_def.dirt_correction_factor.to(
            ureg.dimensionless).m
def add_material_no_mass(idf: IDF, idf_obj_name: str, mat_def: OpaqueMaterial,
                         thermal_resistance: pint.Quantity,
                         ureg: pint.UnitRegistry) -> None:
    """
    For materials without mass specified (e.g. vapour barriers)
    :param idf:
    :param idf_obj_name:
    :param mat_def:
    :param thermal_resistance:
    :param ureg:
    :return:
    """
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material_no_mass, idf_obj_name):
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material_no_mass)
        idf_mat.Name = idf_obj_name
        idf_mat.Roughness = get_idf_roughness_string_for(mat_def.roughness)
        idf_mat.Thermal_Resistance = thermal_resistance.to(
            (ureg.m**2 * ureg.K) / ureg.W).m
        idf_mat.Thermal_Absorptance = mat_def.thermal_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Solar_Absorptance = mat_def.solar_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Visible_Absorptance = mat_def.visible_absorptance.to(
            ureg.dimensionless).m
def add_opaque_material(idf: IDF, idf_obj_name: str, mat_def: OpaqueMaterial,
                        thickness: pint.Quantity,
                        ureg: pint.UnitRegistry) -> None:
    """
    For materials without mass specified (e.g. vapour barriers) thickness is not
    :param idf:
    :param idf_obj_name:
    :param mat_def:
    :param thickness:
    :param ureg:
    :return:
    """
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material, idf_obj_name):
        assert mat_def.is_mass_fully_specified(
        ), f"trying to add opaque material {mat_def.name}, but no mass properties specified"
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material)
        idf_mat.Name = idf_obj_name
        idf_mat.Roughness = get_idf_roughness_string_for(mat_def.roughness)
        idf_mat.Thickness = thickness.to(ureg.m).m
        idf_mat.Conductivity = mat_def.conductivity.to(ureg.W /
                                                       (ureg.m * ureg.K)).m
        # checking for mass properties at begin, thus ignore type warning due to Optional[] declaration
        idf_mat.Density = mat_def.density.to(ureg.kg /
                                             ureg.m**3).m  # type: ignore
        idf_mat.Specific_Heat = mat_def.specific_heat.to(
            ureg.J / (ureg.kg * ureg.K)).m  # type: ignore
        idf_mat.Thermal_Absorptance = mat_def.thermal_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Solar_Absorptance = mat_def.solar_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Visible_Absorptance = mat_def.visible_absorptance.to(
            ureg.dimensionless).m
示例#34
0
def create_cases():
    cases = {}
    cases["cases"] = []
    id = 0

    for idf_f in glob.glob("./idfs/*.idf"):
        if not "injected" in idf_f:
            idf = IDF(idf_f)

            # CHW Reset
            cases, id = chwreset(idf, idf_f, id, cases)

            # HW Reset
            cases, id = hwreset(idf, idf_f, id, cases)

            # SAT Reset
            cases, id = sat_reset(idf, idf_f, id, cases)

            # Zone temperature setpoint deadband
            cases, id = zone_temp_ctrl(idf, idf_f, id, cases)
            cases, id = zone_temp_ctrl_depth_htg(idf, idf_f, id, cases)
            cases, id = zone_temp_ctrl_depth_clg(idf, idf_f, id, cases)
            cases, id = zone_temp_ctrl_min(idf, idf_f, id, cases)
            cases, id = zone_temp_ctrl_max(idf, idf_f, id, cases)

            # Integrated economizer
            cases, id = integrated_econ(idf, idf_f, id, cases)

            # Diff enthalpy economizer with no OA DB limit
            cases, id = diff_enthalpy_econ(idf, idf_f, id, cases)

    json.dump(cases, open("./verification_cases.json", "w"), indent=4)
示例#35
0
def test_getfieldnamesendswith():
    """py.test for getfieldnamesendswith"""
    idftxt = """PIPE:ADIABATIC,
        np2,                      !- Name
        np1_np2_node,             !- Inlet Node Name
        np2_outlet;               !- Outlet Node Name

    """
    tdata = (
        ("Inlet_Node_Name", ["Inlet_Node_Name"]
        ),  # endswith, fieldnames
        (
            "Node_Name",
            ["Inlet_Node_Name",
             "Outlet_Node_Name"]),  # endswith, fieldnames
        (
            "Name",
            [
                "Name",
                "Inlet_Node_Name",
                "Outlet_Node_Name"]),  # endswith, fieldnames
    )
    fhandle = StringIO(idftxt)
    idf = IDF(fhandle)
    idfobject = idf.idfobjects["PIPE:ADIABATIC"][0]
    for endswith, fieldnames in tdata:
        result = hvacbuilder.getfieldnamesendswith(idfobject, endswith)
        assert result == fieldnames
示例#36
0
def add_night_ventilation_for_zone(idf: IDF, idf_zone_name: str,
                                   night_vent_model: NightVent):
    """
    For description of model used for night ventilation please refer to docs/features/passive-cooling.rst.

    :param idf: eppy IDF object for which to add shading. Zones must already be defined in passed IDF object!
    :param idf_zone_name: zone name in idf for which to add night ventilation
    :param night_vent_model: parameters for the night ventilation
    :return: nothing, idf is extended in place
    """

    max_temp_profile_idf_name = add_schedule(
        idf,
        night_vent_model.maximum_indoor_temp_profile,
        required_type=cesarp.common.ScheduleTypeLimits.TEMPERATURE())
    night_vent_schedule_name = _adding_the_schedule(
        idf, night_vent_model.start_hour, night_vent_model.end_hour)

    night_vent_obj = idf.newidfobject("ZoneVentilation:DesignFlowRate")
    night_vent_obj.Name = idf_zone_name + "_night_vent"
    night_vent_obj.Zone_or_ZoneList_Name = idf_zone_name
    night_vent_obj.Schedule_Name = night_vent_schedule_name
    night_vent_obj.Design_Flow_Rate_Calculation_Method = idf_strings.FlowRateCalculationMethod.air_changes_per_hour
    night_vent_obj.Air_Changes_per_Hour = night_vent_model.flow_rate.to(
        "ACH").m
    night_vent_obj.Ventilation_Type = "Natural"
    night_vent_obj.Minimum_Indoor_Temperature = night_vent_model.min_indoor_temperature.to(
        "degreeC").m
    night_vent_obj.Maximum_Indoor_Temperature_Schedule_Name = max_temp_profile_idf_name
    night_vent_obj.Delta_Temperature = night_vent_model.maximum_in_out_deltaT.to(
        "degreeC").m
    night_vent_obj.Maximum_Wind_Speed = night_vent_model.max_wind_speed.to(
        "m/s").m
def add_shading_surface_construction(idf: IDF,
                                     shading_constr: ShadingObjectConstruction,
                                     glazing_constr_idf_obj_name: str,
                                     ureg: pint.UnitRegistry) -> Any:
    """
    Adds a ShadingProperty:Reflectance idf object. The object is not linked to a surface geometry here,
    thus make sure to set property "Shading_Surface_Name" on the EpBunch object to link it to a geometry!

    :param idf: IDF object for which to add shading construction
    :param shading_constr: properties of shading construction
    :param glazing_constr_idf_obj_name: idf object name of the glazing construction; needs to be passed because here we cannot handle appropriately to add the
                                        glazing construction if needed as it might be a ConstructionAsIDF...
    :param ureg: pint unit registry
    :return: eppy EpBunch of added ShadingProperty:Reflectance idf object
    """
    shading_reflectence_idf_obj = idf.newidfobject(
        idf_strings.IDFObjects.shading_prop_reflectance)
    shading_reflectence_idf_obj.Diffuse_Solar_Reflectance_of_Unglazed_Part_of_Shading_Surface = shading_constr.diffuse_solar_reflectance_unglazed_part.to(
        ureg.dimensionless).m
    shading_reflectence_idf_obj.Diffuse_Visible_Reflectance_of_Unglazed_Part_of_Shading_Surface = shading_constr.diffuse_visible_reflectance_unglazed_part.to(
        ureg.dimensionless).m
    shading_reflectence_idf_obj.Fraction_of_Shading_Surface_That_Is_Glazed = shading_constr.glazing_ratio.to(
        ureg.dimensionless).m
    shading_reflectence_idf_obj.Glazing_Construction_Name = glazing_constr_idf_obj_name
    # make sure to set the name of returned idf obj to match the name of the shading geometry object you want to link it to!
    # e.g. shading_reflectence_idf_obj.Shading_Surface_Name = "xyz"
    return shading_reflectence_idf_obj
def setconstruction(idf, climatezone):
    """Put in appropriate baseline construction for roof, wall, floor, window."""
    materail_constr_txt = ASHRAE_constr.constr_importer(climatezone)
    IDF = idf.__class__ # sneaky way to avoid `from eppy.modeleditor import IDF`
    materail_constr_idf = IDF(io.StringIO(materail_constr_txt))

    idf_helpers.copyidfintoidf(idf, materail_constr_idf)
    constructions = idf.idfobjects['CONSTRUCTION']
    windowconstr = constructions[-4]
    roofconstr = constructions[-3]
    wallconstr = constructions[-2]
    floorconstr = constructions[-1] # the order is hard coded

    filteredsurfaces = surfacefilter(idf)
    roofs = filteredsurfaces['roofs']
    walls = filteredsurfaces['walls']
    floors = filteredsurfaces['floors']

    for roof in roofs:
        roof.Construction_Name = roofconstr.Name
    for wall in walls:
        wall.Construction_Name = wallconstr.Name
    for floor in floors:
        floor.Construction_Name = floorconstr.Name

    windows = glazingfilter(idf)
    for window in windows:
    	window.Construction_Name = windowconstr.Name
    return idf
示例#39
0
def LoadZoneTag(myIDFfile, ID):
    fname = myIDFfile
    my_idf = IDF(fname)
    zones = my_idf.idfobjects['ZONE']
    #    myZones = np.array([zone.Name for zone in zones])
    zoneTag = zones[int(ID) - 1].Name[-9:-4]
    return zoneTag
示例#40
0
 def test_save(self):
     """Test save with a changed version number.
     
     Fails if the version number has not been changed.
     
     """
     idf = IDF(self.startfile)
     setversion(idf, '7.4')
     idf.save()
     idf2 = IDF(self.startfile)
     assert idf is not idf2  # be sure we don't just have an in-memory copy
     
     result = getversion(idf2)
     expected = '7.4'
     
     assert result == expected
示例#41
0
def test_idfinmsequence():
    """py.test for setting of theidf in Idf_MSequence"""
    idftxt = """Version, 6.0;"""
    # theidf set in Idf_MSequence.__init__
    idf = IDF(StringIO(idftxt))
    versions = idf.idfobjects['version'.upper()]
    assert versions.theidf == idf
    assert versions[0].theidf == idf
    # theidf set in Idf_MSequence.insert()
    material = idf.newidfobject('material'.upper())
    assert material.theidf == idf
    # theidf set when you pop an item
    newmaterial = idf.newidfobject('material'.upper())
    materials = idf.idfobjects['material'.upper()]
    material = materials.pop(0)
    assert material.theidf == None
    assert materials[0].theidf == idf
示例#42
0
def test_idfinmsequence():
    """py.test for setting of theidf in Idf_MSequence"""
    idftxt = """Version, 6.0;"""
    # theidf set in Idf_MSequence.__init__
    idf = IDF(StringIO(idftxt))
    versions = idf.idfobjects["version".upper()]
    assert versions.theidf == idf
    assert versions[0].theidf == idf
    # theidf set in Idf_MSequence.insert()
    material = idf.newidfobject("material".upper())
    assert material.theidf == idf
    # theidf set when you pop an item
    newmaterial = idf.newidfobject("material".upper())
    materials = idf.idfobjects["material".upper()]
    material = materials.pop(0)
    assert material.theidf == None
    assert materials[0].theidf == idf
示例#43
0
def test_renamenodes():
    """py.test for renamenodes"""
    idftxt = """PIPE:ADIABATIC,
         np1,
         np1_inlet,
         np1_outlet;
         !- ['np1_outlet', 'np1_np2_node'];

    BRANCH,
         sb0,
         0.0,
         ,
         Pipe:Adiabatic,
         np1,
         np1_inlet,
         np1_outlet,
         Bypass;
    """
    outtxt = """PIPE:ADIABATIC,
         np1,
         np1_inlet,
         np1_np2_node;
         !- ['np1_outlet', 'np1_np2_node'];

    BRANCH,
         sb0,
         0.0,
         ,
         Pipe:Adiabatic,
         np1,
         np1_inlet,
         np1_np2_node,
         Bypass;
    """
    # !- ['np1_outlet', 'np1_np2_node'];
    fhandle = StringIO(idftxt)
    idf = IDF(fhandle)
    pipe = idf.idfobjects["PIPE:ADIABATIC"][0]
    pipe.Outlet_Node_Name = [
        "np1_outlet",
        "np1_np2_node",
    ]  # this is the first step of the replace
    hvacbuilder.renamenodes(idf, fieldtype="node")
    outidf = IDF(StringIO(outtxt))
    result = idf.idfobjects["PIPE:ADIABATIC"][0].obj
    assert result == outidf.idfobjects["PIPE:ADIABATIC"][0].obj
def add_airgap(idf: IDF, idf_obj_name: str, thermal_resistance: pint.Quantity,
               ureg: pint.UnitRegistry) -> None:
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material_air_gap, idf_obj_name):
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material_air_gap)
        idf_mat.Name = idf_obj_name
        idf_mat.Thermal_Resistance = thermal_resistance.to(ureg.m**2 * ureg.K /
                                                           ureg.W).m
示例#45
0
 def test_lineendings(self):
     """Test lineendings are set correctly on each platform.
     """
     idf = IDF(self.startfile)
     idf.save(lineendings='windows')
     with open(self.startfile, 'rb') as sf:
         txt = sf.read()
     print(txt.count(b'\r\n'))
     lines = txt.splitlines()
     numlines = len(lines)
     assert numlines == txt.count(b'\r\n') + 1 # no CR on last line
     idf.save(lineendings='unix')
     with open(self.origfile, 'rb') as of:
         txt = of.read()
     lines = txt.splitlines()
     numlines = len(lines)
     assert numlines == txt.count(b'\n') + 1 # no CR on last line
示例#46
0
def add_window_component(idf1, idfwindowfile):
    windows = idf1.idfobjects['FENESTRATIONSURFACE:DETAILED']
    nbwindows_so_far = len(windows)
    newwindow = IDF(idfwindowfile).idfobjects['FENESTRATIONSURFACE:DETAILED']
    for i in range(0, len(newwindow)):
        idf1.newidfobject('FENESTRATIONSURFACE:DETAILED')
        windows = idf1.idfobjects['FENESTRATIONSURFACE:DETAILED']
        windows[nbwindows_so_far + i] = newwindow[i]
示例#47
0
def test_getbranchcomponents():
    """py.test for getbranchcomponents"""
    tdata = (
        ("""BRANCH,
            sb1,
            0,
            ,
            PIPE:ADIABATIC,
            np1,
            np1_inlet,
            np1_np2_node,
            ,
            PIPE:ADIABATIC,
            np2,
            np1_np2_node,
            np2_outlet,
            ;
            """, True, [('PIPE:ADIABATIC', 'np1'), ('PIPE:ADIABATIC', 'np2')
                        ]),  # idftxt, utest, componentlist
        ("""BRANCH,
            sb1,
            0,
            ,
            PIPE:ADIABATIC,
            np1,
            np1_inlet,
            np1_np2_node,
            ,
            PIPE:ADIABATIC,
            np2,
            np1_np2_node,
            np2_outlet,
            ;
            PIPE:ADIABATIC,
            np1,
            np1_inlet,
            np1_np2_node;

            PIPE:ADIABATIC,
            np2,
            np1_np2_node,
            np2_outlet;

            """, False,
         [['PIPE:ADIABATIC', 'np1', 'np1_inlet', 'np1_np2_node'],
          ['PIPE:ADIABATIC', 'np2', 'np1_np2_node', 'np2_outlet']]),
        # idftxt, utest, componentlist
    )
    for idftxt, utest, componentlist in tdata:
        fhandle = StringIO(idftxt)
        idf = IDF(fhandle)
        branch = idf.idfobjects['BRANCH'][0]
        result = hvacbuilder.getbranchcomponents(idf, branch, utest=utest)
        if utest:
            assert result == componentlist
        else:
            lresult = [item.obj for item in result]
            assert lresult == componentlist
示例#48
0
def idfreadtest(iddhandle, idfhandle1, idfhandle2, verbose=False, save=False):
    """compare the results of eppy reader and simple reader"""
    # read using eppy:
    try:
        IDF.setiddname(iddhandle)
    except modeleditor.IDDAlreadySetError:
        # idd has already been set
        pass
    idf = IDF(idfhandle1)
    idfstr = idf.idfstr()
    idfstr = idf2txt(idfstr)
    # -
    # do a simple read
    simpletxt = idfhandle2.read()
    try:
        simpletxt = simpletxt.decode('ISO-8859-2')
    except AttributeError:
        pass
    simpletxt = idf2txt(simpletxt)
    # -
    if save:
        open('simpleread.idf', 'w').write(idfstr)
        open('eppyread.idf', 'w').write(simpletxt)
    # do the compare
    lines1 = idfstr.splitlines()
    lines2 = simpletxt.splitlines()
    for i, (line1, line2) in enumerate(zip(lines1, lines2)):
        if line1 != line2:
            # test if it is a mismatch in number format
            try:
                line1 = float(line1[:-1])
                line2 = float(line2[:-1])
                if line1 != line2:
                    if verbose:
                        print()
                        print("%s- : %s" % (i, line1))
                        print("%s- : %s" % (i, line2))
                    return False
            except ValueError:
                if verbose:
                    print()
                    print("%s- : %s" % (i, line1))
                    print("%s- : %s" % (i, line2))
                return False
    return True
示例#49
0
    def to_eppy(self, idd_file: str):
        try:
            IDF.setiddname(str(idd_file))
        except IDDAlreadySetError as e:
            pass
        idf = IDF(io.StringIO(""))
        eppy_objects = []

        # Create shade object
        transmittance_schedule_type_limit = idf.newidfobject("SCHEDULETYPELIMITS")
        transmittance_schedule_type_limit.Name = "constant"
        transmittance_schedule_type_limit.Lower_Limit_Value = 0
        transmittance_schedule_type_limit.Upper_Limit_Value = 1
        transmittance_schedule_type_limit.Numeric_Type = "Continuous"
        eppy_objects.append(transmittance_schedule_type_limit)

        transmittance_schedule = idf.newidfobject("SCHEDULE:CONSTANT")
        transmittance_schedule.Name = "constant"
        transmittance_schedule.Schedule_Type_Limits_Name = "constant"
        transmittance_schedule.Hourly_Value = 0
        eppy_objects.append(transmittance_schedule)

        shade = idf.newidfobject("SHADING:SITE:DETAILED")
        shade.Name = random_id()
        shade.Transmittance_Schedule_Name = "constant"
        shade.Number_of_Vertices = len(self.vertices)
        for nn, vtx in enumerate(self.vertices):
            setattr(shade, "Vertex_{}_Xcoordinate".format(nn + 1), vtx.x)
            setattr(shade, "Vertex_{}_Ycoordinate".format(nn + 1), vtx.y)
            setattr(shade, "Vertex_{}_Zcoordinate".format(nn + 1), vtx.z)
        eppy_objects.append(shade)

        return eppy_objects
示例#50
0
def test_replacebranch():
    """py.test for replacebranch"""
    tdata = (
        (
            "p_loop",
            ["sb0", ["sb1", "sb2", "sb3"], "sb4"],
            ["db0", ["db1", "db2", "db3"], "db4"],
            "sb0",
            [
                ("Chiller:Electric".upper(), "Central_Chiller", "Chilled_Water_"),
                ("PIPE:ADIABATIC", "np1", None),
                ("PIPE:ADIABATIC", "np2", None),
            ],
            "Water",
            [
                "BRANCH",
                "sb0",
                "0",
                "",
                "CHILLER:ELECTRIC",
                "Central_Chiller",
                "p_loop Supply Inlet",
                "Central_Chiller_np1_node",
                "",
                "PIPE:ADIABATIC",
                "np1",
                "Central_Chiller_np1_node",
                "np1_np2_node",
                "",
                "PIPE:ADIABATIC",
                "np2",
                "np1_np2_node",
                "np2_Outlet_Node_Name",
                "",
            ],
        ),  # loopname, sloop, dloop, branchname, componenttuple, fluid, outbranch
    )
    for (loopname, sloop, dloop, branchname, componenttuple, fluid, outbranch) in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        loop = hvacbuilder.makeplantloop(idf, loopname, sloop, dloop)
        components_thisnodes = [(idf.newidfobject(key, nm), thisnode) for key, nm, thisnode in componenttuple]
        branch = idf.getobject("BRANCH", branchname)
        newbr = hvacbuilder.replacebranch(idf, loop, branch, components_thisnodes, fluid=fluid)
        assert newbr.obj == outbranch
示例#51
0
    def test_save_as(self):
        """Test saveas with a changed filename.
        
        IDF.saveas(fname) changes the filename. The next save should save with 
        new name.
        
        Fails if the filename isn't changed on the file with the new name.
        """
        idf = IDF(self.startfile)
        idf.saveas(self.saveasfile)  # sets the new filename
        setversion(idf, '7.4')
        idf.save()  # should also save with the new filename
        idf2 = IDF(self.saveasfile)
        
        result = getversion(idf2)
        expected = '7.4'

        assert result == expected
示例#52
0
def test_zonearea_zonevolume():
    """py.test for zonearea and zonevolume"""
    idftxt = "Zone, 473222, 0.0, 0.0, 0.0, 0.0, , 1;  BuildingSurface:Detailed, F7289B, Floor, Exterior Floor, 473222, Ground, , NoSun, NoWind, , 4, 2.23, 2.56, 0.0, 2.23, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.56, 0.0;  BuildingSurface:Detailed, F3659B, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 2.56, 1.49, 2.23, 2.56, 0.0, 0.0, 2.56, 0.0, 0.0, 2.56, 1.49;  BuildingSurface:Detailed, 46C6C9, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 0.0, 1.49, 2.23, 0.0, 0.0, 2.23, 1.02548139464, 0.0, 2.23, 1.02548139464, 1.49;  BuildingSurface:Detailed, 4287DD, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 0.0, 2.56, 1.49, 0.0, 2.56, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.49;  BuildingSurface:Detailed, 570C2E, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 0.0, 0.0, 1.49, 0.0, 0.0, 0.0, 2.23, 0.0, 0.0, 2.23, 0.0, 1.49;  BuildingSurface:Detailed, BAEA99, Roof, Exterior Roof, 473222, Outdoors, , SunExposed, WindExposed, , 4, 0.0, 2.56, 1.49, 0.0, 0.0, 1.49, 2.23, 0.0, 1.49, 2.23, 2.56, 1.49;  BuildingSurface:Detailed, C879FE, Floor, Exterior Floor, 473222, Ground, , NoSun, NoWind, , 4, 3.22, 2.52548139464, 0.0, 3.22, 1.02548139464, 0.0, 2.23, 1.02548139464, 0.0, 2.23, 2.52548139464, 0.0;  BuildingSurface:Detailed, 25B601, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 1.02548139464, 1.49, 2.23, 1.02548139464, 0.0, 2.23, 2.52548139464, 0.0, 2.23, 2.52548139464, 1.49;  BuildingSurface:Detailed, F5EADC, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 1.02548139464, 1.49, 2.23, 1.02548139464, 0.0, 3.22, 1.02548139464, 0.0, 3.22, 1.02548139464, 1.49;  BuildingSurface:Detailed, D0AABE, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 3.22, 1.02548139464, 1.49, 3.22, 1.02548139464, 0.0, 3.22, 2.52548139464, 0.0, 3.22, 2.52548139464, 1.49;  BuildingSurface:Detailed, B0EA02, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 3.22, 2.52548139464, 1.49, 3.22, 2.52548139464, 0.0, 2.23, 2.52548139464, 0.0, 2.23, 2.52548139464, 1.49;  BuildingSurface:Detailed, E6DF3B, Roof, Exterior Roof, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 2.52548139464, 1.49, 2.23, 1.02548139464, 1.49, 3.22, 1.02548139464, 1.49, 3.22, 2.52548139464, 1.49;  BuildingSurface:Detailed, 4F8681, Wall, Exterior Wall, 473222, Outdoors, , SunExposed, WindExposed, , 4, 2.23, 2.52548139464, 1.49, 2.23, 2.52548139464, 0.0, 2.23, 2.56, 0.0, 2.23, 2.56, 1.49;  "
    idf = IDF(StringIO(idftxt))
    result = modeleditor.zonearea(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zonearea_floor(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zonearea_roofceiling(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zone_floor2roofheight(idf, '473222')
    assert almostequal(result, 1.49)
    result = modeleditor.zoneheight(idf, '473222')
    assert almostequal(result, 1.49)
    result = modeleditor.zone_floor2roofheight(idf, '473222')
    assert almostequal(result, 1.49)
    result = modeleditor.zonevolume(idf, '473222')
    assert almostequal(result, 10.718762)
    # remove floor
    zone = idf.getobject('ZONE', '473222')
    surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
    zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
    floors = [s for s in zone_surfs if s.Surface_Type.upper() == 'FLOOR']
    for floor in floors:
        idf.removeidfobject(floor)
    result = modeleditor.zonearea_floor(idf, '473222')
    assert almostequal(result, 0)
    result = modeleditor.zonearea_roofceiling(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zonearea(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zoneheight(idf, '473222')
    assert almostequal(result, 1.49)
    result = modeleditor.zonevolume(idf, '473222')
    assert almostequal(result, 10.718762)
    # reload idf and remove roof/ceiling
    idf = IDF(StringIO(idftxt))
    zone = idf.getobject('ZONE', '473222')
    surfs = idf.idfobjects['BuildingSurface:Detailed'.upper()]
    zone_surfs = [s for s in surfs if s.Zone_Name == zone.Name]
    roofs = [s for s in zone_surfs if s.Surface_Type.upper() == 'ROOF']
    ceilings = [s for s in zone_surfs if s.Surface_Type.upper() == 'CEILING']
    topsurfaces = roofs + ceilings
    for surf in topsurfaces:
        idf.removeidfobject(surf)
    result = modeleditor.zonearea_roofceiling(idf, '473222')
    assert almostequal(result, 0)
    result = modeleditor.zonearea(idf, '473222')
    assert almostequal(result, 7.1938)
    result = modeleditor.zoneheight(idf, '473222')
    assert almostequal(result, 1.49)
    result = modeleditor.zonevolume(idf, '473222')
    assert almostequal(result, 10.718762)
        
示例#53
0
def main():
    """the main routine"""
    from StringIO import StringIO
    import eppy.iddv7 as iddv7
    IDF.setiddname(StringIO(iddv7.iddtxt))
    idf1 = IDF(StringIO(''))
    loopname = "p_loop"
    sloop = ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4']
    dloop = ['db0', ['db1', 'db2', 'db3'], 'db4']
    # makeplantloop(idf1, loopname, sloop, dloop)
    loopname = "c_loop"
    sloop = ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4']
    dloop = ['db0', ['db1', 'db2', 'db3'], 'db4']
    # makecondenserloop(idf1, loopname, sloop, dloop)
    loopname = "a_loop"
    sloop = ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4']
    dloop = ['zone1', 'zone2', 'zone3']
    makeairloop(idf1, loopname, sloop, dloop)
    idf1.savecopy("hh1.idf")
示例#54
0
def test_getnodefieldname():
    """py.test for getnodefieldname"""
    tdata = (
        ("PIPE:ADIABATIC", "pipe1", "Inlet_Node_Name", "", "Inlet_Node_Name"),
        # objtype, objname, endswith, fluid, nodefieldname
        ("CHILLER:ELECTRIC", "pipe1", "Inlet_Node_Name", "", "Chilled_Water_Inlet_Node_Name"),
        # objtype, objname, endswith, fluid, nodefieldname
        ("COIL:COOLING:WATER", "pipe1", "Inlet_Node_Name", "Water", "Water_Inlet_Node_Name"),
        # objtype, objname, endswith, fluid, nodefieldname
        ("COIL:COOLING:WATER", "pipe1", "Inlet_Node_Name", "Air", "Air_Inlet_Node_Name"),
        # objtype, objname, endswith, fluid, nodefieldname
        ("COIL:COOLING:WATER", "pipe1", "Outlet_Node_Name", "Air", "Air_Outlet_Node_Name"),
        # objtype, objname, endswith, fluid, nodefieldname
    )
    for objtype, objname, endswith, fluid, nodefieldname in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        idfobject = idf.newidfobject(objtype, objname)
        result = hvacbuilder.getnodefieldname(idfobject, endswith, fluid)
        assert result == nodefieldname
示例#55
0
def test_initreadtxt():
    """Test for IDF.initreadtxt().
    """
    idftxt = """
        Material,
          G01a 19mm gypsum board,  !- Name
          MediumSmooth,            !- Roughness
          0.019,                   !- Thickness {m}
          0.16,                    !- Conductivity {W/m-K}
          800,                     !- Density {kg/m3}
          1090;                    !- Specific Heat {J/kg-K}

        Construction,
          Interior Wall,           !- Name
          G01a 19mm gypsum board,  !- Outside Layer
          F04 Wall air space resistance,  !- Layer 2
          G01a 19mm gypsum board;  !- Layer 3
        """
    idf = IDF()
    idf.initreadtxt(idftxt)
    assert idf.getobject('MATERIAL', 'G01a 19mm gypsum board')
示例#56
0
 def test_save_with_lineendings_and_encodings(self):
     """
     Test the IDF.save() function with combinations of encodings and line 
     endings.
 
     """
     idf = IDF(self.startfile)
     lineendings = ('windows', 'unix', 'default')
     encodings = ('ascii', 'latin-1', 'UTF-8')
 
     for le, enc in product(lineendings, encodings):
         idf.save(lineendings=le, encoding=enc)
         
         with open(self.startfile, 'rb') as sf:
             result = sf.read()
         if le == 'windows':
             assert b'\r\n' in result
         elif le == 'unix':
             assert b'\r\n' not in result
         elif le == 'default':
             assert os.linesep.encode(enc) in result
示例#57
0
def test_connectcomponents():
    """py.test for connectcomponents"""
    fhandle = StringIO("")
    idf = IDF(fhandle)

    tdata = (
        (
            [(idf.newidfobject("PIPE:ADIABATIC", "pipe1"), None),
             (idf.newidfobject("PIPE:ADIABATIC", "pipe2"), None)],
            ["pipe1_Inlet_Node_Name", ["pipe2_Inlet_Node_Name",
                                       "pipe1_pipe2_node"]],
            [["pipe1_Outlet_Node_Name", "pipe1_pipe2_node"],
             "pipe2_Outlet_Node_Name"], '',
        ),
        # components_thisnodes, inlets, outlets, fluid
        (
            [(idf.newidfobject("Coil:Cooling:Water".upper(), "pipe1"),
              'Water_'),
             (idf.newidfobject("Coil:Cooling:Water".upper(), "pipe2"),
              'Water_')],
            ['pipe1_Water_Inlet_Node_Name', '',
             'pipe2_Water_Inlet_Node_Name',
             ['', 'pipe1_pipe2_node']],
            [['pipe1_Water_Outlet_Node_Name', 'pipe1_pipe2_node'], '',
             'pipe2_Water_Outlet_Node_Name', ''],
            'Air'
        ),
        # components_thisnodes, inlets, outlets, fluid
        (
            [(idf.newidfobject("PIPE:ADIABATIC".upper(), "pipe1"), None),
             (idf.newidfobject("Coil:Cooling:Water".upper(), "pipe2"),
              'Water_')],
            ["pipe1_Inlet_Node_Name", "pipe2_Water_Inlet_Node_Name",
             ['pipe2_Air_Inlet_Node_Name', 'pipe1_pipe2_node']],
            [['pipe1_Outlet_Node_Name', 'pipe1_pipe2_node'],
             "pipe2_Water_Outlet_Node_Name", ""],
            'Air'
        ),
        # components_thisnodes, inlets, outlets, fluid
    )
    for components_thisnodes, inlets, outlets, fluid in tdata:
        # init the nodes in the new components
        for component, thisnode in components_thisnodes:
            hvacbuilder.initinletoutlet(idf, component, thisnode)
        hvacbuilder.connectcomponents(idf, components_thisnodes, fluid)
        inresult = []
        for component, thisnode in components_thisnodes:
            fldnames = hvacbuilder.getfieldnamesendswith(component,
                                                         "Inlet_Node_Name")
            for name in fldnames:
                inresult.append(component[name])
        assert inresult == inresult
        outresult = []
        for component, thisnode in components_thisnodes:
            fldnames = hvacbuilder.getfieldnamesendswith(component,
                                                         "Outlet_Node_Name")
            for name in fldnames:
                outresult.append(component[name])
        assert outresult == outlets
示例#58
0
def test_save_with_lineendings_and_encodings():
    """
    Test the IDF.save() function with combinations of encodings and line
    endings.

    """
    file_text = "Material,TestMaterial,  !- Name"
    idf = IDF(StringIO(file_text))
    lineendings = ('windows', 'unix', 'default')
    encodings = ('ascii', 'latin-1', 'UTF-8')

    for le, enc in product(lineendings, encodings):
        file_handle = StringIO()
        idf.save(file_handle, encoding=enc, lineendings=le)
        file_handle.seek(0)
        result = file_handle.read().encode(enc)
        if le == 'windows':
            assert b'\r\n' in result
        elif le == 'unix':
            assert b'\r\n' not in result
        elif le == 'default':
            assert os.linesep.encode(enc) in result
示例#59
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
        except getopt.error, msg:
            raise Usage(msg)
    
        # option processing
        for option, value in opts:
            if option == "-v":
                verbose = True
            if option in ("-h", "--help"):
                raise Usage(help_message)
            if option in ("-o", "--output"):
                output = value
        iddfile, fname1, fname2 = args
        IDF.setiddname(iddfile)
        idf1 = IDF(fname1)
        idf2 = IDF(fname2)

        idfdiffs(idf1, idf2)
示例#60
0
def test_getnodefieldname():
    """py.test for getnodefieldname"""
    tdata = (
        ('PIPE:ADIABATIC', 'pipe1', 'Inlet_Node_Name', '', 'Inlet_Node_Name'),
        # objtype, objname, endswith, fluid, nodefieldname
        ('CHILLER:ELECTRIC', 'pipe1', 'Inlet_Node_Name', '',
         'Chilled_Water_Inlet_Node_Name'),
        # objtype, objname, endswith, fluid, nodefieldname
        ('COIL:COOLING:WATER', 'pipe1', 'Inlet_Node_Name', 'Water',
         'Water_Inlet_Node_Name'),
        # objtype, objname, endswith, fluid, nodefieldname
        ('COIL:COOLING:WATER', 'pipe1', 'Inlet_Node_Name', 'Air',
         'Air_Inlet_Node_Name'),
        # objtype, objname, endswith, fluid, nodefieldname
        ('COIL:COOLING:WATER', 'pipe1', 'Outlet_Node_Name', 'Air',
         'Air_Outlet_Node_Name'),
        # objtype, objname, endswith, fluid, nodefieldname
        )
    for objtype, objname, endswith, fluid, nodefieldname in tdata:
        fhandle = StringIO("")
        idf = IDF(fhandle)
        idfobject = idf.newidfobject(objtype, objname)
        result = hvacbuilder.getnodefieldname(idfobject, endswith, fluid)
        assert result == nodefieldname