1
2 """
3 Application class that implements pyFoamMeshUtilityRunner
4 """
5
6 from os import listdir,path,system
7
8 from PyFoamApplication import PyFoamApplication
9
10 from PyFoam.Execution.BasicRunner import BasicRunner
11 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
12
13 from CommonLibFunctionTrigger import CommonLibFunctionTrigger
14 from CommonServer import CommonServer
15 from CommonVCSCommit import CommonVCSCommit
16
17 -class MeshUtilityRunner(PyFoamApplication,
18 CommonServer,
19 CommonLibFunctionTrigger,
20 CommonVCSCommit):
22 description="""\
23 Runs an OpenFoam utility that manipulates meshes. Needs the usual 3
24 arguments (<solver> <directory> <case>) and passes them on (plus
25 additional arguments).
26
27 Output is sent to stdout and a logfile inside the case directory
28 (PyFoamMeshUtility.logfile)
29
30 Before running it clears all timesteps but the first.
31
32 After the utility ran it moves all the data from the
33 polyMesh-directory of the first time-step to the
34 constant/polyMesh-directory
35
36 ATTENTION: This utility erases quite a lot of data without asking and
37 should therefor be used with care
38 """
39
40 PyFoamApplication.__init__(self,
41 exactNr=False,
42 args=args,
43 description=description)
44
49
51 cName=self.parser.casePath()
52
53 self.checkCase(cName)
54
55 sol=SolutionDirectory(cName,archive=None)
56
57 print "Clearing out old timesteps ...."
58
59 sol.clearResults()
60
61 self.checkAndCommit(SolutionDirectory(cName,archive=None))
62
63 run=BasicRunner(argv=self.parser.getArgs(),
64 server=self.opts.server,
65 logname="PyFoamMeshUtility")
66
67 self.addLibFunctionTrigger(run,sol)
68
69 self.addToCaseLog(cName,"Starting")
70
71 run.start()
72
73 self.setData(run.data)
74
75 sol.reread(force=True)
76
77 self.addToCaseLog(cName,"Ending")
78
79 if sol.latestDir()!=sol.initialDir():
80 for f in listdir(path.join(sol.latestDir(),"polyMesh")):
81 system("mv -f "+path.join(sol.latestDir(),"polyMesh",f)+" "+sol.polyMeshDir())
82
83 print "\nClearing out new timesteps ...."
84
85 sol.clearResults()
86 else:
87 print "\n\n No new timestep. Utility propably failed"
88