Exemplo n.º 1
0
    def run(self):
        decomposeParWithRegion=(foamVersion()>=(1,6))

        if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None):
            warning("Option --keep-pseudocases only makes sense for multi-region-cases")

        if decomposeParWithRegion and self.opts.keeppseudo:
            warning("Option --keep-pseudocases doesn't make sense since OpenFOAM 1.6 because decomposePar supports regions")

        nr=int(self.parser.getArgs()[1])
        if nr<2:
            error("Number of processors",nr,"too small (at least 2)")

        case=path.abspath(self.parser.getArgs()[0])
        method=self.opts.method

        result={}
        result["numberOfSubdomains"]=nr
        result["method"]=method

        coeff={}
        result[method+"Coeffs"]=coeff

        if self.opts.globalFaceZones!=None:
            try:
                fZones=eval(self.opts.globalFaceZones)
            except SyntaxError:
                fZones=FoamStringParser(
                    self.opts.globalFaceZones,
                    listDict=True
                ).data

            result["globalFaceZones"]=fZones

        if method in ["metis","scotch","parMetis"]:
            if self.opts.processorWeights!=None:
                weigh=eval(self.opts.processorWeights)
                if nr!=len(weigh):
                    error("Number of processors",nr,"and length of",weigh,"differ")
                coeff["processorWeights"]=weigh
        elif method=="manual":
            if self.opts.dataFile==None:
                error("Missing required option dataFile")
            else:
                coeff["dataFile"]="\""+self.opts.dataFile+"\""
        elif method=="simple" or method=="hierarchical":
            if self.opts.n==None or self.opts.delta==None:
                error("Missing required option n or delta")
            n=eval(self.opts.n)
            if len(n)!=3:
                error("Needs to be three elements, not",n)
            if nr!=n[0]*n[1]*n[2]:
                error("Subdomains",n,"inconsistent with processor number",nr)
            coeff["n"]="(%d %d %d)" % (n[0],n[1],n[2])

            coeff["delta"]=float(self.opts.delta)
            if method=="hierarchical":
                if self.opts.order==None:
                    error("Missing reuired option order")
                if len(self.opts.order)!=3:
                    error("Order needs to be three characters")
                coeff["order"]=self.opts.order
        else:
            error("Method",method,"not yet implementes")

        gen=FoamFileGenerator(result)

        if self.opts.test:
            print_(str(gen))
            return -1
        else:
            f=open(path.join(case,"system","decomposeParDict"),"w")
            writeDictionaryHeader(f)
            f.write(str(gen))
            f.close()

        if self.opts.clear:
            print_("Clearing processors")
            for p in glob(path.join(case,"processor*")):
                print_("Removing",p)
                rmtree(p,ignore_errors=True)

        self.checkAndCommit(SolutionDirectory(case,archive=None))

        if self.opts.doDecompose:
            if self.opts.region:
                regionNames=self.opts.region[:]
                while True:
                    try:
                        i=regionNames.index("region0")
                        regionNames[i]=None
                    except ValueError:
                        break
            else:
                regionNames=[None]

            regions=None

            sol=SolutionDirectory(case)
            if not decomposeParWithRegion:
                if self.opts.regions or self.opts.region!=None:
                    print_("Building Pseudocases")
                    regions=RegionCases(sol,clean=True,processorDirs=False)

            if self.opts.regions:
                regionNames=sol.getRegions(defaultRegion=True)

            for theRegion in regionNames:
                theCase=path.normpath(case)
                if theRegion!=None and not decomposeParWithRegion:
                    theCase+="."+theRegion

                if oldApp():
                    argv=[self.opts.decomposer,".",theCase]
                else:
                    argv=[self.opts.decomposer,"-case",theCase]
                    if foamVersion()>=(2,0) and not self.opts.doFunctionObjects:
                        argv+=["-noFunctionObjects"]
                    if theRegion!=None and decomposeParWithRegion:
                        argv+=["-region",theRegion]

                        f=open(path.join(case,"system",theRegion,"decomposeParDict"),"w")
                        writeDictionaryHeader(f)
                        f.write(str(gen))
                        f.close()

                self.setLogname(default="Decomposer",useApplication=False)

                run=UtilityRunner(argv=argv,
                                  silent=self.opts.progress or self.opts.silent,
                                  logname=self.opts.logname,
                                  compressLog=self.opts.compress,
                                  server=self.opts.server,
                                  noLog=self.opts.noLog,
                                  logTail=self.opts.logTail,
                                  echoCommandLine=self.opts.echoCommandPrefix,
                                  jobId=self.opts.jobId)
                run.start()

                if theRegion!=None and not decomposeParWithRegion:
                    print_("Syncing into master case")
                    regions.resync(theRegion)

            if regions!=None and not decomposeParWithRegion:
                if not self.opts.keeppseudo:
                    print_("Removing pseudo-regions")
                    regions.cleanAll()
                else:
                    for r in sol.getRegions():
                        if r not in regionNames:
                            regions.clean(r)

            if self.opts.doConstantLinks:
                print_("Adding symlinks in the constant directories")
                constPath=path.join(case,"constant")
                for f in listdir(constPath):
                    srcExpr=path.join(path.pardir,path.pardir,"constant",f)
                    for p in range(nr):
                        dest=path.join(case,"processor%d"%p,"constant",f)
                        if not path.exists(dest):
                            symlink(srcExpr,dest)

            self.addToCaseLog(case)
Exemplo n.º 2
0
    def run(self):
        if self.opts.keeppseudo and (not self.opts.regions
                                     and self.opts.region == None):
            warning(
                "Option --keep-pseudocases only makes sense for multi-region-cases"
            )

        if self.opts.region:
            regionNames = self.opts.region
        else:
            regionNames = [None]

        regions = None

        casePath = self.parser.casePath()
        self.checkCase(casePath)
        #        self.addLocalConfig(casePath)

        self.addToCaseLog(casePath, "Starting")
        self.prepareHooks()

        if self.opts.regions or self.opts.region != None:
            print_("Building Pseudocases")
            sol = SolutionDirectory(casePath, archive=None)
            regions = RegionCases(sol, clean=True)

            if self.opts.regions:
                regionNames = sol.getRegions()

        self.processPlotLineOptions(autoPath=casePath)

        lam = self.getParallel(SolutionDirectory(casePath, archive=None))

        self.clearCase(SolutionDirectory(casePath,
                                         archive=None,
                                         parallel=lam is not None),
                       runParallel=lam is not None)

        self.checkAndCommit(SolutionDirectory(casePath, archive=None))

        self.initBlink()

        for theRegion in regionNames:
            args = self.buildRegionArgv(casePath, theRegion)
            self.setLogname()
            run = AnalyzedRunner(BoundingLogAnalyzer(
                progress=self.opts.progress,
                doFiles=self.opts.writeFiles,
                singleFile=self.opts.singleDataFilesOnly,
                doTimelines=True),
                                 silent=self.opts.progress or self.opts.silent,
                                 splitThres=self.opts.splitDataPointsThreshold
                                 if self.opts.doSplitDataPoints else None,
                                 argv=self.replaceAutoInArgs(args),
                                 server=self.opts.server,
                                 lam=lam,
                                 restart=self.opts.restart,
                                 logname=self.opts.logname,
                                 compressLog=self.opts.compress,
                                 logTail=self.opts.logTail,
                                 noLog=self.opts.noLog,
                                 remark=self.opts.remark,
                                 parameters=self.getRunParameters(),
                                 echoCommandLine=self.opts.echoCommandPrefix,
                                 jobId=self.opts.jobId)

            run.createPlots(customRegexp=self.lines_,
                            splitThres=self.opts.splitDataPointsThreshold
                            if self.opts.doSplitDataPoints else None,
                            writeFiles=self.opts.writeFiles)

            if self.cursesWindow:
                self.cursesWindow.setAnalyzer(run.analyzer)
                self.cursesWindow.setRunner(run)
                run.analyzer.addTimeListener(self.cursesWindow)

            self.addWriteAllTrigger(run,
                                    SolutionDirectory(casePath, archive=None))
            self.addLibFunctionTrigger(
                run, SolutionDirectory(casePath, archive=None))
            self.runPreHooks()

            if self.blink1:
                run.addTicker(lambda: self.blink1.ticToc())

            run.start()

            if len(regionNames) > 1:
                self.setData({theRegion: run.data})
            else:
                self.setData(run.data)

            self.runPostHooks()

            self.reportUsage(run)
            self.reportRunnerData(run)

            if theRegion != None:
                print_("Syncing into master case")
                regions.resync(theRegion)

        self.stopBlink()

        if regions != None:
            if not self.opts.keeppseudo:
                print_("Removing pseudo-regions")
                regions.cleanAll()
            else:
                for r in sol.getRegions():
                    if r not in regionNames:
                        regions.clean(r)

        self.addToCaseLog(casePath, "Ended")
Exemplo n.º 3
0
                    compressLog=self.opts.compress,
                    server=self.opts.server,
                    noLog=self.opts.noLog,
                    logTail=self.opts.logTail,
                    echoCommandLine=self.opts.echoCommandPrefix,
                    jobId=self.opts.jobId)
                run.start()

                if theRegion != None and not decomposeParWithRegion:
                    print_("Syncing into master case")
                    regions.resync(theRegion)

            if regions != None and not decomposeParWithRegion:
                if not self.opts.keeppseudo:
                    print_("Removing pseudo-regions")
                    regions.cleanAll()
                else:
                    for r in sol.getRegions():
                        if r not in regionNames:
                            regions.clean(r)

            if self.opts.doConstantLinks:
                print_("Adding symlinks in the constant directories")
                constPath = path.join(case, "constant")
                for f in listdir(constPath):
                    srcExpr = path.join(path.pardir, path.pardir, "constant",
                                        f)
                    for p in range(nr):
                        dest = path.join(case, "processor%d" % p, "constant",
                                         f)
                        if not path.exists(dest):
    def run(self):
        if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None):
            warning("Option --keep-pseudocases only makes sense for multi-region-cases")

        if self.opts.region:
            regionNames=self.opts.region
        else:
            regionNames=[None]

        regions=None

        casePath=self.parser.casePath()
        self.checkCase(casePath)
        #        self.addLocalConfig(casePath)

        self.addToCaseLog(casePath,"Starting")
        self.prepareHooks()

        if self.opts.regions or self.opts.region!=None:
            print_("Building Pseudocases")
            sol=SolutionDirectory(casePath,archive=None)
            regions=RegionCases(sol,clean=True)

            if self.opts.regions:
                regionNames=sol.getRegions()

        self.processPlotLineOptions(autoPath=casePath)

        self.clearCase(SolutionDirectory(casePath,archive=None))

        lam=self.getParallel(SolutionDirectory(casePath,archive=None))

        self.checkAndCommit(SolutionDirectory(casePath,archive=None))

        for theRegion in regionNames:
            args=self.buildRegionArgv(casePath,theRegion)
            self.setLogname()
            run=AnalyzedRunner(BoundingLogAnalyzer(progress=self.opts.progress,
                                                   doFiles=self.opts.writeFiles,
                                                   singleFile=self.opts.singleDataFilesOnly,
                                                   doTimelines=True),
                               silent=self.opts.progress or self.opts.silent,
                               argv=args,
                               server=self.opts.server,
                               lam=lam,
                               restart=self.opts.restart,
                               logname=self.opts.logname,
                               compressLog=self.opts.compress,
                               logTail=self.opts.logTail,
                               noLog=self.opts.noLog,
                               remark=self.opts.remark,
                               parameters=self.getRunParameters(),
                               echoCommandLine=self.opts.echoCommandPrefix,
                               jobId=self.opts.jobId)

            run.createPlots(customRegexp=self.lines_,
                            writeFiles=self.opts.writeFiles)

            self.addWriteAllTrigger(run,SolutionDirectory(casePath,archive=None))
            self.addLibFunctionTrigger(run,SolutionDirectory(casePath,archive=None))
            self.runPreHooks()

            run.start()

            if len(regionNames)>1:
                self.setData({theRegion:run.data})
            else:
                self.setData(run.data)

            self.runPostHooks()

            self.reportUsage(run)
            self.reportRunnerData(run)

            if theRegion!=None:
                print_("Syncing into master case")
                regions.resync(theRegion)

        if regions!=None:
            if not self.opts.keeppseudo:
                print_("Removing pseudo-regions")
                regions.cleanAll()
            else:
                for r in sol.getRegions():
                    if r not in regionNames:
                        regions.clean(r)

        self.addToCaseLog(casePath,"Ended")