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

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

Put simplified API imports into init to allow them to be used automatically.

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.shallow_water.data_manager import export_grid
31from anuga.shallow_water.data_manager import csv2building_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 pmesh_to_domain_instance
39
40
41#-----------------------------
42# Standard Boundaries
43#-----------------------------
44from anuga.shallow_water.boundaries import File_boundary
45from anuga.shallow_water.boundaries import Reflective_boundary
46from anuga.shallow_water.boundaries import Field_boundary
47from anuga.shallow_water.boundaries import \
48                    Transmissive_stage_zero_momentum_boundary
49from anuga.shallow_water.boundaries import \
50                    Transmissive_momentum_set_stage_boundary
51from anuga.shallow_water.boundaries import \
52                    Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
53
54
55#-----------------------------
56# SWW-specific Boundaries
57#-----------------------------
58from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
59                            import Dirichlet_boundary
60from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
61                            import Time_boundary
62from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
63                            import Time_space_boundary
64from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
65                            import Transmissive_boundary
66
67
68
69#-----------------------------
70# Forcing
71#-----------------------------
72from anuga.shallow_water.forcing import Inflow
73
74#-----------------------------
75# File conversion utilities
76#-----------------------------
77from anuga.file_conversion.file_conversion import sww2obj, dat2obj, \
78                    timefile2netcdf, tsh2sww, urs2sww
79from anuga.file_conversion.urs2nc import urs2nc
80from anuga.file_conversion.dem2pts import dem2pts                   
81from anuga.file_conversion.esri2sww import esri2sww   
82from anuga.file_conversion.sww2dem import sww2dem     
83from anuga.file_conversion.asc2dem import asc2dem     
84from anuga.file_conversion.ferret2sww import ferret2sww     
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.