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

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

Removed redundant data_manager class. Unit tests are running, but may fail.

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