source: anuga_work/production/busselton/standardised_version/setup_model.py @ 6335

Last change on this file since 6335 was 6335, checked in by rwilson, 14 years ago

Final save (except for moving build_urs_boundary.py somewhere).

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