source: anuga_work/production/mandurah_storm_surge_2009/gems_comparison/setup_model_GEMS.py @ 7628

Last change on this file since 7628 was 7628, checked in by fountain, 14 years ago

comparison with GEMS storm surge model for Mandurah

File size: 5.8 KB
RevLine 
[7628]1"""
2Module to import the project_GEMS.py 'configuration' file and perform
3sanity checks plus a quick check on mesh generation.
4
5Also callable as a stand-alone program, mainly to view the results
6of the mesh generation.
7"""
8
9import os
10
11from os.path import join, exists
12from anuga.utilities.polygon import read_polygon, number_mesh_triangles
13
14import project_GEMS
15
16
17#-------------------------------------------------------------------------------
18# Sanity checks - check that required files/directories, etc, exist.
19#-------------------------------------------------------------------------------
20
21# flag - we check many things and then don't proceed if anything wrong
22sanity_error = False               # checked at bottom of this file
23
24# Test that environment variables are defined.
25if os.getenv(project_GEMS.ENV_INUNDATIONHOME) is None:
26        print "Environment variable '%s' is not set" % project_GEMS.ENV_INUNDATIONHOME
27        sanity_error = True
28
29
30#-------------------------------------------------------------------------------
31# Check filename strings that MUST be set
32#-------------------------------------------------------------------------------
33
34if not project_GEMS.gems_order_filename:
35        print ("Sorry, ordering file parameter 'gems_order_filename' "
36                   "isn't set")
37        sanity_error = True
38
39if not project_GEMS.landward_boundary_filename:
40        print ("Sorry, landward bounding points parameter "
41                   "'landward_boundary_filename' isn't set")
42        sanity_error = True
43
44#-------------------------------------------------------------------------------
45# Directory Structure
46#-------------------------------------------------------------------------------
47
48# check folders generated from environment variables.
49if not exists(project_GEMS.home):
50        print "Sorry, data directory '%s' doesn't exist" % project_GEMS.home
51        sanity_error = True
52       
53if not exists(project_GEMS.anuga_folder):
54        print "Sorry, ANUGA directory '%s' doesn't exist" % project_GEMS.anuga_folder
55        sanity_error = True
56
57if not exists(project_GEMS.topographies_folder):
58        print ("Sorry, topo directory '%s' doesn't exist"
59                   % project_GEMS.topographies_folder)
60        sanity_error = True
61
62if not exists(project_GEMS.polygons_folder):
63        print ("Sorry, polygon directory '%s' doesn't exist"
64                   % project_GEMS.polygons_folder)
65        sanity_error = True
66
67if not exists(project_GEMS.boundaries_folder):
68        print ("Sorry, boundaries directory '%s' doesn't exist"
69                   % project_GEMS.boundaries_folder)
70        sanity_error = True
71
72if not exists(project_GEMS.output_folder):
73        print "Sorry, outputs directory '%s' doesn't exist" % project_GEMS.output_folder
74        sanity_error = True
75
76if not exists(project_GEMS.gauges_folder):
77        print "Sorry, gauges directory '%s' doesn't exist" % project_GEMS.gauges_folder
78        sanity_error = True
79
80if not exists(project_GEMS.event_folder):
81        print ("Sorry, you must generate event %s."
82                   % project_GEMS.event)
83        sanity_error = True
84
85#-------------------------------------------------------------------------------
86# Determine type of run
87#-------------------------------------------------------------------------------
88
89if project_GEMS.setup == 'trial':
90        print 'trial'
91        project_GEMS.scale_factor = 100
92        project_GEMS.time_thinning = 96
93        project_GEMS.yieldstep = 240
94elif project_GEMS.setup == 'basic': 
95        print 'basic'
96        project_GEMS.scale_factor = 4
97        project_GEMS.time_thinning = 12
98        project_GEMS.yieldstep = 120
99elif project_GEMS.setup == 'final': 
100        print 'final'
101        project_GEMS.scale_factor = 1
102        project_GEMS.time_thinning = 4
103        project_GEMS.yieldstep = 60
104elif project_GEMS.setup == 'storm_surge_final':
105        print 'storm surge final'
106        project_GEMS.scale_factor = 1
107        project_GEMS.time_thinning = 4
108        project_GEMS.yieldstep = 720   
109else:
110        print ("Sorry, you must set the 'setup' variable to one of:"
111                   '   trial - coarsest mesh, fast\n'
112                   '   basic - coarse mesh\n'
113                   '   final - fine mesh, slowest\n'
114                   '\n'
115                   "'setup' was set to '%s'" % project_GEMS.setup)
116        sanity_error = True
117
118#-------------------------------------------------------------------------------
119# Check for errors detected above.
120#-------------------------------------------------------------------------------
121
122if sanity_error:
123        msg = 'You must fix the above errors before continuing.'
124        raise Exception, msg
125       
126#-------------------------------------------------------------------------------
127# Reading elevation clip polygon
128#-------------------------------------------------------------------------------
129
130project_GEMS.elevation_clip_box = read_polygon(join(project_GEMS.topographies_folder,
131                                                                                         project_GEMS.elevation_clip_box_filename))
132
133#-------------------------------------------------------------------------------
134# Reading polygons and creating interior regions
135#-------------------------------------------------------------------------------
136
137# Create list of land polygons with initial conditions
138project_GEMS.land_initial_conditions = []
139for filename, MSL in project_GEMS.land_initial_conditions_filename:
140        polygon = read_polygon(join(project_GEMS.polygons_folder, filename))
141        project_GEMS.land_initial_conditions.append([polygon, MSL])
142
143# Create list of interior polygons with scaling factor
144project_GEMS.interior_regions = []
145for filename, maxarea in project_GEMS.interior_regions_data:
146        polygon = read_polygon(join(project_GEMS.polygons_folder, filename))
147        project_GEMS.interior_regions.append([polygon,
148                                                                         maxarea*project_GEMS.scale_factor])
149
150# Initial bounding polygon for data clipping
151project_GEMS.bounding_polygon = read_polygon(join(project_GEMS.polygons_folder,
152                                                                                         project_GEMS.bounding_polygon_filename))
153project_GEMS.bounding_maxarea = project_GEMS.bounding_polygon_maxarea*project_GEMS.scale_factor
154
155# Estimate the number of triangles                     
156trigs_min = number_mesh_triangles(project_GEMS.interior_regions,
157                                                                  project_GEMS.bounding_polygon,
158                                                                  project_GEMS.bounding_maxarea)
159
160print 'min estimated number of triangles', trigs_min
Note: See TracBrowser for help on using the repository browser.