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