[7780] | 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 |
---|
[7775] | 7 | modules, which can be used directly by including the following line in |
---|
| 8 | the user's code: |
---|
| 9 | |
---|
| 10 | import anuga |
---|
[7780] | 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. |
---|
[7775] | 15 | |
---|
| 16 | Also, it isolates the user from "under-the-hood" refactorings. |
---|
[3518] | 17 | """ |
---|
| 18 | |
---|
| 19 | pass |
---|
| 20 | |
---|
| 21 | #Add path of package to PYTHONPATH to allow C-extensions to be loaded |
---|
| 22 | import sys |
---|
| 23 | sys.path += __path__ |
---|
[7751] | 24 | |
---|
[7810] | 25 | |
---|
[7775] | 26 | #----------------------------------------------------- |
---|
| 27 | # Make selected classes available directly |
---|
| 28 | #----------------------------------------------------- |
---|
[8226] | 29 | from anuga.__metadata__ import __version__, __date__, __author__ |
---|
[7751] | 30 | |
---|
[7778] | 31 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
[7751] | 32 | |
---|
[8154] | 33 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 34 | |
---|
[7841] | 35 | from anuga.abstract_2d_finite_volumes.util import file_function, \ |
---|
| 36 | sww2timeseries, sww2csv_gauges |
---|
[7775] | 37 | |
---|
[7841] | 38 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \ |
---|
| 39 | rectangular |
---|
[7775] | 40 | |
---|
[7778] | 41 | from anuga.file.csv_file import load_csv_as_building_polygons, \ |
---|
| 42 | load_csv_as_polygons |
---|
[7775] | 43 | |
---|
| 44 | from anuga.file.sts import create_sts_boundary |
---|
| 45 | |
---|
[7874] | 46 | from anuga.file.ungenerate import load_ungenerate |
---|
| 47 | |
---|
[7999] | 48 | from anuga.geometry.polygon import read_polygon, plot_polygons, polygon_area, \ |
---|
| 49 | inside_polygon, polygon_area |
---|
[7858] | 50 | from anuga.geometry.polygon_function import Polygon_function |
---|
[7775] | 51 | |
---|
[7778] | 52 | from anuga.abstract_2d_finite_volumes.pmesh2domain import \ |
---|
| 53 | pmesh_to_domain_instance |
---|
[7775] | 54 | |
---|
[7796] | 55 | from anuga.utilities.system_tools import file_length |
---|
[7841] | 56 | from anuga.utilities.sww_merge import sww_merge |
---|
[7796] | 57 | from anuga.utilities.file_utils import copy_code_files |
---|
[7999] | 58 | from anuga.utilities.numerical_tools import safe_acos as acos |
---|
[7796] | 59 | |
---|
[7858] | 60 | from anuga.geometry.polygon import read_polygon |
---|
[7796] | 61 | from anuga.caching import cache |
---|
| 62 | |
---|
[7775] | 63 | #----------------------------- |
---|
| 64 | # Standard Boundaries |
---|
| 65 | #----------------------------- |
---|
| 66 | from anuga.shallow_water.boundaries import File_boundary |
---|
| 67 | from anuga.shallow_water.boundaries import Reflective_boundary |
---|
| 68 | from anuga.shallow_water.boundaries import Field_boundary |
---|
| 69 | from anuga.shallow_water.boundaries import \ |
---|
| 70 | Transmissive_stage_zero_momentum_boundary |
---|
| 71 | from anuga.shallow_water.boundaries import \ |
---|
| 72 | Transmissive_momentum_set_stage_boundary |
---|
| 73 | from anuga.shallow_water.boundaries import \ |
---|
| 74 | Transmissive_n_momentum_zero_t_momentum_set_stage_boundary |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | #----------------------------- |
---|
| 78 | # SWW-specific Boundaries |
---|
| 79 | #----------------------------- |
---|
| 80 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
| 81 | import Dirichlet_boundary |
---|
| 82 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
| 83 | import Time_boundary |
---|
| 84 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
| 85 | import Time_space_boundary |
---|
| 86 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ |
---|
| 87 | import Transmissive_boundary |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | #----------------------------- |
---|
[7810] | 92 | # Shalow Water Tsunamis |
---|
| 93 | #----------------------------- |
---|
| 94 | |
---|
| 95 | from anuga.shallow_water.smf import slide_tsunami, slump_tsunami |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | #----------------------------- |
---|
[7775] | 99 | # Forcing |
---|
| 100 | #----------------------------- |
---|
[7869] | 101 | from anuga.shallow_water.forcing import Inflow, Rainfall, Wind_stress |
---|
[7775] | 102 | |
---|
| 103 | #----------------------------- |
---|
| 104 | # File conversion utilities |
---|
| 105 | #----------------------------- |
---|
[7814] | 106 | from anuga.file_conversion.file_conversion import sww2obj, \ |
---|
[7800] | 107 | timefile2netcdf, tsh2sww |
---|
| 108 | from anuga.file_conversion.urs2nc import urs2nc |
---|
| 109 | from anuga.file_conversion.urs2sww import urs2sww |
---|
[7796] | 110 | from anuga.file_conversion.urs2sts import urs2sts |
---|
[7775] | 111 | from anuga.file_conversion.dem2pts import dem2pts |
---|
| 112 | from anuga.file_conversion.esri2sww import esri2sww |
---|
[7776] | 113 | from anuga.file_conversion.sww2dem import sww2dem, sww2dem_batch |
---|
[7775] | 114 | from anuga.file_conversion.asc2dem import asc2dem |
---|
| 115 | from anuga.file_conversion.ferret2sww import ferret2sww |
---|
[7796] | 116 | from anuga.file_conversion.dem2dem import dem2dem |
---|
[7775] | 117 | |
---|
[7796] | 118 | |
---|
[7775] | 119 | #----------------------------- |
---|
[7800] | 120 | # Mesh API |
---|
| 121 | #----------------------------- |
---|
| 122 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 123 | |
---|
| 124 | #----------------------------- |
---|
[7775] | 125 | # SWW file access |
---|
| 126 | #----------------------------- |
---|
| 127 | from anuga.shallow_water.sww_interrogate import get_flow_through_cross_section |
---|
[7810] | 128 | |
---|
[7775] | 129 | |
---|
[8133] | 130 | |
---|
| 131 | #--------------------------- |
---|
| 132 | # Operators |
---|
| 133 | #--------------------------- |
---|
| 134 | from anuga.operators.base_operator import Operator |
---|
| 135 | |
---|
| 136 | #--------------------------- |
---|
[8154] | 137 | # Structure Operators |
---|
[8133] | 138 | #--------------------------- |
---|
| 139 | from anuga.structures.structure_operator import Structure_operator |
---|
| 140 | from anuga.structures.boyd_box_operator import Boyd_box_operator |
---|
| 141 | from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator |
---|
| 142 | |
---|
| 143 | #--------------------------- |
---|
| 144 | # User Access Functions |
---|
| 145 | #--------------------------- |
---|
| 146 | |
---|
| 147 | from anuga.utilities.system_tools import get_user_name, get_host_name, get_revision_number |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
[7775] | 152 | #----------------------------- |
---|
| 153 | # rectangular domains |
---|
| 154 | #----------------------------- |
---|
| 155 | def rectangular_cross_domain(*args, **kwargs): |
---|
[7791] | 156 | """ |
---|
| 157 | Create a rectangular domain with triangulation made |
---|
| 158 | up of m+1 by n+1 uniform rectangular cells divided |
---|
| 159 | into 4 triangles in a cross pattern |
---|
| 160 | |
---|
| 161 | Arguments |
---|
| 162 | m: number of cells in x direction |
---|
| 163 | n: number of cells in y direction |
---|
| 164 | len1: length of domain in x direction (left to right) |
---|
| 165 | (default 1.0) |
---|
| 166 | len2: length of domain in y direction (bottom to top) |
---|
| 167 | (default 1.0) |
---|
| 168 | origin: tuple (x,y) specifying location of lower left corner |
---|
| 169 | of domain (default (0,0)) |
---|
| 170 | """ |
---|
[7775] | 171 | points, vertices, boundary = rectangular_cross(*args, **kwargs) |
---|
| 172 | return Domain(points, vertices, boundary) |
---|
| 173 | |
---|
| 174 | #---------------------------- |
---|
| 175 | # Create domain from file |
---|
| 176 | #---------------------------- |
---|
| 177 | def create_domain_from_file(file): |
---|
[7791] | 178 | """ |
---|
| 179 | Create a domain from a file |
---|
| 180 | """ |
---|
[7775] | 181 | return pmesh_to_domain_instance(file,Domain) |
---|
| 182 | |
---|
| 183 | #--------------------------- |
---|
| 184 | # Create domain from regions |
---|
| 185 | #--------------------------- |
---|
| 186 | |
---|
| 187 | def create_domain_from_regions(bounding_polygon, |
---|
| 188 | boundary_tags, |
---|
| 189 | maximum_triangle_area=None, |
---|
| 190 | mesh_filename=None, |
---|
| 191 | interior_regions=None, |
---|
| 192 | interior_holes=None, |
---|
[8009] | 193 | hole_tags=None, |
---|
[7775] | 194 | poly_geo_reference=None, |
---|
| 195 | mesh_geo_reference=None, |
---|
| 196 | minimum_triangle_angle=28.0, |
---|
| 197 | fail_if_polygons_outside=True, |
---|
| 198 | use_cache=False, |
---|
| 199 | verbose=True): |
---|
| 200 | """Create domain from bounding polygons and resolutions. |
---|
| 201 | |
---|
| 202 | bounding_polygon is a list of points in Eastings and Northings, |
---|
| 203 | relative to the zone stated in poly_geo_reference if specified. |
---|
| 204 | Otherwise points are just x, y coordinates with no particular |
---|
| 205 | association to any location. |
---|
| 206 | |
---|
| 207 | boundary_tags is a dictionary of symbolic tags. For every tag there |
---|
| 208 | is a list of indices referring to segments associated with that tag. |
---|
| 209 | If a segment is omitted it will be assigned the default tag ''. |
---|
| 210 | |
---|
| 211 | maximum_triangle_area is the maximal area per triangle |
---|
| 212 | for the bounding polygon, excluding the interior regions. |
---|
| 213 | |
---|
| 214 | Interior_regions is a list of tuples consisting of (polygon, |
---|
| 215 | resolution) for each region to be separately refined. Do not have |
---|
| 216 | polygon lines cross or be on-top of each other. Also do not have |
---|
| 217 | polygon close to each other. |
---|
| 218 | |
---|
| 219 | NOTE: If a interior_region is outside the bounding_polygon it should |
---|
| 220 | throw an error |
---|
| 221 | |
---|
[7841] | 222 | interior_holes is a list of ploygons for each hole. These polygons do not |
---|
| 223 | need to be closed, but their points must be specified in a counter-clockwise |
---|
| 224 | order. |
---|
[7775] | 225 | |
---|
[8133] | 226 | hole_tags is a list of tag segment dictionaries. |
---|
| 227 | |
---|
[7775] | 228 | This function does not allow segments to share points - use underlying |
---|
| 229 | pmesh functionality for that |
---|
| 230 | |
---|
| 231 | poly_geo_reference is the geo_reference of the bounding polygon and |
---|
| 232 | the interior polygons. |
---|
| 233 | If none, assume absolute. Please pass one though, since absolute |
---|
| 234 | references have a zone. |
---|
| 235 | |
---|
| 236 | mesh_geo_reference is the geo_reference of the mesh to be created. |
---|
| 237 | If none is given one will be automatically generated. It was use |
---|
| 238 | the lower left hand corner of bounding_polygon (absolute) |
---|
| 239 | as the x and y values for the geo_ref. |
---|
| 240 | |
---|
| 241 | Returns the shallow water domain instance |
---|
| 242 | |
---|
| 243 | Note, interior regions should be fully nested, as overlaps may cause |
---|
| 244 | unintended resolutions. |
---|
| 245 | |
---|
| 246 | fail_if_polygons_outside: If True (the default) Exception in thrown |
---|
| 247 | where interior polygons fall outside bounding polygon. If False, these |
---|
| 248 | will be ignored and execution continued. |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | """ |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | # Build arguments and keyword arguments for use with caching or apply. |
---|
| 255 | args = (bounding_polygon, |
---|
| 256 | boundary_tags) |
---|
| 257 | |
---|
| 258 | kwargs = {'maximum_triangle_area': maximum_triangle_area, |
---|
| 259 | 'mesh_filename': mesh_filename, |
---|
| 260 | 'interior_regions': interior_regions, |
---|
| 261 | 'interior_holes': interior_holes, |
---|
[8009] | 262 | 'hole_tags': hole_tags, |
---|
[7775] | 263 | 'poly_geo_reference': poly_geo_reference, |
---|
| 264 | 'mesh_geo_reference': mesh_geo_reference, |
---|
| 265 | 'minimum_triangle_angle': minimum_triangle_angle, |
---|
| 266 | 'fail_if_polygons_outside': fail_if_polygons_outside, |
---|
| 267 | 'verbose': verbose} #FIXME (Ole): See ticket:14 |
---|
| 268 | |
---|
| 269 | # Call underlying engine with or without caching |
---|
| 270 | if use_cache is True: |
---|
| 271 | try: |
---|
| 272 | from anuga.caching import cache |
---|
| 273 | except: |
---|
| 274 | msg = 'Caching was requested, but caching module'+\ |
---|
| 275 | 'could not be imported' |
---|
[8124] | 276 | raise (msg) |
---|
[7775] | 277 | |
---|
| 278 | |
---|
| 279 | domain = cache(_create_domain_from_regions, |
---|
| 280 | args, kwargs, |
---|
| 281 | verbose=verbose, |
---|
| 282 | compression=False) |
---|
| 283 | else: |
---|
| 284 | domain = apply(_create_domain_from_regions, |
---|
| 285 | args, kwargs) |
---|
| 286 | |
---|
| 287 | return domain |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | def _create_domain_from_regions(bounding_polygon, |
---|
| 291 | boundary_tags, |
---|
| 292 | maximum_triangle_area=None, |
---|
| 293 | mesh_filename=None, |
---|
| 294 | interior_regions=None, |
---|
| 295 | interior_holes=None, |
---|
[8009] | 296 | hole_tags=None, |
---|
[7775] | 297 | poly_geo_reference=None, |
---|
| 298 | mesh_geo_reference=None, |
---|
| 299 | minimum_triangle_angle=28.0, |
---|
| 300 | fail_if_polygons_outside=True, |
---|
| 301 | verbose=True): |
---|
| 302 | """_create_domain_from_regions - internal function. |
---|
| 303 | |
---|
| 304 | See create_domain_from_regions for documentation. |
---|
| 305 | """ |
---|
| 306 | |
---|
[8248] | 307 | #from anuga.shallow_water.shallow_water_domain import Domain |
---|
[7775] | 308 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 309 | |
---|
| 310 | create_mesh_from_regions(bounding_polygon, |
---|
| 311 | boundary_tags, |
---|
| 312 | maximum_triangle_area=maximum_triangle_area, |
---|
| 313 | interior_regions=interior_regions, |
---|
| 314 | filename=mesh_filename, |
---|
| 315 | interior_holes=interior_holes, |
---|
[8009] | 316 | hole_tags=hole_tags, |
---|
[7775] | 317 | poly_geo_reference=poly_geo_reference, |
---|
| 318 | mesh_geo_reference=mesh_geo_reference, |
---|
| 319 | minimum_triangle_angle=minimum_triangle_angle, |
---|
| 320 | fail_if_polygons_outside=fail_if_polygons_outside, |
---|
| 321 | use_cache=False, |
---|
| 322 | verbose=verbose) |
---|
[8248] | 323 | |
---|
[7775] | 324 | domain = Domain(mesh_filename, use_cache=False, verbose=verbose) |
---|
| 325 | |
---|
| 326 | |
---|
| 327 | return domain |
---|
| 328 | |
---|
[7851] | 329 | import logging as log |
---|
[7775] | 330 | |
---|
[7999] | 331 | from anuga.config import use_psyco, g, velocity_protection |
---|
[7810] | 332 | if use_psyco: |
---|
| 333 | # try using psyco if available |
---|
| 334 | try: |
---|
| 335 | import psyco |
---|
| 336 | except: |
---|
| 337 | import os |
---|
[8179] | 338 | import sys |
---|
[7810] | 339 | if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']: |
---|
| 340 | pass |
---|
| 341 | # Psyco isn't supported on 64 bit systems, but it doesn't matter |
---|
[8179] | 342 | elif sys.version[:3] == '2.7' : |
---|
| 343 | pass |
---|
| 344 | # Psyco isn't available for python 2.7 (16/05/2011) |
---|
[7810] | 345 | else: |
---|
| 346 | log.critical('WARNING: psyco (speedup) could not be imported, ' |
---|
| 347 | 'you may want to consider installing it') |
---|
| 348 | else: |
---|
| 349 | psyco.full() # aggressively compile everything |
---|
| 350 | #psyco.background() # attempt to profile code - only compile most used |
---|
| 351 | |
---|
[8129] | 352 | |
---|
| 353 | |
---|
[7775] | 354 | |
---|
| 355 | |
---|