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 = 200 # width of boudary in metres |
---|
21 | #W = WidtH/8 |
---|
22 | #L = W |
---|
23 | outer_polygon = [[0,0],[5*WidtH,0],[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 = 20 # depth of building side to oncoming wave |
---|
29 | wh = depth/2 |
---|
30 | breadth = 20 # breadth of building |
---|
31 | lh = breadth/2 |
---|
32 | |
---|
33 | print "building footprint" |
---|
34 | print depth * breadth , "m^2" |
---|
35 | block = 625 |
---|
36 | BL = block**0.5 |
---|
37 | ForDep = (0.2*WidtH) + (BL/2) |
---|
38 | RearDep = 1.2*WidtH |
---|
39 | porosity = breadth/BL |
---|
40 | print porosity, " Building porosity" |
---|
41 | |
---|
42 | Breadths = Numeric.arrayrange( (BL/2), WidtH, (BL)) |
---|
43 | print Breadths, "Breadths" |
---|
44 | Depths = Numeric.arrayrange( ForDep, RearDep, BL ) |
---|
45 | print Depths, "Depths" |
---|
46 | |
---|
47 | for D in Depths: |
---|
48 | #Breadths = Breadths + BL/2 #Used to offset buildings |
---|
49 | for B in Breadths: |
---|
50 | polygon = [[D-wh,B-lh],[D+wh,B-lh],[D+wh,B+lh],[D-wh,B+lh]] |
---|
51 | m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. |
---|
52 | |
---|
53 | |
---|
54 | #print polygon |
---|
55 | m.generate_mesh(maximum_triangle_area=maximum_triangle_area) |
---|
56 | triangle_count = m.get_triangle_count() |
---|
57 | |
---|
58 | if mesh_file is None: |
---|
59 | return m, triangle_count |
---|
60 | else: |
---|
61 | if triangles_in_name is True: |
---|
62 | mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ |
---|
63 | + mesh_file[-4:] |
---|
64 | m.export_mesh_file(mesh_file) |
---|
65 | return mesh_file, triangle_count |
---|
66 | |
---|
67 | #------------------------------------------------------------- |
---|
68 | if __name__ == "__main__": |
---|
69 | _, triangle_count = create_mesh(10,mesh_file="test.tsh") |
---|
70 | print "triangle_count",triangle_count |
---|