Changeset 6889


Ignore:
Timestamp:
Apr 23, 2009, 5:13:30 PM (16 years ago)
Author:
ole
Message:

Made sure demos in the manual run and did some cleanup

Location:
anuga_core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/documentation/user_manual/demos/cairns/project.py

    r4932 r6889  
    1 # -*- coding: cp1252 -*-
    21"""Common filenames and locations for topographic data, meshes and outputs.
    32"""
    43
    5 from os import sep, environ, getenv, getcwd
    6 from os.path import expanduser
    7 import sys
    8 from time import localtime, strftime, gmtime
    94from anuga.utilities.polygon import read_polygon, plot_polygons, \
    105                                    polygon_area, is_inside_polygon
    116
    12 ###############################
     7                                   
     8#------------------------------------------------------------------------------
     9# Define scenario as either slide or fixed_wave.
     10#------------------------------------------------------------------------------
     11#scenario = 'slide'
     12scenario = 'fixed_wave'
     13                                   
     14                                   
     15#------------------------------------------------------------------------------
     16# Filenames
     17#------------------------------------------------------------------------------
     18demname = 'cairns'
     19meshname = demname + '.msh'
     20
     21# Filename for locations where timeseries are to be produced
     22gauge_filename = 'gauges.csv'
     23                                 
     24                                   
     25#------------------------------------------------------------------------------
    1326# Domain definitions
    14 ###############################
     27#------------------------------------------------------------------------------
    1528
    1629# bounding polygon for study area
    1730bounding_polygon = read_polygon('extent.csv')
    1831
    19 print 'Area of bounding polygon', polygon_area(bounding_polygon)/1000000.0
     32A = polygon_area(bounding_polygon)/1000000.0
     33print 'Area of bounding polygon = %.2f km^2' % A
    2034
    21 ###############################
     35
     36#------------------------------------------------------------------------------
    2237# Interior region definitions
    23 ###############################
     38#------------------------------------------------------------------------------
    2439
    25 # interior polygons
     40# Read interior polygons
    2641poly_cairns = read_polygon('cairns.csv')
    2742poly_island0 = read_polygon('islands.csv')
     
    3146poly_shallow = read_polygon('shallow.csv')
    3247
    33 plot_polygons([bounding_polygon,poly_cairns,poly_island0,poly_island1,\
    34                poly_island2,poly_island3,poly_shallow],\
    35                style='boundingpoly',verbose=False)
     48# Optionally plot points making up these polygons
     49#plot_polygons([bounding_polygon,poly_cairns,poly_island0,poly_island1,\
     50#               poly_island2,poly_island3,poly_shallow],\
     51#               style='boundingpoly',verbose=False)
    3652
    3753
    38 ###################################################################
    39 # Clipping regions for export to asc and regions for clipping data
    40 ###################################################################
    4154
    42 # exporting asc grid
     55# Define resolutions (max area per triangle) for each polygon
     56default_res = 10000000 # Background resolution
     57islands_res = 100000
     58cairns_res = 100000
     59shallow_res = 500000
     60
     61# Define list of interior regions with associated resolutions
     62interior_regions = [[poly_cairns, cairns_res],
     63                    [poly_island0, islands_res],
     64                    [poly_island1, islands_res],
     65                    [poly_island2, islands_res],
     66                    [poly_island3, islands_res],
     67                    [poly_shallow, shallow_res]]
     68
     69
     70
     71#------------------------------------------------------------------------------
     72# Data for exporting ascii grid
     73#------------------------------------------------------------------------------
    4374eastingmin = 363000
    4475eastingmax = 418000
     
    4677northingmax = 8145700
    4778
    48 
    49 slide_origin = [451871, 8128376] # move onto the continental shelf, depth = 500
     79#------------------------------------------------------------------------------
     80# Data for landslide
     81#------------------------------------------------------------------------------
     82slide_origin = [451871, 8128376] # Assume to be on continental shelf
    5083slide_depth = 500.
    5184
    52 gauge_filename = 'gauges.csv'
    5385
    5486
     87
     88
  • anuga_core/documentation/user_manual/demos/cairns/runcairns.py

    r4869 r6889  
    99the elevation data and a tsunami wave generated by a submarine mass failure.
    1010
    11 Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and
    12 Nick Bartzis, GA - 2006
     11Geoscience Australia, 2004-present
    1312"""
    1413
     
    2322
    2423# Related major packages
    25 from anuga.shallow_water import Domain
    26 from anuga.shallow_water import Reflective_boundary
    27 from anuga.shallow_water import Dirichlet_boundary
    28 from anuga.shallow_water import Time_boundary
    29 from anuga.shallow_water import File_boundary
    30 from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
    31 from anuga.pmesh.mesh_interface import create_mesh_from_regions
     24from anuga.interface import create_domain_from_regions
     25from anuga.interface import Reflective_boundary
     26from anuga.interface import Dirichlet_boundary
     27from anuga.interface import Time_boundary
     28from anuga.interface import File_boundary
     29from anuga.interface import Transmissive_stage_zero_momentum_boundary
     30
    3231from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf
    3332from anuga.shallow_water.data_manager import dem2pts
    3433
     34from anuga.shallow_water.smf import slide_tsunami 
     35
    3536# Application specific imports
    3637import project                 # Definition of file names and polygons
    37 
    38 
    39 #------------------------------------------------------------------------------
    40 # Define scenario as either slide or fixed_wave.
    41 #------------------------------------------------------------------------------
    42 scenario = 'slide'
    43 #scenario = 'fixed_wave'
    44 
    45 if os.access(scenario, os.F_OK) == 0:
    46     os.mkdir(scenario)
    47 basename = scenario + 'source'
    4838
    4939
     
    5343#------------------------------------------------------------------------------
    5444
    55 # Filenames
    56 dem_name = 'cairns'
    57 meshname = 'cairns.msh'
    58 
    5945# Create DEM from asc data
    60 convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True)
     46convert_dem_from_ascii2netcdf(project.demname, use_cache=True, verbose=True)
    6147
    6248# Create pts file for onshore DEM
    63 dem2pts(dem_name, use_cache=True, verbose=True)
     49dem2pts(project.demname, use_cache=True, verbose=True)
    6450
    6551
    6652#------------------------------------------------------------------------------
    67 # Create the triangular mesh based on overall clipping polygon with a tagged
    68 # boundary and interior regions defined in project.py along with
    69 # resolutions (maximal area of per triangle) for each polygon
     53# Create the triangular mesh and domain based on
     54# overall clipping polygon with a tagged
     55# boundary and interior regions as defined in project.py
    7056#------------------------------------------------------------------------------
    7157
    72 remainder_res = 10000000
    73 islands_res = 100000
    74 cairns_res = 100000
    75 shallow_res = 500000
    76 interior_regions = [[project.poly_cairns, cairns_res],
    77                     [project.poly_island0, islands_res],
    78                     [project.poly_island1, islands_res],
    79                     [project.poly_island2, islands_res],
    80                     [project.poly_island3, islands_res],
    81                     [project.poly_shallow, shallow_res]]
    82 
    83 create_mesh_from_regions(project.bounding_polygon,
    84                          boundary_tags={'top': [0],
    85                                         'ocean_east': [1],
    86                                         'bottom': [2],
    87                                         'onshore': [3]},
    88                          maximum_triangle_area=remainder_res,
    89                          filename=meshname,
    90                          interior_regions=interior_regions,
    91                          use_cache=False,
    92                          verbose=True)
     58domain = create_domain_from_regions(project.bounding_polygon,
     59                                    boundary_tags={'top': [0],
     60                                                   'ocean_east': [1],
     61                                                   'bottom': [2],
     62                                                   'onshore': [3]},
     63                                    maximum_triangle_area=project.default_res,
     64                                    mesh_filename=project.meshname,
     65                                    interior_regions=project.interior_regions,
     66                                    use_cache=True,
     67                                    verbose=True)
    9368
    9469
    95 #------------------------------------------------------------------------------
    96 # Setup computational domain
    97 #------------------------------------------------------------------------------
    98 from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance
    99 from anuga.caching import cache
    100 
    101 ##domain = cache(Domain(meshname, use_cache=True, verbose=True)
    102 
    103 domain = cache(pmesh_to_domain_instance,
    104                (meshname, Domain),
    105                dependencies = [meshname])
    106 
     70# Print some stats about mesh and domain
    10771print 'Number of triangles = ', len(domain)
    10872print 'The extent is ', domain.get_extent()
    10973print domain.statistics()
    110 
    111 domain.set_name(basename)
    112 domain.set_datadir(scenario)
    113 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
    114 domain.set_minimum_storable_height(0.01)
    115 
    116 #print 'domain.tight_slope_limiters', domain.tight_slope_limiters
    117 domain.tight_slope_limiters = 0
    118 print 'domain.tight_slope_limiters', domain.tight_slope_limiters
     74                                   
     75#------------------------------------------------------------------------------
     76# Setup parameters of computational domain
     77#------------------------------------------------------------------------------
    11978
    12079
     80domain.set_name('cairns_' + project.scenario) # Name of sww file
     81domain.set_datadir('.')                       # Store sww output here
     82domain.set_minimum_storable_height(0.01)      # Store only depth > 1cm
    12183
    122 domain.points_file_block_line_size = 50000
    12384
    12485#------------------------------------------------------------------------------
     
    13091domain.set_quantity('friction', 0.0)
    13192domain.set_quantity('elevation',
    132                     filename=dem_name + '.pts',
     93                    filename=project.demname + '.pts',
    13394                    use_cache=True,
    13495                    verbose=True,
    13596                    alpha=0.1)
     97
    13698
    13799#------------------------------------------------------------------------------
     
    139101#------------------------------------------------------------------------------
    140102
    141 if scenario == 'slide':
     103if project.scenario == 'slide':
    142104    # Function for submarine slide
    143     from anuga.shallow_water.smf import slide_tsunami 
    144105    tsunami_source = slide_tsunami(length=35000.0,
    145106                                   depth=project.slide_depth,
     
    159120print 'Available boundary tags', domain.get_boundary_tags()
    160121
    161 Br = Reflective_boundary(domain)
    162 Bd = Dirichlet_boundary([tide,0,0])
    163122
    164 # 60 min square wave starting at 1 min, 50m high
    165 if scenario == 'fixed_wave':
    166     Bw = Transmissive_Momentum_Set_Stage_boundary(domain = domain,
    167                           function=lambda t: [(60<t<3660)*50, 0, 0])
     123Bd = Dirichlet_boundary([tide,0,0]) # Mean water level
     124Bs = Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary
     125
     126
     127if project.scenario == 'fixed_wave':
     128    # Huge 50m wave starting after 60 seconds and lasting 1 hour.
     129    Bw = Time_boundary(domain=domain,
     130                       function=lambda t: [(60<t<3660)*50, 0, 0])
     131                       
    168132    domain.set_boundary({'ocean_east': Bw,
    169                          'bottom': Bd,
     133                         'bottom': Bs,
    170134                         'onshore': Bd,
    171                          'top': Bd})
     135                         'top': Bs})
    172136
    173 # boundary conditions for slide scenario
    174 if scenario == 'slide':
     137if project.scenario == 'slide':
     138    # Boundary conditions for slide scenario
    175139    domain.set_boundary({'ocean_east': Bd,
    176140                         'bottom': Bd,
     
    189153from anuga.abstract_2d_finite_volumes.quantity import Quantity
    190154
    191 if scenario == 'slide':
     155if project.scenario == 'slide':
    192156   
    193     for t in domain.evolve(yieldstep = 10, finaltime = 60):
    194         domain.write_time()
    195         domain.write_boundary_statistics(tags = 'ocean_east')     
     157    for t in domain.evolve(yieldstep=10, finaltime=60):
     158        print domain.timestepping_statistics()
     159        print domain.boundary_statistics(tags='ocean_east')        
    196160       
    197     # add slide
     161    # Add slide
    198162    thisstagestep = domain.get_quantity('stage')
    199163    if allclose(t, 60):
     
    202166        domain.set_quantity('stage', slide + thisstagestep)
    203167
    204     for t in domain.evolve(yieldstep = 10, finaltime = 5000,
     168    for t in domain.evolve(yieldstep=10, finaltime=5000,
    205169                           skip_initial_step = True):
    206         domain.write_time()
    207         domain.write_boundary_statistics(tags = 'ocean_east')
     170        print domain.timestepping_statistics()
     171        print domain.boundary_statistics(tags='ocean_east')   
    208172
    209 if scenario == 'fixed_wave':
     173       
     174if project.scenario == 'fixed_wave':
    210175
    211     # save every two mins leading up to wave approaching land
    212     for t in domain.evolve(yieldstep = 120, finaltime = 5000):
    213         domain.write_time()
    214         domain.write_boundary_statistics(tags = 'ocean_east')    
     176    # Save every two mins leading up to wave approaching land
     177    for t in domain.evolve(yieldstep=120, finaltime=5000):
     178        print domain.timestepping_statistics()
     179        print domain.boundary_statistics(tags='ocean_east')   
    215180
    216     # save every 30 secs as wave starts inundating ashore
    217     for t in domain.evolve(yieldstep = 10, finaltime = 10000,
    218                            skip_initial_step = True):
    219         domain.write_time()
    220         domain.write_boundary_statistics(tags = 'ocean_east')
     181    # Save every 30 secs as wave starts inundating ashore
     182    for t in domain.evolve(yieldstep=10, finaltime=10000,
     183                           skip_initial_step=True):
     184        print domain.timestepping_statistics()
     185        print domain.boundary_statistics(tags='ocean_east')
    221186           
    222187print 'That took %.2f seconds' %(time.time()-t0)
  • anuga_core/documentation/user_manual/demos/channel2.py

    r3982 r6889  
    5353#------------------------------------------------------------------------------
    5454for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0):
    55     domain.write_time()
     55    print domain.timestepping_statistics()
    5656
    5757    if domain.get_quantity('stage').\
  • anuga_core/documentation/user_manual/demos/channel3.py

    r5315 r6889  
    1919length = 40.
    2020width = 5.
    21 dx = dy = .05           # Resolution: Length of subdivisions on both axes
     21dx = dy = .1           # Resolution: Length of subdivisions on both axes
    2222
    2323points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
  • anuga_core/documentation/user_manual/demos/runup.py

    r6227 r6889  
    1010#------------------------------------------------------------------------------
    1111
    12 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
     12from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
    1313from anuga.shallow_water import Domain
    1414from anuga.shallow_water import Reflective_boundary
     
    1717from anuga.shallow_water import Transmissive_boundary
    1818
     19from math import sin, pi, exp
    1920
    2021#------------------------------------------------------------------------------
     
    2728domain.set_name('runup')                    # Output to file runup.sww
    2829domain.set_datadir('.')                     # Use current directory for output
    29 domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities
    30                                     'xmomentum',
    31                                     'ymomentum'])   
    3230
    3331
     
    4947#------------------------------------------------------------------------------
    5048
    51 from math import sin, pi, exp
    5249Br = Reflective_boundary(domain)      # Solid reflective wall
    5350Bt = Transmissive_boundary(domain)    # Continue all values on boundary
     
    6562
    6663for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0):
    67     domain.write_time()
     64    print domain.timestepping_statistics()
    6865   
    6966
  • anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r6475 r6889  
    8282    """Time dependent boundary returns values for the
    8383    conserved quantities as a function of time.
    84     Must specify domain to get access to model time and a function f(t)
    85     which must return conserved quantities as a function time
     84    Must specify domain to get access to model time and a function of t
     85    which must return conserved quantities as a function time.
     86   
     87    Example:
     88      B = Time_boundary(domain,
     89                        function=lambda t: [(60<t<3660)*2, 0, 0])
     90     
     91      This will produce a boundary condition with is a 2m high square wave
     92      starting 60 seconds into the simulation and lasting one hour.
     93      Momentum applied will be 0 at all times.
     94                       
    8695    """
    8796
     
    8998    # Transmissive_Momentum_Set_Stage_Boundary (cf posting by rrraman)
    9099    def __init__(self, domain=None,
    91                  f=None,
     100                 f=None, # Should be removed and replaced by function below
     101                 function=None,
    92102                 default_boundary=None,
    93103                 verbose=False):
     
    99109        self.verbose = verbose
    100110
     111       
     112        # FIXME: Temporary code to deal with both f and function
     113        if function is not None and f is not None:
     114            raise Exception, 'Specify either function or f to Time_boundary'
     115           
     116        if function is None and f is None:
     117            raise Exception, 'You must specify a function to Time_boundary'
     118           
     119        if f is None:
     120            f = function
     121        #####
     122       
    101123        try:
    102124            q = f(0.0)
Note: See TracChangeset for help on using the changeset viewer.