1 | """ This is the public API to ANUGA. It provides a toolkit of often-used |
---|
2 | modules, which can be used directly by including the following line in |
---|
3 | the user's code: |
---|
4 | |
---|
5 | import anuga |
---|
6 | |
---|
7 | It abstracts away the internal heirarchy of the ANUGA system, allowing the |
---|
8 | user to concentrate on writing simulations without searching through the |
---|
9 | ANUGA source tree for the functions that they need. |
---|
10 | |
---|
11 | Also, it isolates the user from "under-the-hood" refactorings. |
---|
12 | """ |
---|
13 | |
---|
14 | pass |
---|
15 | |
---|
16 | #Add path of package to PYTHONPATH to allow C-extensions to be loaded |
---|
17 | import sys |
---|
18 | sys.path += __path__ |
---|
19 | |
---|
20 | #----------------------------------------------------- |
---|
21 | # Make selected classes available directly |
---|
22 | #----------------------------------------------------- |
---|
23 | |
---|
24 | from anuga.shallow_water import Domain |
---|
25 | |
---|
26 | from anuga.abstract_2d_finite_volumes.util import file_function |
---|
27 | |
---|
28 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
29 | |
---|
30 | from anuga.shallow_water.data_manager import export_grid |
---|
31 | from anuga.shallow_water.data_manager import csv2building_polygons |
---|
32 | |
---|
33 | from anuga.file.sts import create_sts_boundary |
---|
34 | |
---|
35 | from anuga.geometry.polygon import read_polygon, plot_polygons, polygon_area |
---|
36 | from anuga.geometry.polygon import Polygon_function |
---|
37 | |
---|
38 | from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance |
---|
39 | |
---|
40 | |
---|
41 | #----------------------------- |
---|
42 | # Standard Boundaries |
---|
43 | #----------------------------- |
---|
44 | from anuga.shallow_water.boundaries import File_boundary |
---|
45 | from anuga.shallow_water.boundaries import Reflective_boundary |
---|
46 | from anuga.shallow_water.boundaries import Field_boundary |
---|
47 | from anuga.shallow_water.boundaries import \ |
---|
48 | Transmissive_stage_zero_momentum_boundary |
---|
49 | from anuga.shallow_water.boundaries import \ |
---|
50 | Transmissive_momentum_set_stage_boundary |
---|
51 | from anuga.shallow_water.boundaries import \ |
---|
52 | Transmissive_n_momentum_zero_t_momentum_set_stage_boundary |
---|
53 | |
---|
54 | |
---|
55 | #----------------------------- |
---|
56 | # SWW-specific Boundaries |
---|
57 | #----------------------------- |
---|
58 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
59 | import Dirichlet_boundary |
---|
60 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
61 | import Time_boundary |
---|
62 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
63 | import Time_space_boundary |
---|
64 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
65 | import Transmissive_boundary |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | #----------------------------- |
---|
70 | # Forcing |
---|
71 | #----------------------------- |
---|
72 | from anuga.shallow_water.forcing import Inflow |
---|
73 | |
---|
74 | #----------------------------- |
---|
75 | # File conversion utilities |
---|
76 | #----------------------------- |
---|
77 | from anuga.file_conversion.file_conversion import sww2obj, dat2obj, \ |
---|
78 | timefile2netcdf, tsh2sww, urs2sww |
---|
79 | from anuga.file_conversion.urs2nc import urs2nc |
---|
80 | from anuga.file_conversion.dem2pts import dem2pts |
---|
81 | from anuga.file_conversion.esri2sww import esri2sww |
---|
82 | from anuga.file_conversion.sww2dem import sww2dem |
---|
83 | from anuga.file_conversion.asc2dem import asc2dem |
---|
84 | from anuga.file_conversion.ferret2sww import ferret2sww |
---|
85 | |
---|
86 | #----------------------------- |
---|
87 | # SWW file access |
---|
88 | #----------------------------- |
---|
89 | from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section |
---|
90 | |
---|
91 | #----------------------------- |
---|
92 | # rectangular domains |
---|
93 | #----------------------------- |
---|
94 | def rectangular_cross_domain(*args, **kwargs): |
---|
95 | points, vertices, boundary = rectangular_cross(*args, **kwargs) |
---|
96 | return Domain(points, vertices, boundary) |
---|
97 | |
---|
98 | #---------------------------- |
---|
99 | # Create domain from file |
---|
100 | #---------------------------- |
---|
101 | def create_domain_from_file(file): |
---|
102 | return pmesh_to_domain_instance(file,Domain) |
---|
103 | |
---|
104 | #--------------------------- |
---|
105 | # Create domain from regions |
---|
106 | #--------------------------- |
---|
107 | |
---|
108 | def create_domain_from_regions(bounding_polygon, |
---|
109 | boundary_tags, |
---|
110 | maximum_triangle_area=None, |
---|
111 | mesh_filename=None, |
---|
112 | interior_regions=None, |
---|
113 | interior_holes=None, |
---|
114 | poly_geo_reference=None, |
---|
115 | mesh_geo_reference=None, |
---|
116 | minimum_triangle_angle=28.0, |
---|
117 | fail_if_polygons_outside=True, |
---|
118 | use_cache=False, |
---|
119 | verbose=True): |
---|
120 | """Create domain from bounding polygons and resolutions. |
---|
121 | |
---|
122 | bounding_polygon is a list of points in Eastings and Northings, |
---|
123 | relative to the zone stated in poly_geo_reference if specified. |
---|
124 | Otherwise points are just x, y coordinates with no particular |
---|
125 | association to any location. |
---|
126 | |
---|
127 | boundary_tags is a dictionary of symbolic tags. For every tag there |
---|
128 | is a list of indices referring to segments associated with that tag. |
---|
129 | If a segment is omitted it will be assigned the default tag ''. |
---|
130 | |
---|
131 | maximum_triangle_area is the maximal area per triangle |
---|
132 | for the bounding polygon, excluding the interior regions. |
---|
133 | |
---|
134 | Interior_regions is a list of tuples consisting of (polygon, |
---|
135 | resolution) for each region to be separately refined. Do not have |
---|
136 | polygon lines cross or be on-top of each other. Also do not have |
---|
137 | polygon close to each other. |
---|
138 | |
---|
139 | NOTE: If a interior_region is outside the bounding_polygon it should |
---|
140 | throw an error |
---|
141 | |
---|
142 | Interior_holes is a list of ploygons for each hole. |
---|
143 | |
---|
144 | This function does not allow segments to share points - use underlying |
---|
145 | pmesh functionality for that |
---|
146 | |
---|
147 | poly_geo_reference is the geo_reference of the bounding polygon and |
---|
148 | the interior polygons. |
---|
149 | If none, assume absolute. Please pass one though, since absolute |
---|
150 | references have a zone. |
---|
151 | |
---|
152 | mesh_geo_reference is the geo_reference of the mesh to be created. |
---|
153 | If none is given one will be automatically generated. It was use |
---|
154 | the lower left hand corner of bounding_polygon (absolute) |
---|
155 | as the x and y values for the geo_ref. |
---|
156 | |
---|
157 | Returns the shallow water domain instance |
---|
158 | |
---|
159 | Note, interior regions should be fully nested, as overlaps may cause |
---|
160 | unintended resolutions. |
---|
161 | |
---|
162 | fail_if_polygons_outside: If True (the default) Exception in thrown |
---|
163 | where interior polygons fall outside bounding polygon. If False, these |
---|
164 | will be ignored and execution continued. |
---|
165 | |
---|
166 | |
---|
167 | """ |
---|
168 | |
---|
169 | |
---|
170 | # Build arguments and keyword arguments for use with caching or apply. |
---|
171 | args = (bounding_polygon, |
---|
172 | boundary_tags) |
---|
173 | |
---|
174 | kwargs = {'maximum_triangle_area': maximum_triangle_area, |
---|
175 | 'mesh_filename': mesh_filename, |
---|
176 | 'interior_regions': interior_regions, |
---|
177 | 'interior_holes': interior_holes, |
---|
178 | 'poly_geo_reference': poly_geo_reference, |
---|
179 | 'mesh_geo_reference': mesh_geo_reference, |
---|
180 | 'minimum_triangle_angle': minimum_triangle_angle, |
---|
181 | 'fail_if_polygons_outside': fail_if_polygons_outside, |
---|
182 | 'verbose': verbose} #FIXME (Ole): See ticket:14 |
---|
183 | |
---|
184 | # Call underlying engine with or without caching |
---|
185 | if use_cache is True: |
---|
186 | try: |
---|
187 | from anuga.caching import cache |
---|
188 | except: |
---|
189 | msg = 'Caching was requested, but caching module'+\ |
---|
190 | 'could not be imported' |
---|
191 | raise msg |
---|
192 | |
---|
193 | |
---|
194 | domain = cache(_create_domain_from_regions, |
---|
195 | args, kwargs, |
---|
196 | verbose=verbose, |
---|
197 | compression=False) |
---|
198 | else: |
---|
199 | domain = apply(_create_domain_from_regions, |
---|
200 | args, kwargs) |
---|
201 | |
---|
202 | return domain |
---|
203 | |
---|
204 | |
---|
205 | def _create_domain_from_regions(bounding_polygon, |
---|
206 | boundary_tags, |
---|
207 | maximum_triangle_area=None, |
---|
208 | mesh_filename=None, |
---|
209 | interior_regions=None, |
---|
210 | interior_holes=None, |
---|
211 | poly_geo_reference=None, |
---|
212 | mesh_geo_reference=None, |
---|
213 | minimum_triangle_angle=28.0, |
---|
214 | fail_if_polygons_outside=True, |
---|
215 | verbose=True): |
---|
216 | """_create_domain_from_regions - internal function. |
---|
217 | |
---|
218 | See create_domain_from_regions for documentation. |
---|
219 | """ |
---|
220 | |
---|
221 | from anuga.shallow_water import Domain |
---|
222 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
223 | |
---|
224 | create_mesh_from_regions(bounding_polygon, |
---|
225 | boundary_tags, |
---|
226 | maximum_triangle_area=maximum_triangle_area, |
---|
227 | interior_regions=interior_regions, |
---|
228 | filename=mesh_filename, |
---|
229 | interior_holes=interior_holes, |
---|
230 | poly_geo_reference=poly_geo_reference, |
---|
231 | mesh_geo_reference=mesh_geo_reference, |
---|
232 | minimum_triangle_angle=minimum_triangle_angle, |
---|
233 | fail_if_polygons_outside=fail_if_polygons_outside, |
---|
234 | use_cache=False, |
---|
235 | verbose=verbose) |
---|
236 | domain = Domain(mesh_filename, use_cache=False, verbose=verbose) |
---|
237 | |
---|
238 | |
---|
239 | return domain |
---|
240 | |
---|
241 | |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | |
---|