source: anuga_core/source/anuga/interface.py @ 7519

Last change on this file since 7519 was 7519, checked in by steve, 15 years ago

Have been playing with using a slope limited velocity to calculate
fluxes (hence the addition of evolved_quantities as well as conserved
quantities.

But the commit is to fix a problem Rudy found with sww2dem. Seems
numpy.array2string is a little too clever, in that it summarizes
output if there is a long sequence of zeros to
[0.0, 0.0, 0.0, ... 0.0, 0.0 ,0.0] To get around this I have added
a call to numpy.set_options(threshold=sys.max_int) to turn this
behaviour off!

File size: 7.3 KB
Line 
1"""This is the public API to ANUGA.
2
3Ideally, all tools needed to run simulations should be
4imported from this module
5"""
6
7# FIXME(Ole): This is one step towards the API envisioned in ticket:308
8
9
10from anuga.shallow_water import Domain
11from anuga.shallow_water import Dirichlet_boundary
12from anuga.shallow_water import File_boundary
13from anuga.shallow_water import Reflective_boundary
14from anuga.shallow_water import Field_boundary
15from anuga.shallow_water import Transmissive_stage_zero_momentum_boundary
16from anuga.shallow_water import Transmissive_momentum_set_stage_boundary
17from anuga.shallow_water import Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
18
19from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Time_boundary
20from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Time_space_boundary
21from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Transmissive_boundary
22
23from anuga.abstract_2d_finite_volumes.util import file_function
24
25from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
26
27from anuga.shallow_water.data_manager import export_grid, create_sts_boundary
28from anuga.shallow_water.data_manager import csv2building_polygons
29
30from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area
31from anuga.utilities.polygon import Polygon_function
32
33from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance
34
35
36#-----------------------------
37# rectangular domains
38#-----------------------------
39def rectangular_cross_domain(*args, **kwargs):
40    points, vertices, boundary = rectangular_cross(*args, **kwargs)
41    return Domain(points, vertices, boundary)
42
43#----------------------------
44# Create domain from file
45#----------------------------
46def create_domain_from_file(file):
47    return pmesh_to_domain_instance(file,Domain)
48
49#---------------------------
50# Create domain from regions
51#---------------------------
52
53def create_domain_from_regions(bounding_polygon,
54                               boundary_tags,
55                               maximum_triangle_area=None,
56                               mesh_filename=None,
57                               interior_regions=None,
58                               interior_holes=None,
59                               poly_geo_reference=None,
60                               mesh_geo_reference=None,
61                               minimum_triangle_angle=28.0,
62                               fail_if_polygons_outside=True,
63                               use_cache=False,
64                               verbose=True):
65    """Create domain from bounding polygons and resolutions.
66
67    bounding_polygon is a list of points in Eastings and Northings,
68    relative to the zone stated in poly_geo_reference if specified.
69    Otherwise points are just x, y coordinates with no particular
70    association to any location.
71
72    boundary_tags is a dictionary of symbolic tags. For every tag there
73    is a list of indices referring to segments associated with that tag.
74    If a segment is omitted it will be assigned the default tag ''.
75
76    maximum_triangle_area is the maximal area per triangle
77    for the bounding polygon, excluding the  interior regions.
78
79    Interior_regions is a list of tuples consisting of (polygon,
80    resolution) for each region to be separately refined. Do not have
81    polygon lines cross or be on-top of each other.  Also do not have
82    polygon close to each other.
83   
84    NOTE: If a interior_region is outside the bounding_polygon it should
85    throw an error
86   
87    Interior_holes is a list of ploygons for each hole.
88
89    This function does not allow segments to share points - use underlying
90    pmesh functionality for that
91
92    poly_geo_reference is the geo_reference of the bounding polygon and
93    the interior polygons.
94    If none, assume absolute.  Please pass one though, since absolute
95    references have a zone.
96   
97    mesh_geo_reference is the geo_reference of the mesh to be created.
98    If none is given one will be automatically generated.  It was use
99    the lower left hand corner of  bounding_polygon (absolute)
100    as the x and y values for the geo_ref.
101   
102    Returns the shallow water domain instance
103
104    Note, interior regions should be fully nested, as overlaps may cause
105    unintended resolutions.
106
107    fail_if_polygons_outside: If True (the default) Exception in thrown
108    where interior polygons fall outside bounding polygon. If False, these
109    will be ignored and execution continued.
110       
111   
112    """
113
114
115    # Build arguments and keyword arguments for use with caching or apply.
116    args = (bounding_polygon,
117            boundary_tags)
118   
119    kwargs = {'maximum_triangle_area': maximum_triangle_area,
120              'mesh_filename': mesh_filename,
121              'interior_regions': interior_regions,
122              'interior_holes': interior_holes,
123              'poly_geo_reference': poly_geo_reference,
124              'mesh_geo_reference': mesh_geo_reference,
125              'minimum_triangle_angle': minimum_triangle_angle,
126              'fail_if_polygons_outside': fail_if_polygons_outside,
127              'verbose': verbose} #FIXME (Ole): See ticket:14
128
129    # Call underlying engine with or without caching
130    if use_cache is True:
131        try:
132            from anuga.caching import cache
133        except:
134            msg = 'Caching was requested, but caching module'+\
135                  'could not be imported'
136            raise msg
137
138
139        domain = cache(_create_domain_from_regions,
140                       args, kwargs,
141                       verbose=verbose,
142                       compression=False)
143    else:
144        domain = apply(_create_domain_from_regions,
145                       args, kwargs)
146
147    return domain
148
149       
150def _create_domain_from_regions(bounding_polygon,
151                                boundary_tags,
152                                maximum_triangle_area=None,
153                                mesh_filename=None,                           
154                                interior_regions=None,
155                                interior_holes=None,
156                                poly_geo_reference=None,
157                                mesh_geo_reference=None,
158                                minimum_triangle_angle=28.0,
159                                fail_if_polygons_outside=True,
160                                verbose=True):
161    """_create_domain_from_regions - internal function.
162
163    See create_domain_from_regions for documentation.
164    """
165
166    from anuga.shallow_water import Domain
167    from anuga.pmesh.mesh_interface import create_mesh_from_regions
168   
169    create_mesh_from_regions(bounding_polygon,
170                             boundary_tags,
171                             maximum_triangle_area=maximum_triangle_area,
172                             interior_regions=interior_regions,
173                             filename=mesh_filename,
174                             interior_holes=interior_holes,
175                             poly_geo_reference=poly_geo_reference,
176                             mesh_geo_reference=mesh_geo_reference,
177                             minimum_triangle_angle=minimum_triangle_angle,
178                             fail_if_polygons_outside=fail_if_polygons_outside,
179                             use_cache=False,
180                             verbose=verbose)
181    domain = Domain(mesh_filename, use_cache=False, verbose=verbose)
182
183
184    return domain
185   
186
187
188
189
Note: See TracBrowser for help on using the repository browser.