source: anuga_validation/automated_validation_tests/patong_beach_validation/setup_model.py @ 7651

Last change on this file since 7651 was 7567, checked in by ole, 14 years ago

Got rid of environment variables and move log file to output dir.
The logging module will need some work, though.

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1"""
2Module to import the project.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
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.
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# Directory Structure
35#-------------------------------------------------------------------------------
36
37# check folders generated from environment variables.
38if project.home is None:
39    print 'Sorry, environment variable INUNDATIONHOME is not defined'
40    sanity_error = True
41if not exists(project.home):
42    print "Sorry, data directory '%s' doesn't exist" % project.home
43    sanity_error = True
44   
45if project.muxhome is None:
46    print 'Sorry, environment variable MUXHOME is not defined'
47    sanity_error = True
48if not exists(project.muxhome):
49    print "Sorry, MUX directory '%s' doesn't exist" % project.muxhome
50    sanity_error = True
51   
52if not exists(project.anuga_folder):
53    print "Sorry, ANUGA directory '%s' doesn't exist" % project.anuga_folder
54    sanity_error = True
55
56if not exists(project.topographies_folder):
57    print ("Sorry, topo directory '%s' doesn't exist"
58           % project.topographies_folder)
59    sanity_error = True
60
61if not exists(project.polygons_folder):
62    print ("Sorry, polygon directory '%s' doesn't exist"
63           % project.polygons_folder)
64    sanity_error = True
65
66if not exists(project.boundaries_folder):
67    print ("Sorry, boundaries directory '%s' doesn't exist"
68           % project.boundaries_folder)
69    sanity_error = True
70
71if not exists(project.output_folder):
72    print "Sorry, outputs directory '%s' doesn't exist" % project.output_folder
73    sanity_error = True
74
75if not exists(project.gauges_folder):
76    print "Sorry, gauges directory '%s' doesn't exist" % project.gauges_folder
77    sanity_error = True
78
79if not exists(project.meshes_folder):
80    print "Sorry, meshes directory '%s' doesn't exist" % project.meshes_folder
81    sanity_error = True
82
83if not exists(project.mux_data_folder):
84    print "Sorry, mux data directory '%s' doesn't exist" % project.mux_data_folder
85    sanity_error = True
86
87# if multi_mux is True, check if multi-mux file exists
88if project.multi_mux:
89    if not exists(project.mux_input):
90        print ("Sorry, MUX input file '%s' doesn't exist"
91               % project.mux_input)
92        sanity_error = True
93
94#-----
95# If this directory don't exist, EventSelection hasn't been run.
96#-----
97
98if not exists(project.event_folder):
99    print "project.event_folder=%s" % project.event_folder
100    print ("Sorry, you must generate event %s with EventSelection."
101           % project.event_number)
102    sanity_error = True
103
104#-------------------------------------------------------------------------------
105# Determine type of run
106#-------------------------------------------------------------------------------
107
108if project.setup == 'trial':
109    print 'trial'
110    project.scale_factor = 100
111    project.time_thinning = 96
112    project.yieldstep = 240
113elif project.setup == 'basic': 
114    print 'basic'
115    project.scale_factor = 4
116    project.time_thinning = 12
117    project.yieldstep = 120
118elif project.setup == 'final': 
119    print 'final'
120    project.scale_factor = 1
121    project.time_thinning = 4
122    project.yieldstep = 60
123else:
124    print ("Sorry, you must set the 'setup' variable to one of:"
125           '   trial - coarsest mesh, fast\n'
126           '   basic - coarse mesh\n'
127           '   final - fine mesh, slowest\n'
128           '\n'
129           "'setup' was set to '%s'" % project.setup)
130    sanity_error = True
131
132#-------------------------------------------------------------------------------
133# Check for errors detected above.
134#-------------------------------------------------------------------------------
135
136if sanity_error:
137    msg = 'You must fix the above errors before continuing.'
138    raise Exception, msg
139
140#-------------------------------------------------------------------------------
141# Reading polygons and creating interior regions
142#-------------------------------------------------------------------------------
143
144# Create list of land polygons with initial conditions
145project.land_initial_conditions = []
146for filename, MSL in project.land_initial_conditions_filename:
147    polygon = read_polygon(join(project.polygons_folder, filename))
148    project.land_initial_conditions.append([polygon, MSL])
149
150# Create list of interior polygons with scaling factor
151project.interior_regions = []
152for filename, maxarea in project.interior_regions_data:
153    polygon = read_polygon(join(project.polygons_folder, filename))
154    project.interior_regions.append([polygon,
155                                     maxarea*project.scale_factor])
156
157# Initial bounding polygon for data clipping
158project.bounding_polygon = read_polygon(join(project.polygons_folder,
159                                             project.bounding_polygon_filename))
160project.bounding_maxarea = project.bounding_polygon_maxarea*project.scale_factor
161
162# Estimate the number of triangles                     
163trigs_min = number_mesh_triangles(project.interior_regions,
164                                  project.bounding_polygon,
165                                  project.bounding_maxarea)
166
167print 'min estimated number of triangles', trigs_min
Note: See TracBrowser for help on using the repository browser.