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

Last change on this file since 6266 was 6266, checked in by ole, 15 years ago

Made Transmissive_stage_zero_momentum_boundary available through new anuga interface.

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