Package PyFoam :: Package Applications :: Module RunAtMultipleTimes
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.RunAtMultipleTimes

 1  #  ICE Revision: $Id$ 
 2  """ 
 3  Application class that implements pyFoamRunAtMultipleTimes 
 4  """ 
 5   
 6  from .PyFoamApplication import PyFoamApplication 
 7  from .CommonSelectTimesteps import CommonSelectTimesteps 
 8  from .CommonReportUsage import CommonReportUsage 
 9  from .CommonReportRunnerData import CommonReportRunnerData 
10  from .CommonStandardOutput import CommonStandardOutput 
11  from .CommonServer import CommonServer 
12  from .CommonParallel import CommonParallel 
13   
14  from PyFoam.Execution.UtilityRunner import UtilityRunner 
15  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
16   
17  from PyFoam.ThirdParty.six import print_ 
18   
19  import sys 
20  from os import path 
21   
22 -class RunAtMultipleTimes(PyFoamApplication, 23 CommonReportUsage, 24 CommonReportRunnerData, 25 CommonSelectTimesteps, 26 CommonParallel, 27 CommonServer, 28 CommonStandardOutput):
29 - def __init__(self,args=None):
30 description="""\ 31 Runs a OpenFoam Utility that only supports being run for one or all 32 times to be run at multiple selected times 33 """ 34 PyFoamApplication.__init__(self, 35 exactNr=False, 36 args=args, 37 description=description)
38
39 - def addOptions(self):
40 CommonStandardOutput.addOptions(self,logname="RunAtMultipleTimes") 41 CommonParallel.addOptions(self) 42 CommonServer.addOptions(self) 43 CommonSelectTimesteps.addOptions(self,defaultUnique=True) 44 CommonReportUsage.addOptions(self) 45 CommonReportRunnerData.addOptions(self)
46
47 - def run(self):
48 cName=self.parser.casePath() 49 50 times=self.processTimestepOptions(SolutionDirectory(cName,archive=None)) 51 if len(times)<1: 52 self.warning("Can't continue without time-steps") 53 return 54 55 lam=self.getParallel(SolutionDirectory(cName,archive=None)) 56 57 data=[] 58 59 for i,t in enumerate(times): 60 print_(" Running for t=",t) 61 run=UtilityRunner(argv=self.parser.getArgs()+["-time",t], 62 silent=self.opts.progress or self.opts.silent, 63 server=self.opts.server, 64 logname="%s.%s.t=%s" % (self.opts.logname,self.parser.getApplication(),t), 65 compressLog=self.opts.compress, 66 logTail=self.opts.logTail, 67 noLog=self.opts.noLog, 68 lam=lam) 69 70 self.addToCaseLog(cName,"Starting for t=%s",t) 71 72 run.start() 73 74 self.setData({t:run.data}) 75 76 self.addToCaseLog(cName,"Ending") 77 78 self.reportUsage(run) 79 self.reportRunnerData(run) 80 81 data.append(run.data) 82 83 return data
84 85 # Should work with Python3 and Python2 86