1 | |
---|
2 | import Numeric |
---|
3 | import math |
---|
4 | # add inundation dir to your pythonpath |
---|
5 | from pmesh.mesh import Mesh |
---|
6 | from coordinate_transforms.geo_reference import Geo_reference |
---|
7 | |
---|
8 | |
---|
9 | def create_mesh(maximum_triangle_area, |
---|
10 | mesh_file=None, |
---|
11 | triangles_in_name = False): |
---|
12 | """ |
---|
13 | triangles_in_name, if True is used to append the number of |
---|
14 | triangles in the mesh to the mesh file name. |
---|
15 | """ |
---|
16 | # create a mesh instance of class Mesh |
---|
17 | m = Mesh() |
---|
18 | |
---|
19 | # Boundary of problem |
---|
20 | WidtH = 100 # width of boudary in metres |
---|
21 | #W = WidtH/8 |
---|
22 | #L = W |
---|
23 | outer_polygon = [[0,0],[1.5*WidtH,0],[1.5*WidtH,WidtH],[0,WidtH]] |
---|
24 | print outer_polygon |
---|
25 | m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]}) |
---|
26 | |
---|
27 | # inner polygons => building boundaries |
---|
28 | depth = 15 # depth of building side to oncoming wave |
---|
29 | whs = depth/2 |
---|
30 | breadth = 20 # breadth of building |
---|
31 | lhs = breadth/2 |
---|
32 | |
---|
33 | # Sample rotation Matrix |
---|
34 | Thd = 30 # Degrees |
---|
35 | Th = Thd * 3.14259/180 # Deg to Rad. |
---|
36 | |
---|
37 | wh1 = (-whs) * math.cos(Th) + (-lhs) * math.sin(Th) |
---|
38 | lh1 = (-lhs) * math.cos(Th) - (-whs) * math.sin(Th) |
---|
39 | |
---|
40 | wh2 = (+whs) * math.cos(Th) + (-lhs) * math.sin(Th) |
---|
41 | lh2 = (-lhs) * math.cos(Th) - (+whs) * math.sin(Th) |
---|
42 | |
---|
43 | wh3 = (+whs) * math.cos(Th) + (+lhs) * math.sin(Th) |
---|
44 | lh3 = (+lhs) * math.cos(Th) - (+whs) * math.sin(Th) |
---|
45 | |
---|
46 | wh4 = (-whs) * math.cos(Th) + (+lhs) * math.sin(Th) |
---|
47 | lh4 = (+lhs) * math.cos(Th) - (-whs) * math.sin(Th) |
---|
48 | |
---|
49 | print "building footprint" |
---|
50 | print depth * breadth , "m^2" |
---|
51 | block = 625 |
---|
52 | BL = block**0.5 |
---|
53 | ForDep = (0.2*WidtH) + (BL/2) |
---|
54 | RearDep = 1.2*WidtH |
---|
55 | porosity = breadth/BL |
---|
56 | print porosity, " Building porosity" |
---|
57 | |
---|
58 | Breadths = Numeric.arrayrange( (BL/2), WidtH, (BL)) |
---|
59 | print Breadths, "Breadths" |
---|
60 | Depths = Numeric.arrayrange( ForDep, RearDep, BL ) |
---|
61 | print Depths, "Depths" |
---|
62 | |
---|
63 | for D in Depths: |
---|
64 | #Breadths = Breadths + BL/2 |
---|
65 | for B in Breadths: |
---|
66 | polygon = [[D+wh1,B+lh1],[D+wh2,B+lh2],[D+wh3,B+lh3],[D+wh4,B+lh4]] |
---|
67 | m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. |
---|
68 | |
---|
69 | |
---|
70 | #print polygon |
---|
71 | m.generate_mesh(maximum_triangle_area=maximum_triangle_area) |
---|
72 | triangle_count = m.get_triangle_count() |
---|
73 | |
---|
74 | if mesh_file is None: |
---|
75 | return m, triangle_count |
---|
76 | else: |
---|
77 | if triangles_in_name is True: |
---|
78 | mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ |
---|
79 | + mesh_file[-4:] |
---|
80 | m.export_mesh_file(mesh_file) |
---|
81 | return mesh_file, triangle_count |
---|
82 | |
---|
83 | #------------------------------------------------------------- |
---|
84 | if __name__ == "__main__": |
---|
85 | _, triangle_count = create_mesh(10,mesh_file="test.tsh") |
---|
86 | print "triangle_count",triangle_count |
---|