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 7660 2012-01-07T16:44:40.128256Z 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 21 paraview-State-File modifieing the state-File in such a way that it is 22 usable with the case 23 24 The state-file can be generated using a different case (the script 25 adjusts it before using) but the original case has to have a similar 26 structure to the current one. Also exactly one PV3Reader has to be 27 used in the state-file (this requirement is fullfilled if the 28 StateFile was generated using paraFoam) 29 """ 30 PyFoamApplication.__init__(self, 31 args=args, 32 description=description, 33 usage="%prog [options] <case>", 34 interspersed=True, 35 nr=1)
36
37 - def addOptions(self):
38 paraview=OptionGroup(self.parser, 39 "Paraview specifications", 40 "Options concerning paraview") 41 paraview.add_option("--state-file", 42 dest="state", 43 default=None, 44 help="The pvsm-file that should be used. If none is specified the file 'default.pvsm' in the case-directory is used") 45 46 paraview.add_option("--paraview-command", 47 dest="paraview", 48 default="paraview", 49 help="The paraview-version that should be called. Default: %default") 50 self.parser.add_option_group(paraview)
51
52 - def run(self):
53 case=path.abspath(self.parser.getArgs()[0]) 54 short=path.basename(case) 55 56 if self.opts.state==None: 57 self.opts.state=path.join(case,"default.pvsm") 58 59 if not path.exists(self.opts.state): 60 self.error("The state file",self.opts.state,"does not exist") 61 62 sol=SolutionDirectory(case,paraviewLink=False,archive=None) 63 64 dataFile=path.join(case,short+".OpenFOAM") 65 66 createdDataFile=False 67 if not path.exists(dataFile): 68 createdDataFile=True 69 f=open(dataFile,"w") 70 f.close() 71 72 sf=StateFile(self.opts.state) 73 sf.setCase(dataFile) 74 newState=sf.writeTemp() 75 76 system(self.opts.paraview+" --state="+newState) 77 78 if createdDataFile: 79 self.warning("Removing pseudo-data-file",dataFile) 80 unlink(dataFile)
81