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
26 from os import path
27
28 -class Runner(PyFoamApplication,
29 CommonPlotLines,
30 CommonWriteAllTrigger,
31 CommonLibFunctionTrigger,
32 CommonClearCase,
33 CommonRestart,
34 CommonReportUsage,
35 CommonMultiRegion,
36 CommonParallel,
37 CommonServer,
38 CommonStandardOutput):
40 description="""
41 Runs an OpenFoam solver. Needs the usual 3 arguments (<solver>
42 <directory> <case>) and passes them on (plus additional arguments).
43 Output is sent to stdout and a logfile inside the case directory
44 (PyFoamSolver.logfile) The Directory PyFoamSolver.analyzed contains
45 this information: a) Residuals and other information of the linear
46 solvers b Execution time c) continuity information d) bounding of
47 variables
48 """
49
50 CommonPlotLines.__init__(self)
51 PyFoamApplication.__init__(self,
52 exactNr=False,
53 args=args,
54 description=description)
55
67
69 if self.opts.keeppseudo and (not self.opts.regions and self.opts.region==None):
70 warning("Option --keep-pseudocases only makes sense for multi-region-cases")
71 regionNames=[self.opts.region]
72 regions=None
73
74 casePath=self.parser.casePath()
75 self.checkCase(casePath)
76
77 if self.opts.regions or self.opts.region!=None:
78 print "Building Pseudocases"
79 sol=SolutionDirectory(casePath,archive=None)
80 regions=RegionCases(sol,clean=True)
81
82 if self.opts.regions:
83 regionNames=sol.getRegions()
84
85 self.processPlotLineOptions(autoPath=casePath)
86
87 self.clearCase(SolutionDirectory(casePath,archive=None))
88
89 lam=self.getParallel()
90
91 for theRegion in regionNames:
92 args=self.buildRegionArgv(casePath,theRegion)
93 self.setLogname()
94 run=AnalyzedRunner(BoundingLogAnalyzer(progress=self.opts.progress),
95 silent=self.opts.progress,
96 argv=args,
97 server=self.opts.server,
98 lam=lam,
99 restart=self.opts.restart,
100 logname=self.opts.logname,
101 noLog=self.opts.noLog)
102
103 self.addPlotLineAnalyzers(run)
104
105 self.addWriteAllTrigger(run,SolutionDirectory(casePath,archive=None))
106 self.addLibFunctionTrigger(run,SolutionDirectory(casePath,archive=None))
107
108 run.start()
109
110 self.reportUsage(run)
111
112 if theRegion!=None:
113 print "Syncing into master case"
114 regions.resync(theRegion)
115
116
117 if regions!=None:
118 if not self.opts.keeppseudo:
119 print "Removing pseudo-regions"
120 regions.cleanAll()
121 else:
122 for r in sol.getRegions():
123 if r not in regionNames:
124 regions.clean(r)
125