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