""" Module to import the project.py 'configuration' file and perform sanity checks plus a quick check on mesh generation. Also callable as a stand-alone program, mainly to view the results of the mesh generation. """ import os from os.path import join, exists from anuga.utilities.polygon import read_polygon, number_mesh_triangles import project #------------------------------------------------------------------------------- # Sanity checks - check that required files/directories, etc, exist. #------------------------------------------------------------------------------- # flag - we check many things and then don't proceed if anything wrong sanity_error = False # checked at bottom of this file # Test that environment variables are defined. if os.getenv(project.ENV_INUNDATIONHOME) is None: print "Environment variable '%s' is not set" % project.ENV_INUNDATIONHOME sanity_error = True if os.getenv(project.ENV_MUXHOME) is None: print "Environment variable '%s' is not set" % project.ENV_MUXHOME sanity_error = True #------------------------------------------------------------------------------- # Directory Structure #------------------------------------------------------------------------------- # check folders generated from environment variables. if not exists(project.home): print "Sorry, data directory '%s' doesn't exist" % project.home sanity_error = True if not exists(project.muxhome): print "Sorry, MUX directory '%s' doesn't exist" % project.muxhome sanity_error = True if not exists(project.anuga_folder): print "Sorry, ANUGA directory '%s' doesn't exist" % project.anuga_folder sanity_error = True if not exists(project.topographies_folder): print ("Sorry, topo directory '%s' doesn't exist" % project.topographies_folder) sanity_error = True if not exists(project.polygons_folder): print ("Sorry, polygon directory '%s' doesn't exist" % project.polygons_folder) sanity_error = True if not exists(project.boundaries_folder): print ("Sorry, boundaries directory '%s' doesn't exist" % project.boundaries_folder) sanity_error = True if not exists(project.output_folder): print "Sorry, outputs directory '%s' doesn't exist" % project.output_folder sanity_error = True if not exists(project.gauges_folder): print "Sorry, gauges directory '%s' doesn't exist" % project.gauges_folder sanity_error = True if not exists(project.meshes_folder): print "Sorry, meshes directory '%s' doesn't exist" % project.meshes_folder sanity_error = True if not exists(project.mux_data_folder): print "Sorry, mux data directory '%s' doesn't exist" % project.mux_data_folder sanity_error = True # if multi_mux is True, check if multi-mux file exists if project.multi_mux: if not exists(project.mux_input): print ("Sorry, MUX input file '%s' doesn't exist" % project.mux_input) sanity_error = True #----- # If this directory don't exist, EventSelection hasn't been run. #----- if not exists(project.event_folder): print ("Sorry, you must generate event %s with EventSelection." % project.event_number) sanity_error = True #------------------------------------------------------------------------------- # Determine type of run #------------------------------------------------------------------------------- if project.setup == 'trial': print 'trial' project.scale_factor = 100 project.time_thinning = 96 project.yieldstep = 240 elif project.setup == 'basic': print 'basic' project.scale_factor = 4 project.time_thinning = 12 project.yieldstep = 120 elif project.setup == 'final': print 'final' project.scale_factor = 1 project.time_thinning = 4 project.yieldstep = 5 else: print ("Sorry, you must set the 'setup' variable to one of:" ' trial - coarsest mesh, fast\n' ' basic - coarse mesh\n' ' final - fine mesh, slowest\n' '\n' "'setup' was set to '%s'" % project.setup) sanity_error = True #------------------------------------------------------------------------------- # Check for errors detected above. #------------------------------------------------------------------------------- if sanity_error: msg = 'You must fix the above errors before continuing.' raise Exception, msg #------------------------------------------------------------------------------- # Reading polygons and creating interior regions #------------------------------------------------------------------------------- # Create list of land polygons with initial conditions project.land_initial_conditions = [] for filename, MSL in project.land_initial_conditions_filename: polygon = read_polygon(join(project.polygons_folder, filename)) project.land_initial_conditions.append([polygon, MSL]) # Create list of interior polygons with scaling factor project.interior_regions = [] for filename, maxarea in project.interior_regions_data: polygon = read_polygon(join(project.polygons_folder, filename)) project.interior_regions.append([polygon, maxarea*project.scale_factor]) # Initial bounding polygon for data clipping project.bounding_polygon = read_polygon(join(project.polygons_folder, project.bounding_polygon_filename)) project.bounding_maxarea = project.bounding_polygon_maxarea*project.scale_factor # Estimate the number of triangles trigs_min = number_mesh_triangles(project.interior_regions, project.bounding_polygon, project.bounding_maxarea) print 'min estimated number of triangles', trigs_min