source: DVD_images/extra_files/GoldCoast/project/setup_model.py @ 7300

Last change on this file since 7300 was 7300, checked in by rwilson, 15 years ago
  • Property svn:executable set to *
File size: 5.4 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
29#-------------------------------------------------------------------------------
30# Check filename strings that MUST be set
31#-------------------------------------------------------------------------------
32
33if not project.urs_order_filename:
34    print ("Sorry, thinned ordering file parameter 'urs_order_filename' "
35           "isn't set")
36    sanity_error = True
37
38if not project.landward_boundary_filename:
39    print ("Sorry, landward bounding points parameter "
40           "'landward_boundary_filename' isn't set")
41    sanity_error = True
42
43#-------------------------------------------------------------------------------
44# Directory Structure
45#-------------------------------------------------------------------------------
46
47# check folders generated from environment variables.
48if not exists(project.home):
49    print "Sorry, data directory '%s' doesn't exist" % project.home
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
79#-----
80# If this directory don't exist, EventSelection hasn't been run.
81#-----
82
83if not exists(project.event_folder):
84    print ("Sorry, you must generate event %s with EventSelection."
85           % project.event_number)
86    sanity_error = True
87
88#-------------------------------------------------------------------------------
89# Determine type of run
90#-------------------------------------------------------------------------------
91
92if project.setup == 'trial':
93    print 'trial'
94    project.scale_factor = 100
95    project.time_thinning = 96
96    project.yieldstep = 240
97elif project.setup == 'basic': 
98    print 'basic'
99    project.scale_factor = 4
100    project.time_thinning = 12
101    project.yieldstep = 120
102elif project.setup == 'final': 
103    print 'final'
104    project.scale_factor = 1
105    project.time_thinning = 4
106    project.yieldstep = 60
107else:
108    print ("Sorry, you must set the 'setup' variable to one of:"
109           '   trial - coarsest mesh, fast\n'
110           '   basic - coarse mesh\n'
111           '   final - fine mesh, slowest\n'
112           '\n'
113           "'setup' was set to '%s'" % project.setup)
114    sanity_error = True
115
116#-------------------------------------------------------------------------------
117# Check for errors detected above.
118#-------------------------------------------------------------------------------
119
120if sanity_error:
121    msg = 'You must fix the above errors before continuing.'
122    raise Exception, msg
123
124#-------------------------------------------------------------------------------
125# Reading polygons and creating interior regions
126#-------------------------------------------------------------------------------
127
128# Create list of land polygons with initial conditions
129project.land_initial_conditions = []
130for filename, MSL in project.land_initial_conditions_filename:
131    polygon = read_polygon(join(project.polygons_folder, filename))
132    project.land_initial_conditions.append([polygon, MSL])
133
134# Create list of interior polygons with scaling factor
135project.interior_regions = []
136for filename, maxarea in project.interior_regions_data:
137    polygon = read_polygon(join(project.polygons_folder, filename))
138    project.interior_regions.append([polygon,
139                                     maxarea*project.scale_factor])
140
141# Initial bounding polygon for data clipping
142project.bounding_polygon = read_polygon(join(project.polygons_folder,
143                                             project.bounding_polygon_filename))
144project.bounding_maxarea = project.bounding_polygon_maxarea*project.scale_factor
145
146# Estimate the number of triangles                     
147trigs_min = number_mesh_triangles(project.interior_regions,
148                                  project.bounding_polygon,
149                                  project.bounding_maxarea)
150
151print 'min estimated number of triangles', trigs_min
Note: See TracBrowser for help on using the repository browser.