Changeset 8485


Ignore:
Timestamp:
Jul 31, 2012, 9:36:38 AM (13 years ago)
Author:
steve
Message:

Providing an inherited erosion class for Rudy to play with.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/operators/run_polygon_erosion.py

    r8484 r8485  
    1313from anuga import Time_boundary
    1414
    15 from anuga.operators.erosion_operators import Polygonal_erosion_operator
    1615
    17 #------------------------------------------------------------------------------
    18 # Setup computational domain
    19 #------------------------------------------------------------------------------
    20 length = 24.
    21 width = 5.
    22 dx = dy = 0.1 #.1           # Resolution: Length of subdivisions on both axes
    2316
    24 points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
    25                                                len1=length, len2=width)
    26 domain = Domain(points, vertices, boundary)
    27 domain.set_name('polygon_erosion') # Output name
    28 print domain.statistics()
    29 domain.set_quantities_to_be_stored({'elevation': 2,
    30                                     'stage': 2,
    31                                     'xmomentum': 2,
    32                                     'ymomentum': 2})
     17#===============================================================================
     18# Stick all the class and function definitions here
     19#===============================================================================
    3320
    34 #------------------------------------------------------------------------------
    35 # Setup initial conditions
    36 #------------------------------------------------------------------------------
     21#-------------------------------------------------------------------------------
     22# Here are the def's for defining quantities
     23#-------------------------------------------------------------------------------
    3724def topography(x,y):
    3825    """Complex topography defined by a function of vectors x and y."""
     
    5441            z[i] += 0.4
    5542
    56            
     43
    5744    return z
    5845
     46
     47#-------------------------------------------------------------------------------
     48# Inherit from erosion operator
     49#-------------------------------------------------------------------------------
     50from anuga.operators.erosion_operators import Polygonal_erosion_operator
     51
     52class My_polygon_erosion_operator(Polygonal_erosion_operator):
     53    """
     54    Local version of erosion confined to a polygon
     55
     56    """
     57
     58    def __init__(self, domain,
     59                 threshold=0.0,
     60                 base=0.0,
     61                 polygon=None,
     62                 verbose=False):
     63
     64
     65        Polygonal_erosion_operator.__init__(self, domain, threshold, base, polygon, verbose)
     66
     67
     68
     69    def update_quantities(self):
     70        """Update the vertex values of the quantities to model erosion
     71        """
     72        import numpy as num
     73       
     74        t = self.get_time()
     75        dt = self.get_timestep()
     76
     77
     78        updated = True
     79
     80        if self.indices is None:
     81
     82            #--------------------------------------
     83            # Update all three vertices for each cell
     84            #--------------------------------------
     85            self.elev_v[:] = self.elev_v + 0.0
     86
     87        else:
     88
     89            #--------------------------------------
     90            # Update all three vertices for each cell
     91            #--------------------------------------
     92            ind = self.indices
     93            m = num.sqrt(self.xmom_c[ind]**2 + self.ymom_c[ind]**2)
     94            m = num.vstack((m,m,m)).T
     95            m = num.where(m>self.threshold, m, 0.0)
     96            self.elev_v[ind] = num.maximum(self.elev_v[ind] - m*dt, self.base)
     97             #num.maximum(self.elev_v[ind] - momentum*dt, Z)
     98
     99
     100        return updated
     101
     102
     103
     104#===============================================================================
     105# Now to the standard model setup
     106#===============================================================================
     107
     108
     109#-------------------------------------------------------------------------------
     110# Setup computational domain
     111#-------------------------------------------------------------------------------
     112length = 24.
     113width = 5.
     114dx = dy = 0.1 #.1           # Resolution: Length of subdivisions on both axes
     115
     116points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
     117                                               len1=length, len2=width)
     118domain = Domain(points, vertices, boundary)
     119domain.set_name('polygon_erosion') # Output name
     120print domain.statistics()
     121domain.set_quantities_to_be_stored({'elevation': 2,
     122                                    'stage': 2,
     123                                    'xmomentum': 2,
     124                                    'ymomentum': 2})
     125
     126#-------------------------------------------------------------------------------
     127# Setup initial conditions
     128#-------------------------------------------------------------------------------
    59129
    60130
     
    63133domain.set_quantity('stage', expression='elevation')   # Dry initial condition
    64134
    65 #------------------------------------------------------------------------------
     135#-------------------------------------------------------------------------------
    66136# Setup boundary conditions
    67 #------------------------------------------------------------------------------
     137#-------------------------------------------------------------------------------
    68138Bi = Dirichlet_boundary([0.5, 0, 0])          # Inflow
    69139Br = Reflective_boundary(domain)              # Solid reflective wall
     
    72142domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
    73143
    74 #------------------------------------------------------------------------------
     144#-------------------------------------------------------------------------------
    75145# Setup erosion operator in the middle of dam
    76 #------------------------------------------------------------------------------
    77 
     146#-------------------------------------------------------------------------------
    78147polygon1 = [ [12., 0.0], [13., 0.0], [13., 5.0], [12., 5.0] ]
    79 op1 = Polygonal_erosion_operator(domain, threshold=0.0, base=-0.1, polygon=polygon1)
     148op1 = My_polygon_erosion_operator(domain, threshold=0.0, base=-0.1, polygon=polygon1)
    80149
    81150
    82 #------------------------------------------------------------------------------
     151#-------------------------------------------------------------------------------
    83152# Evolve system through time
    84 #------------------------------------------------------------------------------
     153#-------------------------------------------------------------------------------
    85154for t in domain.evolve(yieldstep=0.2, finaltime=40.0):
    86155    domain.print_timestepping_statistics()
     
    95164
    96165
    97 
Note: See TracChangeset for help on using the changeset viewer.