[2298] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | # add inundation dir to your pythonpath |
---|
[2322] | 5 | from pmesh.mesh import Mesh |
---|
[2298] | 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 |
---|
| 17 | m = Mesh() |
---|
| 18 | |
---|
| 19 | # |
---|
| 20 | outer_polygon = [[0,0],[100,0],[100,100],[0,100]] |
---|
| 21 | m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]}) |
---|
| 22 | |
---|
| 23 | # inner polygons |
---|
| 24 | polygon = [[10,10],[20,10],[20,20],[10,20]] |
---|
| 25 | m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) |
---|
| 26 | |
---|
| 27 | polygon = [[40,40],[50,40],[50,50],[40,50]] |
---|
| 28 | m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) |
---|
| 29 | |
---|
[2301] | 30 | m.add_circle([20,70], 5, hole=True, tag='wall') |
---|
[2298] | 31 | m.generate_mesh(maximum_triangle_area=maximum_triangle_area) |
---|
[2301] | 32 | triangle_count = m.get_triangle_count() |
---|
[2298] | 33 | |
---|
| 34 | if mesh_file is None: |
---|
| 35 | return m, triangle_count |
---|
| 36 | else: |
---|
| 37 | if triangles_in_name is True: |
---|
| 38 | mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ |
---|
| 39 | + mesh_file[-4:] |
---|
| 40 | m.export_mesh_file(mesh_file) |
---|
| 41 | return mesh_file, triangle_count |
---|
| 42 | |
---|
| 43 | #------------------------------------------------------------- |
---|
| 44 | if __name__ == "__main__": |
---|
[2322] | 45 | _, triangle_count = create_mesh(10,mesh_file="test.tsh") |
---|
[2298] | 46 | print "triangle_count",triangle_count |
---|