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