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