source: DVD_images/extra_files/Gosford/project/setup_model.py @ 7205

Last change on this file since 7205 was 7205, checked in by rwilson, 15 years ago

Commit the DVD image generation stuff. This will be archived later.

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