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

Last change on this file since 7796 was 7796, checked in by hudson, 14 years ago

ANUGA core modified to fix errors with new API modules not being found.

File size: 10.4 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
47from anuga.utilities.system_tools import file_length
48
49from anuga.utilities.file_utils import copy_code_files
50
51from anuga.geometry.polygon import read_polygon, Polygon_function
52from anuga.caching import cache
53
54#-----------------------------
55# Standard Boundaries
56#-----------------------------
57from anuga.shallow_water.boundaries import File_boundary
58from anuga.shallow_water.boundaries import Reflective_boundary
59from anuga.shallow_water.boundaries import Field_boundary
60from anuga.shallow_water.boundaries import \
61                    Transmissive_stage_zero_momentum_boundary
62from anuga.shallow_water.boundaries import \
63                    Transmissive_momentum_set_stage_boundary
64from anuga.shallow_water.boundaries import \
65                    Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
66
67
68#-----------------------------
69# SWW-specific Boundaries
70#-----------------------------
71from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
72                            import Dirichlet_boundary
73from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
74                            import Time_boundary
75from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
76                            import Time_space_boundary
77from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
78                            import Transmissive_boundary
79
80
81
82#-----------------------------
83# Forcing
84#-----------------------------
85from anuga.shallow_water.forcing import Inflow
86
87#-----------------------------
88# File conversion utilities
89#-----------------------------
90from anuga.file_conversion.file_conversion import sww2obj, dat2obj, \
91                    timefile2netcdf, tsh2sww, urs2sww
92from anuga.file_conversion.urs2nc import urs2nc 
93from anuga.file_conversion.urs2sts import urs2sts
94from anuga.file_conversion.dem2pts import dem2pts                   
95from anuga.file_conversion.esri2sww import esri2sww   
96from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch
97from anuga.file_conversion.asc2dem import asc2dem     
98from anuga.file_conversion.ferret2sww import ferret2sww     
99from anuga.file_conversion.dem2dem import dem2dem
100
101
102#-----------------------------
103# SWW file access
104#-----------------------------
105from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section
106
107#-----------------------------
108# rectangular domains
109#-----------------------------
110def rectangular_cross_domain(*args, **kwargs):
111    """
112    Create a rectangular domain with triangulation made
113    up of m+1 by n+1 uniform rectangular cells divided
114    into 4 triangles in a cross pattern
115
116    Arguments
117    m:      number of cells in x direction
118    n:      number of cells in y direction
119    len1:   length of domain in x direction (left to right)
120            (default 1.0)
121    len2:   length of domain in y direction (bottom to top)
122            (default 1.0)
123    origin: tuple (x,y) specifying location of lower left corner
124            of domain (default (0,0))
125    """
126    points, vertices, boundary = rectangular_cross(*args, **kwargs)
127    return Domain(points, vertices, boundary)
128
129#----------------------------
130# Create domain from file
131#----------------------------
132def create_domain_from_file(file):
133    """
134    Create a domain from a file
135    """
136    return pmesh_to_domain_instance(file,Domain)
137
138#---------------------------
139# Create domain from regions
140#---------------------------
141
142def create_domain_from_regions(bounding_polygon,
143                               boundary_tags,
144                               maximum_triangle_area=None,
145                               mesh_filename=None,
146                               interior_regions=None,
147                               interior_holes=None,
148                               poly_geo_reference=None,
149                               mesh_geo_reference=None,
150                               minimum_triangle_angle=28.0,
151                               fail_if_polygons_outside=True,
152                               use_cache=False,
153                               verbose=True):
154    """Create domain from bounding polygons and resolutions.
155
156    bounding_polygon is a list of points in Eastings and Northings,
157    relative to the zone stated in poly_geo_reference if specified.
158    Otherwise points are just x, y coordinates with no particular
159    association to any location.
160
161    boundary_tags is a dictionary of symbolic tags. For every tag there
162    is a list of indices referring to segments associated with that tag.
163    If a segment is omitted it will be assigned the default tag ''.
164
165    maximum_triangle_area is the maximal area per triangle
166    for the bounding polygon, excluding the  interior regions.
167
168    Interior_regions is a list of tuples consisting of (polygon,
169    resolution) for each region to be separately refined. Do not have
170    polygon lines cross or be on-top of each other.  Also do not have
171    polygon close to each other.
172   
173    NOTE: If a interior_region is outside the bounding_polygon it should
174    throw an error
175   
176    Interior_holes is a list of ploygons for each hole.
177
178    This function does not allow segments to share points - use underlying
179    pmesh functionality for that
180
181    poly_geo_reference is the geo_reference of the bounding polygon and
182    the interior polygons.
183    If none, assume absolute.  Please pass one though, since absolute
184    references have a zone.
185   
186    mesh_geo_reference is the geo_reference of the mesh to be created.
187    If none is given one will be automatically generated.  It was use
188    the lower left hand corner of  bounding_polygon (absolute)
189    as the x and y values for the geo_ref.
190   
191    Returns the shallow water domain instance
192
193    Note, interior regions should be fully nested, as overlaps may cause
194    unintended resolutions.
195
196    fail_if_polygons_outside: If True (the default) Exception in thrown
197    where interior polygons fall outside bounding polygon. If False, these
198    will be ignored and execution continued.
199       
200   
201    """
202
203
204    # Build arguments and keyword arguments for use with caching or apply.
205    args = (bounding_polygon,
206            boundary_tags)
207   
208    kwargs = {'maximum_triangle_area': maximum_triangle_area,
209              'mesh_filename': mesh_filename,
210              'interior_regions': interior_regions,
211              'interior_holes': interior_holes,
212              'poly_geo_reference': poly_geo_reference,
213              'mesh_geo_reference': mesh_geo_reference,
214              'minimum_triangle_angle': minimum_triangle_angle,
215              'fail_if_polygons_outside': fail_if_polygons_outside,
216              'verbose': verbose} #FIXME (Ole): See ticket:14
217
218    # Call underlying engine with or without caching
219    if use_cache is True:
220        try:
221            from anuga.caching import cache
222        except:
223            msg = 'Caching was requested, but caching module'+\
224                  'could not be imported'
225            raise msg
226
227
228        domain = cache(_create_domain_from_regions,
229                       args, kwargs,
230                       verbose=verbose,
231                       compression=False)
232    else:
233        domain = apply(_create_domain_from_regions,
234                       args, kwargs)
235
236    return domain
237
238       
239def _create_domain_from_regions(bounding_polygon,
240                                boundary_tags,
241                                maximum_triangle_area=None,
242                                mesh_filename=None,                           
243                                interior_regions=None,
244                                interior_holes=None,
245                                poly_geo_reference=None,
246                                mesh_geo_reference=None,
247                                minimum_triangle_angle=28.0,
248                                fail_if_polygons_outside=True,
249                                verbose=True):
250    """_create_domain_from_regions - internal function.
251
252    See create_domain_from_regions for documentation.
253    """
254
255    from anuga.shallow_water.shallow_water_domain import Domain
256    from anuga.pmesh.mesh_interface import create_mesh_from_regions
257   
258    create_mesh_from_regions(bounding_polygon,
259                             boundary_tags,
260                             maximum_triangle_area=maximum_triangle_area,
261                             interior_regions=interior_regions,
262                             filename=mesh_filename,
263                             interior_holes=interior_holes,
264                             poly_geo_reference=poly_geo_reference,
265                             mesh_geo_reference=mesh_geo_reference,
266                             minimum_triangle_angle=minimum_triangle_angle,
267                             fail_if_polygons_outside=fail_if_polygons_outside,
268                             use_cache=False,
269                             verbose=verbose)
270    domain = Domain(mesh_filename, use_cache=False, verbose=verbose)
271
272
273    return domain
274   
275
276
277
278
279
Note: See TracBrowser for help on using the repository browser.