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

Last change on this file since 7463 was 7452, checked in by steve, 16 years ago

Committing latest parallel code

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