1
2 """
3 Class that implements pyFoamPlotRunner
4 """
5
6 from PyFoamApplication import PyFoamApplication
7
8 from PyFoam.FoamInformation import changeFoamVersion
9
10 from PyFoam.Execution.GnuplotRunner import GnuplotRunner
11
12 from PyFoam.Execution.ParallelExecution import LAMMachine
13
14 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
15
16 from PyFoam.Error import warning
17
18 from CommonPlotLines import CommonPlotLines
19 from CommonPlotOptions import CommonPlotOptions
20 from CommonClearCase import CommonClearCase
21 from CommonSafeTrigger import CommonSafeTrigger
22 from CommonWriteAllTrigger import CommonWriteAllTrigger
23
24 from os import path
25
26 -class PlotRunner(PyFoamApplication,
27 CommonPlotOptions,
28 CommonPlotLines,
29 CommonSafeTrigger,
30 CommonWriteAllTrigger,
31 CommonClearCase):
33 description="""
34 runs an OpenFoam solver needs the usual 3 arguments (<solver>
35 <directory> <case>) and passes them on (plus additional arguments).
36 Output is sent to stdout and a logfile inside the case directory
37 (PyFoamSolver.logfile) Information about the residuals is output as
38 graphs
39
40 If the directory contains a file customRegexp this is automatically
41 read and the regular expressions in it are displayed
42 """
43 CommonPlotOptions.__init__(self,persist=True)
44 CommonPlotLines.__init__(self)
45 PyFoamApplication.__init__(self,
46 exactNr=False,
47 args=args,
48 description=description)
49
51 CommonPlotOptions.addOptions(self)
52
53 self.parser.add_option("--procnr",
54 type="int",
55 dest="procnr",
56 default=None,
57 help="The number of processors the run should be started on")
58
59 self.parser.add_option("--machinefile",
60 dest="machinefile",
61 default=None,
62 help="The machinefile that specifies the parallel machine")
63
64 self.parser.add_option("--steady-run",
65 action="store_true",
66 default=False,
67 dest="steady",
68 help="This is a steady run. Stop it after convergence")
69
70 self.parser.add_option("--restart",
71 action="store_true",
72 default=False,
73 dest="restart",
74 help="Restart the simulation from the last time-step")
75
76 self.parser.add_option("--progress",
77 action="store_true",
78 default=False,
79 dest="progress",
80 help="Only prints the progress of the simulation, but swallows all the other output")
81
82 self.parser.add_option("--foamVersion",
83 dest="foamVersion",
84 default=None,
85 help="Change the OpenFOAM-version that is to be used")
86
87 self.parser.add_option("--report-usage",
88 action="store_true",
89 default=False,
90 dest="reportUsage",
91 help="After the execution the maximum memory usage is printed to the screen")
92
93 CommonPlotLines.addOptions(self)
94 CommonClearCase.addOptions(self)
95 CommonSafeTrigger.addOptions(self)
96 CommonWriteAllTrigger.addOptions(self)
97
99 if self.opts.foamVersion!=None:
100 changeFoamVersion(self.opts.foamVersion)
101
102 self.processPlotOptions()
103
104 self.processPlotLineOptions(autoPath=path.join(self.parser.getArgs()[1],self.parser.getArgs()[2]))
105
106 cName=self.parser.getArgs()[2]
107 sol=SolutionDirectory(cName,archive=None)
108
109 self.clearCase(sol)
110
111 lam=None
112 if self.opts.procnr!=None or self.opts.machinefile!=None:
113 lam=LAMMachine(machines=self.opts.machinefile,nr=self.opts.procnr)
114
115 run=GnuplotRunner(argv=self.parser.getArgs(),
116 smallestFreq=self.opts.frequency,
117 persist=self.opts.persist,
118 plotLinear=self.opts.linear,
119 plotCont=self.opts.cont,
120 plotBound=self.opts.bound,
121 plotIterations=self.opts.iterations,
122 plotCourant=self.opts.courant,
123 plotExecution=self.opts.execution,
124 plotDeltaT=self.opts.deltaT,
125 customRegexp=self.plotLines(),
126 writeFiles=self.opts.writeFiles,
127 server=True,
128 lam=lam,
129 raiseit=self.opts.raiseit,
130 steady=self.opts.steady,
131 progress=self.opts.progress,
132 restart=self.opts.restart)
133
134 self.addSafeTrigger(run,sol,steady=self.opts.steady)
135 self.addWriteAllTrigger(run,sol)
136
137 run.start()
138
139 if self.opts.reportUsage:
140 print "\n Used Memory: ",run.run.usedMemory(),"MB"
141