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

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

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

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