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