1 | """ ANUGA models the effect of tsunamis and flooding upon a terrain mesh. |
---|
2 | In typical usage, a Domain class is created for a particular piece of |
---|
3 | terrain. Boundary conditions are specified for the domain, such as inflow |
---|
4 | and outflow, and then the simulation is run. |
---|
5 | |
---|
6 | This is the public API to ANUGA. It provides a toolkit of often-used |
---|
7 | modules, which can be used directly by including the following line in |
---|
8 | the user's code: |
---|
9 | |
---|
10 | import anuga |
---|
11 | |
---|
12 | This usage pattern abstracts away the internal heirarchy of the ANUGA |
---|
13 | system, allowing the user to concentrate on writing simulations without |
---|
14 | searching through the ANUGA source tree for the functions that they need. |
---|
15 | |
---|
16 | Also, it isolates the user from "under-the-hood" refactorings. |
---|
17 | """ |
---|
18 | |
---|
19 | #----------------------------------------------------- |
---|
20 | # Make selected classes available directly |
---|
21 | #----------------------------------------------------- |
---|
22 | |
---|
23 | |
---|
24 | __version__ = '2.0' |
---|
25 | |
---|
26 | __svn_revision__ = filter(str.isdigit, "$Revision: 9737 $") |
---|
27 | |
---|
28 | __svn_revision_date__ = "$Date: 2016-10-04 05:13:00 +0000 (Tue, 04 Oct 2016) $"[7:-1] |
---|
29 | |
---|
30 | |
---|
31 | # We first need to detect if we're being called as part of the anuga setup |
---|
32 | # procedure itself in a reliable manner. |
---|
33 | try: |
---|
34 | __ANUGA_SETUP__ |
---|
35 | except NameError: |
---|
36 | __ANUGA_SETUP__ = False |
---|
37 | |
---|
38 | |
---|
39 | if __ANUGA_SETUP__: |
---|
40 | import sys as _sys |
---|
41 | _sys.stderr.write('Running from anuga source directory.\n') |
---|
42 | del _sys |
---|
43 | else: |
---|
44 | |
---|
45 | try: |
---|
46 | from anuga.__config__ import show as show_config |
---|
47 | except ImportError: |
---|
48 | msg = """Error importing anuga: you should not try to import anuga from |
---|
49 | its source directory; please exit the anuga source tree, and relaunch |
---|
50 | your python interpreter from there.""" |
---|
51 | raise ImportError(msg) |
---|
52 | |
---|
53 | |
---|
54 | #--------------------------------- |
---|
55 | # Setup the nose tester from numpy |
---|
56 | #--------------------------------- |
---|
57 | from numpy.testing import Tester |
---|
58 | test = Tester().test |
---|
59 | |
---|
60 | #-------------------------------- |
---|
61 | # Important basic classes |
---|
62 | #-------------------------------- |
---|
63 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
64 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
65 | from anuga.abstract_2d_finite_volumes.region import Region |
---|
66 | from anuga.geospatial_data.geospatial_data import Geospatial_data |
---|
67 | from anuga.coordinate_transforms.geo_reference import Geo_reference |
---|
68 | from anuga.operators.base_operator import Operator |
---|
69 | from anuga.structures.structure_operator import Structure_operator |
---|
70 | |
---|
71 | |
---|
72 | from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain |
---|
73 | from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh |
---|
74 | #------------------------------------------------------------------------------ |
---|
75 | # Miscellaneous |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | from anuga.abstract_2d_finite_volumes.util import file_function, \ |
---|
78 | sww2timeseries, sww2csv_gauges, \ |
---|
79 | csv2timeseries_graphs |
---|
80 | |
---|
81 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \ |
---|
82 | rectangular |
---|
83 | |
---|
84 | from anuga.file.csv_file import load_csv_as_building_polygons, \ |
---|
85 | load_csv_as_polygons |
---|
86 | |
---|
87 | from anuga.file.sts import create_sts_boundary |
---|
88 | |
---|
89 | from anuga.file.ungenerate import load_ungenerate |
---|
90 | |
---|
91 | from anuga.geometry.polygon import read_polygon |
---|
92 | from anuga.geometry.polygon import plot_polygons |
---|
93 | from anuga.geometry.polygon import inside_polygon |
---|
94 | from anuga.geometry.polygon import polygon_area |
---|
95 | from anuga.geometry.polygon_function import Polygon_function |
---|
96 | |
---|
97 | from anuga.coordinate_transforms.lat_long_UTM_conversion import LLtoUTM, UTMtoLL |
---|
98 | |
---|
99 | from anuga.abstract_2d_finite_volumes.pmesh2domain import \ |
---|
100 | pmesh_to_domain_instance |
---|
101 | |
---|
102 | from anuga.fit_interpolate.fit import fit_to_mesh_file |
---|
103 | from anuga.fit_interpolate.fit import fit_to_mesh |
---|
104 | |
---|
105 | from anuga.utilities.system_tools import file_length |
---|
106 | from anuga.utilities.sww_merge import sww_merge_parallel as sww_merge |
---|
107 | from anuga.utilities.file_utils import copy_code_files |
---|
108 | from anuga.utilities.numerical_tools import safe_acos as acos |
---|
109 | import anuga.utilities.plot_utils as plot_utils |
---|
110 | |
---|
111 | |
---|
112 | from anuga.caching import cache |
---|
113 | from os.path import join |
---|
114 | from anuga.config import indent |
---|
115 | |
---|
116 | #---------------------------- |
---|
117 | # Parallel api |
---|
118 | #---------------------------- |
---|
119 | ## from anuga_parallel.parallel_api import distribute |
---|
120 | ## from anuga_parallel.parallel_api import myid, numprocs, get_processor_name |
---|
121 | ## from anuga_parallel.parallel_api import send, receive |
---|
122 | ## from anuga_parallel.parallel_api import pypar_available, barrier, finalize |
---|
123 | |
---|
124 | ## if pypar_available: |
---|
125 | ## from anuga_parallel.parallel_api import sequential_distribute_dump |
---|
126 | ## from anuga_parallel.parallel_api import sequential_distribute_load |
---|
127 | |
---|
128 | from anuga.parallel.parallel_api import distribute |
---|
129 | from anuga.parallel.parallel_api import myid, numprocs, get_processor_name |
---|
130 | from anuga.parallel.parallel_api import send, receive |
---|
131 | from anuga.parallel.parallel_api import pypar_available, barrier, finalize |
---|
132 | from anuga.parallel.parallel_api import collect_value |
---|
133 | |
---|
134 | if pypar_available: |
---|
135 | from anuga.parallel.parallel_api import sequential_distribute_dump |
---|
136 | from anuga.parallel.parallel_api import sequential_distribute_load |
---|
137 | |
---|
138 | |
---|
139 | #----------------------------- |
---|
140 | # Checkpointing |
---|
141 | #----------------------------- |
---|
142 | from anuga.shallow_water.checkpoint import load_checkpoint_file |
---|
143 | |
---|
144 | |
---|
145 | #----------------------------- |
---|
146 | # SwW Standard Boundaries |
---|
147 | #----------------------------- |
---|
148 | from anuga.shallow_water.boundaries import File_boundary |
---|
149 | from anuga.shallow_water.boundaries import Reflective_boundary |
---|
150 | from anuga.shallow_water.boundaries import Field_boundary |
---|
151 | from anuga.shallow_water.boundaries import \ |
---|
152 | Time_stage_zero_momentum_boundary |
---|
153 | from anuga.shallow_water.boundaries import \ |
---|
154 | Transmissive_stage_zero_momentum_boundary |
---|
155 | from anuga.shallow_water.boundaries import \ |
---|
156 | Transmissive_momentum_set_stage_boundary |
---|
157 | from anuga.shallow_water.boundaries import \ |
---|
158 | Transmissive_n_momentum_zero_t_momentum_set_stage_boundary |
---|
159 | from anuga.shallow_water.boundaries import \ |
---|
160 | Flather_external_stage_zero_velocity_boundary |
---|
161 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \ |
---|
162 | Compute_fluxes_boundary |
---|
163 | |
---|
164 | |
---|
165 | #----------------------------- |
---|
166 | # General Boundaries |
---|
167 | #----------------------------- |
---|
168 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
169 | import Dirichlet_boundary |
---|
170 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
171 | import Time_boundary |
---|
172 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
173 | import Time_space_boundary |
---|
174 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
175 | import Transmissive_boundary |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | #----------------------------- |
---|
180 | # Shallow Water Tsunamis |
---|
181 | #----------------------------- |
---|
182 | from anuga.tsunami_source.smf import slide_tsunami, slump_tsunami |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | #----------------------------- |
---|
187 | # Forcing |
---|
188 | # These are old, should use operators |
---|
189 | #----------------------------- |
---|
190 | from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress |
---|
191 | |
---|
192 | |
---|
193 | #----------------------------- |
---|
194 | # File conversion utilities |
---|
195 | #----------------------------- |
---|
196 | from anuga.file_conversion.file_conversion import sww2obj |
---|
197 | from anuga.file_conversion.file_conversion import timefile2netcdf |
---|
198 | from anuga.file_conversion.file_conversion import tsh2sww |
---|
199 | from anuga.file_conversion.urs2nc import urs2nc |
---|
200 | from anuga.file_conversion.urs2sww import urs2sww |
---|
201 | from anuga.file_conversion.urs2sts import urs2sts |
---|
202 | from anuga.file_conversion.dem2pts import dem2pts |
---|
203 | from anuga.file_conversion.esri2sww import esri2sww |
---|
204 | from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch |
---|
205 | from anuga.file_conversion.asc2dem import asc2dem |
---|
206 | from anuga.file_conversion.xya2pts import xya2pts |
---|
207 | from anuga.file_conversion.ferret2sww import ferret2sww |
---|
208 | from anuga.file_conversion.dem2dem import dem2dem |
---|
209 | from anuga.file_conversion.sww2array import sww2array |
---|
210 | |
---|
211 | #----------------------------- |
---|
212 | # Parsing arguments |
---|
213 | #----------------------------- |
---|
214 | from anuga.utilities.argparsing import create_standard_parser |
---|
215 | from anuga.utilities.argparsing import parse_standard_args |
---|
216 | |
---|
217 | |
---|
218 | def get_args(): |
---|
219 | """ Explicitly parse the argument list using standard anuga arguments |
---|
220 | |
---|
221 | Don't use this if you want to setup your own parser |
---|
222 | """ |
---|
223 | parser = create_standard_parser() |
---|
224 | return parser.parse_args() |
---|
225 | |
---|
226 | |
---|
227 | #----------------------------- |
---|
228 | # Running Script |
---|
229 | #----------------------------- |
---|
230 | from anuga.utilities.run_anuga_script import run_script as run_anuga_script |
---|
231 | |
---|
232 | |
---|
233 | #----------------------------- |
---|
234 | # Mesh API |
---|
235 | #----------------------------- |
---|
236 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
237 | |
---|
238 | #----------------------------- |
---|
239 | # SWW file access |
---|
240 | #----------------------------- |
---|
241 | from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section |
---|
242 | |
---|
243 | #--------------------------- |
---|
244 | # Operators |
---|
245 | #--------------------------- |
---|
246 | from anuga.operators.kinematic_viscosity_operator import Kinematic_viscosity_operator |
---|
247 | |
---|
248 | from anuga.operators.rate_operators import Rate_operator |
---|
249 | from anuga.operators.set_friction_operators import Depth_friction_operator |
---|
250 | |
---|
251 | from anuga.operators.set_elevation_operator import Set_elevation_operator |
---|
252 | from anuga.operators.set_quantity_operator import Set_quantity_operator |
---|
253 | from anuga.operators.set_stage_operator import Set_stage_operator |
---|
254 | |
---|
255 | from anuga.operators.set_elevation import Set_elevation |
---|
256 | from anuga.operators.set_quantity import Set_quantity |
---|
257 | |
---|
258 | from anuga.operators.sanddune_erosion_operator import Sanddune_erosion_operator |
---|
259 | from anuga.operators.erosion_operators import Bed_shear_erosion_operator |
---|
260 | from anuga.operators.erosion_operators import Flat_slice_erosion_operator |
---|
261 | from anuga.operators.erosion_operators import Flat_fill_slice_erosion_operator |
---|
262 | |
---|
263 | #--------------------------- |
---|
264 | # Structure Operators |
---|
265 | #--------------------------- |
---|
266 | |
---|
267 | |
---|
268 | if pypar_available: |
---|
269 | from anuga.parallel.parallel_operator_factory import Inlet_operator |
---|
270 | from anuga.parallel.parallel_operator_factory import Boyd_box_operator |
---|
271 | from anuga.parallel.parallel_operator_factory import Boyd_pipe_operator |
---|
272 | from anuga.parallel.parallel_operator_factory import Weir_orifice_trapezoid_operator |
---|
273 | from anuga.parallel.parallel_operator_factory import Internal_boundary_operator |
---|
274 | else: |
---|
275 | from anuga.structures.inlet_operator import Inlet_operator |
---|
276 | from anuga.structures.boyd_box_operator import Boyd_box_operator |
---|
277 | from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator |
---|
278 | from anuga.structures.weir_orifice_trapezoid_operator import Weir_orifice_trapezoid_operator |
---|
279 | from anuga.structures.internal_boundary_operator import Internal_boundary_operator |
---|
280 | |
---|
281 | |
---|
282 | #---------------------------- |
---|
283 | # Parallel distribute |
---|
284 | #---------------------------- |
---|
285 | |
---|
286 | |
---|
287 | #---------------------------- |
---|
288 | # |
---|
289 | #Added by Petar Milevski 10/09/2013 |
---|
290 | #import time, os |
---|
291 | |
---|
292 | from anuga.utilities.model_tools import get_polygon_from_single_file |
---|
293 | from anuga.utilities.model_tools import get_polygons_from_Mid_Mif |
---|
294 | from anuga.utilities.model_tools import get_polygon_list_from_files |
---|
295 | from anuga.utilities.model_tools import get_polygon_dictionary |
---|
296 | from anuga.utilities.model_tools import get_polygon_value_list |
---|
297 | from anuga.utilities.model_tools import read_polygon_dir |
---|
298 | from anuga.utilities.model_tools import read_hole_dir_multi_files_with_single_poly |
---|
299 | from anuga.utilities.model_tools import read_multi_poly_file |
---|
300 | from anuga.utilities.model_tools import read_hole_dir_single_file_with_multi_poly |
---|
301 | from anuga.utilities.model_tools import read_multi_poly_file_value |
---|
302 | from anuga.utilities.model_tools import Create_culvert_bridge_Operator |
---|
303 | |
---|
304 | |
---|
305 | #--------------------------- |
---|
306 | # User Access Functions |
---|
307 | #--------------------------- |
---|
308 | |
---|
309 | from anuga.utilities.system_tools import get_user_name |
---|
310 | from anuga.utilities.system_tools import get_host_name |
---|
311 | from anuga.utilities.system_tools import get_version |
---|
312 | from anuga.utilities.system_tools import get_revision_number |
---|
313 | from anuga.utilities.system_tools import get_revision_date |
---|
314 | from anuga.utilities.mem_time_equation import estimate_time_mem |
---|
315 | |
---|
316 | |
---|
317 | #------------------------- |
---|
318 | # create domain functions |
---|
319 | #------------------------- |
---|
320 | from anuga.extras import create_domain_from_regions |
---|
321 | from anuga.extras import create_domain_from_file |
---|
322 | from anuga.extras import rectangular_cross_domain |
---|
323 | |
---|
324 | |
---|
325 | #import logging as log |
---|
326 | from anuga.utilities import log |
---|
327 | |
---|
328 | from anuga.config import g |
---|
329 | from anuga.config import velocity_protection |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | |
---|