Changeset 9329


Ignore:
Timestamp:
Sep 9, 2014, 3:38:02 PM (11 years ago)
Author:
davies
Message:

Jono's suggestions for cleaning up template codes

Location:
trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/project.py

    r9328 r9329  
    1414from anuga_parallel import myid, barrier, send, receive, numprocs
    1515# We need the boundary tags info to correctly cache the mesh
    16 from setup_boundary_conditions import BoundaryInfo
     16from setup_boundary_conditions import boundary_info
    1717
    1818
     
    7878# List of filenames (can be .shp and/or .csv)
    7979#
    80 #breakLine_files=glob.glob('../../GIS/Mesh/BreakLines/*.shp')
    81 breakLine_files=[]
     80#breakline_files=glob.glob('../../GIS/Mesh/BreakLines/*.shp')
     81breakline_files=[]
    8282
    8383## Riverwalls
     
    8686# header describing the riverwallPar
    8787#
    88 # riverwall_csvFiles=glob.glob('../../GIS/Mesh/RiverWalls/*.csv')
    89 riverwall_csvFiles = []
     88# riverwall_csv_files=glob.glob('../../GIS/Mesh/RiverWalls/*.csv')
     89riverwall_csv_files = []
    9090
    9191# If breaklines/riverwalls intersect with < this distance between the intersection and an
     
    9494breakLine_intersection_point_movement_threshold=10.
    9595
    96 # Get mesh resolutions = RegionPtAreas [alternative to interior_polygons + res]
     96# Get mesh resolutions = region_point_areas [alternative to interior_polygons + res]
    9797#ptAreas='../../GIS/Mesh/RegionResolutions/RegionResolutions.shp'
    9898ptAreas=None
     
    189189
    190190bounding_polygon=su.read_polygon(bounding_polygon_file)
    191 breakLines=su.readListOfBreakLines(breakLine_files)
    192 riverWalls, riverWall_Par=su.readListOfRiverWalls(riverwall_csvFiles) #{} # Dictionary
     191breaklines=su.readListOfBreakLines(breakline_files)
     192riverwalls, riverwall_par=su.readListOfRiverWalls(riverwall_csv_files) #{} # Dictionary
    193193
    194194if ptAreas is not None:
    195     RegionPtAreas=su.readRegionPtAreas(ptAreas, convert_length_to_area=True)
     195    region_point_areas=su.readregion_point_areas(ptAreas, convert_length_to_area=True)
    196196else:
    197     RegionPtAreas = None
     197    region_point_areas = None
    198198# Hack to override resolution
    199 # RegionPtAreas=[ RegionPtAreas[i][0:2]+[150*150*0.5] for i in range(len(RegionPtAreas))]
     199# region_point_areas=[ region_point_areas[i][0:2]+[150*150*0.5] for i in range(len(region_point_areas))]
    200200
    201201# Redefine interior_regions to contain the polygon data + resolutions
     
    209209
    210210# Deal with intersections in the bounding polygon / breaklines / riverwalls
    211 bounding_polygon, breakLines, riverWalls =\
    212     su.add_intersections_to_domain_features(bounding_polygon, breakLines, riverWalls,\
     211bounding_polygon, breaklines, riverwalls =\
     212    su.add_intersections_to_domain_features(bounding_polygon, breaklines, riverwalls,\
    213213                  point_movement_threshold=breakLine_intersection_point_movement_threshold,
    214214                  verbose=True)
     
    216216# Here we make a unique ID based on the all the mesh geometry inputs
    217217# This tells us if we need to regenerate partitions, or use old ones
    218 mesh_ID_hash=hashlib.md5(json.dumps(\
    219             [bounding_polygon, interior_regions, riverWalls, \
    220              breakLines, RegionPtAreas, default_res, BoundaryInfo]) ).hexdigest()
     218mesh_id_hash=hashlib.md5(json.dumps(\
     219            [bounding_polygon, interior_regions, riverwalls, \
     220             breaklines, region_point_areas, default_res, boundary_info]) ).hexdigest()
    221221
    222222# Fix the output tif bounding polygon
     
    240240# Set up directories etc
    241241if(myid==0):
    242     runTime = time.strftime('%Y%m%d_%H%M%S', time.localtime())
     242    runtime = time.strftime('%Y%m%d_%H%M%S', time.localtime())
    243243    for i in range(1,numprocs):
    244         send(runTime,i)
     244        send(runtime,i)
    245245else:
    246     runTime=receive(0)
     246    runtime=receive(0)
    247247barrier()
    248248       
    249 output_dir = output_basedir+'RUN_'+str(runTime)+'_'+scenario
     249output_dir = output_basedir+'RUN_'+str(runtime)+'_'+scenario
    250250partition_basedir='PARTITIONS/'
    251 partition_dir= partition_basedir+'Mesh_'+str(mesh_ID_hash)
     251partition_dir= partition_basedir+'Mesh_'+str(mesh_id_hash)
    252252meshname=output_dir+'/mesh.tsh'
    253253
     
    297297            for i in range(len(interior_regions)):
    298298                savLines(interior_regions[i][0], filename=spatial_txt_outputDir+'interior_region_'+str(i)+'.txt')
    299         if breakLines is not {}:
    300             for i in range(len(breakLines)):
    301                 savLines(breakLines.values()[i], filename=spatial_txt_outputDir+'breakLine_'+str(i)+'.txt')
    302         if riverWalls is not {}:
    303             for i in range(len(riverWalls)):
    304                 savLines(riverWalls.values()[i], filename=spatial_txt_outputDir+'riverWall_'+str(i)+'.txt')
     299        if breaklines is not {}:
     300            for i in range(len(breaklines)):
     301                savLines(breaklines.values()[i], filename=spatial_txt_outputDir+'breakline_'+str(i)+'.txt')
     302        if riverwalls is not {}:
     303            for i in range(len(riverwalls)):
     304                savLines(riverwalls.values()[i], filename=spatial_txt_outputDir+'riverwall_'+str(i)+'.txt')
    305305
    306306        savLines(bounding_polygon,filename=spatial_txt_outputDir+'boundingPoly.txt')
    307307
    308         if RegionPtAreas is not None:
    309             savLines(RegionPtAreas, filename=spatial_txt_outputDir+'regionPtAreas.txt')
     308        if region_point_areas is not None:
     309            savLines(region_point_areas, filename=spatial_txt_outputDir+'regionPtAreas.txt')
    310310
    311311        # Copy all the txt representations of these files to the output directory
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/run_model.py

    r9328 r9329  
    8181#
    8282####################################################################################
    83 maxQuantities=collect_max_quantities_operator(
     83MaxQuantities=collect_max_quantities_operator(
    8484         domain,
    8585         update_frequency=project.max_quantity_update_frequency,
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/setup_boundary_conditions.py

    r9322 r9329  
    33 THE USER MUST EDIT THIS FILE TO SET THE BOUNDARY CONDITIONS
    44
    5  Both the BoundaryInfo list and the function 'setup_boundary_conditions'
     5 Both the boundary_info list and the function 'setup_boundary_conditions'
    66 require adjustment
    77
     
    2929# These points define the 'ocean_boundary': 1 point per edge on the bounding polygon
    3030#
    31 ocean_boundary_pointsFile='../anuga/boundaries/ocean_boundary_points/ocean_boundary_points.shp'
    32 ocean_boundary_points=su.read_points(ocean_boundary_pointsFile)
     31ocean_boundary_points_file='../anuga/boundaries/ocean_boundary_points/ocean_boundary_points.shp'
     32ocean_boundary_points=su.read_points(ocean_boundary_points_file)
    3333
    3434
     
    3939# assigned to the 'Default' boundary
    4040#
    41 BoundaryInfo=[
     41boundary_info=[
    4242              ['ocean_waterlevel_boundary', ocean_boundary_points],
    4343              ['vertices_without_tagpoints', 'Default']
     
    5353
    5454        2) Next make sure the 'boundary_tags_and_conditions' dictionary
    55            associates the correct 'tags' (defined in BoundaryInfo) to the
     55           associates the correct 'tags' (defined in boundary_info) to the
    5656           correct boundary condition type
    5757    """
     
    6363   
    6464    # Example:
    65     # Transmissive with stage being set by a function 'stageF'
    66     def stageF(t):
     65    # Transmissive with stage being set by a function 'stage_function'
     66    def stage_function(t):
    6767        return min( max( t-120., 0.)/360., 1.)
    68     B_t_stageF = anuga.shallow_water.boundaries.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, stageF)
     68    B_t_stage_function = anuga.shallow_water.boundaries.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, stage_function)
    6969
    70     ## Here we associate each tag in BoundaryInfo with its boundary condition defined above
     70    ## Here we associate each tag in boundary_info with its boundary condition defined above
    7171    boundary_tags_and_conditions={
    72                                   'ocean_waterlevel_boundary': B_t_stageF,
     72                                  'ocean_waterlevel_boundary': B_t_stage_function,
    7373                                  'vertices_without_tagpoints':Br
    7474                                  }
     
    7878#@@@@@@@@@@@@@@@@@#
    7979
    80     ## Check that all tags in BoundaryInfo have been set
    81     for i in range(len(BoundaryInfo)):
    82         tag=BoundaryInfo[i][0]
     80    ## Check that all tags in boundary_info have been set
     81    for i in range(len(boundary_info)):
     82        tag=boundary_info[i][0]
    8383        if not boundary_tags_and_conditions.has_key(tag):
    8484            msg = 'Need to set boundary_tags_and_conditions for tag = ' + tag
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/setup_initial_conditions.py

    r9328 r9329  
    108108
    109109    # Set_quantity data
    110     elevation_Data=[
     110    elevation_data=[
    111111                    ['../anuga/polygons/patong_10m.txt', elevation_patong_10m],
    112112                    ['../anuga/polygons/saddle_10m.txt', elevation_saddle_10m],
     
    130130    default_friction=0.025
    131131    # Set_quantity data
    132     friction_Data =[
     132    friction_data =[
    133133                    ['All', default_friction]
    134134                   ]
     
    146146
    147147    # Set_quantity data
    148     stage_Data = [
     148    stage_data = [
    149149                  ['All', project.tide]
    150150                 ]
     
    163163   
    164164    # Set_quantity data
    165     xmomentum_Data = [
     165    xmomentum_data = [
    166166                      ['All', 0.]
    167167                     ]
     
    173173
    174174    # Set_quantity data
    175     ymomentum_Data = [
     175    ymomentum_data = [
    176176                      ['All', 0.]
    177177                     ]
     
    195195    # location='centroids'
    196196
    197     elevFun=qs.composite_quantity_setting_function(elevation_Data, domain)
    198     domain.set_quantity('elevation', elevFun, location='vertices')
    199     elevAddFun=qs.composite_quantity_setting_function(elevation_additions, domain)
    200     domain.add_quantity('elevation', elevAddFun)
    201    
    202     frictionFun=qs.composite_quantity_setting_function(friction_Data, domain)
    203     domain.set_quantity('friction',  frictionFun,  location='centroids')
    204     frictionAddFun=qs.composite_quantity_setting_function(friction_additions, domain)
    205     domain.add_quantity('friction', frictionAddFun)
    206    
    207     stageFun=qs.composite_quantity_setting_function(stage_Data, domain)
    208     domain.set_quantity('stage',  stageFun,  location='centroids')
    209     stageAddFun=qs.composite_quantity_setting_function(stage_additions, domain)
    210     domain.add_quantity('stage', stageAddFun)
    211 
    212     xmomentumFun=qs.composite_quantity_setting_function(xmomentum_Data, domain)
    213     domain.set_quantity('xmomentum',  xmomentumFun,  location='centroids')
    214     xmomentumAddFun=qs.composite_quantity_setting_function(xmomentum_additions, domain)
    215     domain.add_quantity('xmomentum', xmomentumAddFun)
    216    
    217     ymomentumFun=qs.composite_quantity_setting_function(ymomentum_Data, domain)
    218     domain.set_quantity('ymomentum',  ymomentumFun,  location='centroids')
    219     ymomentumAddFun=qs.composite_quantity_setting_function(ymomentum_additions, domain)
    220     domain.add_quantity('ymomentum', ymomentumAddFun)
     197    elevation_function=qs.composite_quantity_setting_function(elevation_data, domain)
     198    domain.set_quantity('elevation', elevation_function, location='vertices')
     199    elevation_addition_function=qs.composite_quantity_setting_function(elevation_additions, domain)
     200    domain.add_quantity('elevation', elevation_addition_function)
     201   
     202    friction_function=qs.composite_quantity_setting_function(friction_data, domain)
     203    domain.set_quantity('friction',  friction_function,  location='centroids')
     204    friction_addition_function=qs.composite_quantity_setting_function(friction_additions, domain)
     205    domain.add_quantity('friction', friction_addition_function)
     206   
     207    stage_function=qs.composite_quantity_setting_function(stage_data, domain)
     208    domain.set_quantity('stage',  stage_function,  location='centroids')
     209    stage_addition_function=qs.composite_quantity_setting_function(stage_additions, domain)
     210    domain.add_quantity('stage', stage_addition_function)
     211
     212    xmomentum_function=qs.composite_quantity_setting_function(xmomentum_data, domain)
     213    domain.set_quantity('xmomentum',  xmomentum_function,  location='centroids')
     214    xmomentum_addition_function=qs.composite_quantity_setting_function(xmomentum_additions, domain)
     215    domain.add_quantity('xmomentum', xmomentum_addition_function)
     216   
     217    ymomentum_function=qs.composite_quantity_setting_function(ymomentum_data, domain)
     218    domain.set_quantity('ymomentum',  ymomentum_function,  location='centroids')
     219    ymomentum_addition_function=qs.composite_quantity_setting_function(ymomentum_additions, domain)
     220    domain.add_quantity('ymomentum', ymomentum_addition_function)
    221221
    222222    ################################################################################
     
    226226    ################################################################################
    227227
    228     if not project.riverWalls=={}:
    229         domain.riverwallData.create_riverwalls(project.riverWalls, project.riverWall_Par)
     228    if not project.riverwalls=={}:
     229        domain.riverwallData.create_riverwalls(project.riverwalls, project.riverwall_par)
    230230        domain.riverwallData.export_riverwalls_to_text(output_dir=project.output_dir+'/'+project.spatial_txt_outputDir)
    231231
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/setup_mesh.py

    r9320 r9329  
    5555
    5656    # Information on the tags
    57     BoundaryInfo=setup_boundary_conditions.BoundaryInfo
    58 
    59     for i in range(len(BoundaryInfo)):
    60         BI=BoundaryInfo[i]
    61         tag_i=BI[0]
    62         PTS_i=BI[1]
     57    boundary_info=setup_boundary_conditions.boundary_info
     58
     59    for i in range(len(boundary_info)):
     60        bi=boundary_info[i]
     61        # Shorthand for i'th boundary tag
     62        tag_i=bi[0]
     63        # Shorthand for i'th set of boundary points
     64        PTS_i=bi[1]
    6365
    6466        # Add the boundary tag to the list
    6567        boundary_tags[tag_i]=[]
    6668
    67         if(PTS_i=='Default' or i==(len(BoundaryInfo)-1)):
     69        if(PTS_i=='Default' or i==(len(boundary_info)-1)):
    6870            # Assign default boundaries
    69             assert (i==(len(BoundaryInfo)-1) and PTS_i=='Default'),\
    70                 'Default boundary condition must be at the end of the BoundaryInfo list'
     71            assert (i==(len(boundary_info)-1) and PTS_i=='Default'),\
     72                'Default boundary condition must be at the end of the boundary_info list'
    7173            boundary_tags[tag_i]=default_tags
    7274        else:
    7375            # Loop over all points in the boundary condition
    7476            for j in range(len(PTS_i)):
    75                 newInd=su.find_nearest_segment(PTS_i[j], bounding_polygon_closed)[1]
    76                 boundary_tags[tag_i]=boundary_tags[tag_i]+[newInd]     
    77                 default_tags.remove(newInd)
     77                new_index=su.find_nearest_segment(PTS_i[j], bounding_polygon_closed)[1]
     78                boundary_tags[tag_i]=boundary_tags[tag_i]+[new_index]     
     79                default_tags.remove(new_index)
    7880
    7981    return boundary_tags   
     
    8991
    9092    # Create the boundary tags
    91     boundary_Tags=make_boundary_tags(project.bounding_polygon, setup_boundary_conditions)
    92    
    93     # Ensure mesh_breakLines include riverwalls and breakLines
    94     mesh_breakLines=su.combine_breakLines_and_riverWalls_for_mesh(project.breakLines, project.riverWalls)
     93    boundary_tags=make_boundary_tags(project.bounding_polygon, setup_boundary_conditions)
     94   
     95    # Ensure mesh_breaklines include riverwalls and breaklines
     96    mesh_breaklines=su.combine_breakLines_and_riverWalls_for_mesh(project.breaklines, project.riverwalls)
    9597
    9698    ## Make the mesh
    9799    anuga.create_mesh_from_regions(project.bounding_polygon,
    98                              boundary_tags=boundary_Tags,
     100                             boundary_tags=boundary_tags,
    99101                             maximum_triangle_area=project.default_res,
    100102                             filename=project.meshname,
     
    102104                             use_cache=False,
    103105                             verbose=verbose,
    104                              breaklines=mesh_breakLines,
    105                              regionPtArea=project.RegionPtAreas)
     106                             breaklines=mesh_breaklines,
     107                             regionPtArea=project.region_point_areas)
    106108                             
    107109    # Make the domain using the mesh
     
    145147
    146148        # Copy code files to output dir. This should be 'nearly the first' thing we do
    147         modelFiles=glob.glob('*.py')+glob.glob('*.sh')
    148         for modelFile in modelFiles:
    149             anuga.copy_code_files(project.output_dir,modelFile)
     149        model_files=glob.glob('*.py')+glob.glob('*.sh')
     150        for model_file in model_files:
     151            anuga.copy_code_files(project.output_dir,model_file)
    150152   
    151153
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami1/scripts/user_functions.py

    r9320 r9329  
    1616
    1717
    18 def print_velocity_statistics(domain, maxQuantities):
     18def print_velocity_statistics(domain, MaxQuantities):
    1919    """
    2020    Utility for printing velocity stats in the evolve loop
     
    3232            print '    Processor ', myid
    3333            print '    @ Peak velocity is: ', vv.max(), vv.argmax()
    34             print '     &- MaxSpeedHistory: ', maxQuantities.max_speed.max()
     34            print '     &- MaxSpeedHistory: ', MaxQuantities.max_speed.max()
    3535            print '     %- FUF: ', domain.flux_update_frequency.mean()
    3636        else:
Note: See TracChangeset for help on using the changeset viewer.