def assign_defaultData(self): #assign default data newMaterial = Material() newMaterial.assign_defaultData() newThickness = 0.2 #create and append layer to member list newLayer = Layer( newMaterial, newThickness ) self.__listOfLayers = [] self.__listOfLayers.append( newLayer )
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
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