当前位置: 首页>>代码示例>>Python>>正文


Python ParsedParameterFile.writeFileAs方法代码示例

本文整理汇总了Python中PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile.writeFileAs方法的典型用法代码示例。如果您正苦于以下问题:Python ParsedParameterFile.writeFileAs方法的具体用法?Python ParsedParameterFile.writeFileAs怎么用?Python ParsedParameterFile.writeFileAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile的用法示例。


在下文中一共展示了ParsedParameterFile.writeFileAs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: case_setup

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
def case_setup(ci):
    template_case = SolutionDirectory(
        "template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}NC{1}".format(ci.name, ci.nr_classes)
    )

    phase_properties = ParsedParameterFile(
        path.join(template_case.name, "constant", "phaseProperties"))
    phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["numberOfClasses"] = ci.nr_classes
    phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["xi1"] = ci.dv

    # manually fix bad pyfoam parsing
    phase_properties["blending"]["default"]["type"] = "none"
    phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
    phase_properties.writeFileAs(path.join(
        case.name, "constant", "phaseProperties"
    ))

    n0 = ParsedParameterFile(path.join(template_case.name, "0", "n0"))
    for i in range(ci.nr_classes):
        n0.header["object"] = "n" + str(i)
        n0["internalField"].setUniform(ci.Ninit[i])
        n0.writeFileAs(path.join(case.name, "0", "n" + str(i)))

    controlDict = ParsedParameterFile(
        path.join(case.name, "system", "controlDict")
    )
    controlDict["functions"]["probes"]["fields"] = [
        "n{0}".format(n) for n in range(ci.nr_classes)]
    controlDict.writeFile()
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:33,代码来源:setupCases.py

示例2: case_setup

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
def case_setup(ci):
    template_case = SolutionDirectory(
        "template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}{1}".format(ci.name, ci.quadrature_order)
    )

    phase_properties = ParsedParameterFile(
        path.join("./diffs", ci.phase_properties_name))
    phase_properties["air"]["PBEDiameterCoeffs"]["QMOMCoeffs"]["quadratureOrder"] = ci.quadrature_order

    # manually fix bad pyfoam parsing
    phase_properties["blending"]["default"]["type"] = "none"
    phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
    phase_properties.writeFileAs(path.join(
        case.name, "constant", "phaseProperties"
    ))

    m0 = ParsedParameterFile(path.join(template_case.name, "0", "m0"))
    for i in range(ci.number_of_moments):
        m0.header["object"] = "m" + str(i)
        m0["internalField"].setUniform(ci.initial_moments[i])
        m0["dimensions"] = "[0 {0} 0 0 0 0 0]".format(3 * i)
        m0.writeFileAs(path.join(case.name, "0", "m" + str(i)))

    controlDict = ParsedParameterFile(
        path.join(case.name, "system", "controlDict")
    )
    controlDict["functions"]["probes"]["fields"] = [
        "m{0}".format(m) for m in range(ci.number_of_moments)]
    controlDict["endTime"] = ci.end_time
    controlDict["deltaT"] = ci.delta_t
    controlDict.writeFile()
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:35,代码来源:setupCases.py

示例3: arange

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
v = dv + dv * arange(class_number)

if __name__ == "__main__":
    template_case = SolutionDirectory(
        "MOC-template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}{1}".format("MOC", class_number)
    )

    n0 = ParsedParameterFile(path.join(template_case.name, "0", "n0"))
    for i in range(class_number):
        n0.header["object"] = "n" + str(i)
        n0["internalField"].setUniform(
            m0 * (prob.cdf(v[i]) - prob.cdf(v[i] - dv))
        )
        n0.writeFileAs(path.join(case.name, "0", "n" + str(i)))

    phase_properties = ParsedParameterFile(
        path.join(case.name, "constant", "phaseProperties")
    )

    phase_properties["air"]["PBEDiameterCoeffs"]["MOCCoeffs"]["numberOfClasses"] = class_number
    phase_properties["air"]["PBEDiameterCoeffs"]["MOCCoeffs"]["xi1"] = dv
    phase_properties["blending"]["default"]["type"] = "none"
    phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
    phase_properties.writeFile()

    control_dict = ParsedParameterFile(
        path.join(case.name, "system", "controlDict")
    )
    control_dict["functions"]["probes"]["fields"] = [
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:33,代码来源:setupIC.py

示例4: updateFieldFiles

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
    def updateFieldFiles(self):
        #tengo que releer cada uno de los campos en el directorio actual,
        #pisar los boundaries por los que aparece en constant/polyMesh/boundary
        #imponerles alguna CB por defecto dependiendo del tipo de patch
        boundaries = BoundaryDict(self.currentFolder)
        #veo los campos que tengo en el directorio inicial
        [timedir,fields,currtime] = currentFields(self.currentFolder, nproc = self.window().nproc, filterTurb=False)
        
        fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder
        dictDict = []
        if os.path.isfile(fileDict):
            dictDict = ParsedParameterFile(fileDict,createZipped=False)

        for ifield in fields:
            if dictDict==[]:
                filename = '%s/%s'%(timedir,ifield)
                fieldData = ParsedParameterFile(filename,createZipped=False)
            else:
                fieldData = dictDict['dictionaryReplacement'][ifield]

            oldKeys = fieldData['boundaryField'].keys()
            fieldData['boundaryField'] = {}
            for ipatch in boundaries.getValueDict():
                if ipatch not in fieldData['boundaryField']:
                    if boundaries[ipatch]['nFaces']==0:
                        continue
                    patchDict={}
                    if ifield in unknowns:
                        if boundaries[ipatch]['type']=='empty':
                            patchDict['type'] = 'empty'
                            if ipatch in oldKeys:
                                patchDict['ZZvalue'] = '0'
                        else:
                            patchDict['type'] = 'zeroGradient'
                            if ipatch in oldKeys:
                                patchDict['ZZvalue'] = '0'
                    else:
                        patchDict['type'] = 'calculated'
                        if ipatch in oldKeys:
                                patchDict['ZZvalue'] = '0'
                    fieldData['boundaryField'][ipatch] = patchDict
            
            # poner el campo interno uniforme en cero
            if types[ifield] == 'scalar':
                fieldData['internalField'] = 'uniform 0'
            elif types[ifield] == 'vector':
                fieldData['internalField'] = 'uniform (0 0 0)'

            if dictDict==[]:
                fieldData.writeFile()

        if dictDict!=[]:
            dictDict.writeFile()
            dictDictBak = ParsedParameterFile(fileDict,createZipped=False)
            keysDict = dictDict['dictionaryReplacement'].keys()
            dictDictBak['dictionaryReplacement'] = {}
            for ikey in keysDict:
                if ikey in self.fields:
                    dictDictBak['dictionaryReplacement'][ikey] = dictDict['dictionaryReplacement'][ikey]
            dictDictBak.writeFileAs('%s/system/changeDictionaryPetroSym.bak'%self.currentFolder)
            
            command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak'%(self.currentFolder)
            os.system(command)
            
            #chequear que no bloquee
            if self.window().nproc<=1:
                command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &'%(self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
            else:
                command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &'%(str(self.nproc),self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
            os.system(command)
            
        return
开发者ID:jmarcelogimenez,项目名称:petroSym,代码行数:74,代码来源:mesh.py

示例5: changePatchType

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
    def changePatchType(self,item):
        texto = str(item.text())
        w = bcPatch(self.boundaries[texto]['type'])
        result = w.exec_()
        if result:
            patchType = w.getPatchType()
            self.boundaries[texto]['type'] = patchType
            self.boundaries.writeFile()
            
            fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder
            dictDict = []
            if os.path.isfile(fileDict):
                dictDict = ParsedParameterFile(fileDict,createZipped=False)
                
            for ifield in self.fields:
                
                if dictDict==[]:
                    filename = '%s/%s'%(self.timedir,ifield)
                    fieldData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False)
                else:
                    fieldData = dictDict['dictionaryReplacement'][ifield]

                newDict = {}
                if patchType == 'empty':
                    newDict['type'] = 'empty'
                    newDict['ZZvalue'] = '0'
                else:
                    if ifield in unknowns:
                        newDict['type'] = 'zeroGradient'
                        newDict['ZZvalue'] = '0'
                    else:
                        newDict['type'] = 'calculated'
                        newDict['ZZvalue'] = '0'
                
                fieldData['boundaryField'][texto] = newDict

                if dictDict==[]:
                    fieldData.writeFile()
                else:
                    dictDict['dictionaryReplacement'][ifield] = fieldData
            
            if dictDict!=[]:
                dictDict.writeFile()
                dictDictBak = ParsedParameterFile(fileDict,createZipped=False)
                keysDict = dictDict['dictionaryReplacement'].keys()
                dictDictBak['dictionaryReplacement'] = {}
                for ikey in keysDict:
                    if ikey in self.fields:
                        dictDictBak['dictionaryReplacement'][ikey] = {}
                        dictDictBak['dictionaryReplacement'][ikey]['boundaryField'] = dictDict['dictionaryReplacement'][ikey]['boundaryField']
                dictDictBak.writeFileAs('%s/system/changeDictionaryPetroSym.bak'%self.currentFolder)
                
                command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak'%(self.currentFolder)
                os.system(command)
                
                #chequear que no bloquee
                if self.nproc<=1:
                    command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &'%(self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
                else:
                    command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &'%(str(self.nproc),self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
                os.system(command)
            
            self.loadData()
开发者ID:jmarcelogimenez,项目名称:petroSym,代码行数:65,代码来源:bc.py

示例6: saveBCs

# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFileAs [as 别名]
    def saveBCs(self):
        
        ipatch = str(self.listWidget.currentItem().text())
        
        fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder
        dictDict = []
        if os.path.isfile(fileDict):
            dictDict = ParsedParameterFile(fileDict,createZipped=False)
            
        for itab in range(self.tabWidget.count()):
            ifield = str(self.tabWidget.tabText(itab))
            itype = str(self.tabWidget.widget(itab).findChildren(QtGui.QComboBox)[0].currentText())
            layout = self.tabWidget.widget(itab).findChildren(QtGui.QVBoxLayout)[0]
            if dictDict == []:
                filename = '%s/%s'%(self.timedir,ifield)
                parsedData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False)
                thisPatch = parsedData['boundaryField'][ipatch]
            else:
                thisPatch = dictDict['dictionaryReplacement'][ifield]['boundaryField'][ipatch]

            thisPatch = {}
            thisPatch['type'] = itype
            
            if itype == 'zeroGradient':
                thisPatch['ZZvalue'] = '0'
                
            #debo tomar los valores extras, si los tiene
            extraInfo = extras[ifield][itype]
            L = range(layout.count())
            L = L[1:-1]
            iExtra = 0
            #print ipatch
            
            for l in L:
                layout2 = layout.itemAt(l).layout()
                if layout2:
                    if layout2.itemAt(1).widget().currentText() != 'table':
                        if layout2.count()==3:
                             thisPatch[extraInfo[iExtra*4]] = '%s %s' %(layout2.itemAt(1).widget().currentText(),layout2.itemAt(2).widget().text())
                        else:
                             thisPatch[extraInfo[iExtra*4]] = '%s (%s %s %s)' %(layout2.itemAt(1).widget().currentText(),layout2.itemAt(2).widget().text(),layout2.itemAt(3).widget().text(),layout2.itemAt(4).widget().text())
                    else:
                        #determinar que hacer si quiero cargar una table!!!     
                        #('table', [[0, 0.0], [1e6-0.01, 0.0], [1e6, 1.0], [1e6, 1.0]])
                        tabla = self.getTabla(itab)
                        thisPatch[extraInfo[iExtra*4]] = ('table',tabla)
                    iExtra = iExtra+1
            
            if dictDict == []:
                parsedData['boundaryField'][ipatch] = thisPatch
                parsedData.writeFile()
            else:
                dictDict['dictionaryReplacement'][ifield]['boundaryField'][ipatch] = thisPatch
                dictDict.writeFile()
                dictDictBak = ParsedParameterFile(fileDict,createZipped=False)
                keysDict = dictDict['dictionaryReplacement'].keys()
                dictDictBak['dictionaryReplacement'] = {}
                for ikey in keysDict:
                    if ikey in self.fields:
                        dictDictBak['dictionaryReplacement'][ikey] = {}
                        dictDictBak['dictionaryReplacement'][ikey]['boundaryField'] = dictDict['dictionaryReplacement'][ikey]['boundaryField']
                dictDictBak.writeFileAs('%s/system/changeDictionaryPetroSym.bak'%self.currentFolder)
                
                command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak'%(self.currentFolder)
                os.system(command)
                
                #chequear que no bloquee
                if self.nproc<=1:
                    command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &'%(self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
                else:
                    command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &'%(str(self.nproc),self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder)
                os.system(command)
        self.pushButton.setEnabled(False)
        return
开发者ID:jmarcelogimenez,项目名称:petroSym,代码行数:76,代码来源:bc.py


注:本文中的PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile.writeFileAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。