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 | from numpy.testing import Tester |
---|
24 | test = Tester().test |
---|
25 | |
---|
26 | #from anuga.__metadata__ import __date__, __author__ |
---|
27 | |
---|
28 | from .version import git_revision as __git_revision__ |
---|
29 | from .version import svn_revision as __svn_revision__ |
---|
30 | from .version import version as __version__ |
---|
31 | |
---|
32 | |
---|
33 | # We first need to detect if we're being called as part of the anuga setup |
---|
34 | # procedure itself in a reliable manner. |
---|
35 | try: |
---|
36 | __ANUGA_SETUP__ |
---|
37 | except NameError: |
---|
38 | __ANUGA_SETUP__ = False |
---|
39 | |
---|
40 | |
---|
41 | if __ANUGA_SETUP__: |
---|
42 | import sys as _sys |
---|
43 | _sys.stderr.write('Running from anuga source directory.\n') |
---|
44 | del _sys |
---|
45 | else: |
---|
46 | |
---|
47 | try: |
---|
48 | from anuga.__config__ import show as show_config |
---|
49 | except ImportError: |
---|
50 | msg = """Error importing anuga: you should not try to import anuga from |
---|
51 | its source directory; please exit the anuga source tree, and relaunch |
---|
52 | your python interpreter from there.""" |
---|
53 | raise ImportError(msg) |
---|
54 | |
---|
55 | #-------------------------------- |
---|
56 | # Important basic classes |
---|
57 | #-------------------------------- |
---|
58 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
59 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
60 | from anuga.abstract_2d_finite_volumes.region import Region |
---|
61 | from anuga.geospatial_data.geospatial_data import Geospatial_data |
---|
62 | from anuga.operators.base_operator import Operator |
---|
63 | from anuga.structures.structure_operator import Structure_operator |
---|
64 | |
---|
65 | |
---|
66 | from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain |
---|
67 | from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | # Miscellaneous |
---|
70 | #------------------------------------------------------------------------------ |
---|
71 | from anuga.abstract_2d_finite_volumes.util import file_function, \ |
---|
72 | sww2timeseries, sww2csv_gauges, \ |
---|
73 | csv2timeseries_graphs |
---|
74 | |
---|
75 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \ |
---|
76 | rectangular |
---|
77 | |
---|
78 | from anuga.file.csv_file import load_csv_as_building_polygons, \ |
---|
79 | load_csv_as_polygons |
---|
80 | |
---|
81 | from anuga.file.sts import create_sts_boundary |
---|
82 | |
---|
83 | from anuga.file.ungenerate import load_ungenerate |
---|
84 | |
---|
85 | from anuga.geometry.polygon import read_polygon |
---|
86 | from anuga.geometry.polygon import plot_polygons |
---|
87 | from anuga.geometry.polygon import inside_polygon |
---|
88 | from anuga.geometry.polygon import polygon_area |
---|
89 | from anuga.geometry.polygon_function import Polygon_function |
---|
90 | |
---|
91 | from anuga.abstract_2d_finite_volumes.pmesh2domain import \ |
---|
92 | pmesh_to_domain_instance |
---|
93 | |
---|
94 | from anuga.utilities.system_tools import file_length |
---|
95 | from anuga.utilities.sww_merge import sww_merge_parallel as sww_merge |
---|
96 | from anuga.utilities.file_utils import copy_code_files |
---|
97 | from anuga.utilities.numerical_tools import safe_acos as acos |
---|
98 | import anuga.utilities.plot_utils as plot_utils |
---|
99 | |
---|
100 | |
---|
101 | from anuga.caching import cache |
---|
102 | from os.path import join |
---|
103 | from anuga.config import indent |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | #---------------------------- |
---|
108 | # Parallel api |
---|
109 | #---------------------------- |
---|
110 | ## from anuga_parallel.parallel_api import distribute |
---|
111 | ## from anuga_parallel.parallel_api import myid, numprocs, get_processor_name |
---|
112 | ## from anuga_parallel.parallel_api import send, receive |
---|
113 | ## from anuga_parallel.parallel_api import pypar_available, barrier, finalize |
---|
114 | |
---|
115 | ## if pypar_available: |
---|
116 | ## from anuga_parallel.parallel_api import sequential_distribute_dump |
---|
117 | ## from anuga_parallel.parallel_api import sequential_distribute_load |
---|
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 | |
---|
129 | #----------------------------- |
---|
130 | # Checkpointing |
---|
131 | #----------------------------- |
---|
132 | from anuga.shallow_water.checkpoint import load_checkpoint_file |
---|
133 | |
---|
134 | |
---|
135 | #----------------------------- |
---|
136 | # SwW Standard Boundaries |
---|
137 | #----------------------------- |
---|
138 | from anuga.shallow_water.boundaries import File_boundary |
---|
139 | from anuga.shallow_water.boundaries import Reflective_boundary |
---|
140 | from anuga.shallow_water.boundaries import Field_boundary |
---|
141 | from anuga.shallow_water.boundaries import \ |
---|
142 | Time_stage_zero_momentum_boundary |
---|
143 | from anuga.shallow_water.boundaries import \ |
---|
144 | Transmissive_stage_zero_momentum_boundary |
---|
145 | from anuga.shallow_water.boundaries import \ |
---|
146 | Transmissive_momentum_set_stage_boundary |
---|
147 | from anuga.shallow_water.boundaries import \ |
---|
148 | Transmissive_n_momentum_zero_t_momentum_set_stage_boundary |
---|
149 | from anuga.shallow_water.boundaries import \ |
---|
150 | Flather_external_stage_zero_velocity_boundary |
---|
151 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \ |
---|
152 | Compute_fluxes_boundary |
---|
153 | |
---|
154 | |
---|
155 | #----------------------------- |
---|
156 | # General Boundaries |
---|
157 | #----------------------------- |
---|
158 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
159 | import Dirichlet_boundary |
---|
160 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
161 | import Time_boundary |
---|
162 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
163 | import Time_space_boundary |
---|
164 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
165 | import Transmissive_boundary |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | #----------------------------- |
---|
170 | # Shallow Water Tsunamis |
---|
171 | #----------------------------- |
---|
172 | |
---|
173 | from anuga.tsunami_source.smf import slide_tsunami, slump_tsunami |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | #----------------------------- |
---|
178 | # Forcing |
---|
179 | # These are old, should use operators |
---|
180 | #----------------------------- |
---|
181 | from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | #----------------------------- |
---|
186 | # File conversion utilities |
---|
187 | #----------------------------- |
---|
188 | from anuga.file_conversion.file_conversion import sww2obj, \ |
---|
189 | timefile2netcdf, tsh2sww |
---|
190 | from anuga.file_conversion.urs2nc import urs2nc |
---|
191 | from anuga.file_conversion.urs2sww import urs2sww |
---|
192 | from anuga.file_conversion.urs2sts import urs2sts |
---|
193 | from anuga.file_conversion.dem2pts import dem2pts |
---|
194 | from anuga.file_conversion.esri2sww import esri2sww |
---|
195 | from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch |
---|
196 | from anuga.file_conversion.asc2dem import asc2dem |
---|
197 | from anuga.file_conversion.xya2pts import xya2pts |
---|
198 | from anuga.file_conversion.ferret2sww import ferret2sww |
---|
199 | from anuga.file_conversion.dem2dem import dem2dem |
---|
200 | from anuga.file_conversion.sww2array import sww2array |
---|
201 | |
---|
202 | #----------------------------- |
---|
203 | # Parsing arguments |
---|
204 | #----------------------------- |
---|
205 | from anuga.utilities.argparsing import create_standard_parser |
---|
206 | from anuga.utilities.argparsing import parse_standard_args |
---|
207 | |
---|
208 | |
---|
209 | def get_args(): |
---|
210 | """ Explicitly parse the argument list using standard anuga arguments |
---|
211 | |
---|
212 | Don't use this if you want to setup your own parser |
---|
213 | """ |
---|
214 | parser = create_standard_parser() |
---|
215 | return parser.parse_args() |
---|
216 | |
---|
217 | |
---|
218 | #----------------------------- |
---|
219 | # Running Script |
---|
220 | #----------------------------- |
---|
221 | from anuga.utilities.run_anuga_script import run_script as run_anuga_script |
---|
222 | |
---|
223 | |
---|
224 | #----------------------------- |
---|
225 | # Mesh API |
---|
226 | #----------------------------- |
---|
227 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
228 | |
---|
229 | #----------------------------- |
---|
230 | # SWW file access |
---|
231 | #----------------------------- |
---|
232 | from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section |
---|
233 | |
---|
234 | #--------------------------- |
---|
235 | # Operators |
---|
236 | #--------------------------- |
---|
237 | from anuga.operators.kinematic_viscosity_operator import Kinematic_viscosity_operator |
---|
238 | |
---|
239 | from anuga.operators.rate_operators import Rate_operator |
---|
240 | from anuga.operators.set_friction_operators import Depth_friction_operator |
---|
241 | |
---|
242 | from anuga.operators.set_elevation_operator import Set_elevation_operator |
---|
243 | from anuga.operators.set_quantity_operator import Set_quantity_operator |
---|
244 | from anuga.operators.set_stage_operator import Set_stage_operator |
---|
245 | |
---|
246 | from anuga.operators.set_elevation import Set_elevation |
---|
247 | from anuga.operators.set_quantity import Set_quantity |
---|
248 | |
---|
249 | from anuga.operators.erosion_operators import Bed_shear_erosion_operator |
---|
250 | from anuga.operators.erosion_operators import Flat_slice_erosion_operator |
---|
251 | from anuga.operators.erosion_operators import Flat_fill_slice_erosion_operator |
---|
252 | |
---|
253 | #--------------------------- |
---|
254 | # Structure Operators |
---|
255 | #--------------------------- |
---|
256 | |
---|
257 | |
---|
258 | if pypar_available: |
---|
259 | from anuga.parallel.parallel_operator_factory import Inlet_operator |
---|
260 | from anuga.parallel.parallel_operator_factory import Boyd_box_operator |
---|
261 | from anuga.parallel.parallel_operator_factory import Boyd_pipe_operator |
---|
262 | from anuga.parallel.parallel_operator_factory import Weir_orifice_trapezoid_operator |
---|
263 | from anuga.parallel.parallel_operator_factory import Internal_boundary_operator |
---|
264 | else: |
---|
265 | from anuga.structures.inlet_operator import Inlet_operator |
---|
266 | from anuga.structures.boyd_box_operator import Boyd_box_operator |
---|
267 | from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator |
---|
268 | from anuga.structures.weir_orifice_trapezoid_operator import Weir_orifice_trapezoid_operator |
---|
269 | from anuga.structures.internal_boundary_operator import Internal_boundary_operator |
---|
270 | |
---|
271 | |
---|
272 | #---------------------------- |
---|
273 | # Parallel distribute |
---|
274 | #---------------------------- |
---|
275 | |
---|
276 | |
---|
277 | #---------------------------- |
---|
278 | # |
---|
279 | #Added by Petar Milevski 10/09/2013 |
---|
280 | #import time, os |
---|
281 | |
---|
282 | from anuga.utilities.model_tools import get_polygon_from_single_file |
---|
283 | from anuga.utilities.model_tools import get_polygons_from_Mid_Mif |
---|
284 | from anuga.utilities.model_tools import get_polygon_list_from_files |
---|
285 | from anuga.utilities.model_tools import get_polygon_dictionary |
---|
286 | from anuga.utilities.model_tools import get_polygon_value_list |
---|
287 | from anuga.utilities.model_tools import read_polygon_dir |
---|
288 | from anuga.utilities.model_tools import read_hole_dir_multi_files_with_single_poly |
---|
289 | from anuga.utilities.model_tools import read_multi_poly_file |
---|
290 | from anuga.utilities.model_tools import read_hole_dir_single_file_with_multi_poly |
---|
291 | from anuga.utilities.model_tools import read_multi_poly_file_value |
---|
292 | from anuga.utilities.model_tools import Create_culvert_bridge_Operator |
---|
293 | |
---|
294 | |
---|
295 | #--------------------------- |
---|
296 | # User Access Functions |
---|
297 | #--------------------------- |
---|
298 | |
---|
299 | from anuga.utilities.system_tools import get_user_name, get_host_name, \ |
---|
300 | get_revision_number |
---|
301 | from anuga.utilities.mem_time_equation import estimate_time_mem |
---|
302 | |
---|
303 | |
---|
304 | #------------------------- |
---|
305 | # create domain functions |
---|
306 | #------------------------- |
---|
307 | from anuga.extras import create_domain_from_regions |
---|
308 | from anuga.extras import create_domain_from_file |
---|
309 | from anuga.extras import rectangular_cross_domain |
---|
310 | |
---|
311 | |
---|
312 | #import logging as log |
---|
313 | from anuga.utilities import log |
---|
314 | |
---|
315 | from anuga.config import g |
---|
316 | from anuga.config import velocity_protection |
---|
317 | |
---|
318 | ## if use_psyco: |
---|
319 | ## # try using psyco if available |
---|
320 | ## try: |
---|
321 | ## import psyco |
---|
322 | ## except: |
---|
323 | ## import os |
---|
324 | ## import sys |
---|
325 | ## if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']: |
---|
326 | ## pass |
---|
327 | ## # Psyco isn't supported on 64 bit systems, but it doesn't matter |
---|
328 | ## elif sys.version[:3] == '2.7' : |
---|
329 | ## pass |
---|
330 | ## # Psyco isn't available for python 2.7 (16/05/2011) |
---|
331 | ## else: |
---|
332 | ## log.critical('WARNING: psyco (speedup) could not be imported, ' |
---|
333 | ## 'you may want to consider installing it') |
---|
334 | ## else: |
---|
335 | ## psyco.full() # aggressively compile everything |
---|
336 | ## #psyco.background() # attempt to profile code - only compile most used |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | |
---|
341 | |
---|