Esempio n. 1
0
    def read_DelphinDataSet(self, stringFilePathName_d6p, stringFilePath_m6 ):
        
        #try to read file and replace invalid prefix in delphin project file
        try:
            fileString = open(stringFilePathName_d6p, "r").read()
        except Exception:
            print("Invalid file or file access not possible: %s" % stringFilePathName_d6p)
        else:
            buggyString = "xsi:schemaLocation" #undefined prefix causes error in xml parsing function
            newString = "schemaLocation"
            #find false string
            if (buggyString in fileString):
                newFileString = fileString.replace( buggyString, newString )
                newFile = open(stringFilePathName_d6p, "w")
                newFile.write(newFileString)
                newFile.close()

        #read xml project file
        try:
            xml_fileTreeObject = DOM.parse( stringFilePathName_d6p )
        except Exception:
            print("XML file reading of file %s failed. Invalid xml file structure." % stringFilePathName_d6p)
            return False
        else:
            #init properties temporary property/ element lists
            materialList = []           #container for material objects specified in this file
            layerThickList = []         #contains string values with layer thicknesses in m

            #construction file reading successful, now try to parse included material files
            for matTag in  xml_fileTreeObject.getElementsByTagName("MaterialReference"):
                
                #get tag properties
                matName = matTag.getAttribute("displayName")
                matFileString = matTag.firstChild.nodeValue

                #get file location for material file
                placeHolder = "${Material Database}/"
                folder = stringFilePath_m6 + os.sep
                matFileLocation = matFileString.replace( placeHolder , folder )
                #print("Identified and submitted file string is %s." % matFileLocation )
                
                #read data set and create material object with specific name
                newMaterial = Material()
                if (newMaterial.read_DelphinDataSet( matFileLocation ) == True):
                    #print("Material %s identified." % matName)
                    newMaterial.set_matName( matName )
                    materialList.append( newMaterial )
                else:
                    print("One or several materials in delivered construction file %s are invalid." % stringFilePathName_d6p)
                    return False
                
            #now get layer thicknesses
            allSteps = xml_fileTreeObject.getElementsByTagName("XSteps")[0].firstChild.nodeValue
            for step in allSteps.split():
                layerThickList.append(step)
                #print("Layer thickness %s identified." % step)

            #read layer order and create layers for this construction
            layerCounter = 0
            for assTag in xml_fileTreeObject.getElementsByTagName("Assignment"):
                if ( assTag.getAttribute("type") == "Material" ):
                    tempMatName = assTag.getElementsByTagName("Reference")[0].getAttribute("displayName")
                    #print("Referenced material name %s identified." % tempMatName)
                    for matObject in materialList:
                        #print("checked name for material: %s" % matObject.return_name() )
                        if (matObject.return_name() == tempMatName):
                            #matching material, create layer
                            self.add_layer( matObject, layerThickList[ layerCounter ], layerCounter )
                            #print("Matching material %s identified. Layer created." % matObject.return_name() )
                            layerCounter = layerCounter + 1
                else:
                    print("Delphin project file parsing of file %s failed. Invalid layer definiton." % stringFilePathName_d6p)
                    return False               
            
            return True
Esempio n. 2
0
    def read_DelphinDataSet(self, stringFilePathName_d6p, stringFilePath_m6 ):
        
        #try to read file and replace invalid prefix in delphin project file
        print("Reading of Delphin construction file.")
        try:
            fileString = open(stringFilePathName_d6p, "r").read()
        except Exception:
            print("Invalid file or file access not possible: %s" % stringFilePathName_d6p)
        else:
            buggyString = "xsi:schemaLocation" #undefined prefix causes error in xml parsing function
            newString = "schemaLocation"
            #find false string
            if (buggyString in fileString):
                newFileString = fileString.replace( buggyString, newString )
                newFile = open(stringFilePathName_d6p, "w")
                newFile.write(newFileString)
                newFile.close()

        #read xml project file
        try:
            xml_fileTreeObject = DOM.parse( stringFilePathName_d6p )
        except Exception:
            print("XML file reading of file %s failed. Invalid xml file structure." % stringFilePathName_d6p)
            return False
        else:
            #init properties temporary property/ element lists
            materialList = []           #container for material objects specified in this file
            layerThickList = []         #contains string values with layer thicknesses in m

            #construction file reading successful, now try to parse included material files
            for matTag in xml_fileTreeObject.getElementsByTagName("MaterialReference"):
                print("Getting of material references and parameters:")
                #get tag properties
                matName = matTag.getAttribute("displayName")
                print("display name: "+matName)
                matFileString = matTag.firstChild.nodeValue
                print("material file String: "+matFileString)
                #get file location for material file
                placeHolder = "${Material Database}/"
                folder = stringFilePath_m6 + os.sep
                
                matFileLocation = matFileString.replace( placeHolder , folder )
                print("Material file location: "+matFileLocation)
                #print("Identified and submitted file string is %s." % matFileLocation )
                
                #read data set and create material object with specific name
                newMaterial = Material()
                
                if (newMaterial.read_DelphinDataSet(matFileLocation) == True):
                    
                    print("Material %s identified." % matName)
                    newMaterial.set_matName(matName)
                    materialList.append(newMaterial)
                else:
                    
                    print("One or several materials in delivered construction file %s are invalid." % stringFilePathName_d6p)
                    return False
                
            #now get layer thicknesses
            allSteps = xml_fileTreeObject.getElementsByTagName("XSteps")[0].firstChild.nodeValue
            
            for step in allSteps.split():
                layerThickList.append(step)
                #print("Layer thickness %s identified." % step)

            #read layer order and create layers for this construction
            layerCounter = 0
            
            for assTag in xml_fileTreeObject.getElementsByTagName("Assignment"):
                
                if ( assTag.getAttribute("type") == "Material" ):
                    
                    tempMatName = assTag.getElementsByTagName("Reference")[0].getAttribute("displayName")
                    print("Referenced material name %s identified." % tempMatName)
                    
                    for matObject in materialList:
                        
                        print("checked name for material: %s" % matObject.return_name() )
                        
                        if (matObject.return_name() == tempMatName):
                            #matching material, create layer
                            self.add_layer( matObject, layerThickList[ layerCounter ], layerCounter )
                            #print("Matching material %s identified. Layer created." % matObject.return_name() )
                            layerCounter = layerCounter + 1
                            print layerCounter
                            
                        else:
                            
                            print("Material layer was not added: ")
                else:
                    
                    print("Delphin project file parsing of file %s failed. Invalid layer definiton." % stringFilePathName_d6p)
                    return False
            
            return True
Esempio n. 3
0
    def return_modifiedZoneObject(self, currentZoneObject, key ):

        #check initialization
        if (self.__xmlFileInitialized == False):
            print("SimulationMatrix:ReturnModifiedZoneObject: simulation matrix xml file must be initialized correctly before calling this function.")
        
        #copy submitted zone object
        newZoneObject = currentZoneObject

        #get list of variable reference ids
        varRefList = []
        for entry in self.__combObjectList:
            if(key == entry.return_ID()):
                varRefList = list( entry.return_VariableAssignmentDict().keys() )

        #check database directories and get name list of available entries
        
        
        #loop over variable id list and go through xml structure to find the referenced element
        for varRef in varRefList:

            #go through xml structure to find referenced id in different types of variable variants
            
            #check if this is a construction modification reference
            for conTypeNode in self.__file_xml_tree.getElementsByTagName("ConstructionType"):
                
                #get only last part of source identification
                conSource = ""
                conSource_long = conTypeNode.getAttribute("source")
                if(os.sep in conSource_long): conSource = conSource_long.split(os.sep)[-1]
                elif("/" in conSource_long): conSource = conSource_long.split("/")[-1]
                elif("\\" in conSource_long): conSource = conSource_long.split("\\")[-1]
                else: conSource = conSource_long
                
                #go through const variants to compare reference id with defined ids
                for conTypeVarNode in conTypeNode.getElementsByTagName("ConstructionTypeVariant"):
                    conTypeVarId = conTypeVarNode.getAttribute("id")
                    if( varRef == conTypeVarId ):
                        
                        #go through all constructions of this file to get the matching source attribute(s)
                        for conObject in newZoneObject.return_ConsList():
                            conSourceRef = ""
                            conSourceRef_long = conObject.return_source()
                            if(os.sep in conSourceRef_long): conSourceRef = conSourceRef_long.split(os.sep)[-1]
                            elif("/" in conSourceRef_long): conSourceRef = conSourceRef_long.split("/")[-1]
                            elif("\\" in conSourceRef_long): conSourceRef = conSourceRef_long.split("\\")[-1]
                            else: conSourceRef = conSourceRef_long

                            #check if both ids are equal and modify constructions due to xml specifications
                            if ( conSourceRef == conSource ):

                                #list which keeps all new layers
                                newLayers_List = []

                                #create new layer structure for this construction
                                for layNode in conTypeVarNode.getElementsByTagName("Layer"):

                                    #get layer thickness
                                    d = float( layNode.getAttribute("thickness"))

                                    #get material path and extract file name 
                                    matFilePath = layNode.firstChild.nodeValue
                                    matFileName = ""
                                    if(os.sep in matFilePath): matFileName = matFilePath.split(os.sep)[-1]
                                    elif("/" in matFilePath): matFileName = matFilePath.split("/")[-1]
                                    elif("\\" in matFilePath): matFileName = matFilePath.split("\\")[-1]
                                    else: matFileName = matFilePath
                                    
                                    #check if this material is included in target directory (Materials)
                                    if( matFileName not in os.listdir(self.__matDir_T)):
                                        print("SimulationMatrix: ReturnModifiedZoneObject: Material %s (defined in SimMa) is not included in target directory." % matFileName)
                                        #call ResCon here
    
                                    #parse material properties if material is available
                                    matFilePath = self.__matDir_T + os.sep + matFileName
                                    matObject = Material()
                                    if( matObject.read_DelphinDataSet(matFilePath) == False):
                                        matObject.assign_defaultData()
                                        print("SimulationMatrix: ReturnModifiedZoneObject: Material %s can't be parsed. Default data is assumed." % matFileName)

                                    #create new layer from this and keep it
                                    newLayer = Layer( matObject, d)
                                    newLayers_List.append(newLayer)

                                #remove all layers from current construction and submit new layer structure
                                conObject.remove_allLayers()
                                for layerObject in newLayers_List:
                                    conObject.add_layer( layerObject.mat , layerObject.d, 0 )


            #check if this is a construction modification reference
            for winTypeNode in self.__file_xml_tree.getElementsByTagName("WindowType"):
                
                #get only last part of source identification
                winSource = ""
                winSource_long = winTypeNode.getAttribute("source")
                if(os.sep in winSource_long): winSource = winSource_long.split(os.sep)[-1]
                elif("/" in winSource_long): winSource = winSource_long.split("/")[-1]
                elif("\\" in winSource_long): winSource = winSource_long.split("\\")[-1]
                else: winSource = winSource_long
                
                #go through const variants to compare reference id with defined ids
                for winTypeVarNode in winTypeNode.getElementsByTagName("WindowTypeVariant"):
                    winTypeVarId = winTypeVarNode.getAttribute("id")
                    if( varRef == winTypeVarId ):
                        #go through all windows of this file to get the matching source attribute(s)
                        for conObject in newZoneObject.return_ConsList():
                            winSourceRef = ""
                            if (conObject.return_numberOfEmbObjects() > 0):
                                #get id 
                                winSourceRef_long = conObject.return_embObject(0).source
                                #get only file name from id if possible
                                if(os.sep in winSourceRef_long): winSourceRef = winSourceRef_long.split(os.sep)[-1]
                                elif("/" in winSourceRef_long): winSourceRef = winSourceRef_long.split("/")[-1]
                                elif("\\" in winSourceRef_long): winSourceRef = winSourceRef_long.split("\\")[-1]
                                else: winSourceRef = winSourceRef_long

                                #check if both ids are equal and modify window due to xml specifications
                                if ( winSourceRef == winSource ):
                                    
                                    #get copy of existing embedded object and modify all specified values
                                    newEmbeddedObject = conObject.return_embObject(0)
                                    
                                    if( len(winTypeVarNode.getElementsByTagName("GlassFraction")) > 0):
                                        #get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.fGlass = (1.0, float(winTypeVarNode.getElementsByTagName("GlassFraction")[0].firstChild.nodeValue))
                                    if( len(winTypeVarNode.getElementsByTagName("FrameFraction")) > 0):
                                        #get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.fGlass = (1.0 - float(winTypeVarNode.getElementsByTagName("FrameFraction")[0].firstChild.nodeValue))
                                    if( len(winTypeVarNode.getElementsByTagName("ThermalTransmittance")) > 0):
                                        #get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.uValue = float(winTypeVarNode.getElementsByTagName("ThermalTransmittance")[0].firstChild.nodeValue)
                                    if( len(winTypeVarNode.getElementsByTagName("SolarHeatGainCoefficient")) > 0):
                                        #get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.shgc = float(winTypeVarNode.getElementsByTagName("SolarHeatGainCoefficient")[0].firstChild.nodeValue)

                                    #submit embedded object to current construction
                                    conObject.replace_embObject(newEmbeddedObject)
                            #else:
                                #print("SimulationMatrix: ReturnModifiedZoneObject: Requested construction object does not include a window object which can be modified.")


        return newZoneObject
Esempio n. 4
0
    def return_modifiedZoneObject(self, currentZoneObject, key):

        # check initialization
        if (self.__xmlFileInitialized == False):

            print(
                "SimulationMatrix:ReturnModifiedZoneObject: simulation matrix xml file must be initialized correctly before calling this function."
            )

        # copy submitted zone object
        newZoneObject = copy.deepcopy(currentZoneObject)

        # get list of variable reference ids
        varRefList = []

        for entry in self.__combObjectList:

            if (key == entry.return_ID()):

                varRefList = list(entry.return_VariableAssignmentDict().keys())

        # check database directories and get name list of available entries

        # loop over variable id list and go through xml structure to find the referenced element
        for varRef in varRefList:
            # go through xml structure to find referenced id in different types of variable variants
            # check if this is a construction modification reference
            for conTypeNode in self.__file_xml_tree.getElementsByTagName(
                    "ConstructionType"):
                # get only last part of source identification
                conSource = ""
                conSource = conTypeNode.getAttribute("source")
                print("Current source of construction: " + conSource)

                # go through const variants to compare reference id with defined ids
                # inner loop through one <ConstructionType>
                for conTypeVarNode in conTypeNode.getElementsByTagName(
                        "ConstructionTypeVariant"):

                    conTypeVarId = conTypeVarNode.getAttribute("id")

                    if (varRef == conTypeVarId):
                        # go through all constructions of this file to get the matching source attribute(s)
                        print(
                            "Positive matching of construction type variant from simulation matrix."
                        )

                        for conObject in newZoneObject.return_ConsList():

                            conSourceRef = ""
                            conSourceRef = conObject.return_source()
                            print("source from zone object:" + conSourceRef)

                            # check if both ids are equal and modify constructions due to xml specifications
                            if (conSourceRef == conSource):

                                print(
                                    "matching of conSourceRef and conSource:" +
                                    conSourceRef)
                                # list which keeps all new layers
                                newLayers_List = []
                                # create new layer structure for this construction
                                for layNode in conTypeVarNode.getElementsByTagName(
                                        "Layer"):
                                    # get layer thickness
                                    d = float(
                                        layNode.getAttribute("thickness"))

                                    matFileName = layNode.firstChild.nodeValue
                                    # check if this material is included in target directory (Materials)
                                    if (matFileName not in os.listdir(
                                            self.__matDir_T)):

                                        self.__call_ResCon(
                                            "Material", matFileName)
                                        # open combinations.csv and get the new path of the material file
                                        # it is the second argument in a data row
                                        # first argument is the source which can be used to compare
                                        try:
                                            combinations = os.path.join(
                                                os.getcwd(),
                                                "combinations.csv")
                                            fileObject = open(
                                                combinations, "r")

                                        except Exception as e:

                                            print(
                                                "Error while parsing material file %s."
                                                % combinations)

                                            return False

                                        else:

                                            for line in fileObject.readlines():

                                                pair = line.split(",")
                                                source = pair[0]
                                                destination = pair[1]

                                                #get value string and remove white spaces
                                                if (matFileName == source):

                                                    print(
                                                        "Material file name matches: "
                                                        + source)
                                                    pathOfNewMaterial = destination.split(
                                                        os.sep)
                                                    matFileName = pathOfNewMaterial[
                                                        len(pathOfNewMaterial)
                                                        - 1]
                                                    matFileName = matFileName.replace(
                                                        "\n", "")
                                                    print("mat file name: " +
                                                          matFileName)
                                                #end if'
                                            #end for
                                    else:
                                        print(
                                            "Material was found in material database."
                                        )

                                    # parse material properties if material is available
                                    matFilePath = os.path.join(
                                        self.__matDir_T, matFileName)
                                    matObject = Material()

                                    if (matObject.read_DelphinDataSet(
                                            matFilePath) == False):
                                        matObject.assign_defaultData()
                                        print(
                                            "SimulationMatrix: ReturnModifiedZoneObject: Material %s can't be parsed. Default data is assumed."
                                            % matFileName)
                                    # create new layer from this and keep it
                                    newLayer = Layer(matObject, d)
                                    newLayers_List.append(newLayer)
                                    print(len(newLayers_List))
                                    print(
                                        "Current number of layers of one construction element"
                                    )

                                # remove all layers from current construction and submit new layer structure
                                conObject.remove_allLayers()

                                for layerObject in newLayers_List:

                                    conObject.add_layer(
                                        layerObject.mat, layerObject.d, 0)
                                #end for
                    else:

                        print(
                            "no construction influences for current construction in Simulationmatrix"
                        )
                #end for
            # check if this is a construction modification reference
            for winTypeNode in self.__file_xml_tree.getElementsByTagName(
                    "WindowType"):

                # get only last part of source identification
                winSource = ""
                winSource_long = winTypeNode.getAttribute("source")
                if (os.sep in winSource_long):
                    winSource = winSource_long.split(os.sep)[-1]
                elif ("/" in winSource_long):
                    winSource = winSource_long.split("/")[-1]
                elif ("\\" in winSource_long):
                    winSource = winSource_long.split("\\")[-1]
                else:
                    winSource = winSource_long

                # go through const variants to compare reference id with defined ids
                for winTypeVarNode in winTypeNode.getElementsByTagName(
                        "WindowTypeVariant"):

                    winTypeVarId = winTypeVarNode.getAttribute("id")

                    if (varRef == winTypeVarId):
                        # go through all windows of this file to get the matching source attribute(s)
                        for conObject in newZoneObject.return_ConsList():

                            winSourceRef = ""

                            if (conObject.return_numberOfEmbObjects() > 0):
                                # get id
                                winSourceRef_long = conObject.return_embObject(
                                    0).source
                                # get only file name from id if possible
                                if (os.sep in winSourceRef_long):
                                    winSourceRef = winSourceRef_long.split(
                                        os.sep)[-1]
                                elif ("/" in winSourceRef_long):
                                    winSourceRef = winSourceRef_long.split(
                                        "/")[-1]
                                elif ("\\" in winSourceRef_long):
                                    winSourceRef = winSourceRef_long.split(
                                        "\\")[-1]
                                else:
                                    winSourceRef = winSourceRef_long

                                # check if both ids are equal and modify window due to xml specifications
                                if (winSourceRef == winSource):

                                    # get copy of existing embedded object and modify all specified values
                                    newEmbeddedObject = conObject.return_embObject(
                                        0)

                                    if (len(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "GlassFraction")) > 0):
                                        # get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.fGlass = (
                                            1.0 - float(
                                                winTypeVarNode.
                                                getElementsByTagName(
                                                    "GlassFraction")
                                                [0].firstChild.nodeValue))
                                    if (len(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "FrameFraction")) > 0):
                                        # get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.fGlass = (
                                            1.0 - float(
                                                winTypeVarNode.
                                                getElementsByTagName(
                                                    "FrameFraction")
                                                [0].firstChild.nodeValue))
                                    if (len(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "ThermalTransmittance")) > 0):
                                        # get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.uValue = float(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "ThermalTransmittance")
                                            [0].firstChild.nodeValue)
                                    if (len(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "SolarHeatGainCoefficient")) >
                                            0):
                                        # get Value and submit it to construction - embedded object properties
                                        newEmbeddedObject.shgc = float(
                                            winTypeVarNode.
                                            getElementsByTagName(
                                                "SolarHeatGainCoefficient")
                                            [0].firstChild.nodeValue)

                                    # submit embedded object to current construction
                                    conObject.replace_embObject(
                                        newEmbeddedObject)
                            # else:

            for weatherDataSetType in self.__file_xml_tree.getElementsByTagName(
                    "WeatherDataSetVariant"):

                currentDataSetId = weatherDataSetType.getAttribute("id")

                if (varRef == currentDataSetId):

                    if (weatherDataSetType.getAttribute("type").__contains__(
                            "CCD")):

                        currentWeatherDataSetSource = weatherDataSetType.firstChild.nodeValue
                        currentClimateSource = os.path.join(
                            self.__cliDir_T, "ISES_climate")
                        currentClimateSourceTemporary = os.path.join(
                            self.__cliDir_T, "ISES_climate_temporary")
                        currentClimateVariante = os.path.join(
                            self.__binDir, "Therakles", "data", "DB_climate",
                            "ISES_climate_" + key)
                        currentClimateVarianteWindows = os.path.join(
                            self.__binDir, "Therakles", "resources", "IBK",
                            "DB_Climate", "ISES_climate_" + key)
                        #rename the current ISES_climate folder because the call of ResCon will replace the current folder.
                        os.rename(currentClimateSource,
                                  currentClimateSourceTemporary)
                        self.__call_ResCon("Climate",
                                           currentWeatherDataSetSource)
                        shutil.copytree(currentClimateSource,
                                        currentClimateVariante)
                        shutil.move(currentClimateSource,
                                    currentClimateVarianteWindows)
                        newZoneObject.add_ClimateLocation("ISES_climate_" +
                                                          key)

                        os.rename(currentClimateSourceTemporary,
                                  currentClimateSource)
                    else:

                        print(
                            "Current data set format for climate information is not supported, yet."
                        )

                        # print("SimulationMatrix: ReturnModifiedZoneObject: Requested construction object does not include a window object which can be modified.")
        return newZoneObject