예제 #1
0
def _help_package(path, name, uses=None, within=None):
    """creates a package.mo file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.mo should be placed
    name : string
        name of the Modelica package
    within : string
        path of Modelica package containing this package

    """

    package_template = Template(filename=utilities.get_full_path(
        "data/output/modelicatemplate/package"))
    out_file = open(
        utilities.get_full_path(os.path.join(path, "package.mo")), 'w')
    out_file.write(package_template.render_unicode(
        name=name,
        within=within,
        uses=uses))
    out_file.close()
예제 #2
0
def export_parameters_txt(prj, path):
    '''Exports parameters of all buildings in a readable text file

    Parameters
    ----------

    path : string
        if the Files should not be stored in OutputData, an alternative
        can be specified
    '''
    if path is None:
        path = "OutputData/"+prj.name
    else:
        path = path+"/"+prj.name

    for bldg in prj.buildings:
        bldg_path = path + "/" + bldg.name + "/"
        utilitis.create_path(utilitis.get_full_path(bldg_path))
        readable_template = Template(
            filename=utilitis.get_full_path(
                "data/output/texttemplate/ReadableBuilding"))

        out_file = open(utilitis.get_full_path
                        (bldg_path+"ReadableOutput.txt"), 'w')
        out_file.write(readable_template.render_unicode
                       (bldg=bldg, prj=prj))
        out_file.close()
예제 #3
0
def _help_package(path, name, uses=None, within=None):
    '''creates a package.mo file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.mo should be placed
    name : string
        name of the Modelica package
    within : string
        path of Modelica package containing this package

    '''

    package_template = Template(filename=utilitis.get_full_path
                                ("data/output/modelicatemplate/package"))
    out_file = open(
        utilitis.get_full_path(path + "/" + "package" + ".mo"), 'w')
    out_file.write(package_template.render_unicode(name=name,
                                                   within=within,
                                                   uses=uses))
    out_file.close()
예제 #4
0
def _help_package_order(path, package_list, addition=None, extra=None):
    '''creates a package.order file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.order should be placed
    package_list : [string]
        name of all models or packages contained in the package
    addition : string
        if there should be a suffix in front of package_list.string it can
        be specified
    extra : string
        an extra package or model not contained in package_list can be
        specified

    '''
    order_template = Template(filename=utilitis.get_full_path(
        "Data\\Output\\ModelicaTemplate\\package_order"))

    out_file = open(utilitis.get_full_path(path + "\\" + "package" + ".order"),
                    'w')
    out_file.write(
        order_template.render_unicode(list=package_list,
                                      addition=addition,
                                      extra=extra))
    out_file.close()
예제 #5
0
    def save_project(self, file_name=None, path=None):
        '''Saves the project to a tXML file

        calls the function save_teaser_xml in data.TeaserXML.py

        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified
        '''
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = utilitis.get_full_path("OutputData") + "\\" + name
        else:
            new_path = path + "\\" + name
            utilitis.create_path(utilitis.get_full_path(path))

        txml_out.save_teaser_xml(new_path, self)
예제 #6
0
    def save_citygml(self, file_name=None, path=None):
        '''Saves the project to a citygml file

        calls the function save_gml in data.CityGML we make use of CityGML core
        and EnergyADE to store semantic information


        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified

        '''
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = utilitis.get_full_path("OutputData") + "\\" + name
        else:
            new_path = path + "\\" + name
            utilitis.create_path(utilitis.get_full_path(path))

        citygml_out.save_gml(self, new_path)
예제 #7
0
파일: project.py 프로젝트: R33B/TEASER
    def save_project(self, file_name=None, path=None):
        '''Saves the project to a tXML file

        calls the function save_teaser_xml in data.TeaserXML.py

        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified

        '''
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = utilitis.get_full_path("OutputData") + "\\" + name
        else:
            new_path = path + "\\" + name
            utilitis.create_path(utilitis.get_full_path(path))

        txml_out.save_teaser_xml(new_path, self)
예제 #8
0
def _help_package_order(path, package_list, addition=None, extra=None):
    '''creates a package.order file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.order should be placed
    package_list : [string]
        name of all models or packages contained in the package
    addition : string
        if there should be a suffix in front of package_list.string it can
        be specified
    extra : string
        an extra package or model not contained in package_list can be
        specified

    '''
    order_template = Template(filename=utilitis.get_full_path
                              ("data/output/modelicatemplate/package_order"))

    out_file = open(
        utilitis.get_full_path(path + "/" + "package" + ".order"), 'w')
    out_file.write(order_template.render_unicode
                   (list=package_list, addition=addition, extra=extra))
    out_file.close()
예제 #9
0
def export_parameters_txt(prj, path):
    '''Exports parameters of all buildings in a readable text file

    Parameters
    ----------

    path : string
        if the Files should not be stored in OutputData, an alternative
        can be specified
    '''
    if path is None:
        path = "OutputData\\" + prj.name
    else:
        path = path + "\\" + prj.name

    for bldg in prj.buildings:
        bldg_path = path + "\\" + bldg.name + "\\"
        utilitis.create_path(utilitis.get_full_path(bldg_path))
        readable_template = Template(filename=utilitis.get_full_path(
            "Data\\Output\\TextTemplate\\ReadableBuilding"))

        out_file = open(
            utilitis.get_full_path(bldg_path + "ReadableOutput.txt"), 'w')
        out_file.write(readable_template.render_unicode(bldg=bldg, prj=prj))
        out_file.close()
예제 #10
0
파일: project.py 프로젝트: R33B/TEASER
    def save_citygml(self, file_name=None, path=None):
        '''Saves the project to a citygml file

        calls the function save_gml in data.CityGML we make use of CityGML core
        and EnergyADE to store semantic information


        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified

        '''
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = utilitis.get_full_path("OutputData") + "\\" + name
        else:
            new_path = path + "\\" + name
            utilitis.create_path(utilitis.get_full_path(path))

        citygml_out.save_gml(self, new_path)
예제 #11
0
    def __init__(self, used_statistic="iwu"):
        """Construct DataClass."""
        self.used_statistic = used_statistic
        self.element_bind = None
        if self.used_statistic == "iwu":
            self.path_tb = utils.get_full_path(
                "data/input/inputdata/TypeBuildingElements.json")
            self.load_tb_binding()
        elif self.used_statistic == "tabula_de":
            self.path_tb = utils.get_full_path(
                os.path.join("data", "input", "inputdata",
                             "TypeElements_TABULA_DE.json"))
            self.load_tb_binding()
        elif self.used_statistic == "tabula_dk":
            self.path_tb = utils.get_full_path(
                os.path.join("data", "input", "inputdata",
                             "TypeElements_TABULA_DK.json"))
            self.load_tb_binding()
        elif self.used_statistic is None:
            pass
        self.material_bind = None
        self.path_mat = utils.get_full_path(
            "data/input/inputdata/MaterialTemplates.json")
        self.conditions_bind = None
        self.path_uc = utils.get_full_path(
            "data/input/inputdata/UseConditions.json")

        self.load_uc_binding()
        self.load_mat_binding()
예제 #12
0
    def __init__(self, used_statistic='iwu'):
        """Constructor of DataClass
        """
        self.used_statistic = used_statistic
        self.element_bind = None
        if self.used_statistic == 'iwu':
            self.path_tb = utils.get_full_path(
                "data/input/inputdata/TypeBuildingElements.xml")
            self.load_tb_binding()
        elif self.used_statistic == 'tabula_de':
            self.path_tb = utils.get_full_path(
                os.path.join('data', 'input', 'inputdata',
                             'TypeElements_TABULA_DE.xml'))
            self.load_tb_binding()
        elif self.used_statistic is None:
            pass
        self.material_bind = None
        self.path_mat = utils.get_full_path(
            "data/input/inputdata/MaterialTemplates.xml")
        self.conditions_bind = None
        self.path_uc = utils.get_full_path(
            "data/input/inputdata/UseConditions.xml")

        self.load_uc_binding()
        self.load_mat_binding()
예제 #13
0
def export_parameters_txt(prj, path):
    """Exports parameters of all buildings in a readable text file

    Parameters
    ----------

    prj : TEASER project
        Project to export
    path : string
        if the Files should not be stored in OutputData, an alternative
        can be specified
    """

    lookup = TemplateLookup(directories=[
        utilities.get_full_path(
            os.path.join('data', 'output', 'modelicatemplate'))
    ])

    model_template_1 = Template(filename=utilities.get_full_path(
        os.path.join('data', 'output', 'texttemplate',
                     'ReadableBuilding_OneElement')),
                                lookup=lookup)
    model_template_2 = Template(filename=utilities.get_full_path(
        os.path.join('data', 'output', 'texttemplate',
                     'ReadableBuilding_TwoElement')),
                                lookup=lookup)
    model_template_3 = Template(filename=utilities.get_full_path(
        os.path.join('data', 'output', 'texttemplate',
                     'ReadableBuilding_ThreeElement')),
                                lookup=lookup)
    model_template_4 = Template(filename=utilities.get_full_path(
        os.path.join('data', 'output', 'texttemplate',
                     'ReadableBuilding_FourElement')),
                                lookup=lookup)

    for bldg in prj.buildings:
        bldg_path = os.path.join(path, bldg.name + "_txtOutput")
        utilities.create_path(bldg_path)
        out_file = open(os.path.join(bldg_path, bldg.name + ".txt"), 'w')

        if type(bldg.thermal_zones[0].model_attr).__name__ == "OneElement":
            out_file.write(model_template_1.render_unicode(bldg=bldg))
        elif type(bldg.thermal_zones[0].model_attr).__name__ == "TwoElement":
            out_file.write(model_template_2.render_unicode(bldg=bldg))
        elif type(bldg.thermal_zones[0].model_attr).__name__ == "ThreeElement":
            out_file.write(model_template_3.render_unicode(bldg=bldg))
        elif type(bldg.thermal_zones[0].model_attr).__name__ == "FourElement":
            out_file.write(model_template_4.render_unicode(bldg=bldg))

        out_file.close()
예제 #14
0
def save_material(material):
    '''Material saver.

    Saves Material specified in the XML.

    Parameters
    ----------
    material : Material()
        instance of TEASERS Material class

    '''

    mat_pyxb = mat_bind.MaterialType()
    mat_pyxb.name = material.name
    mat_pyxb.density = material.density
    mat_pyxb.thermal_conduc = material.thermal_conduc
    mat_pyxb.heat_capac = material.heat_capac

    path = utilitis.get_full_path("InputData/MaterialTemplates.xml")
    xml_file = open(path, 'r')

    xml_parse = mat_bind.CreateFromDocument(xml_file.read())
    xml_parse.Material.append(mat_pyxb)
    out_file = open(path, 'w')

    out_file.write(xml_parse.toDOM().toprettyxml())
예제 #15
0
def delete_type_element(element, data_class):
    """Delete typical element in json.

    Deletes typical building elements according to their construction
    year and their construction type in the the json file for type building
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file of TypeBuildingElements. If this file does not exist,
    a new file is created.
    Parameters
    ----------
    element : BuildingElement()
        Instance of BuildingElement or inherited Element of TEASER
    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """
    check_str = "{}_{}_{}".format(
        type(element).__name__, element.building_age_group,
        element.construction_type)

    del data_class.element_bind[check_str]

    with open(utilities.get_full_path(data_class.path_tb), "w") as file:
        file.write(
            json.dumps(data_class.element_bind,
                       indent=4,
                       separators=(",", ": ")))
예제 #16
0
def save_material(material):
    '''Material saver.

    Saves Material specified in the XML.

    Parameters
    ----------
    material : Material()
        instance of TEASERS Material class

    '''

    mat_pyxb = mat_bind.MaterialType()
    mat_pyxb.name = material.name
    mat_pyxb.density = material.density
    mat_pyxb.thermal_conduc = material.thermal_conduc
    mat_pyxb.heat_capac = material.heat_capac

    path = utilitis.get_full_path("InputData/MaterialTemplates.xml")
    xml_file = open(path, 'r')

    xml_parse = mat_bind.CreateFromDocument(xml_file.read())
    xml_parse.Material.append(mat_pyxb)
    out_file = open(path, 'w')

    out_file.write(xml_parse.toDOM().toprettyxml())
예제 #17
0
    def __init__(self, load_data=True):
        """Constructor of Project Class.
        """
        self._name = "Project"
        self.modelica_info = ModelicaInfo()

        self.weather_file_path = utilities.get_full_path(
            os.path.join(
                "data",
                "input",
                "inputdata",
                "weatherdata",
                "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos"))

        self.buildings = []

        self.load_data = load_data

        self._number_of_elements_calc = 2
        self._merge_windows_calc = False
        self._used_library_calc = "AixLib"

        if load_data is True:
            self.data = self.instantiate_data_class()
        else:
            self.data = None
예제 #18
0
def create_ibpsa_PI_model(prj, bldg, zone, path):
    lookup = TemplateLookup(directories=["code_templates\\"])
    mpc_template = Template(filename="code_templates\\IBPSA_FourElements_PI",
                            lookup=lookup)

    uses = [
        'Modelica(version="' + prj.modelica_info.version + '")',
        'IBPSA(version="' + prj.buildings[-1].library_attr.version + '")'
    ]

    bldg_path = os.path.join(path, bldg.name)

    zone_path = os.path.join(path, bldg.name, bldg.name + "_Models")

    for zone in bldg.thermal_zones:
        out_file = open(
            utilities.get_full_path(
                os.path.join(zone_path,
                             bldg.name + '_' + zone.name + '_PI.mo')), 'w')
        out_file.write(mpc_template.render_unicode(zone=zone))
        out_file.close()

        with open(os.path.join(zone_path, "package.order"), "a") as myfile:
            myfile.write(str(zone.parent.name + '_' + zone.name + '_PI\n'))
        myfile.close()
예제 #19
0
파일: test_data.py 프로젝트: jensgtz/TEASER
    def test_calc_ebc(self):
        '''
        Parameter Verification for ebc calculation method. Values are compared
        with TEASER3 values.
        '''
        prj.set_default()
        prj.load_project(utilities.get_full_path("examples/examplefiles"
                                              "/new.teaserXML"))
        therm_zone = prj.buildings[0].thermal_zones[0]
        prj.number_of_elements_calc = 2
        prj.merge_windows_calc = False
        prj.used_library_calc = 'AixLib'
        prj.buildings[0].calc_building_parameter()

        assert round(therm_zone.r1_iw, 11) == 4.62113e-06
        assert round(therm_zone.c1_iw, 2) == 1209810287.22
        assert round(therm_zone.area_iw, 5) == 9866.66667
        assert round(therm_zone.alpha_conv_iw, 5) == 2.37568

        assert round(therm_zone.r_rest_ow, 5) == 0.00183
        assert round(therm_zone.r1_ow, 10) == 3.06155e-05
        assert round(therm_zone.c1_ow, 3) == 226923157.846
        assert round(therm_zone.area_ow, 5) == 920.0

        assert round(therm_zone.alpha_conv_inner_ow, 5) == 1.83043

        assert round(therm_zone.alpha_conv_outer_ow, 5) == 20.0
        assert round(therm_zone.alpha_comb_outer_ow, 5) == 25.0
        assert round(therm_zone.alpha_conv_inner_win, 5) == 2.7
        assert round(therm_zone.alpha_conv_outer_win, 5) == 20.0
        assert round(therm_zone.alpha_comb_outer_win, 5) == 25.0

        assert round(therm_zone.weightfactor_ow[0], 5) == 0.04588
        assert round(therm_zone.weightfactor_win[0], 5) == 0.33333
        assert round(therm_zone.weightfactor_ground[0], 5) == 0.54398
예제 #20
0
    def save_citygml(self, file_name=None, path=None):
        """Saves the project to a CityGML file

        calls the function save_gml in data.CityGML we make use of CityGML core
        and EnergyADE to store semantic information


        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified

        """
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = os.path.join(utilities.get_default_path(), name)
        else:
            new_path = os.path.join(path, name)
            utilities.create_path(utilities.get_full_path(path))

        citygml_out.save_gml(self, new_path)
예제 #21
0
    def save_project(self, file_name=None, path=None):
        """Saves the project to a tXML file

        calls the function save_teaser_xml in data.TeaserXML.py

        Parameters
        ----------

        file_name : string
            name of the new file
        path : string
            if the Files should not be stored in OutputData, an alternative
            can be specified
        """
        if file_name is None:
            name = self.name
        else:
            name = file_name

        if path is None:
            new_path = os.path.join(utilities.get_default_path(), name)
        else:
            new_path = os.path.join(utilities.get_default_path(), name)
            utilities.create_path(utilities.get_full_path(path))

        txml_out.save_teaser_xml(new_path, self)
예제 #22
0
def modify_material(material, data_class):
    """Material modifier.

    Modifies material and their properties the XML file for type building
    elements. If the Project parent is set, it automatically modifies it to
    the file given in Project.data.

    Parameters
    ----------
    material : Material()
        instance of TEASERS Material class

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """

    mat_binding = data_class.material_bind

    for mat in mat_binding.Material:
        if mat.material_id == material.material_id:
            # mat_binding.Material.remove(mat)
            mat.material_id = material.material_id
            mat.name = material.name
            mat.density = material.density
            mat.thermal_conduc = material.thermal_conduc
            mat.heat_capac = material.heat_capac
            # mat_binding.Material.append(mat)"""
            break

    out_file = open(utilities.get_full_path(data_class.path_mat), "w")
    out_file.write(mat_binding.toDOM().toprettyxml())
예제 #23
0
def example_save():
    """"This function demonstrates different loading options of TEASER"""

    # In example e4_save we saved two TEASER projects using *.teaserXML and
    # Python package pickle. This example shows how to import these
    # information into your python environment again.

    # To load data from *.teaserXML we can use a simple API function. So
    # first we need to instantiate our API (similar to example
    # e1_generate_archetype). The XML file is called
    # `ArchetypeExample.teaserXML` and saved in the default path. You need to
    #  run e4 first before you can load this example file.

    from teaser.project import Project

    prj = Project()

    load_xml = os.path.join(utilities.get_default_path(),
                            'ArchetypeExample.teaserXML')

    prj.load_project(path=load_xml)
    prj = Project()
    prj.load_project(
        utilities.get_full_path("examples/examplefiles/new.teaserXML"))
    prj.save_project(file_name="new", path=None)

    # To reload data from a pickle file, we do not need to instantiate an
    # API, as pickle will automatically instantiate all classes as they have
    # been saved. The saved file from example e4 is called ´teaser_pickle.p´

    import pickle

    load_pickle = os.path.join(utilities.get_default_path(), 'teaser_pickle.p')

    pickle_prj = pickle.load(open(load_pickle, "rb"))

    # The last option to import data into TEASER is using a CityGML file. The
    # import of CityGML underlies some limitations e.g. concerning data
    # given in the file and the way the buildings are modeled.

    prj_gml = Project()

    load_gml = utilities.get_full_path(
        os.path.join('examples', 'examplefiles', 'CityGMLSample.gml'))

    prj_gml.load_citygml(path=load_gml)
예제 #24
0
    def __init__(self):
        """Constructor of DataClass
        """

        self.element_bind = None
        self.path_tb = utils.get_full_path(
            "data/input/inputdata/TypeBuildingElements.xml")
        self.material_bind = None
        self.path_mat = utils.get_full_path(
            "data/input/inputdata/MaterialTemplates.xml")
        self.conditions_bind = None
        self.path_uc = utils.get_full_path(
            "data/input/inputdata/UseConditions.xml")

        self.load_tb_binding()
        self.load_uc_binding()
        self.load_mat_binding()
예제 #25
0
def save_material(material, data_class):
    """Material saver.

    Saves material and their properties the XML file for type building
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file with Materials. If this file does not exist, a new file is created.

    Parameters
    ----------
    material : Material()
        instance of TEASERS Material class

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """
    mat_binding = data_class.material_bind
    add_to_xml = True
    mat_binding.version = "0.6"
    warning_text = ("Material with same name and same properties already "
                    "exists in XML, consider this material or revising your "
                    "properties")

    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(
        mat_bind.Namespace, 'materials')

    for check in mat_binding.Material:
        if check.name == material.name and \
                check.density == material.density and \
                check.thermal_conduc == material.thermal_conduc and \
                check.heat_capac == material.heat_capac and \
                check.thickness_default == material.thickness_default and \
                check.thickness_list == material.thickness_list:
            warnings.warn(warning_text)
            add_to_xml = False
            break

    if add_to_xml is True:
        mat_pyxb = mat_bind.MaterialType()

        mat_pyxb.name = material.name
        mat_pyxb.density = material.density
        mat_pyxb.thermal_conduc = material.thermal_conduc
        mat_pyxb.heat_capac = material.heat_capac
        mat_pyxb.material_id = material.material_id
        mat_pyxb.thickness_default = material.thickness_default
        mat_pyxb.thickness_list = material.thickness_list
        mat_pyxb.solar_absorp = material.solar_absorp

        mat_binding.Material.append(mat_pyxb)
        out_file = open(utilities.get_full_path(data_class.path_mat), "w")

        out_file.write(mat_binding.toDOM().toprettyxml())
예제 #26
0
    def __init__(self):
        '''Constructor of DataClass
        '''

        self.element_bind = None
        self.material_bind = None
        self.conditions_bind = None


        self.path_tb = utilitis.get_full_path(
            "data/input/inputdata/TypeBuildingElements.xml")
        self.path_uc = utilitis.get_full_path(
            "data/input/inputdata/UseConditions.xml")
        self.path_mat = utilitis.get_full_path(
            "data/input/inputdata/MaterialTemplates.xml")

        self.load_tb_binding()
        self.load_uc_binding()
        self.load_mat_binding()
def load_file():

    prj = Project(load_data=True)

    prj.load_project(utilities.get_full_path(os.path.join("examples",
                                                          "examplefiles",
                                                          "ASHRAE140_900."
                                                          "teaserXML")))

    return prj
예제 #28
0
def example_export_ibpsa():
    """"This function demonstrates the export to Modelica library IBPSA using
    the API function of TEASER"""

    # In e1_generate_archetype we created a Project with three archetype
    # buildings to get this Project we rerun this example

    prj = e1.example_generate_archetype()

    # To make sure the export is using the desired parameters you should
    # always set model settings in the Project.
    # Project().used_library_calc specifies the used Modelica library
    # Project().number_of_elements_calc sets the models order
    # Project().merge_windows_calc specifies if thermal conduction through
    # windows is lumped into outer walls or not.
    # For more information on models we'd like to refer you to the docs. By
    # default TEASER uses a weather file provided in
    # teaser.data.input.inputdata.weatherdata. You can use your own weather
    # file by setting Project().weather_file_path. However we will use default
    # weather file.

    prj.used_library_calc = 'IBPSA'
    prj.number_of_elements_calc = 4
    prj.merge_windows_calc = False
    prj.weather_file_path = utilities.get_full_path(
        os.path.join(
            "data",
            "input",
            "inputdata",
            "weatherdata",
            "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos"))

    # To make sure the parameters are calculated correctly we recommend to
    # run calc_all_buildings() function

    prj.calc_all_buildings()

    # To export the ready-to-run models simply call Project.export_ibpsa().
    # First specify the IBPSA related library you want to export the models
    # for. The models are identical in each library, but IBPSA Modelica
    # library is  just a core set of models and should not be used
    # standalone. Valid values are 'AixLib' (default), 'Buildings',
    # 'BuildingSystems' and 'IDEAS'. We chose AixLib
    # You can specify the path, where the model files should be saved.
    # None means, that the default path in your home directory
    # will be used. If you only want to export one specific building, you can
    # pass over the internal_id of that building and only this model will be
    # exported. In this case we want to export all buildings to our home
    # directory, thus we are passing over None for both parameters.

    prj.export_ibpsa(
        library='AixLib',
        internal_id=None,
        path=None)
예제 #29
0
def _help_package(path, name, uses=None):
    '''creates a package.mo file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.mo should be placed
    name : string
        name of the Modelica package

    '''

    package_template = Template(filename=utilitis.get_full_path
                                ("Data\\Output\\ModelicaTemplate\\package"))
    out_file = open(
        utilitis.get_full_path(path + "\\" + "package" + ".mo"), 'w')
    out_file.write(package_template.render_unicode(name=name, uses=uses))
    out_file.close()
예제 #30
0
def _help_package(path, name, uses=None):
    '''creates a package.mo file

    private function, do not call

    Parameters
    ----------

    path : string
        path of where the package.mo should be placed
    name : string
        name of the Modelica package

    '''

    package_template = Template(filename=utilitis.get_full_path(
        "Data\\Output\\ModelicaTemplate\\package"))
    out_file = open(utilitis.get_full_path(path + "\\" + "package" + ".mo"),
                    'w')
    out_file.write(package_template.render_unicode(name=name, uses=uses))
    out_file.close()
예제 #31
0
    def test_load_save_project(self):
        '''test of load_project and save_project'''

        prj.load_project(
            utilities.get_full_path(("examples/examplefiles"
                                     "/new.teaserXML")))
        therm_zone = prj.buildings[-1].thermal_zones[0]
        assert therm_zone.outer_walls[0].area == 40.0
        tz_area = sum([tz.area for tz in prj.buildings[-1].thermal_zones])
        assert prj.buildings[-1].net_leased_area == tz_area
        prj.save_project("unitTest")
        prj.set_default()
예제 #32
0
파일: test_data.py 프로젝트: jensgtz/TEASER
    def test_load_save_project(self):
        '''test of load_project and save_project'''

        prj.load_project(utilities.get_full_path(("examples/examplefiles"
                                               "/new.teaserXML")))
        therm_zone = prj.buildings[-1].thermal_zones[0]
        assert therm_zone.outer_walls[0].area == 40.0
        tz_area = sum([tz.area for tz in prj.buildings[
            -1].thermal_zones])
        assert prj.buildings[-1].net_leased_area == tz_area
        prj.save_project("unitTest")
        prj.set_default()
예제 #33
0
def parameter_room1():

    prj = Project(False)
    prj.name = "VDI_Verification_Room1"

    prj.load_project(
        utilities.get_full_path("examples/examplefiles/VDI6007_Room1.json"))

    prj.buildings[0].calc_building_parameter(number_of_elements=2,
                                             merge_windows=True,
                                             used_library='AixLib')

    return prj
예제 #34
0
    def __init__(self, type_element_file=None):
        '''Constructor of DataClass

        '''
        if type_element_file is None:
            self.path_tb = utilitis.get_full_path(
                "Data/Input/InputData/TypeBuildingElements.xml")
        else:
            self.path_tb = utilitis.get_full_path("Data/Input/InputData/" +
                                                  str(type_element_file))

        __xml_file_tb = open(self.path_tb, 'r')
        self.element_bind = tb_bind.CreateFromDocument(__xml_file_tb.read())
        self.path_uc = utilitis.get_full_path(
            "Data/Input/InputData/UseConditions.xml")
        __xml_file_uc = open(self.path_uc, 'r')
        self.conditions_bind = uc_bind.CreateFromDocument(__xml_file_uc.read())

        __path_mat = utilitis.get_full_path(
            "Data/Input/InputData/MaterialTemplates.xml")
        __xml_file_mat = codecs.open(__path_mat, 'r', encoding='utf-8')
        self.material_bind = mat_bind.CreateFromDocument(__xml_file_mat.read())
예제 #35
0
파일: dataclass.py 프로젝트: R33B/TEASER
    def __init__(self, type_element_file=None):
        '''Constructor of DataClass

        '''
        if type_element_file is None:
            self.path_tb = utilitis.get_full_path(
                "Data/Input/InputData/TypeBuildingElements.xml")
        else:
            self.path_tb = utilitis.get_full_path("Data/Input/InputData/"+str(
                type_element_file))

        __xml_file_tb = open(self.path_tb, 'r')
        self.element_bind = tb_bind.CreateFromDocument(__xml_file_tb.read())
        self.path_uc = utilitis.get_full_path(
            "Data/Input/InputData/UseConditions.xml")
        __xml_file_uc = open(self.path_uc, 'r')
        self.conditions_bind = uc_bind.CreateFromDocument(__xml_file_uc.read())

        __path_mat = utilitis.get_full_path(
            "Data/Input/InputData/MaterialTemplates.xml")
        __xml_file_mat = codecs.open(__path_mat, 'r', encoding='utf-8')
        self.material_bind = mat_bind.CreateFromDocument(__xml_file_mat.read())
예제 #36
0
def parameter_room10():

    prj = Project(load_data=True)

    prj.load_project(
        utilities.get_full_path(
            "examples/examplefiles/VDI6007_Room10.teaserXML"))

    prj.buildings[0].calc_building_parameter(number_of_elements=2,
                                             merge_windows=True,
                                             used_library='AixLib')

    prj.export_parameters_txt()
예제 #37
0
def save_type_element(element, data_class):
    """Save information about building element to json.

    Saves typical building elements according to their construction
    year and their construction type in the json file for type building
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file of TypeBuildingElements. If this file does not exist,
    a new file is created.

    Parameters
    ----------
    element : BuildingElement()
        Instance of BuildingElement or inherited Element of TEASER

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """
    data_class.element_bind["version"] = "0.7"
    add_to_json = True

    warning_text = ("Construction Type and building age "
                    "group already exist in this json, consider revising "
                    "your inputs. The Element is NOT saved into json")

    check_str = "{}_{}_{}".format(
        type(element).__name__, element.building_age_group,
        element.construction_type)

    if check_str in data_class.element_bind.keys():
        warnings.warn(warning_text)
        add_to_json = False
        return

    if add_to_json is True:
        data_class.element_bind[check_str] = collections.OrderedDict()

        _set_basic_data_json(element=element,
                             wall_out=data_class.element_bind[check_str])

        _set_layer_data_json(element=element,
                             wall_out=data_class.element_bind[check_str])

    with open(utilities.get_full_path(data_class.path_tb), "w") as file:
        file.write(
            json.dumps(data_class.element_bind,
                       indent=4,
                       separators=(",", ": ")))
예제 #38
0
def example_export_aixlib():
    """"This function demonstrates the export to Modelica library AixLib using
    the API function of TEASER"""

    # In e1_generate_archetype we created a Project with three archetype
    # buildings to get this Project we rerun this example

    prj = e1.example_generate_archetype()

    # To make sure the export is using the desired parameters you should
    # always set model settings in the Project.
    # Project().used_library_calc specifies the used Modelica library
    # Project().number_of_elements_calc sets the models order
    # For more information on models we'd like to refer you to the docs. By
    # default TEASER uses a weather file provided in
    # teaser.data.input.inputdata.weatherdata. You can use your own weather
    # file by setting Project().weather_file_path. However we will use default
    # weather file.
    # Be careful: Dymola does not like whitespaces in names and filenames,
    # thus we will delete them anyway in TEASER.

    prj.used_library_calc = 'AixLib'
    prj.number_of_elements_calc = 2
    prj.weather_file_path = utilities.get_full_path(
        os.path.join(
            "data",
            "input",
            "inputdata",
            "weatherdata",
            "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos"))

    # To make sure the parameters are calculated correctly we recommend to
    # run calc_all_buildings() function

    prj.calc_all_buildings()

    # To export the ready-to-run models simply call Project.export_aixlib().
    # You can specify the path, where the model files should be saved.
    # None means, that the default path in your home directory
    # will be used. If you only want to export one specific building, you can
    # pass over the internal_id of that building and only this model will be
    # exported. In this case we want to export all buildings to our home
    # directory, thus we are passing over None for both parameters.

    path = prj.export_aixlib(
        internal_id=None,
        path=None)

    return path
예제 #39
0
    def set_default(self, load_data=None):
        """Sets all attributes to default

        Caution: this will delete all buildings.

        Parameters
        ----------
        load_data : boolean, None-type
            boolean if data bindings for type elements and use conditions
            should be loaded (default = True), in addition it could be a None-
            type to use the already used data bindings
        """

        self._name = "Project"
        self.modelica_info = ModelicaInfo()

        self.weather_file_path = utilities.get_full_path(
            os.path.join(
                "data",
                "input",
                "inputdata",
                "weatherdata",
                "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos"))

        self.buildings = []

        self.load_data = load_data

        self._number_of_elements_calc = 2
        self._merge_windows_calc = False
        self._used_library_calc = "AixLib"

        if load_data is True:
            self.data = self.instantiate_data_class()
        elif not load_data:
            pass
        else:
            self.data = None

        self.name = "Project"

        self.weather_file_header = "wetter"
        self.weather_file_path = "modelica://AixLib/Resources/WeatherData/" \
                                 "TRY2010_12_Jahr_Modelica-Library.txt"
        self.buildings = []
        self._number_of_elements_calc = 2
        self._merge_windows_calc = False
        self._used_library_calc = "AixLib"
예제 #40
0
def save_material(material, data_class):
    """Material saver.

    Saves Material specified in the XML.

    Parameters
    ----------
    material : Material()
        instance of TEASERS Material class

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """
    mat_binding = data_class.material_bind
    add_to_xml = True
    mat_binding.version = "0.4"
    warning_text = ("Material with same name and same properties already "
                    "exists in XML, consider this material or revising your "
                    "properties")

    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(
        mat_bind.Namespace, 'materials')

    for check in mat_binding.Material:
        if check.name == material.name and \
                check.density == material.density and \
                check.thermal_conduc == material.thermal_conduc and \
                check.heat_capac == material.heat_capac:
            warnings.warn(warning_text)
            add_to_xml = False
            break

    if add_to_xml is True:
        mat_pyxb = mat_bind.MaterialType()

        mat_pyxb.name = material.name
        mat_pyxb.density = material.density
        mat_pyxb.thermal_conduc = material.thermal_conduc
        mat_pyxb.heat_capac = material.heat_capac
        mat_pyxb.material_id = material.material_id

        mat_binding.Material.append(mat_pyxb)
        out_file = open(utilitis.get_full_path(data_class.path_mat), "w")

        out_file.write(mat_binding.toDOM().toprettyxml())
예제 #41
0
def parameter_room3():
    '''
    load project of VDI 6007 room from TEASER file
    '''
    prj = Project(False)
    prj.load_project(
        utilitis.get_full_path(
            "examples\\examplefiles\\VDI6007_Room3.teaserXML"))
    '''
    execute VDI calculation for single zone
    '''

    prj.buildings[0].calc_building_parameter(number_of_elements=2,
                                             merge_windows=True,
                                             used_library='AixLib')

    return prj
예제 #42
0
def main(number_of_elements=2):

    prj = from_scratch(number_of_elements=number_of_elements, save=False)
    # prj = load_file()

    prj.used_library_calc = "IBPSA"
    prj.number_of_elements_calc = number_of_elements
    prj.merge_windows_calc = False
    prj.weather_file_path = utilities.get_full_path(
        os.path.join("data", "input", "inputdata", "weatherdata", "ASHRAE140.mos")
    )

    prj.buildings[0].calc_building_parameter(
        number_of_elements=number_of_elements, merge_windows=False, used_library="IBPSA"
    )

    prj.export_ibpsa()
예제 #43
0
def parameter_room3():
    
    '''
    load project of VDI 6007 room from TEASER file
    '''
    prj = Project(False)
    prj.load_project(utilitis.get_full_path(
        "examples\\examplefiles\\VDI6007_Room3.teaserXML"))

    '''
    execute VDI calculation for single zone
    '''
    
    prj.buildings[0].calc_building_parameter(number_of_elements=2,
                                             merge_windows=True,
                                             used_library='AixLib')
    
    return prj
예제 #44
0
파일: __init__.py 프로젝트: jensgtz/TEASER
'''
import sys
import teaser.logic.utilities as utilitis
import os

v = sys.version_info
if v >= (3, 3):
    py33 = True
    py27 = False
elif v >= (2, 7) and v < (3,):
    py33 = False
    py27 = True
else:
    raise Exception('This software runs on python versions 2.7 or >=3.3 only!')

new_path = utilitis.get_full_path("OutputData")
if not os.path.exists(new_path):
    os.makedirs(new_path)

if sys.platform.startswith('win'):
    def read_file(path, mode='r'):
        fp = open(path, mode)
        try:
            data = fp.read()
            return data
        finally:
            fp.close()
    # hot patch loaded module :-)
    import mako.util
    mako.util.read_file = read_file
    del read_file
예제 #45
0
@author: TEASER 4 Development Team

This Scripts loads an project from TEASER 3 and executes the calculation

'''

from teaser.project import Project
import teaser.logic.utilities as utilitis

'''
load project of VDI 6007 room from  TEASER file
'''
prj = Project(False)

prj.load_project(utilitis.get_full_path(
    "examples/examplefiles/new.teaserXML"))

'''
execute VDI calculation for single zone
'''

prj.buildings[0].calc_building_parameter('ebc')

'''
parameters inner wall 
'''
print("Parameters for inner wall")
print("r1_iw:", prj.buildings[0].thermal_zones[0].r1_iw,"K/W ---", "TEASER 3: 4.62113316216e-06 K/W")
print("c1_iw: ", prj.buildings[0].thermal_zones[0].c1_iw,"kJ/K ---", "TEASER 3: 1209810287.22 kJ/K")
print("area_iw: ", prj.buildings[0].thermal_zones[0].area_iw,"qm ---", "TEASER 3: 9866.66666667 qm")
print("alpha_conv_iw: ", prj.buildings[0].thermal_zones[0].alpha_conv_inner_iw,
예제 #46
0
def save_type_element(element, path=None, file_name=None):
    '''Typical element saver.

    Saves typical building elements according to their construction
    year and their construction type in the the XML file for type buidling
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file of TypeBuildingElements. If this file does not exist,
    a new file is created.

    Parameters
    ----------

    element : BuildingElement()
        Instance of BuildingElement or inherited Element of TEASER

    path : str
        path where unique file should be stored
    name : strt
        name of of unique file

    '''

    if element.parent is not None:
        path = element.parent.parent.parent.data.path_tb
        xml_parse = element.parent.parent.parent.data.element_bind
    else:
        path = path + "/" + file_name + ".xml"
        try:
            xml_file = open(utilitis.get_full_path(path))
            xml_parse = tb_bind.CreateFromDocument(xml_file.read())
        except:
            xml_parse = tb_bind.TypeBuildingElements()

    add_to_xml = True
    warning_text = ("Construction Type and building age "
                    "group already exist in this XML, consider revising "
                    "your inputs. The Element is NOT saved into XML")
    if type(element).__name__ == "OuterWall":

        for check in xml_parse.OuterWall:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.OuterWallType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)


            xml_parse.OuterWall.append(pyxb_wall)

    elif type(element).__name__ == 'InnerWall':

        for check in xml_parse.InnerWall:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.InnerWallType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.InnerWall.append(pyxb_wall)

    elif type(element).__name__ == 'Ceiling':

        for check in xml_parse.Ceiling:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.CeilingType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.Ceiling.append(pyxb_wall)

    elif type(element).__name__ == 'Floor':

        for check in xml_parse.Floor:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.FloorType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.Floor.append(pyxb_wall)

    elif type(element).__name__ == 'GroundFloor':

        for check in xml_parse.GroundFloor:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.GroundFloorType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.GroundFloor.append(pyxb_wall)

    elif type(element).__name__ == 'Rooftop':

        for check in xml_parse.Rooftop:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.RooftopType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.Rooftop.append(pyxb_wall)

    elif type(element).__name__ == 'Window':

        for check in xml_parse.Window:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.WindowType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            xml_parse.Window.append(pyxb_wall)

    if add_to_xml is True:

        out_file = open(utilitis.get_full_path(path),"w")

        out_file.write(xml_parse.toDOM().toprettyxml())
예제 #47
0
def delete_type_element(element, data_class):
    """Deletes typical element.

    Deletes typical building elements according to their construction
    year and their construction type in the the XML file for type buidling
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file of TypeBuildingElements. If this file does not exist,
    a new file is created.

    Parameters
    ----------
    element : BuildingElement()
        Instance of BuildingElement or inherited Element of TEASER

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.

    """

    element_binding = data_class.element_bind

    if type(element).__name__ == "OuterWall":
        for check in element_binding.OuterWall:
            if check.building_age_group == element.building_age_group and \
               check.construction_type == element.construction_type:
                element_binding.OuterWall.remove(check)
                break

    elif type(element).__name__ == 'InnerWall':

        for check in element_binding.InnerWall:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.InnerWall.remove(check)
                break

    elif type(element).__name__ == 'Ceiling':

        for check in element_binding.Ceiling:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.Ceiling.remove(check)
                break

    elif type(element).__name__ == 'Floor':

        for check in element_binding.Floor:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.Floor.remove(check)
                break

    elif type(element).__name__ == 'GroundFloor':

        for check in element_binding.GroundFloor:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.GroundFloor.remove(check)
                break

    elif type(element).__name__ == 'Rooftop':

        for check in element_binding.Rooftop:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.Rooftop.remove(check)
                break

    elif type(element).__name__ == 'Window':

        for check in element_binding.Window:
            if check.building_age_group == element.building_age_group and \
                            check.construction_type == element.construction_type:
                element_binding.Window.remove(check)
                break

    out_file = open(utilitis.get_full_path(data_class.path_tb),"w")

    out_file.write(element_binding.toDOM().toprettyxml())
예제 #48
0
def save_type_element(element, data_class):
    '''Typical element saver.

    Saves typical building elements according to their construction
    year and their construction type in the the XML file for type buidling
    elements. If the Project parent is set, it automatically saves it to
    the file given in Project.data. Alternatively you can specify a path to
    a file of TypeBuildingElements. If this file does not exist,
    a new file is created.

    Parameters
    ----------
    element : BuildingElement()
        Instance of BuildingElement or inherited Element of TEASER

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.
    '''

    element_binding = data_class.element_bind
    element_binding.version = "0.4"
    add_to_xml = True

    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(
        tb_bind.Namespace, 'elements')

    warning_text = ("Construction Type and building age "
                    "group already exist in this XML, consider revising "
                    "your inputs. The Element is NOT saved into XML")
    if type(element).__name__ == "OuterWall":

        for check in element_binding.OuterWall:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.OuterWallType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.OuterWall.append(pyxb_wall)

    elif type(element).__name__ == 'InnerWall':

        for check in element_binding.InnerWall:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.InnerWallType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.InnerWall.append(pyxb_wall)

    elif type(element).__name__ == 'Ceiling':

        for check in element_binding.Ceiling:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.CeilingType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.Ceiling.append(pyxb_wall)

    elif type(element).__name__ == 'Floor':

        for check in element_binding.Floor:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.FloorType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.Floor.append(pyxb_wall)

    elif type(element).__name__ == 'GroundFloor':

        for check in element_binding.GroundFloor:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.GroundFloorType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.GroundFloor.append(pyxb_wall)

    elif type(element).__name__ == 'Rooftop':

        for check in element_binding.Rooftop:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.RooftopType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.Rooftop.append(pyxb_wall)

    elif type(element).__name__ == 'Window':

        for check in element_binding.Window:
            if check.building_age_group == element.building_age_group and\
               check.construction_type == element.construction_type:
                warnings.warn(warning_text)
                add_to_xml = False
                break

        if add_to_xml is True:

            pyxb_wall = tb_bind.WindowType()
            _set_basic_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)
            pyxb_wall.Layers = tb_bind.LayersType()
            _set_layer_data_pyxb(element=element,
                                 pyxb_class=pyxb_wall)

            element_binding.Window.append(pyxb_wall)

    if add_to_xml is True:

        out_file = open(utilitis.get_full_path(data_class.path_tb),"w")

        out_file.write(element_binding.toDOM().toprettyxml())
예제 #49
0
def export_annex60(prj,
                   number_of_elements=2,
                   merge_windows=False,
                   internal_id=None,
                   path=None):
    """Exports values to a record file for Annex60 simulation

    The Export function for creating a Annex60 example model

    Parameters
    ----------

    number_of_elements : int
            defines the number of elements, that area aggregated, between 1
            and 4, default is 2
    merge_windows : bool
            True for merging the windows into the outer walls, False for
            separate resistance for window, default is False
    internal_id : float
        setter of the used building which will be exported, if None then
        all buildings will be exported
    path : string
        if the Files should not be stored in OutputData, an alternative
        path can be specified as a full and absolute path

    """

    uses = ['Modelica(version = "3.2.2")',
            'Annex60(version="0.1")']

    if internal_id is not None:
        exported_list_of_buildings = [bldg for bldg in
                                      prj.buildings if
                                      bldg.internal_id == internal_id]
    else:
        exported_list_of_buildings = prj.buildings

    aixlib_output._help_package(path, prj.name, uses, within=None)
    aixlib_output._help_package_order(path, exported_list_of_buildings)

    if number_of_elements == 1:
        pass
    elif number_of_elements == 2:
        zone_template = Template(filename=utilitis.get_full_path(
            "data/output/modelicatemplate/Annex60/Annex60_TwoElements"))
    elif number_of_elements == 3:
        zone_template = Template(filename=utilitis.get_full_path(
            "data/output/modelicatemplate/Annex60/Annex60_ThreeElements"))
    elif number_of_elements == 4:
        zone_template = Template(filename=utilitis.get_full_path(
            "data/output/modelicatemplate/Annex60/Annex60_FourElements"))

    for bldg in exported_list_of_buildings:
        bldg_path = os.path.join(path,
                                 bldg.name)
        utilitis.create_path(utilitis.get_full_path(bldg_path))
        utilitis.create_path(utilitis.get_full_path(bldg_path+ "/" + bldg.name + \
                                                     "_Models"))
        aixlib_output._help_package(bldg_path, bldg.name, within=prj.name)
        aixlib_output._help_package_order(bldg_path,
                                          [bldg],
                                          None,
                                          bldg.name + "_Models")
        for zone in bldg.thermal_zones:
            zone_path = os.path.join(bldg_path,
                                     bldg.name+"_Models")

            out_file = open(utilitis.get_full_path(
                    zone_path + "/" + bldg.name + "_" +
                    zone.name.replace(" ", "") + ".mo"), 'w')
            out_file.write(zone_template.render_unicode(bldg=bldg,
                                                        zone=zone,
                                                        merge_windows=merge_windows,
                                                        within=(prj.name +
                                                                '.' +
                                                                bldg.name +
                                                                '.' +
                                                                bldg.name +
                                                                "_Models"),
                                                        modelica_info=prj.modelica_info))

            aixlib_output._help_package(zone_path,
                                        bldg.name + "_Models",
                                        within=prj.name + '.' + bldg.name)

            aixlib_output._help_package_order(zone_path,
                                              bldg.thermal_zones,
                                              (bldg.name + "_"))

            out_file.close()

    print("Exports can be found here:")
    print(path)
예제 #50
0
def save_bound_conditions(bound_cond, data_class):
    '''Use conditions saver.

    Saves use conditions according to their usage type in the the XML file
    for use conditions in InputData. If the Project parent is set, it
    automatically saves it to the file given in Project.data. Alternatively
    you can specify a path to a file of UseConditions. If this
    file does not exist, a new file is created.

    Parameters
    ----------

    bound_cond : BoundaryConditions()
        Instance of TEASERs
        BuildingObjects.BoundaryConditions.BoundaryConditions

    data_class : DataClass()
        DataClass containing the bindings for TypeBuildingElement and
        Material (typically this is the data class stored in prj.data,
        but the user can individually change that.ile
    '''

    conditions_bind = data_class.conditions_bind
    add_to_xml = True

    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace(
        uc_bind.Namespace, 'usecond')

    for check in conditions_bind.BoundaryConditions:
        if check.usage == bound_cond.usage:
            warnings.warn("Usage already exist in this XML, consider " +
                          "revising your inputs. The UseConditions is  " +
                          "NOT saved into XML")
            add_to_xml = False
            break
    conditions_bind.version = "0.4"
    if add_to_xml is True:

        usage_pyxb = uc_bind.BoundaryConditionsType()
        usage_pyxb.UsageOperationTime = uc_bind.UsageOperationTimeType()
        usage_pyxb.Lighting = uc_bind.LightingType()
        usage_pyxb.RoomClimate = uc_bind.RoomClimateType()
        usage_pyxb.InternalGains = uc_bind.InternalGainsType()
        usage_pyxb.AHU = uc_bind.AHUType()

        usage_pyxb.usage = bound_cond.usage

        usage_pyxb.UsageOperationTime.usage_time =\
            bound_cond.usage_time
        usage_pyxb.UsageOperationTime.daily_usage_hours = \
            bound_cond.daily_usage_hours
        usage_pyxb.UsageOperationTime.yearly_usage_days = \
            bound_cond.yearly_usage_days
        usage_pyxb.UsageOperationTime.yearly_usage_hours_day = \
            bound_cond.yearly_usage_hours_day
        usage_pyxb.UsageOperationTime.yearly_usage_hours_night = \
            bound_cond.yearly_usage_hours_night
        usage_pyxb.UsageOperationTime.daily_operation_ahu_cooling = \
            bound_cond.daily_operation_ahu_cooling
        usage_pyxb.UsageOperationTime.yearly_heating_days = \
            bound_cond.yearly_heating_days
        usage_pyxb.UsageOperationTime.yearly_ahu_days = \
            bound_cond.yearly_ahu_days
        usage_pyxb.UsageOperationTime.yearly_cooling_days = \
            bound_cond.yearly_cooling_days
        usage_pyxb.UsageOperationTime.daily_operation_heating = \
            bound_cond.daily_operation_heating

        usage_pyxb.Lighting.maintained_illuminance = \
            bound_cond.maintained_illuminance
        usage_pyxb.Lighting.usage_level_height = bound_cond.usage_level_height
        usage_pyxb.Lighting.red_factor_visual = bound_cond.red_factor_visual
        usage_pyxb.Lighting.rel_absence = bound_cond.rel_absence
        usage_pyxb.Lighting.room_index = bound_cond.room_index
        usage_pyxb.Lighting.part_load_factor_lighting = \
            bound_cond.part_load_factor_lighting
        usage_pyxb.Lighting.ratio_conv_rad_lighting = \
            bound_cond.ratio_conv_rad_lighting

        usage_pyxb.RoomClimate.set_temp_heat = bound_cond.set_temp_heat
        usage_pyxb.RoomClimate.set_temp_cool = bound_cond.set_temp_cool
        usage_pyxb.RoomClimate.temp_set_back = bound_cond.temp_set_back
        usage_pyxb.RoomClimate.min_temp_heat = bound_cond.min_temp_heat
        usage_pyxb.RoomClimate.max_temp_cool = bound_cond.max_temp_cool
        usage_pyxb.RoomClimate.rel_humidity = bound_cond.rel_humidity
        usage_pyxb.RoomClimate.cooling_time = bound_cond.cooling_time
        usage_pyxb.RoomClimate.heating_time = bound_cond.heating_time
        usage_pyxb.RoomClimate.min_air_exchange = bound_cond.min_air_exchange
        usage_pyxb.RoomClimate.rel_absence_ahu = bound_cond.rel_absence_ahu
        usage_pyxb.RoomClimate.part_load_factor_ahu = \
            bound_cond.part_load_factor_ahu

        usage_pyxb.InternalGains.persons = bound_cond.persons
        usage_pyxb.InternalGains.profile_persons = bound_cond.profile_persons
        usage_pyxb.InternalGains.machines = bound_cond.machines
        usage_pyxb.InternalGains.profile_machines = bound_cond.profile_machines
        usage_pyxb.InternalGains.lighting_power = bound_cond.lighting_power
        usage_pyxb.InternalGains.profile_lighting = bound_cond.profile_lighting

        usage_pyxb.AHU.min_ahu = bound_cond.min_ahu
        usage_pyxb.AHU.max_ahu = bound_cond.max_ahu
        usage_pyxb.AHU.with_ahu = bound_cond.with_ahu
        usage_pyxb.typical_length = bound_cond.typical_length
        usage_pyxb.typical_width = bound_cond.typical_width

        conditions_bind.append(usage_pyxb)

        out_file = open(utilitis.get_full_path(data_class.path_uc), 'w')

        out_file.write(conditions_bind.toDOM().toprettyxml())
예제 #51
0
def save_bound_conditions(bound_cond, path=None, file_name=None):
    '''Use conditions saver.

    Saves use conditions according to their usage type in the the XML file
    for use conditions in InputData. If the Project parent is set, it
    automatically saves it to the file given in Project.data. Alternatively
    you can specify a path to a file of UseConditions. If this
    file does not exist, a new file is created.

    Parameters
    ----------

    bound_cond : BoundaryConditions()
        Instance of TEASERs
        BuildingObjects.BoundaryConditions.BoundaryConditions

    path : str
        path where unique file should be stored
    name : str
        name of of unique file
    '''

    if bound_cond.parent is not None:
        path = bound_cond.parent.parent.parent.data.path_uc
        xml_parse = bound_cond.parent.parent.parent.data.conditions_bind
    else:
        path = path + "/" + file_name + ".xml"
        try:
            xml_file = open(utilitis.get_full_path(path))
            xml_parse = uc_bind.CreateFromDocument(xml_file.read())
        except:
            xml_parse = uc_bind.UseConditions()

    add_to_xml = True

    for check in xml_parse.BoundaryConditions:
        if check.usage == bound_cond.usage:
            warnings.warn("Usage already exist in this XML, consider " +
                          "revising your inputs. The UseConditions is  " +
                          "NOT saved into XML")
            add_to_xml = False
            break

    if add_to_xml is True:

        usage_pyxb = uc_bind.BoundaryConditionsType()
        usage_pyxb.UsageOperationTime = uc_bind.UsageOperationTimeType()
        usage_pyxb.Lighting = uc_bind.LightingType()
        usage_pyxb.RoomClimate = uc_bind.RoomClimateType()
        usage_pyxb.InternalGains = uc_bind.InternalGainsType()
        usage_pyxb.AHU = uc_bind.AHUType()

        usage_pyxb.usage = bound_cond.usage

        usage_pyxb.UsageOperationTime.usage_time =\
            bound_cond.usage_time
        usage_pyxb.UsageOperationTime.daily_usage_hours = \
            bound_cond.daily_usage_hours
        usage_pyxb.UsageOperationTime.yearly_usage_days = \
            bound_cond.yearly_usage_days
        usage_pyxb.UsageOperationTime.yearly_usage_hours_day = \
            bound_cond.yearly_usage_hours_day
        usage_pyxb.UsageOperationTime.yearly_usage_hours_night = \
            bound_cond.yearly_usage_hours_night
        usage_pyxb.UsageOperationTime.daily_operation_ahu_cooling = \
            bound_cond.daily_operation_ahu_cooling
        usage_pyxb.UsageOperationTime.yearly_heating_days = \
            bound_cond.yearly_heating_days
        usage_pyxb.UsageOperationTime.yearly_ahu_days = \
            bound_cond.yearly_ahu_days
        usage_pyxb.UsageOperationTime.yearly_cooling_days = \
            bound_cond.yearly_cooling_days
        usage_pyxb.UsageOperationTime.daily_operation_heating = \
            bound_cond.daily_operation_heating

        usage_pyxb.Lighting.maintained_illuminace = \
            bound_cond.maintained_illuminace
        usage_pyxb.Lighting.usage_level_height = bound_cond.usage_level_height
        usage_pyxb.Lighting.red_factor_visual = bound_cond.red_factor_visual
        usage_pyxb.Lighting.rel_absence = bound_cond.rel_absence
        usage_pyxb.Lighting.room_index = bound_cond.room_index
        usage_pyxb.Lighting.part_load_factor_lighting = \
            bound_cond.part_load_factor_lighting
        usage_pyxb.Lighting.ratio_conv_rad_lighting = \
            bound_cond.ratio_conv_rad_lighting

        usage_pyxb.RoomClimate.set_temp_heat = bound_cond.set_temp_heat
        usage_pyxb.RoomClimate.set_temp_cool = bound_cond.set_temp_cool
        usage_pyxb.RoomClimate.temp_set_back = bound_cond.temp_set_back
        usage_pyxb.RoomClimate.min_temp_heat = bound_cond.min_temp_heat
        usage_pyxb.RoomClimate.max_temp_cool = bound_cond.max_temp_cool
        usage_pyxb.RoomClimate.rel_humidity = bound_cond.rel_humidity
        usage_pyxb.RoomClimate.cooling_time = bound_cond.cooling_time
        usage_pyxb.RoomClimate.heating_time = bound_cond.heating_time
        usage_pyxb.RoomClimate.min_air_exchange = bound_cond.min_air_exchange
        usage_pyxb.RoomClimate.rel_absence_ahu = bound_cond.rel_absence_ahu
        usage_pyxb.RoomClimate.part_load_factor_ahu = \
            bound_cond.part_load_factor_ahu

        usage_pyxb.InternalGains.persons = bound_cond.persons
        usage_pyxb.InternalGains.profile_persons = bound_cond.profile_persons
        usage_pyxb.InternalGains.machines = bound_cond.machines
        usage_pyxb.InternalGains.profile_machines = bound_cond.profile_machines
        usage_pyxb.InternalGains.lighting_power = bound_cond.lighting_power
        usage_pyxb.InternalGains.profile_lighting = bound_cond.profile_lighting

        usage_pyxb.AHU.min_ahu = bound_cond.min_ahu
        usage_pyxb.AHU.max_ahu = bound_cond.max_ahu
        usage_pyxb.AHU.with_ahu = bound_cond.with_ahu
        usage_pyxb.typical_length = bound_cond.typical_length
        usage_pyxb.typical_width = bound_cond.typical_width

        xml_parse.append(usage_pyxb)

        out_file = open(utilitis.get_full_path(path), 'w')

        out_file.write(xml_parse.toDOM().toprettyxml())
예제 #52
0
def export_aixlib(prj,
                  building_model="None",
                  zone_model="None",
                  corG=None,
                  internal_id=None,
                  path=None):
    '''Exports values to a record file for Modelica simulation

    The Export function for creating a AixLib LOM Multizone model

    Parameters
    ----------

    building_model : string
        setter of the used Aixlib building model (None, MultizoneEquipped,
        Multizone)
    zone_model : string
        setter of the used Aixlib zone model (ThermalZoneEquipped,
        ThermalZone)
    corG : boolean
        setter of the used g value calculation in the model
    internal_id : float
        setter of the used building which will be exported, if None then
        all buildings will be exported
    path : string
        if the Files should not be stored in OutputData, an alternative
        path can be specified as a full and absolute path

    '''

    #check the arguments
    assert building_model in ["None", "MultizoneEquipped", "Multizone"]
    assert zone_model in ["None", "ThermalZoneEquipped", "ThermalZone"]
    assert corG in [None, True, False]

    uses = ['Modelica(version = "3.2.1")',
            "AixLib(version=\"0.3.1\")"]

    # use the same zone templates for all exports
    zone_template = Template(
        filename=utilitis.get_full_path(
            "data/output/modelicatemplate/AixLib/AixLib_zone"))
    model_template = Template(
        filename=utilitis.get_full_path(
            "data/output/modelicatemplate/AixLib/AixLib_model"))
    zone_base_template = Template(
        filename=utilitis.get_full_path(
            "data/output/modelicatemplate/AixLib/AixLib_base"))
    # list which contains exported buildings
    if internal_id is not None:
        exported_list_of_buildings = [bldg for bldg in
                                      prj.buildings if
                                      bldg.internal_id == internal_id]
    else:
        exported_list_of_buildings = prj.buildings

    # here we diff between zonerecord export and full model support
    if building_model != "None" and zone_model != "None" and\
        corG is not None:
        # full model support here
        print("full model support")

        _help_package(path, prj.name, uses, within=None)
        _help_package_order(path, exported_list_of_buildings)

        for bldg in exported_list_of_buildings:

            if bldg.merge_windows_calc is True:
                calc_method = 'vdi'
            elif bldg.merge_windows_calc is False:
                calc_method = 'ebc'

            bldg_path = path + "/" + bldg.name + "/"
            utilitis.create_path(utilitis.get_full_path(bldg_path))
            utilitis.create_path(utilitis.get_full_path
                               (bldg_path + bldg.name + "_DataBase"))
            aixlib.modelica_set_temp(bldg=bldg, path=path + "/" + bldg.name)
            aixlib.modelica_AHU_boundary(bldg=bldg, path=path + "/" + bldg.name)
            aixlib.modelica_gains_boundary(bldg=bldg, path=path + "/" + bldg.name)

            _help_package(bldg_path, bldg.name, within=prj.name)
            _help_package_order(bldg_path, [bldg], None,
                                     bldg.name + "_DataBase")

            out_file = open(utilitis.get_full_path
                            (bldg_path + bldg.name + ".mo"), 'w')


            out_file.write(model_template.render_unicode(
                           bldg=bldg, mod_prj=prj.modelica_project,
                           weather=prj.weather_file_path,
                           weather_header=prj.weather_file_header,
                           model=building_model,
                           zone=zone_model,
                           physics=calc_method,
                           gFac=corG))
            out_file.close()

            for zone in bldg.thermal_zones:
                zone_path = bldg_path + bldg.name + "_DataBase" + "/"

                out_file = open(utilitis.get_full_path(
                    zone_path + "/" + bldg.name + "_" +
                    zone.name.replace(" ", "") + ".mo"), 'w')
                out_file.write(zone_template.render_unicode(
                    bldg=bldg,
                    zone=zone,
                    mod_prj=prj.modelica_project))
                out_file.close()

            _help_package(zone_path,
                          bldg.name + "_DataBase",
                          within=prj.name + '.' + bldg.name)
            _help_package_order(zone_path,
                                bldg.thermal_zones,
                                bldg.name + "_", bldg.name + "_base")

            out_file = open(utilitis.get_full_path
                            (zone_path + bldg.name + "_base.mo"),
                            'w')
            if bldg.central_ahu:
                out_file.write(zone_base_template.render_unicode(
                    bldg=bldg,
                    zone=zone,
                    mod_prj=prj.modelica_project,
                    central_ahu=bldg.central_ahu))
                out_file.close()
            else:
                out_file.write(zone_base_template.render_unicode(
                    bldg=bldg,
                    zone=zone,
                    mod_prj=prj.modelica_project))
                out_file.close()
        print("Exports can be found here:")
        print(path)

    elif building_model == "None" and zone_model == "None" and\
        corG is None:
        # only export the baserecords
        _help_package(path, prj.name, uses)
        _help_package_order(path, exported_list_of_buildings)
        for bldg in exported_list_of_buildings:

            bldg_path = path + "/" + bldg.name + "/"
            utilitis.create_path(utilitis.get_full_path(bldg_path))
            utilitis.create_path(utilitis.get_full_path
                               (bldg_path + bldg.name + "_DataBase"))

            _help_package(bldg_path, bldg.name, within=prj.name)
            _help_package_order(bldg_path, [bldg], None,
                                     bldg.name + "_DataBase")

            for zone in bldg.thermal_zones:
                zone_path = bldg_path + bldg.name + "_DataBase" + "/"

                out_file = open(utilitis.get_full_path(
                    zone_path + "/" + bldg.name + "_" +
                    zone.name.replace(" ", "") + ".mo"), 'w')
                out_file.write(zone_template.render_unicode(
                    bldg=bldg,
                    zone=zone,
                    calc_core=bldg._calculation_method,
                    mod_prj=prj.modelica_project))

                out_file.close()

            _help_package(zone_path,
                          bldg.name + "_DataBase",
                          within=prj.name + '.' + bldg.name)
            _help_package_order(zone_path,
                                bldg.thermal_zones,
                                bldg.name + "_", bldg.name + "_base")

        print("Exports can be found here:")
        print(path)

    else:
        # not clearly specified
        print("please specify you export clearly")