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

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

Fixed a bunch of failing tests - only 3 still failing.

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