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