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

Source Code for Module PyFoam.Applications.PVLoadState

 1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Applications/PVLoadState.py 4474 2009-01-30T13:01:26.935403Z bgschaid  $  
 2  """ 
 3  Class that implements pyFoamPVLoadState 
 4  """ 
 5   
 6  from optparse import OptionGroup 
 7   
 8  from PyFoamApplication import PyFoamApplication 
 9   
10  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
11  from PyFoam.Paraview.ServermanagerWrapper import ServermanagerWrapper as SM 
12  from PyFoam.Paraview.StateFile import StateFile 
13   
14  from os import path,unlink,system 
15  import sys,string 
16   
17 -class PVLoadState(PyFoamApplication):
18 - def __init__(self,args=None):
19 description=""" 20 Starts paraview with an OpenFOAM-case and a predefined paraview-State-File 21 modifieing the state-File in such a way that it is usable with the case 22 23 The state-file can be generated using a different case (the script adjusts 24 it before using) but the original case has to have a similar structure to the 25 current one. Also exactly one PV3Reader has to be used in the state-file (this 26 requirement is fullfilled if the StateFile was generated using paraFoam) 27 """ 28 PyFoamApplication.__init__(self, 29 args=args, 30 description=description, 31 usage="%prog [options] <case>", 32 interspersed=True, 33 nr=1)
34
35 - def addOptions(self):
36 paraview=OptionGroup(self.parser, 37 "Paraview specifications", 38 "Options concerning paraview") 39 paraview.add_option("--state-file", 40 dest="state", 41 default=None, 42 help="The pvsm-file that should be used. If none is specified the file 'default.pvsm' in the case-directory is used") 43 44 paraview.add_option("--paraview-command", 45 dest="paraview", 46 default="paraview", 47 help="The paraview-version that should be called. Default: %default") 48 self.parser.add_option_group(paraview)
49
50 - def run(self):
51 case=path.abspath(self.parser.getArgs()[0]) 52 short=path.basename(case) 53 54 if self.opts.state==None: 55 self.opts.state=path.join(case,"default.pvsm") 56 57 if not path.exists(self.opts.state): 58 self.error("The state file",self.opts.state,"does not exist") 59 60 sol=SolutionDirectory(case,paraviewLink=False,archive=None) 61 62 dataFile=path.join(case,short+".OpenFOAM") 63 64 createdDataFile=False 65 if not path.exists(dataFile): 66 createdDataFile=True 67 f=open(dataFile,"w") 68 f.close() 69 70 sf=StateFile(self.opts.state) 71 sf.setCase(dataFile) 72 newState=sf.writeTemp() 73 74 system(self.opts.paraview+" --state="+newState) 75 76 if createdDataFile: 77 self.warning("Removing pseudo-data-file",dataFile) 78 unlink(dataFile)
79