1
2 """A parsed blockMeshDict"""
3
4 from ParsedParameterFile import ParsedParameterFile
5
7 """ A parsed version of a blockMeshDict-file. Adds some
8 convenience-methods to access parts of the file"""
9
10 - def __init__(self,
11 name,
12 backup=False,
13 debug=False,
14 doMacroExpansion=False):
21
23 return float(self["convertToMeters"])
24
26 factor=self.convertToMeters()
27 return map(lambda x:map(lambda y:float(y)*factor,x),self["vertices"])
28
30 """Returns a list with the 8 vertices that define each block"""
31 result=[]
32 i=1
33 while i<len(self["blocks"]):
34 result.append(map(int,self["blocks"][i]))
35 if type(self["blocks"][i+1])==str:
36 i+=6
37 else:
38 i+=5
39
40 return result
41
43 """Returns a dictionary with lists of 4-tuples that define each patch"""
44 result={}
45 if "boundary" in self:
46
47 for k,d in zip(self["boundary"][0::2],self["boundary"][1::2]):
48 result[k]=map(lambda x:map(int,x),d["faces"])
49 else:
50 for i in range(1,len(self["patches"]),3):
51 result[self["patches"][i]]=map(lambda x:map(int,x),self["patches"][i+1])
52
53 return result
54
56 factor=self.convertToMeters()
57 result=[]
58 try:
59 for i in range(len(self["edges"])):
60 if str(self["edges"][i])=='arc':
61 result.append((int(self["edges"][i+1]),
62 map(lambda y:float(y)*factor,self["edges"][i+3]),
63 int(self["edges"][i+2])))
64 except KeyError:
65 pass
66
67 return result
68
70 v=self.vertices()
71 mi=[ 1e10, 1e10, 1e10]
72 ma=[-1e10,-1e10,-1e10]
73 for p in v:
74 for i in range(3):
75 mi[i]=min(p[i],mi[i])
76 ma[i]=max(p[i],ma[i])
77 return mi,ma
78
80 mi,ma=self.getBounds()
81
82 biggest=max(ma[0]-mi[0],ma[1]-mi[1],ma[2]-mi[2])
83 smallest=min(ma[0]-mi[0],ma[1]-mi[1],ma[2]-mi[2])
84
85
86 return (biggest+smallest)/2
87