def calcSkyVector(skyDescr, epwFile=None, skyFile=None, reuse=True, skyVectorParam=None): assert epwFile or skyFile,\ 'Either an epwFile or a skyFile need to be provided for the skyVector to' \ 'be calculated.' if epwFile and os.path.exists(epwFile): epwName = os.path.split(epwFile)[1] skyMtxName = os.path.splitext(epwName)[0] + '%s.smx' % skyDescr weaName = os.path.splitext(epwFile)[0] + '.wea' if os.path.exists(skyMtxName) and reuse: return skyMtxName weaFile = Epw2wea(epwFile=epwFile, outputWeaFile=weaName) weaFile.execute() if skyVectorParam: assert isinstance(skyVectorParam, GendaymtxParameters),\ 'The input for skyVectorParam must be an instance of GendaymtxParameters.' gendayParam = skyVectorParam else: gendayParam = GendaymtxParameters() gendayParam.skyDensity = skyDescr genday = Gendaymtx(weaFile=weaName, outputName=skyMtxName) genday.gendaymtxParameters = skyVectorParam genday.execute() return skyMtxName elif skyFile and os.path.exists(skyFile): skyMtxName = os.path.splitext(skyFile)[0] + '%s.smx' % skyDescr if os.path.exists(skyMtxName) and reuse: return skyMtxName genskv = Genskyvec() genskv.inputSkyFile = skyFile genskv.skySubdivision = skyDescr genskv.outputFile = skyMtxName genskv.execute() return skyMtxName else: raise Exception( 'The input path for the skyFile or epwFile are not valid.')
def run3phase(phasesToCalculate={'v': True, 't': True, 'd': True, 's': True}, calculationType='annual', epwFile=None, tmatrixFile=None): if phasesToCalculate['v']: # Step1: Create the view matrix. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = True rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientBounces = 10 rfluxPara.ambientDivisions = 65536 rfluxPara.limitWeight = 1E-5 # step 1.1 Invert glazing surface with xform so that it faces inwards xfrPara = XformParameters() xfrPara.invertSurfaces = True xfr = Xform() xfr.xformParameters = xfrPara xfr.radFile = 'glazing.rad' xfr.outputFile = 'glazingI.rad' xfr.execute() rflux = Rfluxmtx() rflux.sender = '-' # This needs to be automated based on the normal of each window. # Klems full basis sampling and the window faces +Y recCtrlPar = rflux.ControlParameters(hemiType='kf', hemiUpDirection='+Z') rflux.receiverFile = rflux.addControlParameters('glazingI.rad', {'Exterior_Window': recCtrlPar}) rflux.rfluxmtxParameters = rfluxPara rflux.pointsFile = 'indoor_points.pts' rflux.outputMatrix = r'temp/vmatrix.vmx' rflux.radFiles = ['room.mat', 'room.rad'] rflux.execute() vMatrix = r'temp/vmatrix.vmx' # Step2: Assign T matrix from precalculated XML files. tMatrix = tmatrixFile or r'xmls/clear.xml' if phasesToCalculate['d']: # Step3: Create D matrix. rfluxPara = RfluxmtxParameters() rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientDivisions = 1024 rfluxPara.ambientBounces = 2 rfluxPara.limitWeight = 0.0000001 rflux2 = Rfluxmtx() rflux2.samplingRaysCount = 1000 rflux2.sender = 'glazingI_m.rad' skyFile = rflux2.defaultSkyGround(r'temp/rfluxSky.rad', skyType='r1') rflux2.receiverFile = skyFile rflux2.rfluxmtxParameters = rfluxPara rflux2.radFiles = [r"room.mat", r"room.rad"] rflux2.outputMatrix = r"temp/dmatrix.dmx" rflux2.execute() dMatrix = r"temp/dmatrix.dmx" # Step4a: Create the sky vector. # Step4a.1: Create a sky defintion # Step s: Creating the sky matrix if phasesToCalculate['s']: if calculationType == 'annual': weaFile = Epw2wea(epwFile=epwFile or 'test.epw', outputWeaFile=r'temp/test.wea') weaFile.execute() gendayParam = GendaymtxParameters() gendayParam.skyDensity = 1 genday = Gendaymtx(weaFile=r'temp/test.wea', outputName=r'temp/day.smx') genday.gendaymtxParameters = gendayParam genday.execute() skyVector = r'temp/day.smx' else: gensk = Gensky() gensk.monthDayHour = (11, 11, 11) gensk.outputFile = 'temp/sky.rad' # gensk.execute() genskv = Genskyvec() genskv.inputSkyFile = r'temp/sky.rad' genskv.outputFile = r'temp/sky.vec' genskv.skySubdivision = 1 genskv.execute() skyVector = r'temp/sky.vec' else: skyVector = r'temp/sky.vec' # Step5: Generate results dct = Dctimestep() dct.tmatrixFile = tMatrix dct.vmatrixSpec = vMatrix dct.dmatrixFile = dMatrix dct.skyVectorFile = skyVector dct.outputFileName = r'temp/results3p.tmp' dct.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[r'temp/results3p.tmp'], outputFile=r'temp/illuminance3p.ill') mtx2.rmtxopParameters = mtx2Param mtx2.execute() return 'temp/illuminance3p.ill'
def improvedDCcalc(epwFile, materialFile, geometryFiles, pointsFile, folderForCalculations, outputIllFilePath, reinhartPatches=1, calcDict={ 'skyVectors': True, 'DirectDCCoeff': True, 'DCCoeff': True, 'DirectSun': True }): """ Args: epwFile: Epw file path. materialFile: Path for a single material file. geometryFiles: One or more geometry files. pointsFile: Path for poitns file folderForCalculations: Folder for storing intermediate files. outputIllFilePath: reinhartPatches: Default is 1. calcDict: This is useful for selectively running different parts of the simulation. Returns: """ #a sad logging hack statusMsg = lambda msg: "\n%s:%s\n%s\n" % (time.ctime(), msg, "*~" * 25) weaFilePath = os.path.join( folderForCalculations, os.path.splitext(os.path.split(epwFile)[1])[0] + '.wea') weaFile = Epw2wea(epwFile=epwFile, outputWeaFile=weaFilePath) weaFile.execute() #Calculate complete sky matrix. skyMatrix = os.path.join(folderForCalculations, 'skyMatrix.mtx') gendayParam = GendaymtxParameters() gendayParam.skyDensity = reinhartPatches genday = Gendaymtx(weaFile=weaFilePath, outputName=skyMatrix) genday.gendaymtxParameters = gendayParam if calcDict['skyVectors']: print(genday.toRadString()) genday.execute() #Calculate direct only matrix. skyMatrixDirect = os.path.join(folderForCalculations, 'skyMatrixDirect.mtx') gendayParam = GendaymtxParameters() gendayParam.skyDensity = reinhartPatches gendayParam.onlyDirect = True genday = Gendaymtx(weaFile=weaFilePath, outputName=skyMatrixDirect) genday.gendaymtxParameters = gendayParam if calcDict['skyVectors']: print(genday.toRadString()) genday.execute() skyDomeFile = os.path.join(folderForCalculations, 'rfluxSky.rad') dcCoeffMatrix = os.path.join(folderForCalculations, 'dc.mtx') dcCoeffMatrixDirect = os.path.join(folderForCalculations, 'dcDirect.mtx') sceneData = [materialFile] #Append if single, extend if multiple if isinstance(geometryFiles, basestring): sceneData.append(geometryFiles) elif isinstance(geometryFiles, (tuple, list)): sceneData.extend(geometryFiles) # Step2: Generate daylight coefficients for normal sky-matrix using rfluxmtx. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = True rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientDivisions = 20000 rfluxPara.ambientBounces = 5 rfluxPara.limitWeight = 1E-7 rfluxPara.ambientResolution = 10000 rflux = Rfluxmtx() rflux.sender = '-' skyFile = rflux.defaultSkyGround(skyDomeFile, skyType='r%s' % reinhartPatches) rflux.receiverFile = skyDomeFile rflux.rfluxmtxParameters = rfluxPara rflux.radFiles = sceneData rflux.samplingRaysCount = 1 rflux.pointsFile = pointsFile rflux.outputMatrix = dcCoeffMatrix if calcDict['DCCoeff']: rflux.execute() tempIll = os.path.join(folderForCalculations, 'temp.ill') ill = os.path.join(folderForCalculations, 'Illuminance.ill') dct = Dctimestep() dct.daylightCoeffSpec = dcCoeffMatrix dct.skyVectorFile = skyMatrix dct.outputFile = tempIll if calcDict['DCCoeff']: dct.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[tempIll], outputFile=ill) mtx2.rmtxopParameters = mtx2Param if calcDict['DCCoeff']: mtx2.execute() # Step3: Generate direct daylight coefficients for normal sky-matrix using rfluxmtx. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = True rfluxPara.ambientAccuracy = 0.01 rfluxPara.ambientDivisions = 20000 rfluxPara.ambientBounces = 1 rfluxPara.limitWeight = 1E-7 rfluxPara.ambientResolution = 10000 rflux = Rfluxmtx() rflux.sender = '-' skyFile = rflux.defaultSkyGround(skyDomeFile, skyType='r%s' % reinhartPatches) rflux.receiverFile = skyDomeFile rflux.rfluxmtxParameters = rfluxPara rflux.radFiles = sceneData rflux.samplingRaysCount = 1 rflux.pointsFile = pointsFile rflux.outputMatrix = dcCoeffMatrixDirect if calcDict['DirectDCCoeff']: rflux.execute() tempDirectIll = os.path.join(folderForCalculations, 'tempDirect.ill') illDirect = os.path.join(folderForCalculations, 'IlluminanceDirect.ill') dct = Dctimestep() dct.daylightCoeffSpec = dcCoeffMatrixDirect dct.skyVectorFile = skyMatrixDirect dct.outputFile = tempDirectIll if calcDict['DCCoeff']: dct.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[tempDirectIll], outputFile=illDirect) mtx2.rmtxopParameters = mtx2Param if calcDict['DirectDCCoeff']: mtx2.execute() solarDiscPath = os.path.join(folderForCalculations, 'solarDiscs.rad') sunListPath = os.path.join(folderForCalculations, 'sunList.txt') sunMatrixPath = os.path.join(folderForCalculations, 'sunMatrix.mtx') #Calculate direct only ill files. directSunIll = os.path.join(folderForCalculations, 'directSunIll.ill') if calcDict['DirectSun']: sunOnlyIll = calcDirectIlluminance( epwFile=epwFile, solarDiscPath=solarDiscPath, sunListPath=sunListPath, sunMatrixPath=sunMatrixPath, materialFile=materialFile, geometryFiles=geometryFiles, pointsFile=pointsFile, folderForCalculations=folderForCalculations, outputIllFilePath=directSunIll) #Instantiate matrices for subtraction and addition. finalMatrix = Rmtxop() #std. dc matrix. dcMatrix = RmtxopMatrix() dcMatrix.matrixFile = ill #direct dc matrix. -1 indicates that this one is being subtracted from dc matrix. dcDirectMatrix = RmtxopMatrix() dcDirectMatrix.matrixFile = illDirect dcDirectMatrix.scalarFactors = [-1] #Sun coefficient matrix. sunCoeffMatrix = RmtxopMatrix() sunCoeffMatrix.matrixFile = directSunIll #combine the matrices together. Sequence is extremely important finalMatrix.rmtxopMatrices = [dcMatrix, dcDirectMatrix, sunCoeffMatrix] finalMatrix.outputFile = outputIllFilePath #Done! finalMatrix.execute() return outputIllFilePath
def improvedDCcalc(epwFile, materialFile, geometryFiles, pointsFile, folderForCalculations, outputIllFilePath, glazingGeometry=None, reinhartPatches=1, ambBounces=5, ambDiv=5000, limitWt=0.0002, calcDict={ 'skyVectors': True, 'DirectDCCoeff': True, 'DCCoeff': True, 'DirectSun': True }, cleanUpTempFiles=True): """ Args: epwFile: Epw file path. materialFile: Path for a single material file. geometryFiles: One or more geometry files. pointsFile: Path for poitns file folderForCalculations: Folder for storing intermediate files. outputIllFilePath: reinhartPatches: Default is 1. calcDict: This is useful for selectively running different parts of the simulation. ambBounces: Ambient bounces. Defaults to 5 ambDiv: Ambient divisions. Defaults to 5000. limitWt: Limit weight. Defaults to 0.0002 cleanUpTempFiles: Delete all the temporary files that were created during the calculations. Returns: The path of the illuminance file generated through the calculations. """ # a sad logging hack statusMsg = lambda msg: "\n%s:%s\n%s\n" % (time.ctime(), msg, "*~" * 25) blackMaterial = "void plastic black 0 0 5 0 0 0 0 0" if limitWt > (1 / ambDiv): warnings.warn( "The value for limitWt(%s) should be set to a value equal to or " "less (%s) which is 1/ambDiv(%s)" % (limitWt, 1 / ambDiv, ambDiv)) # crate a tempfolder inside the folderForCalculations. tmpFolder = os.path.join(folderForCalculations, 'tmp') if not os.path.exists(tmpFolder): os.mkdir(tmpFolder) weaFilePath = os.path.join( tmpFolder, os.path.splitext(os.path.split(epwFile)[1])[0] + '.wea') weaFile = Epw2wea(epwFile=epwFile, outputWeaFile=weaFilePath) weaFile.execute() # Calculate complete sky matrix. skyMatrix = os.path.join(tmpFolder, 'skyMatrix.mtx') gendayParam = GendaymtxParameters() gendayParam.skyDensity = reinhartPatches genday = Gendaymtx(weaFile=weaFilePath, outputName=skyMatrix) genday.gendaymtxParameters = gendayParam if calcDict['skyVectors']: print(genday.toRadString()) genday.execute() # Calculate direct only matrix. skyMatrixDirect = os.path.join(tmpFolder, 'skyMatrixDirect.mtx') gendayParam = GendaymtxParameters() gendayParam.skyDensity = reinhartPatches gendayParam.onlyDirect = True genday = Gendaymtx(weaFile=weaFilePath, outputName=skyMatrixDirect) genday.gendaymtxParameters = gendayParam if calcDict['skyVectors']: print(genday.toRadString()) genday.execute() skyDomeFile = os.path.join(tmpFolder, 'rfluxSky.rad') dcCoeffMatrix = os.path.join(tmpFolder, 'dc.mtx') dcCoeffMatrixDirect = os.path.join(tmpFolder, 'dcDirect.mtx') blackMaterial = os.path.join(tmpFolder, 'black.mat') with open(blackMaterial, 'w') as blackMat: blackMat.write("void plastic black 0 0 5 0 0 0 0 0") sceneData = [materialFile] sceneDataBlack = [blackMaterial] geometryData = [] # Append if single, extend if multiple if isinstance(geometryFiles, basestring): geometryData.append(geometryFiles) elif isinstance(geometryFiles, (tuple, list)): geometryData.extend(geometryFiles) sceneData = sceneData + geometryData xfrPara = XformParameters() xfrPara.modReplace = 'black' # Note: Xform has this thing it only works well if the paths are absolute. blackGeometry = os.path.join(tmpFolder, 'blackGeometry.rad') xfr = Xform() xfr.xformParameters = xfrPara xfr.radFile = geometryData xfr.outputFile = blackGeometry xfr.execute() # Material file added in the end with the assumption that the material props for the # glazing are defined in the material file. As Radiance parses scene data in a # strictly linear fashion, even if the material for glazing is defined inside # the glazing geometry, it will still be fine. sceneDataBlack = sceneDataBlack + [blackGeometry] + [materialFile] if isinstance(glazingGeometry, basestring): sceneData.append(glazingGeometry) sceneDataBlack.append(glazingGeometry) elif isinstance(glazingGeometry, (tuple, list)): sceneData.extend(glazingGeometry) sceneDataBlack.extend(glazingGeometry) # Step2: Generate daylight coefficients for normal sky-matrix using rfluxmtx. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = True rfluxPara.ambientDivisions = ambDiv rfluxPara.ambientBounces = ambBounces rfluxPara.limitWeight = limitWt rflux = Rfluxmtx() rflux.sender = '-' skyFile = rflux.defaultSkyGround(skyDomeFile, skyType='r%s' % reinhartPatches) rflux.receiverFile = skyDomeFile rflux.rfluxmtxParameters = rfluxPara rflux.radFiles = sceneData rflux.samplingRaysCount = 1 rflux.pointsFile = pointsFile rflux.outputMatrix = dcCoeffMatrix if calcDict['DCCoeff']: print(rflux.toRadString()) rflux.execute() tempIll = os.path.join(tmpFolder, 'temp.ill') ill = os.path.join(tmpFolder, 'Illuminance.ill') dct = Dctimestep() dct.daylightCoeffSpec = dcCoeffMatrix dct.skyVectorFile = skyMatrix dct.outputFile = tempIll if calcDict['DCCoeff']: print(dct.toRadString()) dct.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[tempIll], outputFile=ill) mtx2.rmtxopParameters = mtx2Param if calcDict['DCCoeff']: mtx2.execute() # Step3: Generate direct daylight coefficients for normal sky-matrix using rfluxmtx. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = True rfluxPara.ambientDivisions = ambDiv rfluxPara.ambientBounces = 1 rfluxPara.limitWeight = limitWt rflux = Rfluxmtx() rflux.sender = '-' skyFile = rflux.defaultSkyGround(skyDomeFile, skyType='r%s' % reinhartPatches) rflux.receiverFile = skyDomeFile rflux.rfluxmtxParameters = rfluxPara rflux.radFiles = sceneDataBlack rflux.samplingRaysCount = 1 rflux.pointsFile = pointsFile rflux.outputMatrix = dcCoeffMatrixDirect if calcDict['DirectDCCoeff']: rflux.execute() tempDirectIll = os.path.join(tmpFolder, 'tempDirect.ill') illDirect = os.path.join(tmpFolder, 'IlluminanceDirect.ill') dct = Dctimestep() dct.daylightCoeffSpec = dcCoeffMatrixDirect dct.skyVectorFile = skyMatrixDirect dct.outputFile = tempDirectIll if calcDict['DCCoeff']: dct.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[tempDirectIll], outputFile=illDirect) mtx2.rmtxopParameters = mtx2Param if calcDict['DirectDCCoeff']: mtx2.execute() solarDiscPath = os.path.join(tmpFolder, 'solarDiscs.rad') sunListPath = os.path.join(tmpFolder, 'sunList.txt') sunMatrixPath = os.path.join(tmpFolder, 'sunMatrix.mtx') # Calculate direct only ill files. directSunIll = os.path.join(tmpFolder, 'directSunIll.ill') if calcDict['DirectSun']: calcDirectIlluminance(epwFile=epwFile, solarDiscPath=solarDiscPath, sunListPath=sunListPath, sunMatrixPath=sunMatrixPath, materialFile=blackMaterial, geometryFiles=sceneDataBlack, pointsFile=pointsFile, folderForCalculations=folderForCalculations, outputIllFilePath=directSunIll) # Instantiate matrices for subtraction and addition. finalMatrix = Rmtxop() # std. dc matrix. dcMatrix = RmtxopMatrix() dcMatrix.matrixFile = ill # direct dc matrix. -1 indicates that this one is being subtracted from dc matrix. dcDirectMatrix = RmtxopMatrix() dcDirectMatrix.matrixFile = illDirect dcDirectMatrix.scalarFactors = [-1] # Sun coefficient matrix. sunCoeffMatrix = RmtxopMatrix() sunCoeffMatrix.matrixFile = directSunIll # combine the matrices together. Sequence is extremely important finalMatrix.rmtxopMatrices = [dcMatrix, dcDirectMatrix, sunCoeffMatrix] finalMatrix.outputFile = outputIllFilePath # Done! finalMatrix.execute() return outputIllFilePath
def runDc(phasesToCalculate={ 'dc': True, 's': True }, calculationType='single', epwFile=None, hdrResultsFileName=None, timeStamp=None, skyDensity=1): if phasesToCalculate['dc']: # Step1: Create the view matrix. vwrParaDim = VwraysParameters() vwrParaDim.calcImageDim = True vwrParaDim.xResolution = 800 vwrParaDim.yResolution = 800 vwrDim = Vwrays() vwrDim.vwraysParameters = vwrParaDim vwrDim.viewFile = 'viewSouth1.vf' vwrDim.outputFile = r'temp/viewSouthDimensions.txt' vwrDim.execute() vwrParaSamp = VwraysParameters() vwrParaSamp.xResolution = 800 vwrParaSamp.yResolution = 800 vwrParaSamp.samplingRaysCount = 9 vwrParaSamp.samplingRaysCount = 3 vwrParaSamp.jitter = 0.7 vwrSamp = Vwrays() vwrSamp.vwraysParameters = vwrParaSamp vwrSamp.viewFile = 'viewSouth1.vf' vwrSamp.outputFile = r'temp/viewSouthRays.txt' vwrSamp.outputDataFormat = 'f' vwrSamp.execute() rfluxPara = RfluxmtxParameters() rfluxPara.ambientAccuracy = 0.1 # rfluxPara.ambientBounces = 10 # using this for a quicker run rfluxPara.ambientBounces = 5 # rfluxPara.ambientDivisions = 65536 # using this for a quicker run rfluxPara.ambientDivisions = 2000 # rfluxPara.limitWeight = 1E-5 rfluxPara.limitWeight = 1E-2 rflux = Rfluxmtx() rflux.sender = '-' groundFileFormat = 'temp/viewSouth%s.hdr' % (1 + 144 * (skyDensity**2)) # Klems full basis sampling and the window faces +Y rflux.receiverFile = rflux.defaultSkyGround( r'temp/rfluxSky.rad', skyType='r1', groundFileFormat=groundFileFormat, skyFileFormat=r'temp/%03d.hdr') rflux.outputDataFormat = 'fc' rflux.verbose = True rflux.numProcessors = 8 rflux.rfluxmtxParameters = rfluxPara rflux.viewInfoFile = r'temp/viewSouthDimensions.txt' rflux.viewRaysFile = r'temp/viewSouthRays.txt' rflux.radFiles = ['room.mat', 'room.rad', 'glazing.rad'] rflux.samplingRaysCount = 9 rflux.samplingRaysCount = 3 rflux.execute() # Step4a: Create the sky vector. # Step4a.1: Create a sky defintion # Step s: Creating the sky matrix if phasesToCalculate['s']: if calculationType == 'annual': weaFile = Epw2wea(epwFile=epwFile or 'test.epw', outputWeaFile=r'temp/test.wea') weaFile.execute() gendayParam = GendaymtxParameters() gendayParam.skyDensity = skyDensity genday = Gendaymtx(weaFile=r'temp/test.wea', outputName=r'temp/day.smx') genday.gendaymtxParameters = gendayParam genday.execute() skyVector = r'temp/day.smx' else: gensk = Gensky() gensk.monthDayHour = timeStamp or (11, 11, 11) gensk.outputFile = 'temp/sky.rad' gensk.execute() genskv = Genskyvec() genskv.inputSkyFile = os.path.abspath(r'temp/sky.rad') genskv.outputFile = os.path.abspath(r'temp/sky.vec') genskv.skySubdivision = skyDensity genskv.execute() skyVector = r'temp/sky.vec' else: skyVector = r'temp/sky.vec' # Step5: Generate results dct = Dctimestep() dct.daylightCoeffSpec = r'temp/%03d.hdr' dct.skyVectorFile = skyVector dct.outputFile = r'temp/results.hdr' dct.execute() return 'temp/results.txt'
def run2Phase(calculationType='annual'): if calculationType == 'annual': weaFile = Epw2wea(epwFile='test.epw', outputWeaFile=r'temp/test.wea') weaFile.execute() gendayParam = GendaymtxParameters() gendayParam.skyDensity = 4 genday = Gendaymtx(weaFile=r'temp/test.wea', outputName=r'temp/day.smx') genday.gendaymtxParameters = gendayParam # genday.execute() skyVector = r'temp/day.smx' else: gensk = Gensky() gensk.monthDayHour = (11, 11, 11) gensk.outputFile = 'temp/sky.rad' gensk.execute() genskv = Genskyvec() genskv.inputSkyFile = r'temp/sky.rad' genskv.outputFile = r'temp/sky.vec' genskv.skySubdivision = 4 genskv.execute() skyVector = r'temp/sky.vec' # # Step2: Generate daylight coefficients using rfluxmtx. rfluxPara = RfluxmtxParameters() rfluxPara.irradianceCalc = False rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientDivisions = 10 rfluxPara.ambientBounces = 1 rfluxPara.limitWeight = 0.1 rfluxPara.quality = 0 rflux = Rfluxmtx() rflux.sender = '-' skyFile = rflux.defaultSkyGround(r'temp/rfluxSky.rad',skyType='r4') rflux.receiverFile = skyFile rflux.rfluxmtxParameters = rfluxPara rflux.radFiles = [r"room.mat", r"room.rad"] rflux.pointsFile = r"indoor_points.pts" rflux.outputMatrix = r"temp/dayCoeff.dc" rflux.execute() mtx1 = Rmtxop(matrixFiles=(os.path.abspath(r'temp/dayCoeff.dc'), os.path.abspath(skyVector)), outputFile=r'temp/illuminance.tmp') mtx1.execute() mtx2Param = RmtxopParameters() mtx2Param.outputFormat = 'a' mtx2Param.combineValues = (47.4, 119.9, 11.6) # mtx2Param.transposeMatrix = True mtx2 = Rmtxop(matrixFiles=[r'temp/illuminance.tmp'], outputFile=r'temp/illuminance.ill') mtx2.rmtxopParameters = mtx2Param mtx2.execute() with open(r'temp/illuminance.ill') as illFile: for lines in illFile: try: print(map(float, lines.split())) except ValueError: pass
def run3phase(phasesToCalculate={'v':True,'t':True,'d':True,'s':True}, calculationType='annual',epwFile=None,tmatrixFile=None, hdrResultsFileName=None,numProcessors=1,timeStamp=None): if phasesToCalculate['v']: # Step1: Create the view matrix. rfluxPara = RfluxmtxParameters() rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientBounces = 10 # using this for a quicker run rfluxPara.ambientBounces = 5 rfluxPara.ambientDivisions = 65536 # using this for a quicker run # rfluxPara.ad = 1000 rfluxPara.limitWeight = 1E-5 # rfluxPara.lw = 1E-2 #step 1.1 Invert glazing surface with xform so that it faces inwards xfrPara = XformParameters() xfrPara.invertSurfaces = True xfr = Xform() xfr.xformParameters = xfrPara xfr.radFile = 'glazing.rad' xfr.outputFile = 'glazingI.rad' xfr.execute() vwrParaDim = VwraysParameters() vwrParaDim.calcImageDim = True vwrParaDim.xResolution = 800 vwrParaDim.yResolution = 800 vwrDim = Vwrays() vwrDim.vwraysParameters = vwrParaDim vwrDim.viewFile = 'viewSouth1.vf' vwrDim.outputFile = r'temp/viewSouthDimensions.txt' vwrDim.execute() vwrParaSamp = VwraysParameters() vwrParaSamp.xResolution = 800 vwrParaSamp.yResolution = 800 vwrParaSamp.samplingRaysCount = 9 # vwrParaSamp.samplingRaysCount = 3 vwrParaSamp.jitter = 0.7 vwrSamp = Vwrays() vwrSamp.vwraysParameters = vwrParaSamp vwrSamp.viewFile = 'viewSouth1.vf' vwrSamp.outputFile = r'temp/viewSouthRays.txt' vwrSamp.outputDataFormat = 'f' vwrSamp.execute() rflux = Rfluxmtx() rflux.sender = '-' #Klems full basis sampling and the window faces +Y recCtrlPar = rflux.ControlParameters(hemiType='kf',hemiUpDirection='+Z') rflux.receiverFile = rflux.addControlParameters('glazingI.rad', {'Exterior_Window':recCtrlPar}) rflux.outputDataFormat = 'fc' rflux.verbose = True rflux.rfluxmtxParameters = rfluxPara rflux.viewInfoFile = r'temp/viewSouthDimensions.txt' rflux.viewRaysFile = r'temp/viewSouthRays.txt' rflux.radFiles = ['room.mat','room.rad','glazing.rad'] rflux.outputFilenameFormat = r'temp/%03d.hdr' rflux.samplingRaysCount = 9 # rflux.samplingRaysCount = 3 rflux.numProcessors = numProcessors rflux.execute() vMatrix = r'temp/vmatrix.vmx' #Step2: Assign T matrix from precalculated XML files. tMatrix = tmatrixFile or r'xmls/clear.xml' if phasesToCalculate['d']: #Step3: Create D matrix. rfluxPara = RfluxmtxParameters() rfluxPara.ambientAccuracy = 0.1 rfluxPara.ambientDivisions = 1024 rfluxPara.ambientBounces = 2 rfluxPara.limitWeight = 0.0000001 rflux2 = Rfluxmtx() rflux2.numProcessors = numProcessors rflux2.samplingRaysCount = 1000 rflux2.sender = 'glazingI.rad_m' skyFile = rflux2.defaultSkyGround(r'temp/rfluxSky.rad', skyType='r4') rflux2.receiverFile = skyFile rflux2.rfluxmtxParameters = rfluxPara rflux2.radFiles = [r"room.mat", r"room.rad", 'glazing.rad'] rflux2.outputMatrix = r"temp/dmatrix.dmx" rflux2.execute() dMatrix = r"temp/dmatrix.dmx" #Step4a: Create the sky vector. #Step4a.1: Create a sky defintion # Step s: Creating the sky matrix if phasesToCalculate['s']: if calculationType == 'annual': weaFile = Epw2wea(epwFile=epwFile or 'test.epw', outputWeaFile=r'temp/test.wea') weaFile.execute() gendayParam = GendaymtxParameters() gendayParam.skyDensity = 4 genday = Gendaymtx(weaFile=r'temp/test.wea', outputName=r'temp/day.smx') genday.gendaymtxParameters = gendayParam genday.execute() skyVector = r'temp/day.smx' else: genskPar = GenskyParameters() gensk = Gensky() gensk.monthDayHour = timeStamp or (11,11,11) gensk.outputFile = 'temp/sky.rad' gensk.execute() genskv = Genskyvec() genskv.inputSkyFile = r'temp/sky.rad' genskv.outputFile = r'temp/sky.vec' genskv.skySubdivision = 4 genskv.execute() skyVector = r'temp/sky.vec' else: skyVector = r'temp/sky.vec' # Step5: Generate results dct = Dctimestep() dct.tmatrixFile = tMatrix dct.vmatrixSpec = r'temp/%03d.hdr' dct.dmatrixFile = dMatrix dct.skyVectorFile = skyVector dct.outputFileName = hdrResultsFileName or r'temp/results.hdr' dct.execute() return 'temp/results.txt'