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

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

urs2sww has an extra urs_ungridded2sww function.

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