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):
20
22 return float(self["convertToMeters"])
23
25 factor=self.convertToMeters()
26 return map(lambda x:map(lambda y:float(y)*factor,x),self["vertices"])
27
29 """Returns a list with the 8 vertices that define each block"""
30 result=[]
31 i=1
32 while i<len(self["blocks"]):
33 result.append(map(int,self["blocks"][i]))
34 if type(self["blocks"][i+1])==str:
35 i+=6
36 else:
37 i+=5
38
39 return result
40
42 """Returns a dictionary with lists of 4-tuples that define each patch"""
43 result={}
44 if "boundary" in self:
45
46 for k,d in zip(self["boundary"][0::2],self["boundary"][1::2]):
47 result[k]=map(lambda x:map(int,x),d["faces"])
48 else:
49 for i in range(1,len(self["patches"]),3):
50 result[self["patches"][i]]=map(lambda x:map(int,x),self["patches"][i+1])
51
52 return result
53
55 factor=self.convertToMeters()
56 result=[]
57 try:
58 for i in range(len(self["edges"])):
59 if str(self["edges"][i])=='arc':
60 result.append((int(self["edges"][i+1]),
61 map(lambda y:float(y)*factor,self["edges"][i+3]),
62 int(self["edges"][i+2])))
63 except KeyError:
64 pass
65
66 return result
67
69 v=self.vertices()
70 mi=[ 1e10, 1e10, 1e10]
71 ma=[-1e10,-1e10,-1e10]
72 for p in v:
73 for i in range(3):
74 mi[i]=min(p[i],mi[i])
75 ma[i]=max(p[i],ma[i])
76 return mi,ma
77
79 mi,ma=self.getBounds()
80
81 biggest=max(ma[0]-mi[0],ma[1]-mi[1],ma[2]-mi[2])
82 smallest=min(ma[0]-mi[0],ma[1]-mi[1],ma[2]-mi[2])
83
84
85 return (biggest+smallest)/2
86