Changeset 9354


Ignore:
Timestamp:
Oct 21, 2014, 3:30:43 PM (11 years ago)
Author:
davies
Message:

Updates to merwether validation test + a report

Location:
trunk/anuga_core
Files:
7 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/plot_utils.py

    r9347 r9354  
    10391039
    10401040
    1041             if(bounding_polygon is not None):
     1041            if ( (bounding_polygon is not None) and (len(cut_points)>0)):
    10421042                # Cut the points outside the bounding polygon
    10431043                gridq[cut_points]= numpy.nan
     
    10601060    return
    10611061
    1062 def plot_triangles(p, adjustLowerLeft=False):
     1062def plot_triangles(p, adjustLowerLeft=False, values=None, color='k'):
    10631063    """ Add mesh triangles to a pyplot plot
    1064     """
     1064       
     1065       @param p = object holding sww vertex information (from util.get_output)
     1066       @param adjustLowerLeft = if TRUE, use spatial coordinates, otherwise use ANUGA internal coordinates     
     1067       @param values = list or array of length(p.x), or None. All triangles are assigned this value (for face plotting colors).
     1068       @param color = edge color for polygons (using matplotlib.colors notation)
     1069    """
     1070    import matplotlib
    10651071    from matplotlib import pyplot as pyplot
     1072    from matplotlib.collections import PolyCollection
    10661073    #
    10671074    x0=p.xllcorner
    10681075    x1=p.yllcorner
    1069     #
     1076
     1077    # Get current figure information
     1078    #ax = pyplot.axes()
     1079
     1080    ##
     1081    vertices = []
    10701082    for i in range(len(p.vols)):
    10711083        k1=p.vols[i][0]
    10721084        k2=p.vols[i][1]
    10731085        k3=p.vols[i][2]
    1074         if(not adjustLowerLeft):
    1075             pyplot.plot([p.x[k1], p.x[k2], p.x[k3], p.x[k1]], [p.y[k1], p.y[k2], p.y[k3], p.y[k1]],'-',color='black')
     1086        if not adjustLowerLeft:
     1087            vertices.append([ [p.x[k1], p.y[k1]], [p.x[k2], p.y[k2]], [p.x[k3], p.y[k3]] ])
    10761088        else:
    1077             pyplot.plot([p.x[k1]+x0, p.x[k2]+x0, p.x[k3]+x0, p.x[k1]+x0], [p.y[k1]+x1, p.y[k2]+x1, p.y[k3]+x1, p.y[k1]+x1],'-',color='black')
    1078         #pyplot.plot([p.x[k3], p.x[k2]], [p.y[k3], p.y[k2]],'-',color='black')
    1079         #pyplot.plot([p.x[k3], p.x[k1]], [p.y[k3], p.y[k1]],'-',color='black')
     1089            vertices.append([ [p.x[k1]+x0, p.y[k1]+y0], [p.x[k2]+x0, p.y[k2]+y0], [p.x[k3]+x0, p.y[k3]+y0] ])
     1090     
     1091    if values is None:
     1092        all_poly = PolyCollection( vertices, array = numpy.zeros(len(p.vols)),
     1093            edgecolors=color)
     1094        all_poly.set_facecolor('none')
     1095    else:
     1096        assert len(values)==len(p.vols), 'len(values) must either be 1, or the same as len(p.vols)'
     1097        all_poly = PolyCollection( vertices, array = values, cmap = matplotlib.cm.jet, edgecolors=color)
     1098
     1099    pyplot.gca().add_collection(all_poly)
     1100    #    if(not adjustLowerLeft):
     1101    #        pyplot.plot([p.x[k1], p.x[k2], p.x[k3], p.x[k1]], [p.y[k1], p.y[k2], p.y[k3], p.y[k1]],'-',color=color)
     1102    #    else:
     1103    #        pyplot.plot([p.x[k1]+x0, p.x[k2]+x0, p.x[k3]+x0, p.x[k1]+x0], [p.y[k1]+x1, p.y[k2]+x1, p.y[k3]+x1, p.y[k1]+x1],'-',color=color)
     1104    #    #pyplot.plot([p.x[k3], p.x[k2]], [p.y[k3], p.y[k2]],'-',color='black')
     1105    #    #pyplot.plot([p.x[k3], p.x[k1]], [p.y[k3], p.y[k1]],'-',color='black')
    10801106
    10811107def find_neighbours(p,ind):
  • trunk/anuga_core/validation_tests/case_studies/merewether/merewether.py

    r8871 r9354  
    77
    88Water Research Laboratory, UNSW
     9
     10Edits by Steve Roberts & Gareth Davies, 2014
    911"""
    1012
     
    2224# Related major packages
    2325import anuga
    24 from anuga_parallel import myid, distribute, finalize
     26from anuga_parallel import myid, distribute, finalize, barrier
    2527
    2628from anuga_parallel.parallel_operator_factory import Inlet_operator
     29from anuga.utilities import quantity_setting_functions as qs
     30from anuga import plot_utils as util
    2731
    2832# Application specific imports
    2933import project                 # Definition of file names and polygons
    3034
    31 verbose = project.verbose
     35#verbose = project.verbose
    3236use_cache = project.use_cache
    3337
     
    4145meshname = 'merewether.msh'
    4246dem_name = 'topography1.dem'
     47
     48args = anuga.get_args()
     49alg = args.alg
     50verbose = args.verbose
    4351
    4452if myid == 0:
     
    6068holes_res = 1.0
    6169interior_regions = [[project.poly_merewether, merewether_res]]
    62 holes = project.holes
     70
     71# Either use houses as holes, or as part of the mesh (with breaklines)
     72houses_as_holes = False
     73if houses_as_holes:
     74    holes = project.holes
     75    breaklines = []
     76else:
     77    # Houses as elevation
     78    house_height = 3.0
     79    holes = []
     80    breaklines = project.holes
     81    house_addition_poly_fun_pairs = []
     82    for i in range(len(breaklines)):
     83        breaklines[i] = breaklines[i] + [breaklines[i][0]]
     84        house_addition_poly_fun_pairs.append(
     85            [ breaklines[i], house_height])
     86    house_addition_poly_fun_pairs.append(['All', 0.])
     87
     88#------------------------------------------------------------------------------
     89# Make domain
     90#------------------------------------------------------------------------------
    6391
    6492if myid == 0:
    65     domain = anuga.create_domain_from_regions(project.bounding_polygon,
    66                 boundary_tags={'bottom': [0],
    67                                'right': [1],
    68                                'top': [2],
    69                                'left': [3]},
    70                                 maximum_triangle_area=remainder_res,
    71                                 interior_holes=holes,
    72                                 mesh_filename=meshname,
    73                                 interior_regions=interior_regions,
    74                                 use_cache=use_cache,
    75                                 verbose=verbose)
     93    mesh = anuga.create_mesh_from_regions(
     94            project.bounding_polygon,
     95            boundary_tags={'bottom': [0],
     96                           'right': [1],
     97                           'top': [2],
     98                           'left': [3]},
     99            maximum_triangle_area=remainder_res,
     100            interior_holes=holes,
     101            breaklines=breaklines,
     102            filename=meshname,
     103            interior_regions=interior_regions,
     104            use_cache=use_cache,
     105            verbose=verbose)
     106
     107    domain = anuga.create_domain_from_file(meshname)
     108   
     109    domain.set_flow_algorithm(alg)
    76110
    77111    #------------------------------------------------------------------------------
     
    79113    #------------------------------------------------------------------------------
    80114    domain.set_quantity('stage', 0.0)
    81     domain.set_quantity('friction', 0.02)
    82     domain.set_quantity('elevation', filename='topography1.pts',
    83                                           use_cache=use_cache,
    84                                           verbose=verbose)
    85 
     115
     116    # Friction -- 2 options
     117    variable_friction = True
     118    if not variable_friction:
     119        # Constant friction
     120        domain.set_quantity('friction', 0.02)
     121
     122    else:
     123        # Set friction to 0.02 on roads, 0.04 elsewhere
     124        road_polygon = anuga.read_polygon('Road/RoadPolygon.csv')
     125        friction_function = qs.composite_quantity_setting_function(
     126            [ [road_polygon, 0.02], ['All', 0.04] ],
     127            domain)
     128        domain.set_quantity('friction', friction_function)
     129
     130    # Elevation
     131    if houses_as_holes:
     132        domain.set_quantity('elevation', filename='topography1.pts',
     133                              use_cache=use_cache,
     134                                  verbose=verbose)
     135
     136    else:
     137        domain.set_quantity('elevation', filename='topography1.pts',
     138                              use_cache=use_cache,
     139                              verbose=verbose, location='vertices')
     140        # Add house_height inside houses   
     141        house_addition_function = qs.composite_quantity_setting_function(
     142            house_addition_poly_fun_pairs, domain)
     143        domain.add_quantity('elevation', house_addition_function,
     144                            location='centroids')
    86145else:
    87146    domain = None
     
    93152domain = distribute(domain)
    94153
     154domain.set_store_vertices_uniquely()
     155
    95156#------------------------------------------------------------------------------
    96157# Setup computational domain
     
    98159domain.set_name('merewether_1m') # Name of sww file
    99160domain.set_datadir('.') # Store sww output here
    100 domain.set_minimum_storable_height(0.001) # Store only depth > 1cm
     161#domain.set_minimum_storable_height(0.001) # Store only depth > 1cm
    101162
    102163
     
    112173
    113174domain.set_boundary({'interior': Br,
    114                      'bottom':   Br,
     175                     'bottom':   Br,
    115176                     'right':    Bt, # outflow
    116177                     'top':      Bt, # outflow
     
    121182
    122183#fixed_inflow = anuga.Inflow(domain,
    123 #                       center=(382300.0,6354290.0),
    124 #                       radius=15.00,
    125 #                       rate=19.7)
     184#           center=(382300.0,6354290.0),
     185#           radius=15.00,
     186#           rate=19.7)
    126187#domain.forcing_terms.append(fixed_inflow)
    127188#hydrograph = anuga.Inflow(center=(382300.0,6354290.0),radius=30.0,rate=anuga.file_function('test_hydrograph2.tms', quantities=['hydrograph'])
     
    132193#------------------------------------------------------------------------------
    133194
    134 for t in domain.evolve(yieldstep=10,finaltime=2000):
    135         if myid == 0: print domain.timestepping_statistics()
     195for t in domain.evolve(yieldstep=10,finaltime=1000):
     196    if myid == 0: print domain.timestepping_statistics()
    136197
    137198
    138199domain.sww_merge()
    139200
     201#------------------------------------------------------------------------------
     202# Make geotif output
     203#------------------------------------------------------------------------------
     204
     205barrier()
     206if myid==0:
     207    util.Make_Geotif('merewether_1m.sww',
     208                     output_quantities=['depth', 'velocity',
     209                                        'friction', 'elevation'],
     210                     myTimeStep='last',
     211                     CellSize=1.0,
     212                     EPSG_CODE=32756,
     213                     bounding_polygon=project.bounding_polygon,
     214                     k_nearest_neighbours=1)
    140215
    141216finalize()
  • trunk/anuga_core/validation_tests/case_studies/merewether/project.py

    r8833 r9354  
    1919# bounding polygon for study area
    2020bounding_polygon = anuga.read_polygon('extent.csv')
    21 print 'Area of bounding polygon', anuga.polygon_area(bounding_polygon)/1000000.0
     21print 'Area of bounding polygon (km^2)', anuga.polygon_area(bounding_polygon)/1.0e+06
    2222
    2323
Note: See TracChangeset for help on using the changeset viewer.