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

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

Bug in new interface and work on Patong

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