1
2 """
3 Application class that implements pyFoamRunner
4 """
5
6 from PyFoamApplication import PyFoamApplication
7
8 from PyFoam.Execution.AnalyzedRunner import AnalyzedRunner
9 from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
10 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
11 from PyFoam.RunDictionary.RegionCases import RegionCases
12
13 from PyFoam.Error import warning,error
14
15 from CommonMultiRegion import CommonMultiRegion
16 from CommonPlotLines import CommonPlotLines
17 from CommonClearCase import CommonClearCase
18 from CommonReportUsage import CommonReportUsage
19 from CommonWriteAllTrigger import CommonWriteAllTrigger
20 from CommonLibFunctionTrigger import CommonLibFunctionTrigger
21 from CommonStandardOutput import CommonStandardOutput
22 from CommonParallel import CommonParallel
23 from CommonRestart import CommonRestart
24 from CommonServer import CommonServer
25 from CommonVCSCommit import CommonVCSCommit
26
27 from os import path
28
29 -class Runner(PyFoamApplication,
30 CommonPlotLines,
31 CommonWriteAllTrigger,
32 CommonLibFunctionTrigger,
33 CommonClearCase,
34 CommonRestart,
35 CommonReportUsage,
36 CommonMultiRegion,
37 CommonParallel,
38 CommonServer,
39 CommonStandardOutput,
40 CommonVCSCommit):
42 description="""
43 Runs an OpenFoam solver. Needs the usual 3 arguments (<solver>
44 <directory> <case>) and passes them on (plus additional arguments).
45 Output is sent to stdout and a logfile inside the case directory
46 (PyFoamSolver.logfile) The Directory PyFoamSolver.analyzed contains
47 this information: a) Residuals and other information of the linear
48 solvers b Execution time c) continuity information d) bounding of
49 variables
50 """
51
52 CommonPlotLines.__init__(self)
53 PyFoamApplication.__init__(self,
54 exactNr=False,
55 args=args,
56 description=description)
57
70
72 if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None):
73 warning("Option --keep-pseudocases only makes sense for multi-region-cases")
74 regionNames=[self.opts.region]
75 regions=None
76
77 casePath=self.parser.casePath()
78 self.checkCase(casePath)
79 self.addLocalConfig(casePath)
80
81 self.addToCaseLog(casePath,"Starting")
82
83 if self.opts.regions or self.opts.region!=None:
84 print "Building Pseudocases"
85 sol=SolutionDirectory(casePath,archive=None)
86 regions=RegionCases(sol,clean=True)
87
88 if self.opts.regions:
89 regionNames=sol.getRegions()
90
91 self.processPlotLineOptions(autoPath=casePath)
92
93 self.clearCase(SolutionDirectory(casePath,archive=None))
94
95 lam=self.getParallel(SolutionDirectory(casePath,archive=None))
96
97 self.checkAndCommit(SolutionDirectory(casePath,archive=None))
98
99 for theRegion in regionNames:
100 args=self.buildRegionArgv(casePath,theRegion)
101 self.setLogname()
102 run=AnalyzedRunner(BoundingLogAnalyzer(progress=self.opts.progress,
103 doFiles=self.opts.writeFiles,
104 singleFile=self.opts.singleDataFilesOnly,
105 doTimelines=True),
106 silent=self.opts.progress,
107 argv=args,
108 server=self.opts.server,
109 lam=lam,
110 restart=self.opts.restart,
111 logname=self.opts.logname,
112 compressLog=self.opts.compress,
113 noLog=self.opts.noLog,
114 remark=self.opts.remark,
115 jobId=self.opts.jobId)
116
117 run.createPlots(customRegexp=self.lines_,
118 writeFiles=self.opts.writeFiles)
119
120 self.addWriteAllTrigger(run,SolutionDirectory(casePath,archive=None))
121 self.addLibFunctionTrigger(run,SolutionDirectory(casePath,archive=None))
122
123 run.start()
124
125 self.reportUsage(run)
126
127 if theRegion!=None:
128 print "Syncing into master case"
129 regions.resync(theRegion)
130
131
132 if regions!=None:
133 if not self.opts.keeppseudo:
134 print "Removing pseudo-regions"
135 regions.cleanAll()
136 else:
137 for r in sol.getRegions():
138 if r not in regionNames:
139 regions.clean(r)
140
141 self.addToCaseLog(casePath,"Ended")
142