source: trunk/anuga_core/source/anuga/__init__.py @ 7780

Last change on this file since 7780 was 7780, checked in by hudson, 12 years ago

Almost all failing tests fixed.

File size: 9.6 KB
Line 
1""" ANUGA models the effect of tsunamis and flooding upon a terrain mesh.
2    In typical usage, a Domain class is created for a particular piece of
3    terrain. Boundary conditions are specified for the domain, such as inflow
4    and outflow, and then the simulation is run.
5
6    This is the public API to ANUGA. It provides a toolkit of often-used
7    modules, which can be used directly by including the following line in
8    the user's code:
9
10    import anuga
11       
12    This usage pattern abstracts away the internal heirarchy of the ANUGA
13    system, allowing the user to concentrate on writing simulations without
14    searching through the ANUGA source tree for the functions that they need.
15   
16    Also, it isolates the user from "under-the-hood" refactorings.
17"""
18
19pass
20
21#Add path of package to PYTHONPATH to allow C-extensions to be loaded
22import sys
23sys.path += __path__
24
25#-----------------------------------------------------
26# Make selected classes available directly
27#-----------------------------------------------------
28
29from anuga.shallow_water.shallow_water_domain import Domain
30
31from anuga.abstract_2d_finite_volumes.util import file_function
32
33from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
34
35from anuga.file.csv_file import load_csv_as_building_polygons,  \
36                                load_csv_as_polygons
37
38from anuga.file.sts import create_sts_boundary
39
40from anuga.geometry.polygon import read_polygon, plot_polygons, polygon_area
41from anuga.geometry.polygon import Polygon_function
42
43from anuga.abstract_2d_finite_volumes.pmesh2domain import \
44                                            pmesh_to_domain_instance
45
46
47#-----------------------------
48# Standard Boundaries
49#-----------------------------
50from anuga.shallow_water.boundaries import File_boundary
51from anuga.shallow_water.boundaries import Reflective_boundary
52from anuga.shallow_water.boundaries import Field_boundary
53from anuga.shallow_water.boundaries import \
54                    Transmissive_stage_zero_momentum_boundary
55from anuga.shallow_water.boundaries import \
56                    Transmissive_momentum_set_stage_boundary
57from anuga.shallow_water.boundaries import \
58                    Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
59
60
61#-----------------------------
62# SWW-specific Boundaries
63#-----------------------------
64from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
65                            import Dirichlet_boundary
66from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
67                            import Time_boundary
68from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
69                            import Time_space_boundary
70from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
71                            import Transmissive_boundary
72
73
74
75#-----------------------------
76# Forcing
77#-----------------------------
78from anuga.shallow_water.forcing import Inflow
79
80#-----------------------------
81# File conversion utilities
82#-----------------------------
83from anuga.file_conversion.file_conversion import sww2obj, dat2obj, \
84                    timefile2netcdf, tsh2sww, urs2sww
85from anuga.file_conversion.urs2nc import urs2nc
86from anuga.file_conversion.dem2pts import dem2pts                   
87from anuga.file_conversion.esri2sww import esri2sww   
88from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch
89from anuga.file_conversion.asc2dem import asc2dem     
90from anuga.file_conversion.ferret2sww import ferret2sww     
91from anuga.file_conversion.dem2dem import dem2dem
92
93#-----------------------------
94# SWW file access
95#-----------------------------
96from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section
97
98#-----------------------------
99# rectangular domains
100#-----------------------------
101def rectangular_cross_domain(*args, **kwargs):
102    points, vertices, boundary = rectangular_cross(*args, **kwargs)
103    return Domain(points, vertices, boundary)
104
105#----------------------------
106# Create domain from file
107#----------------------------
108def create_domain_from_file(file):
109    return pmesh_to_domain_instance(file,Domain)
110
111#---------------------------
112# Create domain from regions
113#---------------------------
114
115def create_domain_from_regions(bounding_polygon,
116                               boundary_tags,
117                               maximum_triangle_area=None,
118                               mesh_filename=None,
119                               interior_regions=None,
120                               interior_holes=None,
121                               poly_geo_reference=None,
122                               mesh_geo_reference=None,
123                               minimum_triangle_angle=28.0,
124                               fail_if_polygons_outside=True,
125                               use_cache=False,
126                               verbose=True):
127    """Create domain from bounding polygons and resolutions.
128
129    bounding_polygon is a list of points in Eastings and Northings,
130    relative to the zone stated in poly_geo_reference if specified.
131    Otherwise points are just x, y coordinates with no particular
132    association to any location.
133
134    boundary_tags is a dictionary of symbolic tags. For every tag there
135    is a list of indices referring to segments associated with that tag.
136    If a segment is omitted it will be assigned the default tag ''.
137
138    maximum_triangle_area is the maximal area per triangle
139    for the bounding polygon, excluding the  interior regions.
140
141    Interior_regions is a list of tuples consisting of (polygon,
142    resolution) for each region to be separately refined. Do not have
143    polygon lines cross or be on-top of each other.  Also do not have
144    polygon close to each other.
145   
146    NOTE: If a interior_region is outside the bounding_polygon it should
147    throw an error
148   
149    Interior_holes is a list of ploygons for each hole.
150
151    This function does not allow segments to share points - use underlying
152    pmesh functionality for that
153
154    poly_geo_reference is the geo_reference of the bounding polygon and
155    the interior polygons.
156    If none, assume absolute.  Please pass one though, since absolute
157    references have a zone.
158   
159    mesh_geo_reference is the geo_reference of the mesh to be created.
160    If none is given one will be automatically generated.  It was use
161    the lower left hand corner of  bounding_polygon (absolute)
162    as the x and y values for the geo_ref.
163   
164    Returns the shallow water domain instance
165
166    Note, interior regions should be fully nested, as overlaps may cause
167    unintended resolutions.
168
169    fail_if_polygons_outside: If True (the default) Exception in thrown
170    where interior polygons fall outside bounding polygon. If False, these
171    will be ignored and execution continued.
172       
173   
174    """
175
176
177    # Build arguments and keyword arguments for use with caching or apply.
178    args = (bounding_polygon,
179            boundary_tags)
180   
181    kwargs = {'maximum_triangle_area': maximum_triangle_area,
182              'mesh_filename': mesh_filename,
183              'interior_regions': interior_regions,
184              'interior_holes': interior_holes,
185              'poly_geo_reference': poly_geo_reference,
186              'mesh_geo_reference': mesh_geo_reference,
187              'minimum_triangle_angle': minimum_triangle_angle,
188              'fail_if_polygons_outside': fail_if_polygons_outside,
189              'verbose': verbose} #FIXME (Ole): See ticket:14
190
191    # Call underlying engine with or without caching
192    if use_cache is True:
193        try:
194            from anuga.caching import cache
195        except:
196            msg = 'Caching was requested, but caching module'+\
197                  'could not be imported'
198            raise msg
199
200
201        domain = cache(_create_domain_from_regions,
202                       args, kwargs,
203                       verbose=verbose,
204                       compression=False)
205    else:
206        domain = apply(_create_domain_from_regions,
207                       args, kwargs)
208
209    return domain
210
211       
212def _create_domain_from_regions(bounding_polygon,
213                                boundary_tags,
214                                maximum_triangle_area=None,
215                                mesh_filename=None,                           
216                                interior_regions=None,
217                                interior_holes=None,
218                                poly_geo_reference=None,
219                                mesh_geo_reference=None,
220                                minimum_triangle_angle=28.0,
221                                fail_if_polygons_outside=True,
222                                verbose=True):
223    """_create_domain_from_regions - internal function.
224
225    See create_domain_from_regions for documentation.
226    """
227
228    from anuga.shallow_water.shallow_water_domain import Domain
229    from anuga.pmesh.mesh_interface import create_mesh_from_regions
230   
231    create_mesh_from_regions(bounding_polygon,
232                             boundary_tags,
233                             maximum_triangle_area=maximum_triangle_area,
234                             interior_regions=interior_regions,
235                             filename=mesh_filename,
236                             interior_holes=interior_holes,
237                             poly_geo_reference=poly_geo_reference,
238                             mesh_geo_reference=mesh_geo_reference,
239                             minimum_triangle_angle=minimum_triangle_angle,
240                             fail_if_polygons_outside=fail_if_polygons_outside,
241                             use_cache=False,
242                             verbose=verbose)
243    domain = Domain(mesh_filename, use_cache=False, verbose=verbose)
244
245
246    return domain
247   
248
249
250
251
252
Note: See TracBrowser for help on using the repository browser.