Package PyFoam :: Package Applications :: Module MeshUtilityRunner
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.MeshUtilityRunner

 1  #  ICE Revision: $Id$ 
 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  from PyFoam.ThirdParty.six import print_ 
18   
19 -class MeshUtilityRunner(PyFoamApplication, 20 CommonServer, 21 CommonLibFunctionTrigger, 22 CommonVCSCommit):
23 - def __init__(self, 24 args=None, 25 **kwargs):
26 description="""\ 27 Runs an OpenFoam utility that manipulates meshes. Needs the usual 3 28 arguments (<solver> <directory> <case>) and passes them on (plus 29 additional arguments). 30 31 Output is sent to stdout and a logfile inside the case directory 32 (PyFoamMeshUtility.logfile) 33 34 Before running it clears all timesteps but the first. 35 36 After the utility ran it moves all the data from the 37 polyMesh-directory of the first time-step to the 38 constant/polyMesh-directory 39 40 ATTENTION: This utility erases quite a lot of data without asking and 41 should therefor be used with care 42 """ 43 44 PyFoamApplication.__init__(self, 45 exactNr=False, 46 args=args, 47 description=description, 48 **kwargs)
49
50 - def addOptions(self):
54
55 - def run(self):
56 cName=self.parser.casePath() 57 58 self.checkCase(cName) 59 60 sol=SolutionDirectory(cName,archive=None) 61 62 print_("Clearing out old timesteps ....") 63 64 sol.clearResults() 65 66 self.checkAndCommit(SolutionDirectory(cName,archive=None)) 67 68 run=BasicRunner(argv=self.parser.getArgs(), 69 server=self.opts.server, 70 logname="PyFoamMeshUtility") 71 72 self.addLibFunctionTrigger(run,sol) 73 74 self.addToCaseLog(cName,"Starting") 75 76 run.start() 77 78 self.setData(run.data) 79 80 sol.reread(force=True) 81 82 self.addToCaseLog(cName,"Ending") 83 84 if sol.latestDir()!=sol.initialDir(): 85 for f in listdir(path.join(sol.latestDir(),"polyMesh")): 86 system("mv -f "+path.join(sol.latestDir(),"polyMesh",f)+" "+sol.polyMeshDir()) 87 88 print_("\nClearing out new timesteps ....") 89 90 sol.clearResults() 91 else: 92 print_("\n\n No new timestep. Utility propably failed")
93 94 # Should work with Python3 and Python2 95