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
14
15 from .CommonMultiRegion import CommonMultiRegion
16 from .CommonPlotLines import CommonPlotLines
17 from .CommonClearCase import CommonClearCase
18 from .CommonReportUsage import CommonReportUsage
19 from .CommonReportRunnerData import CommonReportRunnerData
20 from .CommonWriteAllTrigger import CommonWriteAllTrigger
21 from .CommonLibFunctionTrigger import CommonLibFunctionTrigger
22 from .CommonStandardOutput import CommonStandardOutput
23 from .CommonParallel import CommonParallel
24 from .CommonRestart import CommonRestart
25 from .CommonServer import CommonServer
26 from .CommonVCSCommit import CommonVCSCommit
27 from .CommonPrePostHooks import CommonPrePostHooks
28
29 from PyFoam.ThirdParty.six import print_
30
31 -class Runner(PyFoamApplication,
32 CommonPlotLines,
33 CommonWriteAllTrigger,
34 CommonLibFunctionTrigger,
35 CommonClearCase,
36 CommonRestart,
37 CommonReportUsage,
38 CommonReportRunnerData,
39 CommonMultiRegion,
40 CommonParallel,
41 CommonServer,
42 CommonStandardOutput,
43 CommonVCSCommit,
44 CommonPrePostHooks):
45 - def __init__(self,
46 args=None,
47 **kwargs):
48 description="""\
49 Runs an OpenFoam solver. Needs the usual 3 arguments (<solver>
50 <directory> <case>) and passes them on (plus additional arguments).
51 Output is sent to stdout and a logfile inside the case directory
52 (PyFoamSolver.logfile) The Directory PyFoamSolver.analyzed contains
53 this information: a) Residuals and other information of the linear
54 solvers b Execution time c) continuity information d) bounding of
55 variables
56 """
57
58 CommonPlotLines.__init__(self)
59 PyFoamApplication.__init__(self,
60 exactNr=False,
61 args=args,
62 description=description,
63 **kwargs)
64
79
81 if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None):
82 warning("Option --keep-pseudocases only makes sense for multi-region-cases")
83
84 if self.opts.region:
85 regionNames=self.opts.region
86 else:
87 regionNames=[None]
88
89 regions=None
90
91 casePath=self.parser.casePath()
92 self.checkCase(casePath)
93 self.addLocalConfig(casePath)
94
95 self.addToCaseLog(casePath,"Starting")
96 self.prepareHooks()
97
98 if self.opts.regions or self.opts.region!=None:
99 print_("Building Pseudocases")
100 sol=SolutionDirectory(casePath,archive=None)
101 regions=RegionCases(sol,clean=True)
102
103 if self.opts.regions:
104 regionNames=sol.getRegions()
105
106 self.processPlotLineOptions(autoPath=casePath)
107
108 self.clearCase(SolutionDirectory(casePath,archive=None))
109
110 lam=self.getParallel(SolutionDirectory(casePath,archive=None))
111
112 self.checkAndCommit(SolutionDirectory(casePath,archive=None))
113
114 for theRegion in regionNames:
115 args=self.buildRegionArgv(casePath,theRegion)
116 self.setLogname()
117 run=AnalyzedRunner(BoundingLogAnalyzer(progress=self.opts.progress,
118 doFiles=self.opts.writeFiles,
119 singleFile=self.opts.singleDataFilesOnly,
120 doTimelines=True),
121 silent=self.opts.progress or self.opts.silent,
122 argv=args,
123 server=self.opts.server,
124 lam=lam,
125 restart=self.opts.restart,
126 logname=self.opts.logname,
127 compressLog=self.opts.compress,
128 logTail=self.opts.logTail,
129 noLog=self.opts.noLog,
130 remark=self.opts.remark,
131 parameters=self.getRunParameters(),
132 echoCommandLine=self.opts.echoCommandPrefix,
133 jobId=self.opts.jobId)
134
135 run.createPlots(customRegexp=self.lines_,
136 writeFiles=self.opts.writeFiles)
137
138 self.addWriteAllTrigger(run,SolutionDirectory(casePath,archive=None))
139 self.addLibFunctionTrigger(run,SolutionDirectory(casePath,archive=None))
140 self.runPreHooks()
141
142 run.start()
143
144 if len(regionNames)>1:
145 self.setData({theRegion:run.data})
146 else:
147 self.setData(run.data)
148
149 self.runPostHooks()
150
151 self.reportUsage(run)
152 self.reportRunnerData(run)
153
154 if theRegion!=None:
155 print_("Syncing into master case")
156 regions.resync(theRegion)
157
158 if regions!=None:
159 if not self.opts.keeppseudo:
160 print_("Removing pseudo-regions")
161 regions.cleanAll()
162 else:
163 for r in sol.getRegions():
164 if r not in regionNames:
165 regions.clean(r)
166
167 self.addToCaseLog(casePath,"Ended")
168
169
170