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