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


Python SolutionDirectory.nrProcs方法代码示例

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


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

示例1: lookForCases

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import nrProcs [as 别名]
        def lookForCases(d):
            for n in tqdm(listdir(d),
                          unit="entries",
                          leave=False,
                          desc=path.basename(path.abspath(d)),
                          disable=not self.opts.progressBar):
                if not self.fnmatch(n):
                    continue
                cName=path.join(d,n)
                if path.isdir(cName):
                    try:
                        sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
                        if sol.isValid():
                            if self.opts.progress:
                                print_("Processing",cName)

                            data={}

                            data["mtime"]=stat(cName)[ST_MTIME]
                            times=sol.getTimes()
                            try:
                                data["first"]=times[0]
                            except IndexError:
                                data["first"]="None"
                            try:
                                data["last"]=times[-1]
                            except IndexError:
                                data["last"]="None"
                            data["nrSteps"]=len(times)
                            data["procs"]=sol.nrProcs()
                            data["pFirst"]=-1
                            data["pLast"]=-1
                            data["nrParallel"]=-1
                            if self.opts.parallel:
                                pTimes=sol.getParallelTimes()
                                data["nrParallel"]=len(pTimes)
                                if len(pTimes)>0:
                                    data["pFirst"]=pTimes[0]
                                    data["pLast"]=pTimes[-1]
                            data["name"]=cName
                            data["diskusage"]=-1
                            if self.opts.diskusage:
                                data["diskusage"]=diskUsage(cName)
                                totalDiskusage+=data["diskusage"]
                            if self.opts.parallel:
                                for f in listdir(cName):
                                    if re.compile("processor[0-9]+").match(f):
                                        data["mtime"]=max(stat(path.join(cName,f))[ST_MTIME],data["mtime"])

                            if self.opts.state or self.opts.estimateEndTime:
                                try:
                                    data["startedAt"]=time.mktime(time.strptime(self.readState(sol,"StartedAt")))
                                except ValueError:
                                    data["startedAt"]="nix"

                            if self.opts.state:
                                try:
                                    data["nowTime"]=float(self.readState(sol,"CurrentTime"))
                                except ValueError:
                                    data["nowTime"]=None

                                try:
                                    data["lastOutput"]=time.mktime(time.strptime(self.readState(sol,"LastOutputSeen")))
                                except ValueError:
                                    data["lastOutput"]="nix"

                                data["state"]=self.readState(sol,"TheState")
                                if data["state"]=="Running":
                                    try:
                                        gone=time.time()-data["lastOutput"]
                                        if gone>self.opts.deadThreshold:
                                            data["state"]="Dead "+humanReadableDuration(gone)
                                    except KeyError:
                                        pass
                                    except TypeError:
                                        pass

                            if self.opts.startEndTime or self.opts.estimateEndTime:
                                try:
                                    ctrlDict=ParsedParameterFile(sol.controlDict(),doMacroExpansion=True)
                                except PyFoamParserError:
                                    # Didn't work with Macro expansion. Let's try without
                                    try:
                                        ctrlDict=ParsedParameterFile(sol.controlDict())
                                    except PyFoamParserError:
                                        ctrlDict=None
                                if ctrlDict:
                                    data["startTime"]=ctrlDict["startTime"]
                                    data["endTime"]=ctrlDict["endTime"]
                                else:
                                    data["startTime"]=None
                                    data["endTime"]=None

                            if self.opts.estimateEndTime:
                                data["endTimeEstimate"]=None
                                if self.readState(sol,"TheState")=="Running":
                                    gone=time.time()-data["startedAt"]
                                    try:
                                        current=float(self.readState(sol,"CurrentTime"))
                                        frac=(current-data["startTime"])/(data["endTime"]-data["startTime"])
#.........这里部分代码省略.........
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:103,代码来源:ListCases.py

示例2: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import nrProcs [as 别名]
    def run(self):
        dirs=self.parser.getArgs()

        if len(dirs)==0:
            dirs=[path.curdir]

        cData=[]
        totalDiskusage=0
        useSolverInData=False

        self.hasState=False

        customData=[]
        for i,c in enumerate(self.opts.customData):
            lst=c.split("=")
            if len(lst)==2:
                name,spec=lst
                name+="_"  # Make sure that there is no collision with standard-names
            elif len(lst)==1:
                name,spec="Custom%d" % (i+1),c
            else:
                self.error("Custom specification",c,"does not fit the pattern 'name=subs1::subs2::..'")
            customData.append((name,spec.split("::")))

        if len(customData)>0 and not self.opts.solverNameForCustom:
            self.warning("Parameter '--solver-name-for-custom-data' should be set if '--custom-data' is used")
            useSolverInData=True

        for d in dirs:
            for n in listdir(d):
                cName=path.join(d,n)
                if path.isdir(cName):
                    try:
                        sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
                        if sol.isValid():
                            if self.opts.progress:
                                print_("Processing",cName)

                            data={}

                            data["mtime"]=stat(cName)[ST_MTIME]
                            times=sol.getTimes()
                            try:
                                data["first"]=times[0]
                            except IndexError:
                                data["first"]="None"
                            try:
                                data["last"]=times[-1]
                            except IndexError:
                                data["last"]="None"
                            data["nrSteps"]=len(times)
                            data["procs"]=sol.nrProcs()
                            data["pFirst"]=-1
                            data["pLast"]=-1
                            data["nrParallel"]=-1
                            if self.opts.parallel:
                                pTimes=sol.getParallelTimes()
                                data["nrParallel"]=len(pTimes)
                                if len(pTimes)>0:
                                    data["pFirst"]=pTimes[0]
                                    data["pLast"]=pTimes[-1]
                            data["name"]=cName
                            data["diskusage"]=-1
                            if self.opts.diskusage:
                                data["diskusage"]=diskUsage(cName)
                                totalDiskusage+=data["diskusage"]
                            if self.opts.parallel:
                                for f in listdir(cName):
                                    if re.compile("processor[0-9]+").match(f):
                                        data["mtime"]=max(stat(path.join(cName,f))[ST_MTIME],data["mtime"])

                            if self.opts.state:
                                try:
                                    data["nowTime"]=float(self.readState(sol,"CurrentTime"))
                                except ValueError:
                                    data["nowTime"]=None

                                try:
                                    data["lastOutput"]=time.mktime(time.strptime(self.readState(sol,"LastOutputSeen")))
                                except ValueError:
                                    data["lastOutput"]="nix"

                                data["state"]=self.readState(sol,"TheState")

                            if self.opts.state or self.opts.estimateEndTime:
                                try:
                                    data["startedAt"]=time.mktime(time.strptime(self.readState(sol,"StartedAt")))
                                except ValueError:
                                    data["startedAt"]="nix"

                            if self.opts.startEndTime or self.opts.estimateEndTime:
                                try:
                                    ctrlDict=ParsedParameterFile(sol.controlDict(),doMacroExpansion=True)
                                except PyFoamParserError:
                                    # Didn't work with Macro expansion. Let's try without
                                    try:
                                        ctrlDict=ParsedParameterFile(sol.controlDict())
                                    except PyFoamParserError:
                                        ctrlDict=None
                                if ctrlDict:
#.........这里部分代码省略.........
开发者ID:LeeRuns,项目名称:PyFoam,代码行数:103,代码来源:ListCases.py

示例3: doRegion

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import nrProcs [as 别名]

#.........这里部分代码省略.........

            if self.opts.time==None:
                try:
                    time=sol.timeName(0)
                except IndexError:
                    error("There is no timestep in the case")
            else:
                time=self.opts.time

            tDir=sol[time]

            nameMaxLen=0

            for f in tDir:
                try:
                    fields[f.baseName()]=f.getContent(listLengthUnparsed=self.opts.longlist,
                                                      treatBinaryAsASCII=self.opts.treatBinaryAsASCII,
                                                      doMacroExpansion=self.opts.doMacros)
                    nameMaxLen=max(nameMaxLen,len(f.baseName()))
                except PyFoamParserError:
                    e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
                    warning("Couldn't parse",f.name,"because of an error:",e," -> skipping")

            fieldNames=list(fields.keys())
            fieldNames.sort()

        if self.opts.caseSize:
            print_(ReST.heading("Size of the case"))

            nFaces=0
            nPoints=0
            nCells=0
            if self.opts.parallel:
                procs=list(range(sol.nrProcs()))
                print_("Accumulated from",sol.nrProcs(),"processors")
            else:
                procs=[None]

            for p in procs:
                info=MeshInformation(sol.name,
                                     processor=p,
                                     region=theRegion,
                                     time=self.opts.time)
                nFaces+=info.nrOfFaces()
                nPoints+=info.nrOfPoints()
                try:
                    nCells+=info.nrOfCells()
                except:
                    nCells="Not available"
            tab=ReST.table()
            tab[0]=("Faces",nFaces)
            tab[1]=("Points",nPoints)
            tab[2]=("Cells",nCells)
            print_(tab)

        if self.opts.decomposition:
            print_(ReST.heading("Decomposition"))

            if sol.nrProcs()<2:
                print_("This case is not decomposed")
            else:
                print_("Case is decomposed for",sol.nrProcs(),"processors")
                print_()

                nCells=[]
                nFaces=[]
开发者ID:martinep,项目名称:foam-extend-svn,代码行数:70,代码来源:CaseReport.py

示例4: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import nrProcs [as 别名]
    def run(self):
        dirs=self.parser.getArgs()

        if len(dirs)==0:
            dirs=[path.curdir]

        cData=[]
        totalDiskusage=0

        self.hasState=False

        for d in dirs:
            for n in listdir(d):
                cName=path.join(d,n)
                if path.isdir(cName):
                    try:
                        sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
                        if sol.isValid():
                            if self.opts.progress:
                                print_("Processing",cName)

                            data={}

                            data["mtime"]=stat(cName)[ST_MTIME]
                            times=sol.getTimes()
                            try:
                                data["first"]=times[0]
                            except IndexError:
                                data["first"]="None"
                            try:
                                data["last"]=times[-1]
                            except IndexError:
                                data["last"]="None"
                            data["nrSteps"]=len(times)
                            data["procs"]=sol.nrProcs()
                            data["pFirst"]=-1
                            data["pLast"]=-1
                            data["nrParallel"]=-1
                            if self.opts.parallel:
                                pTimes=sol.getParallelTimes()
                                data["nrParallel"]=len(pTimes)
                                if len(pTimes)>0:
                                    data["pFirst"]=pTimes[0]
                                    data["pLast"]=pTimes[-1]
                            data["name"]=cName
                            data["diskusage"]=-1
                            if self.opts.diskusage:
                                try:
                                    data["diskusage"]=int(
                                        subprocess.Popen(
                                            ["du","-sb",cName],
                                            stdout=subprocess.PIPE,
                                            stderr=open(os.devnull,"w")
                                        ).communicate()[0].split()[0])
                                except IndexError:
                                    # assume that this du does not support -b
                                    data["diskusage"]=int(
                                        subprocess.Popen(
                                            ["du","-sk",cName],
                                            stdout=subprocess.PIPE
                                        ).communicate()[0].split()[0])*1024

                                totalDiskusage+=data["diskusage"]
                            if self.opts.parallel:
                                for f in listdir(cName):
                                    if re.compile("processor[0-9]+").match(f):
                                        data["mtime"]=max(stat(path.join(cName,f))[ST_MTIME],data["mtime"])

                            if self.opts.state:
                                try:
                                    data["nowTime"]=float(self.readState(sol,"CurrentTime"))
                                except ValueError:
                                    data["nowTime"]=None

                                try:
                                    data["lastOutput"]=time.mktime(time.strptime(self.readState(sol,"LastOutputSeen")))
                                except ValueError:
                                    data["lastOutput"]="nix"

                                data["state"]=self.readState(sol,"TheState")

                            if self.opts.state or self.opts.estimateEndTime:
                                try:
                                    data["startedAt"]=time.mktime(time.strptime(self.readState(sol,"StartedAt")))
                                except ValueError:
                                    data["startedAt"]="nix"

                            if self.opts.startEndTime or self.opts.estimateEndTime:
                                try:
                                    ctrlDict=ParsedParameterFile(sol.controlDict(),doMacroExpansion=True)
                                except PyFoamParserError:
                                    # Didn't work with Macro expansion. Let's try without
                                    ctrlDict=ParsedParameterFile(sol.controlDict())

                                data["startTime"]=ctrlDict["startTime"]
                                data["endTime"]=ctrlDict["endTime"]

                            if self.opts.estimateEndTime:
                                data["endTimeEstimate"]=None
                                if self.readState(sol,"TheState")=="Running":
#.........这里部分代码省略.........
开发者ID:martinep,项目名称:foam-extend-svn,代码行数:103,代码来源:ListCases.py

示例5: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import nrProcs [as 别名]
    def run(self):
        dirs=self.parser.getArgs()
        
        if len(dirs)==0:
            dirs=[path.curdir]

        cData=[]
        totalDiskusage=0

        self.hasState=False
        
        for d in dirs:
            for n in listdir(d):
                cName=path.join(d,n)
                if path.isdir(cName):
                    try:
                        sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
                        if sol.isValid():
                            if self.opts.progress:
                                print "Processing",cName

                            data={}

                            data["mtime"]=stat(cName)[ST_MTIME]
                            times=sol.getTimes()
                            try:
                                data["first"]=times[0]
                            except IndexError:
                                data["first"]="None"                            
                            try:
                                data["last"]=times[-1]
                            except IndexError:
                                data["last"]="None"                            
                            data["nrSteps"]=len(times)
                            data["procs"]=sol.nrProcs()
                            data["pFirst"]=-1
                            data["pLast"]=-1
                            data["nrParallel"]=-1
                            if self.opts.parallel:
                                pTimes=sol.getParallelTimes()
                                data["nrParallel"]=len(pTimes)
                                if len(pTimes)>0:
                                    data["pFirst"]=pTimes[0]
                                    data["pLast"]=pTimes[-1]                                
                            data["name"]=cName
                            data["diskusage"]=-1
                            if self.opts.diskusage:
                                data["diskusage"]=int(subprocess.Popen(["du","-sm",cName], stdout=subprocess.PIPE).communicate()[0].split()[0])
                                totalDiskusage+=data["diskusage"]
                            if self.opts.parallel:
                                for f in listdir(cName):
                                    if re.compile("processor[0-9]+").match(f):
                                        data["mtime"]=max(stat(path.join(cName,f))[ST_MTIME],data["mtime"])

                            if self.opts.state:
                                try:
                                    data["nowTime"]=float(self.readState(sol,"CurrentTime"))
                                except ValueError:
                                    data["nowTime"]=None
                                    
                                try:
                                    data["lastOutput"]=time.mktime(time.strptime(self.readState(sol,"LastOutputSeen")))
                                except ValueError:
                                    data["lastOutput"]="nix"
                                try:
                                    data["startedAt"]=time.mktime(time.strptime(self.readState(sol,"StartedAt")))
                                except ValueError:
                                    data["startedAt"]="nix"

                                data["state"]=self.readState(sol,"TheState")
                                    
                            cData.append(data)
                    except OSError:
                        print cName,"is unreadable"
                        
        if self.opts.progress:
            print "Sorting data"
            
        if self.opts.reverse:
            cData.sort(lambda x,y:cmp(y[self.opts.sort],x[self.opts.sort]))
        else:
            cData.sort(lambda x,y:cmp(x[self.opts.sort],y[self.opts.sort]))

        if len(cData)==0:
            print "No cases found"
            return

        if self.opts.dump:
            print cData
            return
        
        lens={}
        for k in cData[0].keys():
            lens[k]=len(k)
        for c in cData:
            for k in ["mtime","lastOutput","startedAt"]:
                try:
                    if self.opts.relativeTime:
                        c[k]=datetime.timedelta(seconds=long(time.time()-c[k]))
                    else:
#.........这里部分代码省略.........
开发者ID:floli,项目名称:tools,代码行数:103,代码来源:ListCases.py


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