[2927] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
| 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],[WidtH,0],[WidtH,WidtH],[0,WidtH]] |
---|
| 24 | m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]}) |
---|
| 25 | |
---|
| 26 | # inner polygons => building boundaries |
---|
| 27 | width = 15 |
---|
| 28 | wh = width/2 |
---|
| 29 | length = 15 |
---|
| 30 | lh = length/2 |
---|
| 31 | Wm = [12.5,37.5,62.5,87.5] |
---|
| 32 | Lm = [12.5,37.5,62.5,87.5] |
---|
| 33 | |
---|
| 34 | for W in Wm: |
---|
| 35 | polygon = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]] |
---|
| 36 | m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. |
---|
| 37 | |
---|
| 38 | for L in Lm: |
---|
| 39 | polygon1 = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]] |
---|
| 40 | m.add_hole_from_polygon(polygon1, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | #polygon = [[10,10],[20,10],[20,20],[10,20]] |
---|
| 44 | #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) |
---|
| 45 | |
---|
| 46 | #polygon = [[40,40],[50,40],[50,50],[40,50]] |
---|
| 47 | #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) |
---|
| 48 | |
---|
| 49 | #m.add_circle([20,70], 5, hole=True, tag='wall') |
---|
| 50 | m.generate_mesh(maximum_triangle_area=maximum_triangle_area) |
---|
| 51 | triangle_count = m.get_triangle_count() |
---|
| 52 | |
---|
| 53 | if mesh_file is None: |
---|
| 54 | return m, triangle_count |
---|
| 55 | else: |
---|
| 56 | if triangles_in_name is True: |
---|
| 57 | mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ |
---|
| 58 | + mesh_file[-4:] |
---|
| 59 | m.export_mesh_file(mesh_file) |
---|
| 60 | return mesh_file, triangle_count |
---|
| 61 | |
---|
| 62 | #------------------------------------------------------------- |
---|
| 63 | if __name__ == "__main__": |
---|
| 64 | _, triangle_count = create_mesh(10,mesh_file="test.tsh") |
---|
| 65 | print "triangle_count",triangle_count |
---|