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

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

Cleaned up unit tests to use API.

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