# add inundation dir to your pythonpath from pmesh.mesh import Mesh from coordinate_transforms.geo_reference import Geo_reference def create_mesh(maximum_triangle_area, mesh_file=None, triangles_in_name = False): """ triangles_in_name, if True is used to append the number of triangles in the mesh to the mesh file name. """ # create a mesh instance of class Mesh m = Mesh() # Boundary of problem WidtH = 200 # width of boudary in metres #W = WidtH/8 #L = W outer_polygon = [[0,0],[WidtH,0],[WidtH,WidtH],[0,WidtH]] m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]}) # inner polygons => building boundaries width = 15 wh = width/2 length = 15 lh = length/2 Wm = [12.5,37.5,62.5,87.5] Lm = [12.5,37.5,62.5,87.5] for W in Wm: polygon = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]] m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. for L in Lm: polygon1 = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]] m.add_hole_from_polygon(polygon1, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries. #polygon = [[10,10],[20,10],[20,20],[10,20]] #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) #polygon = [[40,40],[50,40],[50,50],[40,50]] #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) #m.add_circle([20,70], 5, hole=True, tag='wall') m.generate_mesh(maximum_triangle_area=maximum_triangle_area) triangle_count = m.get_triangle_count() if mesh_file is None: return m, triangle_count else: if triangles_in_name is True: mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ + mesh_file[-4:] m.export_mesh_file(mesh_file) return mesh_file, triangle_count #------------------------------------------------------------- if __name__ == "__main__": _, triangle_count = create_mesh(10,mesh_file="test.tsh") print "triangle_count",triangle_count