Changeset 8974


Ignore:
Timestamp:
Sep 12, 2013, 9:32:39 PM (11 years ago)
Author:
steve
Message:

Cleaning up import anuga

Location:
trunk/anuga_core
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/demos/channel1.py

    r8728 r8974  
    77# Import necessary modules
    88#------------------------------------------------------------------------------
    9 
    10 # Import standard shallow water domain and standard boundaries.
    119import anuga
    12 
    1310
    1411#------------------------------------------------------------------------------
    1512# Setup computational domain
    1613#------------------------------------------------------------------------------
    17 points, vertices, boundary = anuga.rectangular_cross(10, 5,
    18                                                len1=10.0, len2=5.0) # Mesh
     14# Create a domain with named boundaries "left", "right", "top" and "bottom"
     15domain = anuga.rectangular_cross_domain(10, 5, len1=10.0, len2=5.0) # Create domain
    1916
    20 domain = anuga.Domain(points, vertices, boundary)  # Create domain
     17
    2118domain.set_name('channel1')                  # Output name
    2219
     
    4441#------------------------------------------------------------------------------
    4542for t in domain.evolve(yieldstep=0.2, finaltime=40.0):
    46     print domain.timestepping_statistics()
     43    domain.print_timestepping_statistics()
    4744
  • trunk/anuga_core/source/anuga/__init__.py

    r8972 r8974  
    6666
    6767#-----------------------------
    68 # Standard Boundaries
     68# SwW Standard Boundaries
    6969#-----------------------------
    7070from anuga.shallow_water.boundaries import File_boundary
     
    8282
    8383#-----------------------------
    84 # SWW-specific Boundaries
     84# General Boundaries
    8585#-----------------------------
    8686from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     
    9696
    9797#-----------------------------
    98 # Shalow Water Tsunamis
     98# Shallow Water Tsunamis
    9999#-----------------------------
    100100
     
    106106#-----------------------------
    107107from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress
     108
     109
    108110
    109111#-----------------------------
     
    140142from anuga.operators.base_operator import Operator
    141143from anuga.operators.kinematic_viscosity_operator import Kinematic_viscosity_operator
     144from anuga.operators.rate_operators import Rate_operator
     145from anuga.operators.set_friction_operators import Depth_friction_operator
    142146
    143147#---------------------------
     
    371375import time
    372376from os.path import join
    373 from scipy import interpolate
     377
    374378from anuga import indent
    375379from anuga.utilities.model_tools import read_polygon_dir, read_hole_dir, read_multi_poly_file, read_multi_poly_file_value
    376 from anuga.operators.rate_operators import Rate_operator, Polygonal_rate_operator
    377 from anuga.operators.set_friction_operators import Depth_friction_operator
    378 from anuga.structures.boyd_box_operator import Boyd_box_operator
    379 from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/file_function.py

    r8953 r8974  
    179179               'First argument to File_function must be a string'
    180180
    181     try:
    182         fid = open(filename)
    183     except IOError, e:
    184         msg = 'File "%s" could not be opened: Error="%s"' % (filename, e)
    185         raise IOError(msg)
    186 
     181    #try:
     182    #    fid = open(filename)
     183    #except IOError, e:
     184    #    msg = 'File "%s" could not be opened: Error="%s"' % (filename, e)
     185    #    raise IOError(msg)
     186   
    187187    # read first line of file, guess file type
    188     line = fid.readline()
    189     fid.close()
    190 
    191     if line[:3] == 'CDF':
     188    #line = fid.readline()
     189    #fid.close()
     190       
     191    import os
     192    ext = os.path.splitext(filename)[1]
     193    msg = 'Extension should be csv  sww, tms or sts '
     194    assert ext in [".csv",  ".sww", ".tms", ".sts"], msg
     195
     196
     197    if ext in [".sww", ".tms", ".sts"]:
    192198        return get_netcdf_file_function(filename,
    193199                                        quantities,
     
    199205                                        boundary_polygon=boundary_polygon,
    200206                                        output_centroids=output_centroids)
    201     else:
     207    elif ext in [".csv"]:
    202208        # FIXME (Ole): Could add csv file here to address Ted Rigby's
    203209        # suggestion about reading hydrographs.
    204         # This may also deal with the gist of ticket:289
     210        # This may also deal with the gist of ticket:289
     211        raise Exception('Must be a NetCDF File')
     212    else:
     213
    205214        raise Exception('Must be a NetCDF File')
    206215
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r8973 r8974  
    12571257        points = ensure_absolute(points, geo_reference=self.domain.geo_reference)
    12581258           
    1259         print numpy.max(points[:,0])
    1260         print numpy.min(points[:,0])
    1261         print numpy.max(points[:,1])
    1262         print numpy.min(points[:,1])
    1263        
    1264         print numpy.max(x)
    1265         print numpy.min(x)
    1266         print numpy.max(y)
    1267         print numpy.min(y)
     1259#         print numpy.max(points[:,0])
     1260#         print numpy.min(points[:,0])
     1261#         print numpy.max(points[:,1])
     1262#         print numpy.min(points[:,1])
     1263#        
     1264#         print numpy.max(x)
     1265#         print numpy.min(x)
     1266#         print numpy.max(y)
     1267#         print numpy.min(y)
    12681268       
    12691269       
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r8973 r8974  
    13881388
    13891389    def test_set_values_from_asc_vertices(self):
     1390       
     1391       
     1392       
     1393
     1394
     1395        x0 = 0.0
     1396        y0 = 0.0
     1397
     1398        a = [0.0, 0.0]
     1399        b = [0.0, 2.0]
     1400        c = [2.0, 0.0]
     1401        d = [0.0, 4.0]
     1402        e = [2.0, 2.0]
     1403        f = [4.0, 0.0]
     1404
     1405        points = [a, b, c, d, e, f]
     1406
     1407        #bac, bce, ecf, dbe
     1408        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
     1409
     1410        mesh4 = Generic_Domain(points, elements)
     1411                     #  geo_reference = Geo_reference(56, x0, y0))
     1412        mesh4.check_integrity()
     1413        quantity = Quantity(mesh4)
     1414
    13901415        """ Format of asc file
    13911416        ncols         11
     
    13961421        NODATA_value  -9999
    13971422        """
    1398 
    1399         #x0 = 314036.58727982
    1400         #y0 = 6224951.2960092
    1401         x0 = 0.0
    1402         y0 = 0.0
    1403 
    1404         a = [0.0, 0.0]
    1405         b = [0.0, 2.0]
    1406         c = [2.0, 0.0]
    1407         d = [0.0, 4.0]
    1408         e = [2.0, 2.0]
    1409         f = [4.0, 0.0]
    1410 
    1411         points = [a, b, c, d, e, f]
    1412 
    1413         #bac, bce, ecf, dbe
    1414         elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    1415 
    1416         mesh4 = Generic_Domain(points, elements)
    1417                      #  geo_reference = Geo_reference(56, x0, y0))
    1418         mesh4.check_integrity()
    1419         quantity = Quantity(mesh4)
    1420 
    1421 
    14221423        ncols = 11  # Nx
    14231424        nrows = 12  # Ny
  • trunk/anuga_core/source/anuga/config.py

    r8970 r8974  
    223223netcdf_mode_a = 'a'
    224224netcdf_mode_r = 'r'
     225
     226
     227indent = '    '
    225228
    226229# Code to set the write mode depending on
  • trunk/anuga_core/source/anuga/operators/rate_operators.py

    r8945 r8974  
    1111
    1212
    13 from anuga import indent
     13from anuga.config import indent
    1414import numpy as num
    1515import anuga.utilities.log as log
  • trunk/anuga_core/source/anuga/operators/set_elevation.py

    r8931 r8974  
    1717
    1818from anuga.operators.set_quantity import Set_quantity
    19 
    20 from anuga import indent
     19from anuga.config import indent
    2120
    2221class Set_elevation(Set_quantity):
  • trunk/anuga_core/source/anuga/operators/set_elevation_operator.py

    r8945 r8974  
    1313from anuga.operators.set_elevation import Set_elevation
    1414
    15 from anuga import indent
     15from anuga.config import indent
    1616
    1717
  • trunk/anuga_core/source/anuga/operators/set_friction_operators.py

    r8951 r8974  
    1515from anuga.operators.base_operator import Operator
    1616from anuga.operators.region import Region
    17 
    18 
    19 from anuga import indent
     17from anuga.config import indent
    2018
    2119
  • trunk/anuga_core/source/anuga/operators/set_quantity.py

    r8931 r8974  
    1717from anuga.utilities.function_utils import determine_function_type
    1818from anuga.operators.region import Region
    19 from anuga import indent
     19from anuga.config import indent
    2020
    2121class Set_quantity(Region):
  • trunk/anuga_core/source/anuga/operators/set_quantity_operator.py

    r8945 r8974  
    1313from anuga.operators.base_operator import Operator
    1414from anuga.operators.set_quantity import Set_quantity
    15 
    16 from anuga import indent
     15from anuga.config import indent
    1716
    1817
  • trunk/anuga_core/source/anuga/operators/set_stage_operator.py

    r8945 r8974  
    1818
    1919from anuga.operators.set_quantity_operator import Set_quantity_operator
    20 
    21 
    22 from anuga import indent
     20from anuga.config import indent
    2321
    2422
  • trunk/anuga_core/source/anuga/operators/set_w_uh_vh_operators.py

    r8619 r8974  
    2020from anuga.fit_interpolate.interpolate import Modeltime_too_early, \
    2121                                              Modeltime_too_late
    22 from anuga import indent
     22from anuga.config import indent
    2323
    2424
  • trunk/anuga_core/source/anuga/structures/test_inlet_operator.py

    r8874 r8974  
    299299# =========================================================================
    300300if __name__ == "__main__":
    301     suite = unittest.makeSuite(Test_inlet_operator, 'test_inlet_constant_Q_polygon')
     301    suite = unittest.makeSuite(Test_inlet_operator, 'test')
    302302    runner = unittest.TextTestRunner()
    303303    runner.run(suite)
  • trunk/anuga_core/source/anuga/version.py

    r8251 r8974  
    1 #! /usr/bin/python
    2 
    3 # To change this template, choose Tools | Templates
    4 # and open the template in the editor.
    5 
    6 __author__="steve"
    7 __date__ ="$18/11/2011 11:35:22 AM$"
    8 
    9 if __name__ == "__main__":
    10     import anuga
    11     print 'Anuga version:',anuga.__version__
     1version = 8973
     2status = 'Modified'
     3date = '2013/09/12 15:18:38'
  • trunk/anuga_core/user_manual/anuga_user_manual.tex

    r8973 r8974  
    4545
    4646\title{\anuga User Manual}
    47 \author{Geoscience Australia and the Australian National University}
     47\author{Stephen Roberts, Ole Nielsen, Duncan Gray and Jane Sexton}
    4848
    4949% Please at least include a long-lived email address;
     
    6161% stages to make it easier to handle versions.
    6262
    63 \longdate       % Make date format long using datetime.sty
     63%\longdate       % Make date format long using datetime.sty
    6464%\settimeformat{xxivtime} % 24 hour Format
    65 \settimeformat{oclock} % Verbose
    66 \date{\today, \ \currenttime}
     65%\settimeformat{oclock} % Verbose
     66\date{\today \ \currenttime}
    6767%\hyphenation{set\_datadir}
    6868
     
    13941394\end{verbatim}
    13951395
    1396 All modules are in the folder \file{inundation} or one of its subfolders, and the
    1397 location of each module is described relative to \file{inundation}. Rather
     1396All modules are in the folder \file{anuga} or one of its subfolders, and the
     1397location of each module is described relative to \file{anuga}. Rather
    13981398than using pathnames, whose syntax depends on the operating system,
    13991399we use the format adopted for importing the function or class for
     
    25662566
    25672567
    2568 \section{Forcing Terms}\index{Forcing terms}
    2569 \label{sec:forcing terms}
    2570 
    2571 \anuga provides a number of predefined forcing functions to be used with simulations.
    2572 Gravity and friction are always calculated using the elevation and friction quantities,
    2573 but the user may additionally add forcing terms to the list
    2574 \code{domain.forcing_terms} and have them affect the model.
    2575 
    2576 Currently, predefined forcing terms are: \\
    2577 \begin{classdesc}{General_forcing}{domain,
    2578                                   quantity_name,
    2579                                   rate=0.0,
    2580                                   center=None,
    2581                                   radius=None,
    2582                                   polygon=None,
    2583                                   default_rate=None,
    2584                                   verbose=False}
    2585 Module: \module{shallow_water.shallow_water_domain}
    2586 
    2587 This is a general class to modify any quantity according to a given rate of change.
    2588 Other specific forcing terms are based on this class but it can be used by itself as well (e.g.\ to modify momentum).
    2589 
    2590 \code{domain} is the domain being evolved.
    2591 
    2592 \code{quantity_name} is the name of the quantity that will be affected by this forcing term.
    2593 
    2594 \code{rate} is the rate at which the quantity should change. This can be either a constant or a
    2595 function of time. Positive values indicate increases, negative values indicate decreases.
    2596 The parameter \code{rate} can be \code{None} at initialisation but must be specified
    2597 before a forcing term is applied (i.e.\ simulation has started).
    2598 The default value is 0.0 -- i.e.\ no forcing.
    2599 
    2600 \code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
    2601 
    2602 \code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
    2603 
    2604 Note: specifying \code{center}, \code{radius} and \code{polygon} will cause an exception to be thrown.
    2605 Moreover, if the specified polygon or circle does not lie fully within the mesh boundary an Exception will be thrown.
    2606 
    2607 Example:
    2608 
    2609 \begin{verbatim}
    2610 P = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]]    # Square polygon
    2611 
    2612 xmom = General_forcing(domain, 'xmomentum', polygon=P)
    2613 ymom = General_forcing(domain, 'ymomentum', polygon=P)
    2614 
    2615 xmom.rate = f
    2616 ymom.rate = g
    2617 
    2618 domain.forcing_terms.append(xmom)
    2619 domain.forcing_terms.append(ymom)
    2620 \end{verbatim}
    2621 
    2622 Here, \code{f} and \code{g} are assumed to be defined as functions of time providing
    2623 a time dependent rate of change for xmomentum and ymomentum respectively.
    2624 \code{P} is assumed to be the polygon, specified as a list of points.
    2625 \end{classdesc}
    2626 
    2627 \begin{classdesc}{Inflow}{domain,
    2628                          rate=0.0,
    2629                          center=None, radius=None,
    2630                          polygon=None,
    2631                          default_rate=None,
    2632                          verbose=False}
    2633 Module: \module{shallow_water.shallow_water_domain}
    2634 
    2635 This is a general class for inflow and abstraction of water according to a given rate of change.
    2636 This class will always modify the \code{stage} quantity.
    2637 
    2638 Inflow is based on the \code{General_forcing} class so the functionality is similar.
    2639 
    2640 \code{domain} is the domain being evolved.
    2641 
    2642 \code{rate} is the flow rate ($m^3/s$) at which the quantity should change. This can be either a constant or a
    2643 function of time. Positive values indicate inflow, negative values indicate outflow.
    2644 Note: The specified flow will be divided by the area of the inflow region and then applied to update the
    2645 stage quantity.
    2646 
    2647 \code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
    2648 
    2649 \code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
    2650 
    2651 Example:
    2652 
    2653 \begin{verbatim}
    2654 hydrograph = Inflow(center=(320, 300), radius=10,
    2655                     rate=file_function('QPMF_Rot_Sub13.tms'))
    2656 
    2657 domain.forcing_terms.append(hydrograph)
    2658 \end{verbatim}
    2659 
    2660 Here, \code{'QPMF_Rot_Sub13.tms'} is assumed to be a NetCDF file in the TMS format defining a timeseries for a hydrograph.
    2661 \end{classdesc}
    2662 
    2663 \begin{classdesc}{Rainfall}{domain,
    2664                            rate=0.0,
    2665                            center=None,
    2666                            radius=None,
    2667                            polygon=None,
    2668                            default_rate=None,
    2669                            verbose=False}
    2670 Module: \module{shallow_water.shallow_water_domain}
    2671 
    2672 This is a general class for implementing rainfall over the domain, possibly restricted to a given circle or polygon.
    2673 This class will always modify the \code{stage} quantity.
    2674 
    2675 Rainfall is based on the \code{General_forcing} class so the functionality is similar.
    2676 
    2677 \code{domain} is the domain being evolved.
    2678 
    2679 \code{rate} is the total rain rate over the specified domain.
    2680 Note: Raingauge Data needs to reflect the time step.
    2681 For example, if rain gauge is \code{mm} read every \code{dt} seconds, then the input
    2682 here is as \code{mm/dt} so 10 mm in 5 minutes becomes
    2683 10/(5x60) = 0.0333mm/s.  This parameter can be either a constant or a
    2684 function of time. Positive values indicate rain being added (or be used for general infiltration),
    2685 negative values indicate outflow at the specified rate (presumably this could model evaporation or abstraction).
    2686 
    2687 \code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
    2688 
    2689 \code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
    2690 
    2691 Example:
    2692 
    2693 \begin{verbatim}
    2694 catchmentrainfall = Rainfall(rate=file_function('Q100_2hr_Rain.tms'))
    2695 domain.forcing_terms.append(catchmentrainfall)
    2696 \end{verbatim}
    2697 
    2698 Here, \code{'Q100_2hr_Rain.tms'} is assumed to be a NetCDF file in the TMS format defining a timeseries for the rainfall.
    2699 \end{classdesc}
    2700 
    2701 \begin{classdesc}{Culvert_flow}{domain,
    2702                  culvert_description_filename=None,
    2703                  culvert_routine=None,
    2704                  end_point0=None,
    2705                  end_point1=None,
    2706                  enquiry_point0=None,
    2707                  enquiry_point1=None,
    2708                  type='box',
    2709                  width=None,
    2710                  height=None,
    2711                  length=None,
    2712                  number_of_barrels=1,
    2713                  trigger_depth=0.01,
    2714                  manning=None,
    2715                  sum_loss=None,
    2716                  use_velocity_head=False,
    2717                  use_momentum_jet=False,
    2718                  label=None,
    2719                  description=None,
    2720                  update_interval=None,
    2721                  log_file=False,
    2722                  discharge_hydrograph=False,
    2723                  verbose=False}
    2724 Module: \module{culvert_flows.culvert_class}
    2725 
    2726 This is a general class for implementing flow through a culvert.
    2727 This class modifies the quantities \code{stage}, \code{xmomentum} and \code{ymomentum} in areas at both ends of the culvert.
    2728 
    2729 The \code{Culvert_flow} forcing term uses \code{Inflow} and \code{General_forcing} to update the quantities.
    2730 The flow direction is determined on-the-fly so openings are referenced simple as opening0 and opening1
    2731 with either being able to take the role as Inflow or Outflow.
    2732 
    2733 The \code{Culvert_flow} class takes as input:
    2734 
    2735  \code{domain}: a reference to the domain being evolved
    2736 
    2737 \code{culvert_description_filename}:
    2738 
    2739 \code{culvert_routine}:
    2740 
    2741   \code{end_point0}: Coordinates of one opening
    2742 
    2743   \code{end_point1}: Coordinates of other opening
    2744 
    2745   \code{enquiry_point0}:
    2746 
    2747  \code{enquiry_point1}:
    2748 
    2749  \code{type}: (default is 'box')
    2750 
    2751  \code{width}:
    2752 
    2753   \code{height}:
    2754 
    2755  \code{length}:
    2756 
    2757   \code{number_of_barrels}: Number of identical pipes in the culvert (default is 1)
    2758 
    2759  \code{trigger_depth}: (default is 0.01)
    2760 
    2761   \code{manning}: Mannings Roughness for Culvert
    2762 
    2763  \code{sum_loss}:
    2764 
    2765  \code{use_velocity_head}:
    2766 
    2767   \code{use_momentum_jet}:
    2768 
    2769    \code{label}: Short text naming the culvert
    2770 
    2771   \code{description}: Text describing the culvert
    2772 
    2773     \code{update_interval}:
    2774 
    2775  \code{log_file}:
    2776 
    2777   \code{discharge_hydrograph}:
    2778 
    2779 
    2780 The user can specify different culvert routines. However, \anuga currently provides only one, namely the
    2781 \code{boyd_generalised_culvert_model} as used in the example below:
    2782 
    2783 \begin{verbatim}
    2784 from anuga.culvert_flows.culvert_class import Culvert_flow
    2785 from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
    2786 
    2787 culvert1 = Culvert_flow(domain,
    2788                         label='Culvert No. 1',
    2789                         description='This culvert is a test unit 1.2m Wide by 0.75m High',
    2790                         end_point0=[9.0, 2.5],
    2791                         end_point1=[13.0, 2.5],
    2792                         width=1.20,
    2793                         height=0.75,
    2794                         culvert_routine=boyd_generalised_culvert_model,
    2795                         number_of_barrels=1,
    2796                         verbose=True)
    2797 
    2798 culvert2 = Culvert_flow(domain,
    2799                         label='Culvert No. 2',
    2800                         description='This culvert is a circular test with d=1.2m',
    2801                         end_point0=[9.0, 1.5],
    2802                         end_point1=[30.0, 3.5],
    2803                         diameter=1.20,
    2804                         invert_level0=7,
    2805                         culvert_routine=boyd_generalised_culvert_model,
    2806                         number_of_barrels=1,
    2807                         verbose=True)
    2808 
    2809 domain.forcing_terms.append(culvert1)
    2810 domain.forcing_terms.append(culvert2)
    2811 \end{verbatim}
    2812 \end{classdesc}
    2813 
     2568%\section{Forcing Terms}\index{Forcing terms}
     2569%\label{sec:forcing terms}
     2570%
     2571%\anuga provides a number of predefined forcing functions to be used with simulations.
     2572%Gravity and friction are always calculated using the elevation and friction quantities,
     2573%but the user may additionally add forcing terms to the list
     2574%\code{domain.forcing_terms} and have them affect the model.
     2575%
     2576%Currently, predefined forcing terms are: \\
     2577%\begin{classdesc}{General_forcing}{domain,
     2578%                                  quantity_name,
     2579%                                  rate=0.0,
     2580%                                  center=None,
     2581%                                  radius=None,
     2582%                                  polygon=None,
     2583%                                  default_rate=None,
     2584%                                  verbose=False}
     2585%Module: \module{shallow_water.shallow_water_domain}
     2586%
     2587%This is a general class to modify any quantity according to a given rate of change.
     2588%Other specific forcing terms are based on this class but it can be used by itself as well (e.g.\ to modify momentum).
     2589%
     2590%\code{domain} is the domain being evolved.
     2591%
     2592%\code{quantity_name} is the name of the quantity that will be affected by this forcing term.
     2593%
     2594%\code{rate} is the rate at which the quantity should change. This can be either a constant or a
     2595%function of time. Positive values indicate increases, negative values indicate decreases.
     2596%The parameter \code{rate} can be \code{None} at initialisation but must be specified
     2597%before a forcing term is applied (i.e.\ simulation has started).
     2598%The default value is 0.0 -- i.e.\ no forcing.
     2599%
     2600%\code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
     2601%
     2602%\code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
     2603%
     2604%Note: specifying \code{center}, \code{radius} and \code{polygon} will cause an exception to be thrown.
     2605%Moreover, if the specified polygon or circle does not lie fully within the mesh boundary an Exception will be thrown.
     2606%
     2607%Example:
     2608%
     2609%\begin{verbatim}
     2610%P = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]]    # Square polygon
     2611%
     2612%xmom = General_forcing(domain, 'xmomentum', polygon=P)
     2613%ymom = General_forcing(domain, 'ymomentum', polygon=P)
     2614%
     2615%xmom.rate = f
     2616%ymom.rate = g
     2617%
     2618%domain.forcing_terms.append(xmom)
     2619%domain.forcing_terms.append(ymom)
     2620%\end{verbatim}
     2621%
     2622%Here, \code{f} and \code{g} are assumed to be defined as functions of time providing
     2623%a time dependent rate of change for xmomentum and ymomentum respectively.
     2624%\code{P} is assumed to be the polygon, specified as a list of points.
     2625%\end{classdesc}
     2626%
     2627%\begin{classdesc}{Inflow}{domain,
     2628%                         rate=0.0,
     2629%                         center=None, radius=None,
     2630%                         polygon=None,
     2631%                         default_rate=None,
     2632%                         verbose=False}
     2633%Module: \module{shallow_water.shallow_water_domain}
     2634%
     2635%This is a general class for inflow and abstraction of water according to a given rate of change.
     2636%This class will always modify the \code{stage} quantity.
     2637%
     2638%Inflow is based on the \code{General_forcing} class so the functionality is similar.
     2639%
     2640%\code{domain} is the domain being evolved.
     2641%
     2642%\code{rate} is the flow rate ($m^3/s$) at which the quantity should change. This can be either a constant or a
     2643%function of time. Positive values indicate inflow, negative values indicate outflow.
     2644%Note: The specified flow will be divided by the area of the inflow region and then applied to update the
     2645%stage quantity.
     2646%
     2647%\code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
     2648%
     2649%\code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
     2650%
     2651%Example:
     2652%
     2653%\begin{verbatim}
     2654%hydrograph = Inflow(center=(320, 300), radius=10,
     2655%                    rate=file_function('QPMF_Rot_Sub13.tms'))
     2656%
     2657%domain.forcing_terms.append(hydrograph)
     2658%\end{verbatim}
     2659%
     2660%Here, \code{'QPMF_Rot_Sub13.tms'} is assumed to be a NetCDF file in the TMS format defining a timeseries for a hydrograph.
     2661%\end{classdesc}
     2662%
     2663%\begin{classdesc}{Rainfall}{domain,
     2664%                           rate=0.0,
     2665%                           center=None,
     2666%                           radius=None,
     2667%                           polygon=None,
     2668%                           default_rate=None,
     2669%                           verbose=False}
     2670%Module: \module{shallow_water.shallow_water_domain}
     2671%
     2672%This is a general class for implementing rainfall over the domain, possibly restricted to a given circle or polygon.
     2673%This class will always modify the \code{stage} quantity.
     2674%
     2675%Rainfall is based on the \code{General_forcing} class so the functionality is similar.
     2676%
     2677%\code{domain} is the domain being evolved.
     2678%
     2679%\code{rate} is the total rain rate over the specified domain.
     2680%Note: Raingauge Data needs to reflect the time step.
     2681%For example, if rain gauge is \code{mm} read every \code{dt} seconds, then the input
     2682%here is as \code{mm/dt} so 10 mm in 5 minutes becomes
     2683%10/(5x60) = 0.0333mm/s.  This parameter can be either a constant or a
     2684%function of time. Positive values indicate rain being added (or be used for general infiltration),
     2685%negative values indicate outflow at the specified rate (presumably this could model evaporation or abstraction).
     2686%
     2687%\code{center} and \code{ radius} optionally restrict forcing to a circle with given center and radius.
     2688%
     2689%\code{polygon} optionally restricts forcing to an area enclosed by the given polygon.
     2690%
     2691%Example:
     2692%
     2693%\begin{verbatim}
     2694%catchmentrainfall = Rainfall(rate=file_function('Q100_2hr_Rain.tms'))
     2695%domain.forcing_terms.append(catchmentrainfall)
     2696%\end{verbatim}
     2697%
     2698%Here, \code{'Q100_2hr_Rain.tms'} is assumed to be a NetCDF file in the TMS format defining a timeseries for the rainfall.
     2699%\end{classdesc}
     2700%
     2701%\begin{classdesc}{Culvert_flow}{domain,
     2702%                 culvert_description_filename=None,
     2703%                 culvert_routine=None,
     2704%                 end_point0=None,
     2705%                 end_point1=None,
     2706%                 enquiry_point0=None,
     2707%                 enquiry_point1=None,
     2708%                 type='box',
     2709%                 width=None,
     2710%                 height=None,
     2711%                 length=None,
     2712%                 number_of_barrels=1,
     2713%                 trigger_depth=0.01,
     2714%                 manning=None,
     2715%                 sum_loss=None,
     2716%                 use_velocity_head=False,
     2717%                 use_momentum_jet=False,
     2718%                 label=None,
     2719%                 description=None,
     2720%                 update_interval=None,
     2721%                 log_file=False,
     2722%                 discharge_hydrograph=False,
     2723%                 verbose=False}
     2724%Module: \module{culvert_flows.culvert_class}
     2725%
     2726%This is a general class for implementing flow through a culvert.
     2727%This class modifies the quantities \code{stage}, \code{xmomentum} and \code{ymomentum} in areas at both ends of the culvert.
     2728%
     2729%The \code{Culvert_flow} forcing term uses \code{Inflow} and \code{General_forcing} to update the quantities.
     2730%The flow direction is determined on-the-fly so openings are referenced simple as opening0 and opening1
     2731%with either being able to take the role as Inflow or Outflow.
     2732%
     2733%The \code{Culvert_flow} class takes as input:
     2734%
     2735% \code{domain}: a reference to the domain being evolved
     2736%
     2737%\code{culvert_description_filename}:
     2738%
     2739%\code{culvert_routine}:
     2740%
     2741%  \code{end_point0}: Coordinates of one opening
     2742%
     2743%  \code{end_point1}: Coordinates of other opening
     2744%
     2745%  \code{enquiry_point0}:
     2746%
     2747% \code{enquiry_point1}:
     2748%
     2749% \code{type}: (default is 'box')
     2750%
     2751% \code{width}:
     2752%
     2753%  \code{height}:
     2754%
     2755% \code{length}:
     2756%
     2757%  \code{number_of_barrels}: Number of identical pipes in the culvert (default is 1)
     2758%
     2759% \code{trigger_depth}: (default is 0.01)
     2760%
     2761%  \code{manning}: Mannings Roughness for Culvert
     2762%
     2763% \code{sum_loss}:
     2764%
     2765% \code{use_velocity_head}:
     2766%
     2767%  \code{use_momentum_jet}:
     2768%
     2769%   \code{label}: Short text naming the culvert
     2770%
     2771%  \code{description}: Text describing the culvert
     2772%
     2773%    \code{update_interval}:
     2774%
     2775% \code{log_file}:
     2776%
     2777%  \code{discharge_hydrograph}:
     2778%
     2779%
     2780%The user can specify different culvert routines. However, \anuga currently provides only one, namely the
     2781%\code{boyd_generalised_culvert_model} as used in the example below:
     2782%
     2783%\begin{verbatim}
     2784%from anuga.culvert_flows.culvert_class import Culvert_flow
     2785%from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
     2786%
     2787%culvert1 = Culvert_flow(domain,
     2788%                        label='Culvert No. 1',
     2789%                        description='This culvert is a test unit 1.2m Wide by 0.75m High',
     2790%                        end_point0=[9.0, 2.5],
     2791%                        end_point1=[13.0, 2.5],
     2792%                        width=1.20,
     2793%                        height=0.75,
     2794%                        culvert_routine=boyd_generalised_culvert_model,
     2795%                        number_of_barrels=1,
     2796%                        verbose=True)
     2797%
     2798%culvert2 = Culvert_flow(domain,
     2799%                        label='Culvert No. 2',
     2800%                        description='This culvert is a circular test with d=1.2m',
     2801%                        end_point0=[9.0, 1.5],
     2802%                        end_point1=[30.0, 3.5],
     2803%                        diameter=1.20,
     2804%                        invert_level0=7,
     2805%                        culvert_routine=boyd_generalised_culvert_model,
     2806%                        number_of_barrels=1,
     2807%                        verbose=True)
     2808%
     2809%domain.forcing_terms.append(culvert1)
     2810%domain.forcing_terms.append(culvert2)
     2811%\end{verbatim}
     2812%\end{classdesc}
     2813%
    28142814
    28152815%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2816 \section{Fractional Step Operators}\index{fractional step operators}
    2817 
    2818 An alternative way to effect the evolution is via fractional step operators.  The idea is that at each inner timestep we can use
    2819 a fractional step operator to change the centroid values of our conserved quantities, the stage and the xmomentum and the ymomentum. The elevation can also be changed but more care needs to be applied as the \code{elevation} quantity needs to remain continuous. The moral, play with \code{elevation} at your peril.
    2820 
    2821 We are tending to move away from forcing terms and towards fractpional step operators as they are easier to parallelize.
    2822 
    2823 
    2824 Currently predefined fractional step operators:
     2816\section{Operators}\index{operators}
     2817
     2818A way to effect the evolution is via fractional step \code{operators}.  The idea is that at each inner timestep we can use
     2819an \code{operator} to change the centroid values of quantities such as the stage and the xmomentum and the ymomentum. T
     2820
     2821The elevation can also be changed but more care needs to be applied as the \code{elevation} quantity needs to remain continuous. The moral, play with \code{elevation} at your peril.
     2822
     2823Currently predefined operators:
    28252824
    28262825
     
    28372836Module: \module{anuga.operators.set_elevation_operator}
    28382837
    2839 Set the elevation in a region (careful to maintain continuitiy of elevation)
     2838Set the elevation in a region (careful to maintain continuity of elevation)
    28402839
    28412840
     
    28542853\code{description} is a description of this operator.
    28552854
    2856 \code{label} is the lable used when reporting on the operator.
     2855\code{label} is the label used when reporting on the operator.
    28572856
    28582857\code{logging} is the boolean flag to set logging to a file.
     
    28632862
    28642863\begin{verbatim}
    2865 from anuga.operators.set_elevation_operator import Set_elevation_operator
    2866 
    2867 op0 =Set_elevation_operator(domain, elevation = lambda t : 0.01*t)
     2864op0 = anuga.Set_elevation_operator(domain, elevation = lambda t : 0.01*t)
    28682865\end{verbatim}
    28692866would setup an operator which raises the elevation over the whole domain 1 cm per second.
     
    28722869While
    28732870\begin{verbatim}
    2874 from anuga.operators.set_elevation_operator import Set_elevation_operator
    28752871P = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]]
    28762872
    2877 op0 =Set_elevation_operator(domain, elevation = lambda t : 0.01*t, polygon=P)
     2873op0 = anuga.Set_elevation_operator(domain, \
     2874                       elevation = lambda t : 0.01*t, polygon=P)
    28782875\end{verbatim}
    28792876would setup an operator which raises the elevation over the polygon \code{P} 1 cm per second.
     
    28812878\end{classdesc}
    28822879
    2883 
    2884 
    2885 \subsection{User developed fractional step operator}
     2880%--------------------------------------------
     2881\subsection{Culvert operators}
     2882
     2883A culvert is a structure that allows water to flow under a road, rail road, trail, or similar obstruction that would otherwise build up behind the embankment. But culverts are also used to drain basins, dams or lakes. \anuga now has the ability to model a culvert by transferring flows from one point in the 2D domain to another. It should be noted that flow from the culvert inlet to the outlet occurs instantaneously with no lagging of the flows.
     2884
     2885Only box culverts and pipe culverts can be modelled at present using the Boyd Method (Generalised head-discharge equations for culverts, Proceedings of the fourth national local government engineering conference pp. 161-165, Perth, August, 1987).
     2886
     2887Usage
     2888
     2889In \anuga, a culvert can be modelled as two points (an inlet point and an outlet point) or along two lines (and inlet line and an outlet line) to account for skew.
     2890
     2891The user needs to nominate the location of the culvert inlet and outlet, any culvert losses (i.e. inlet, outlet, bends etc) and the culvert dimensions (in metres).
     2892
     2893The user can also model the effects of momentum jetting at the outlet of the culvert and also account for velocity head of the flow at the inlet for more realistic results.
     2894
     2895Culvert hydraulics information can be logged by switching logging on or off.
     2896
     2897To use the Boyd Method in \anuga, the user can just copy the code below into their script. So if your model run has 10 pipe culverts, copy the pipe culvert routine five times into your run script and fill in the details for each of your five culverts.
     2898\begin{verbatim}
     2899#------------------------------------- -----------------
     2900# Box Culvert modelled along two lines
     2901#------------------------------------- -----------------
     2902losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
     2903el0 = numpy.array([[297750.2,6181379.1], [297753.5,6181380.9]])
     2904el1 = numpy.array([[297731.8,6181416.4], [297735.1,6181418.3]]) 
     2905culvert = anuga.Boyd_box_operator(domain,
     2906    losses=losses,
     2907    width=1.5,
     2908    height=1.5,
     2909    end_points=[ep0, ep1],
     2910    use_momentum_jet=True, #False to switch it off
     2911    use_velocity_head=True, #False to switch it off
     2912    manning=0.013, #culvert manning's n
     2913    logging=True, #False to switch it off
     2914    label='culvert_log_file',
     2915    verbose=False) 
     2916\end{verbatim}
     2917
     2918\begin{verbatim}
     2919#------------------------------------- ------------------
     2920# Pipe Culvert modelled with a single point
     2921#------------------------------------- ------------------
     2922losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
     2923ep0 = numpy.array([296653.0,6180014.9])
     2924ep1 = numpy.array([296642.5,6180036.3])     
     2925culvert = anuga.Boyd_pipe_operator(domain,
     2926    losses=losses,
     2927    diameter=1.5,
     2928    end_points=[ep0, ep1],
     2929    use_momentum_jet=True, #False to switch it off
     2930    use_velocity_head=True, #False to switch it off
     2931    manning=0.013, #culvert manning's n
     2932    logging=True, #False to switch it off
     2933    label='culvert_log_file',
     2934    verbose=False)
     2935\end{verbatim}
     2936
     2937\subsection{User developed operators}
    28862938
    28872939Suppose we want to add water to our domain at a steady rate. we can create a class based on the \code{Operator} class which has a \code{__call__} function to do the required update to the centroid values of the stage variable.
     
    28892941Here is some code to do this:
    28902942\begin{verbatim}
    2891 from anuga.operators.base_operator import Operator
     2943from anuga import Operator
    28922944
    28932945class My_operator(Operator):
    28942946    """
    2895     Add water to the domain at a given rate (m/sec)
     2947   An operator which adds water to the domain at a given rate (m/sec)
    28962948    """
    28972949
     
    32933345If no inundation is found (within the \code{polygon} and \code{time_interval}, if specified)
    32943346the return value is \code{None}. This indicates "No Runup" or "Everything is dry".
    3295 is \code{None}. This indicates "No Runup" or "Everything is dry".
    32963347\end{funcdesc}
    32973348
Note: See TracChangeset for help on using the changeset viewer.