Changeset 8306


Ignore:
Timestamp:
Jan 18, 2012, 2:31:29 PM (13 years ago)
Author:
davies
Message:

Changes to swb2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/balanced_basic/__init__.py

    r8302 r8306  
    77
    88# Make selected classes available directly
    9 from swb2_domain import Domain
     9from balanced_basic.swb2_domain import Domain as Domain
     10from balanced_basic.swb2_domain import Domain
    1011#, \
    1112#     Transmissive_boundary,\
     
    2021#
    2122
     23#-----------------------------------------------------
     24# Make selected classes available directly
     25#-----------------------------------------------------
     26from anuga.__metadata__ import __version__, __date__, __author__
     27
     28#from anuga.shallow_water.shallow_water_domain import Domain
     29
     30from anuga.abstract_2d_finite_volumes.quantity import Quantity
     31
     32from anuga.abstract_2d_finite_volumes.util import file_function, \
     33                                        sww2timeseries, sww2csv_gauges
     34
     35from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \
     36                                                    rectangular
     37
     38from anuga.file.csv_file import load_csv_as_building_polygons,  \
     39                                load_csv_as_polygons
     40
     41from anuga.file.sts import create_sts_boundary
     42
     43from anuga.file.ungenerate import load_ungenerate
     44
     45from anuga.geometry.polygon import read_polygon, plot_polygons, polygon_area, \
     46                                   inside_polygon, polygon_area
     47from anuga.geometry.polygon_function import Polygon_function
     48
     49from anuga.abstract_2d_finite_volumes.pmesh2domain import \
     50                                            pmesh_to_domain_instance
     51
     52from anuga.utilities.system_tools import file_length
     53from anuga.utilities.sww_merge import sww_merge
     54from anuga.utilities.file_utils import copy_code_files
     55from anuga.utilities.numerical_tools import safe_acos as acos
     56
     57from anuga.geometry.polygon import read_polygon
     58from anuga.caching import cache
     59
     60#-----------------------------
     61# Standard Boundaries
     62#-----------------------------
     63from anuga.shallow_water.boundaries import File_boundary
     64from anuga.shallow_water.boundaries import Reflective_boundary
     65from anuga.shallow_water.boundaries import Field_boundary
     66from anuga.shallow_water.boundaries import \
     67                    Transmissive_stage_zero_momentum_boundary
     68from anuga.shallow_water.boundaries import \
     69                    Transmissive_momentum_set_stage_boundary
     70from anuga.shallow_water.boundaries import \
     71                    Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
     72
     73
     74#-----------------------------
     75# SWW-specific Boundaries
     76#-----------------------------
     77from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     78                            import Dirichlet_boundary
     79from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     80                            import Time_boundary
     81from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     82                            import Time_space_boundary
     83from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     84                            import Transmissive_boundary
     85
     86
     87
     88#-----------------------------
     89# Shalow Water Tsunamis
     90#-----------------------------
     91
     92from anuga.shallow_water.smf import slide_tsunami, slump_tsunami
     93
     94
     95#-----------------------------
     96# Forcing
     97#-----------------------------
     98from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress
     99
     100#-----------------------------
     101# File conversion utilities
     102#-----------------------------
     103from anuga.file_conversion.file_conversion import sww2obj, \
     104                    timefile2netcdf, tsh2sww
     105from anuga.file_conversion.urs2nc import urs2nc
     106from anuga.file_conversion.urs2sww import urs2sww 
     107from anuga.file_conversion.urs2sts import urs2sts
     108from anuga.file_conversion.dem2pts import dem2pts                   
     109from anuga.file_conversion.esri2sww import esri2sww   
     110from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch
     111from anuga.file_conversion.asc2dem import asc2dem     
     112from anuga.file_conversion.ferret2sww import ferret2sww     
     113from anuga.file_conversion.dem2dem import dem2dem
     114
     115
     116#-----------------------------
     117# Mesh API
     118#-----------------------------
     119from anuga.pmesh.mesh_interface import create_mesh_from_regions
     120
     121#-----------------------------
     122# SWW file access
     123#-----------------------------
     124from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section
     125   
     126
     127
     128#---------------------------
     129# Operators
     130#---------------------------
     131from anuga.operators.base_operator import Operator
     132
     133#---------------------------
     134# Structure Operators
     135#---------------------------
     136from anuga.structures.structure_operator import Structure_operator
     137from anuga.structures.boyd_box_operator import Boyd_box_operator
     138from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
     139
     140#---------------------------
     141# User Access Functions
     142#---------------------------
     143
     144from anuga.utilities.system_tools import get_user_name, get_host_name, get_revision_number
     145
     146
     147
     148
     149#-----------------------------
     150# rectangular domains
     151#-----------------------------
     152def rectangular_cross_domain(*args, **kwargs):
     153    """
     154    Create a rectangular domain with triangulation made
     155    up of m+1 by n+1 uniform rectangular cells divided
     156    into 4 triangles in a cross pattern
     157
     158    Arguments
     159    m:      number of cells in x direction
     160    n:      number of cells in y direction
     161    len1:   length of domain in x direction (left to right)
     162            (default 1.0)
     163    len2:   length of domain in y direction (bottom to top)
     164            (default 1.0)
     165    origin: tuple (x,y) specifying location of lower left corner
     166            of domain (default (0,0))
     167    """
     168    points, vertices, boundary = rectangular_cross(*args, **kwargs)
     169    return Domain(points, vertices, boundary)
     170
     171#----------------------------
     172# Create domain from file
     173#----------------------------
     174def create_domain_from_file(file, DomainClass=Domain):
     175    """
     176    Create a domain from a file
     177    """
     178    return pmesh_to_domain_instance(file,DomainClass=DomainClass)
     179
     180#---------------------------
     181# Create domain from regions
     182#---------------------------
     183
     184def create_domain_from_regions(bounding_polygon,
     185                               boundary_tags,
     186                               maximum_triangle_area=None,
     187                               mesh_filename=None,
     188                               interior_regions=None,
     189                               interior_holes=None,
     190                               hole_tags=None,
     191                               poly_geo_reference=None,
     192                               mesh_geo_reference=None,
     193                               minimum_triangle_angle=28.0,
     194                               fail_if_polygons_outside=True,
     195                               use_cache=False,
     196                               verbose=True):
     197    """Create domain from bounding polygons and resolutions.
     198
     199    bounding_polygon is a list of points in Eastings and Northings,
     200    relative to the zone stated in poly_geo_reference if specified.
     201    Otherwise points are just x, y coordinates with no particular
     202    association to any location.
     203
     204    boundary_tags is a dictionary of symbolic tags. For every tag there
     205    is a list of indices referring to segments associated with that tag.
     206    If a segment is omitted it will be assigned the default tag ''.
     207
     208    maximum_triangle_area is the maximal area per triangle
     209    for the bounding polygon, excluding the  interior regions.
     210
     211    Interior_regions is a list of tuples consisting of (polygon,
     212    resolution) for each region to be separately refined. Do not have
     213    polygon lines cross or be on-top of each other.  Also do not have
     214    polygon close to each other.
     215   
     216    NOTE: If a interior_region is outside the bounding_polygon it should
     217    throw an error
     218   
     219    interior_holes is a list of ploygons for each hole. These polygons do not
     220    need to be closed, but their points must be specified in a counter-clockwise
     221    order.
     222
     223    hole_tags  is a list of tag segment dictionaries.
     224
     225    This function does not allow segments to share points - use underlying
     226    pmesh functionality for that
     227
     228    poly_geo_reference is the geo_reference of the bounding polygon and
     229    the interior polygons.
     230    If none, assume absolute.  Please pass one though, since absolute
     231    references have a zone.
     232   
     233    mesh_geo_reference is the geo_reference of the mesh to be created.
     234    If none is given one will be automatically generated.  It was use
     235    the lower left hand corner of  bounding_polygon (absolute)
     236    as the x and y values for the geo_ref.
     237   
     238    Returns the shallow water domain instance
     239
     240    Note, interior regions should be fully nested, as overlaps may cause
     241    unintended resolutions.
     242
     243    fail_if_polygons_outside: If True (the default) Exception in thrown
     244    where interior polygons fall outside bounding polygon. If False, these
     245    will be ignored and execution continued.
     246       
     247   
     248    """
     249
     250
     251    # Build arguments and keyword arguments for use with caching or apply.
     252    args = (bounding_polygon,
     253            boundary_tags)
     254   
     255    kwargs = {'maximum_triangle_area': maximum_triangle_area,
     256              'mesh_filename': mesh_filename,
     257              'interior_regions': interior_regions,
     258              'interior_holes': interior_holes,
     259              'hole_tags': hole_tags,
     260              'poly_geo_reference': poly_geo_reference,
     261              'mesh_geo_reference': mesh_geo_reference,
     262              'minimum_triangle_angle': minimum_triangle_angle,
     263              'fail_if_polygons_outside': fail_if_polygons_outside,
     264              'verbose': verbose} #FIXME (Ole): See ticket:14
     265
     266    # Call underlying engine with or without caching
     267    if use_cache is True:
     268        try:
     269            from anuga.caching import cache
     270        except:
     271            msg = 'Caching was requested, but caching module'+\
     272                  'could not be imported'
     273            raise (msg)
     274
     275
     276        domain = cache(_create_domain_from_regions,
     277                       args, kwargs,
     278                       verbose=verbose,
     279                       compression=False)
     280    else:
     281        domain = apply(_create_domain_from_regions,
     282                       args, kwargs)
     283
     284    return domain
     285
     286       
     287def _create_domain_from_regions(bounding_polygon,
     288                                boundary_tags,
     289                                maximum_triangle_area=None,
     290                                mesh_filename=None,                           
     291                                interior_regions=None,
     292                                interior_holes=None,
     293                                hole_tags=None,
     294                                poly_geo_reference=None,
     295                                mesh_geo_reference=None,
     296                                minimum_triangle_angle=28.0,
     297                                fail_if_polygons_outside=True,
     298                                verbose=True):
     299    """_create_domain_from_regions - internal function.
     300
     301    See create_domain_from_regions for documentation.
     302    """
     303
     304    #from anuga.shallow_water.shallow_water_domain import Domain
     305    from balanced_basic.swb2_domain import Domain
     306    from anuga.pmesh.mesh_interface import create_mesh_from_regions
     307   
     308    create_mesh_from_regions(bounding_polygon,
     309                             boundary_tags,
     310                             maximum_triangle_area=maximum_triangle_area,
     311                             interior_regions=interior_regions,
     312                             filename=mesh_filename,
     313                             interior_holes=interior_holes,
     314                             hole_tags=hole_tags,
     315                             poly_geo_reference=poly_geo_reference,
     316                             mesh_geo_reference=mesh_geo_reference,
     317                             minimum_triangle_angle=minimum_triangle_angle,
     318                             fail_if_polygons_outside=fail_if_polygons_outside,
     319                             use_cache=False,
     320                             verbose=verbose)
     321
     322    domain = Domain(mesh_filename, use_cache=False, verbose=verbose)
     323
     324
     325    return domain
     326   
     327import logging as log
     328
     329from anuga.config import use_psyco, g, velocity_protection
     330if use_psyco:
     331    # try using psyco if available
     332    try:
     333        import psyco
     334    except:
     335        import os
     336        import sys
     337        if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']:
     338            pass
     339            # Psyco isn't supported on 64 bit systems, but it doesn't matter
     340        elif sys.version[:3] == '2.7' :
     341            pass
     342            # Psyco isn't available for python 2.7 (16/05/2011)
     343        else:
     344            log.critical('WARNING: psyco (speedup) could not be imported, '
     345                         'you may want to consider installing it')
     346    else:
     347        psyco.full() # aggressively compile everything
     348        #psyco.background() # attempt to profile code - only compile most used
     349       
    22350
    23351 
Note: See TracChangeset for help on using the changeset viewer.