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 -class RunAtMultipleTimes(PyFoamApplication, 20 CommonReportUsage, 21 CommonReportRunnerData, 22 CommonSelectTimesteps, 23 CommonParallel, 24 CommonServer, 25 CommonStandardOutput):
26 - def __init__(self, 27 args=None, 28 **kwargs):
29 description="""\ 30 Runs a OpenFoam Utility that only supports being run for one or all 31 times to be run at multiple selected times 32 """ 33 PyFoamApplication.__init__(self, 34 exactNr=False, 35 args=args, 36 description=description, 37 **kwargs)
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 echoCommandLine=self.opts.echoCommandPrefix, 69 lam=lam) 70 71 self.addToCaseLog(cName,"Starting for t=%s",t) 72 73 run.start() 74 75 self.setData({t:run.data}) 76 77 self.addToCaseLog(cName,"Ending") 78 79 self.reportUsage(run) 80 self.reportRunnerData(run) 81 82 data.append(run.data) 83 84 return data
85 86 # Should work with Python3 and Python2 87