1 | """Create a mesh of the Gippsland Lakes coast based on 100m |
---|
2 | bathymetric data. |
---|
3 | """ |
---|
4 | |
---|
5 | #import os, sys |
---|
6 | #sys.path.append('..') |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | # add storm_surge dir to your pythonpath |
---|
11 | from pmesh.mesh import * |
---|
12 | from pyvolution.coordinate_transforms.geo_reference import Geo_reference |
---|
13 | |
---|
14 | |
---|
15 | def create_mesh(max_area, mesh_file=None, triangles_in_name=False, |
---|
16 | factor = 1000000): |
---|
17 | |
---|
18 | #Based on a photocopy of the Gippsland area |
---|
19 | p1 = [546000, 5775000] |
---|
20 | p2 = [555000, 5762000] |
---|
21 | p3 = [603000, 5796000] |
---|
22 | p4 = [597000, 5806000] |
---|
23 | p5 = [594000, 5812000] |
---|
24 | p6 = [556000, 5813000] |
---|
25 | p7 = [553000, 5798000] |
---|
26 | p8 = [534000, 5793000] |
---|
27 | |
---|
28 | |
---|
29 | #create geo reference object for use with mesh |
---|
30 | geo = Geo_reference(xllcorner = p2[0], |
---|
31 | yllcorner = p8[1], |
---|
32 | zone = 56) |
---|
33 | print "***********************" |
---|
34 | print "geo ref", geo |
---|
35 | print "***********************" |
---|
36 | |
---|
37 | m = Mesh(geo_reference=geo) |
---|
38 | |
---|
39 | #Boundary |
---|
40 | dict = {} |
---|
41 | dict['points'] = [p1, p2, p3, p4, p5, p6, p7, p8] |
---|
42 | |
---|
43 | dict['segments'] = [[0,1], [1,2], [2,3], [3,4], |
---|
44 | [4,5], [5,6], [6,7], [7,0]] # the outer border |
---|
45 | dict['segment_tags'] = ['side', |
---|
46 | 'ocean', |
---|
47 | 'side', |
---|
48 | 'side', |
---|
49 | 'back', |
---|
50 | 'back', |
---|
51 | 'back', |
---|
52 | 'side'] |
---|
53 | m.addVertsSegs(dict) |
---|
54 | |
---|
55 | #Based on a photocopy of the Gippsland area |
---|
56 | i1 = [564000, 5794000] |
---|
57 | i2 = [592000, 5807000] |
---|
58 | i3 = [590000, 5809000] |
---|
59 | i4 = [557000, 5805000] |
---|
60 | |
---|
61 | #Boundary |
---|
62 | dict = {} |
---|
63 | dict['points'] = [i1, i2, i3, i4] |
---|
64 | |
---|
65 | dict['segments'] = [[0,1], [1,2], [2,3], [3,0]] # the inner border |
---|
66 | m.addVertsSegs(dict) |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | #factor = 10000 #low res 10000, high res 1000 |
---|
71 | low = m.addRegionEN(p1[0]+0.5, p1[1]+0.5) |
---|
72 | maxArea = 100*factor |
---|
73 | print "low region maxArea",maxArea |
---|
74 | low.setMaxArea(maxArea) |
---|
75 | |
---|
76 | medium = m.addRegionEN(i1[0], i1[1]+0.5) |
---|
77 | maxArea = 10*factor |
---|
78 | print "medium region maxArea",maxArea |
---|
79 | medium.setMaxArea(maxArea) |
---|
80 | medium.setTag('medium') |
---|
81 | |
---|
82 | m.generateMesh('q28.0z', maxArea = max_area) |
---|
83 | triangle_count = len(m.getTriangulation()) |
---|
84 | if mesh_file is None: |
---|
85 | return m, triangle_count |
---|
86 | else: |
---|
87 | if triangles_in_name is True: |
---|
88 | mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \ |
---|
89 | + mesh_file[-4:] |
---|
90 | m.export_mesh_file(mesh_file) |
---|
91 | return mesh_file, triangle_count |
---|
92 | |
---|
93 | |
---|
94 | #------------------------------------------------------------- |
---|
95 | if __name__ == "__main__": |
---|
96 | _, triangle_count = create_mesh(1000000, mesh_file = 'newtest.tsh', |
---|
97 | triangles_in_name=True) |
---|
98 | print "triangle_count",triangle_count |
---|