Package PyFoam :: Package RunDictionary :: Module MeshInformation
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.RunDictionary.MeshInformation

 1  """Gets information about the mesh of a case. Makes no attempt to manipulate 
 2  the mesh, because this is better left to the OpenFOAM-utilities""" 
 3   
 4  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
 5  from PyFoam.RunDictionary.ListFile import ListFile 
 6  from PyFoam.Error import PyFoamException 
 7  from PyFoam.RunDictionary.ParsedParameterFile import ParsedFileHeader 
 8   
 9  from os import path 
10  import re 
11   
12 -class MeshInformation:
13 """Reads Information about the mesh on demand""" 14
15 - def __init__(self, 16 case, 17 time="constant", 18 processor=None, 19 region=None):
20 """@param case: Path to the case-directory 21 @param time: Time for which the mesh should be looked at 22 @param processor: Name of the processor directory for decomposed cases""" 23 self.sol=SolutionDirectory(case,paraviewLink=False,archive=None,region=region) 24 self.time=time 25 self.processor=processor
26
27 - def nrOfFaces(self):
28 try: 29 return self.faces 30 except AttributeError: 31 try: 32 faces=ListFile(self.sol.polyMeshDir(time=self.time,processor=self.processor),"faces") 33 self.faces=faces.getSize() 34 except IOError: 35 faces=ListFile(self.sol.polyMeshDir(processor=self.processor),"faces") 36 self.faces=faces.getSize() 37 38 return self.faces
39
40 - def nrOfPoints(self):
41 try: 42 return self.points 43 except AttributeError: 44 try: 45 points=ListFile(self.sol.polyMeshDir(time=self.time,processor=self.processor),"points") 46 self.points=points.getSize() 47 except IOError: 48 points=ListFile(self.sol.polyMeshDir(processor=self.processor),"points") 49 self.points=points.getSize() 50 51 return self.points
52
53 - def nrOfCells(self):
54 try: 55 return self.cells 56 except: 57 try: 58 try: 59 owner=ParsedFileHeader(path.join(self.sol.polyMeshDir(time=self.time,processor=self.processor),"owner")) 60 except IOError: 61 owner=ParsedFileHeader(path.join(self.sol.polyMeshDir(processor=self.processor),"owner")) 62 63 mat=re.compile('.+nCells: *([0-9]+) .+').match(owner["note"]) 64 self.cells=int(mat.group(1)) 65 return self.cells 66 except: 67 raise PyFoamException("Not Implemented")
68