[7276] | 1 | """ |
---|
| 2 | Finite-volume computations of the shallow water wave equation. |
---|
[4004] | 3 | |
---|
[4005] | 4 | Title: ANGUA shallow_water_domain - 2D triangular domains for finite-volume |
---|
| 5 | computations of the shallow water wave equation. |
---|
[3804] | 6 | |
---|
| 7 | |
---|
[5186] | 8 | Author: Ole Nielsen, Ole.Nielsen@ga.gov.au |
---|
| 9 | Stephen Roberts, Stephen.Roberts@anu.edu.au |
---|
| 10 | Duncan Gray, Duncan.Gray@ga.gov.au |
---|
[4004] | 11 | |
---|
| 12 | CreationDate: 2004 |
---|
| 13 | |
---|
| 14 | Description: |
---|
[4005] | 15 | This module contains a specialisation of class Domain from |
---|
| 16 | module domain.py consisting of methods specific to the |
---|
| 17 | Shallow Water Wave Equation |
---|
[4004] | 18 | |
---|
[4005] | 19 | U_t + E_x + G_y = S |
---|
[3804] | 20 | |
---|
[4005] | 21 | where |
---|
[3804] | 22 | |
---|
[4005] | 23 | U = [w, uh, vh] |
---|
| 24 | E = [uh, u^2h + gh^2/2, uvh] |
---|
| 25 | G = [vh, uvh, v^2h + gh^2/2] |
---|
| 26 | S represents source terms forcing the system |
---|
| 27 | (e.g. gravity, friction, wind stress, ...) |
---|
[3804] | 28 | |
---|
[4005] | 29 | and _t, _x, _y denote the derivative with respect to t, x and y |
---|
| 30 | respectively. |
---|
[3804] | 31 | |
---|
| 32 | |
---|
[4005] | 33 | The quantities are |
---|
[3804] | 34 | |
---|
[4005] | 35 | symbol variable name explanation |
---|
| 36 | x x horizontal distance from origin [m] |
---|
| 37 | y y vertical distance from origin [m] |
---|
| 38 | z elevation elevation of bed on which flow is modelled [m] |
---|
| 39 | h height water height above z [m] |
---|
| 40 | w stage absolute water level, w = z+h [m] |
---|
| 41 | u speed in the x direction [m/s] |
---|
| 42 | v speed in the y direction [m/s] |
---|
| 43 | uh xmomentum momentum in the x direction [m^2/s] |
---|
| 44 | vh ymomentum momentum in the y direction [m^2/s] |
---|
[3804] | 45 | |
---|
[4005] | 46 | eta mannings friction coefficient [to appear] |
---|
| 47 | nu wind stress coefficient [to appear] |
---|
[3804] | 48 | |
---|
[4005] | 49 | The conserved quantities are w, uh, vh |
---|
[3804] | 50 | |
---|
[4004] | 51 | Reference: |
---|
[4005] | 52 | Catastrophic Collapse of Water Supply Reservoirs in Urban Areas, |
---|
| 53 | Christopher Zoppou and Stephen Roberts, |
---|
| 54 | Journal of Hydraulic Engineering, vol. 127, No. 7 July 1999 |
---|
[3804] | 55 | |
---|
[7276] | 56 | Hydrodynamic modelling of coastal inundation. |
---|
[4005] | 57 | Nielsen, O., S. Roberts, D. Gray, A. McPherson and A. Hitchman |
---|
| 58 | In Zerger, A. and Argent, R.M. (eds) MODSIM 2005 International Congress on |
---|
| 59 | Modelling and Simulation. Modelling and Simulation Society of Australia and |
---|
| 60 | New Zealand, December 2005, pp. 518-523. ISBN: 0-9758400-2-9. |
---|
| 61 | http://www.mssanz.org.au/modsim05/papers/nielsen.pdf |
---|
[3804] | 62 | |
---|
| 63 | |
---|
[4005] | 64 | SeeAlso: |
---|
| 65 | TRAC administration of ANUGA (User Manuals etc) at |
---|
| 66 | https://datamining.anu.edu.au/anuga and Subversion repository at |
---|
| 67 | $HeadURL: anuga_core/source/anuga/shallow_water/shallow_water_domain.py $ |
---|
[3804] | 68 | |
---|
[4004] | 69 | Constraints: See GPL license in the user guide |
---|
| 70 | Version: 1.0 ($Revision: 7733 $) |
---|
| 71 | ModifiedBy: |
---|
[4005] | 72 | $Author: hudson $ |
---|
| 73 | $Date: 2010-05-19 00:13:06 +0000 (Wed, 19 May 2010) $ |
---|
[3804] | 74 | """ |
---|
| 75 | |
---|
[4769] | 76 | # Subversion keywords: |
---|
[3804] | 77 | # |
---|
[4769] | 78 | # $LastChangedDate: 2010-05-19 00:13:06 +0000 (Wed, 19 May 2010) $ |
---|
| 79 | # $LastChangedRevision: 7733 $ |
---|
| 80 | # $LastChangedBy: hudson $ |
---|
[3804] | 81 | |
---|
| 82 | |
---|
[7276] | 83 | import numpy as num |
---|
| 84 | |
---|
[3804] | 85 | from anuga.abstract_2d_finite_volumes.domain import Domain as Generic_Domain |
---|
[6928] | 86 | |
---|
[7733] | 87 | from anuga.shallow_water.forcing import Cross_section |
---|
[6178] | 88 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[5294] | 89 | from anuga.utilities.numerical_tools import gradient, mean, ensure_numeric |
---|
[5730] | 90 | from anuga.geospatial_data.geospatial_data import ensure_geospatial |
---|
| 91 | |
---|
[6086] | 92 | from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a |
---|
[3804] | 93 | |
---|
[7276] | 94 | from anuga.fit_interpolate.interpolate import Modeltime_too_late, \ |
---|
| 95 | Modeltime_too_early |
---|
[5290] | 96 | |
---|
[7711] | 97 | from anuga.geometry.polygon import inside_polygon, polygon_area, \ |
---|
[7276] | 98 | is_inside_polygon |
---|
[7317] | 99 | import anuga.utilities.log as log |
---|
[5294] | 100 | |
---|
[7342] | 101 | import types |
---|
[5873] | 102 | from types import IntType, FloatType |
---|
[5874] | 103 | from warnings import warn |
---|
[5294] | 104 | |
---|
| 105 | |
---|
[7276] | 106 | ################################################################################ |
---|
[4769] | 107 | # Shallow water domain |
---|
[7276] | 108 | ################################################################################ |
---|
| 109 | |
---|
| 110 | ## |
---|
| 111 | # @brief Class for a shallow water domain. |
---|
[3804] | 112 | class Domain(Generic_Domain): |
---|
| 113 | |
---|
[7342] | 114 | #conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] |
---|
| 115 | #other_quantities = ['elevation', 'friction'] |
---|
[7276] | 116 | |
---|
| 117 | ## |
---|
| 118 | # @brief Instantiate a shallow water domain. |
---|
| 119 | # @param coordinates |
---|
| 120 | # @param vertices |
---|
| 121 | # @param boundary |
---|
| 122 | # @param tagged_elements |
---|
| 123 | # @param geo_reference |
---|
| 124 | # @param use_inscribed_circle |
---|
| 125 | # @param mesh_filename |
---|
| 126 | # @param use_cache |
---|
| 127 | # @param verbose |
---|
[7519] | 128 | # @param evolved_quantities |
---|
[7276] | 129 | # @param full_send_dict |
---|
| 130 | # @param ghost_recv_dict |
---|
| 131 | # @param processor |
---|
| 132 | # @param numproc |
---|
| 133 | # @param number_of_full_nodes |
---|
| 134 | # @param number_of_full_triangles |
---|
[3804] | 135 | def __init__(self, |
---|
| 136 | coordinates=None, |
---|
| 137 | vertices=None, |
---|
| 138 | boundary=None, |
---|
| 139 | tagged_elements=None, |
---|
| 140 | geo_reference=None, |
---|
| 141 | use_inscribed_circle=False, |
---|
| 142 | mesh_filename=None, |
---|
| 143 | use_cache=False, |
---|
| 144 | verbose=False, |
---|
[7573] | 145 | conserved_quantities = None, |
---|
[7519] | 146 | evolved_quantities = None, |
---|
| 147 | other_quantities = None, |
---|
[3804] | 148 | full_send_dict=None, |
---|
| 149 | ghost_recv_dict=None, |
---|
| 150 | processor=0, |
---|
[3926] | 151 | numproc=1, |
---|
[3928] | 152 | number_of_full_nodes=None, |
---|
| 153 | number_of_full_triangles=None): |
---|
[3804] | 154 | |
---|
[7573] | 155 | # Define quantities for the shallow_water domain |
---|
| 156 | if conserved_quantities == None: |
---|
| 157 | conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] |
---|
[7519] | 158 | |
---|
[7573] | 159 | if evolved_quantities == None: |
---|
| 160 | evolved_quantities = ['stage', 'xmomentum', 'ymomentum'] |
---|
| 161 | |
---|
[7519] | 162 | if other_quantities == None: |
---|
| 163 | other_quantities = ['elevation', 'friction'] |
---|
[7342] | 164 | |
---|
[3804] | 165 | Generic_Domain.__init__(self, |
---|
| 166 | coordinates, |
---|
| 167 | vertices, |
---|
| 168 | boundary, |
---|
[7342] | 169 | conserved_quantities, |
---|
[7573] | 170 | evolved_quantities, |
---|
[7342] | 171 | other_quantities, |
---|
[3804] | 172 | tagged_elements, |
---|
| 173 | geo_reference, |
---|
| 174 | use_inscribed_circle, |
---|
| 175 | mesh_filename, |
---|
| 176 | use_cache, |
---|
| 177 | verbose, |
---|
| 178 | full_send_dict, |
---|
| 179 | ghost_recv_dict, |
---|
| 180 | processor, |
---|
[3926] | 181 | numproc, |
---|
| 182 | number_of_full_nodes=number_of_full_nodes, |
---|
[7276] | 183 | number_of_full_triangles=number_of_full_triangles) |
---|
[3804] | 184 | |
---|
[7562] | 185 | self.set_defaults() |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | self.forcing_terms.append(manning_friction_implicit) |
---|
| 189 | self.forcing_terms.append(gravity) |
---|
| 190 | |
---|
| 191 | # Stored output |
---|
| 192 | self.store = True |
---|
| 193 | self.set_store_vertices_uniquely(False) |
---|
| 194 | |
---|
| 195 | self.quantities_to_be_stored = {'elevation': 1, |
---|
| 196 | 'stage': 2, |
---|
| 197 | 'xmomentum': 2, |
---|
| 198 | 'ymomentum': 2} |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | ## |
---|
| 204 | # @brief Set default values, usually read in from a config file |
---|
| 205 | # @param flag |
---|
| 206 | def set_defaults(self): |
---|
| 207 | """Set the default values in this routine. That way we can inherit class |
---|
| 208 | and just over redefine the defaults for the new class |
---|
| 209 | """ |
---|
| 210 | |
---|
| 211 | from anuga.config import minimum_storable_height |
---|
| 212 | from anuga.config import minimum_allowed_height, maximum_allowed_speed |
---|
| 213 | from anuga.config import g, epsilon, beta_w, beta_w_dry,\ |
---|
| 214 | beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, tight_slope_limiters |
---|
| 215 | from anuga.config import alpha_balance |
---|
| 216 | from anuga.config import optimise_dry_cells |
---|
| 217 | from anuga.config import optimised_gradient_limiter |
---|
| 218 | from anuga.config import use_edge_limiter |
---|
| 219 | from anuga.config import use_centroid_velocities |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | |
---|
[7276] | 223 | self.set_minimum_allowed_height(minimum_allowed_height) |
---|
[7562] | 224 | self.maximum_allowed_speed = maximum_allowed_speed |
---|
[4769] | 225 | |
---|
[3804] | 226 | self.g = g |
---|
[7276] | 227 | self.beta_w = beta_w |
---|
| 228 | self.beta_w_dry = beta_w_dry |
---|
| 229 | self.beta_uh = beta_uh |
---|
[3804] | 230 | self.beta_uh_dry = beta_uh_dry |
---|
[7276] | 231 | self.beta_vh = beta_vh |
---|
[3804] | 232 | self.beta_vh_dry = beta_vh_dry |
---|
[3876] | 233 | self.alpha_balance = alpha_balance |
---|
[3804] | 234 | |
---|
[4631] | 235 | self.tight_slope_limiters = tight_slope_limiters |
---|
[4685] | 236 | self.optimise_dry_cells = optimise_dry_cells |
---|
[4239] | 237 | |
---|
[7562] | 238 | |
---|
| 239 | self.set_new_mannings_function(False) |
---|
[3804] | 240 | |
---|
| 241 | self.minimum_storable_height = minimum_storable_height |
---|
[5162] | 242 | |
---|
[7562] | 243 | # Limiters |
---|
[5175] | 244 | self.use_edge_limiter = use_edge_limiter |
---|
[5162] | 245 | self.optimised_gradient_limiter = optimised_gradient_limiter |
---|
[7562] | 246 | self.use_centroid_velocities = use_centroid_velocities |
---|
[3804] | 247 | |
---|
[7276] | 248 | ## |
---|
| 249 | # @brief |
---|
[7519] | 250 | # @param flag |
---|
| 251 | def set_new_mannings_function(self, flag=True): |
---|
| 252 | """Cludge to allow unit test to pass, but to |
---|
| 253 | also introduce new mannings friction function |
---|
| 254 | which takes into account the slope of the bed. |
---|
| 255 | The flag is tested in the python wrapper |
---|
| 256 | mannings_friction_implicit |
---|
| 257 | """ |
---|
| 258 | if flag: |
---|
| 259 | self.use_new_mannings = True |
---|
| 260 | else: |
---|
| 261 | self.use_new_mannings = False |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | ## |
---|
| 265 | # @brief |
---|
| 266 | # @param flag |
---|
| 267 | def set_use_edge_limiter(self, flag=True): |
---|
| 268 | """Cludge to allow unit test to pass, but to |
---|
| 269 | also introduce new edge limiting. The flag is |
---|
| 270 | tested in distribute_to_vertices_and_edges |
---|
| 271 | """ |
---|
| 272 | if flag: |
---|
| 273 | self.use_edge_limiter = True |
---|
| 274 | else: |
---|
| 275 | self.use_edge_limiter = False |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | ## |
---|
| 280 | # @brief |
---|
[7276] | 281 | # @param beta |
---|
[3848] | 282 | def set_all_limiters(self, beta): |
---|
[7276] | 283 | """Shorthand to assign one constant value [0,1] to all limiters. |
---|
[3847] | 284 | 0 Corresponds to first order, where as larger values make use of |
---|
[7276] | 285 | the second order scheme. |
---|
[3847] | 286 | """ |
---|
[3804] | 287 | |
---|
[7276] | 288 | self.beta_w = beta |
---|
| 289 | self.beta_w_dry = beta |
---|
[5162] | 290 | self.quantities['stage'].beta = beta |
---|
[7276] | 291 | |
---|
| 292 | self.beta_uh = beta |
---|
[3847] | 293 | self.beta_uh_dry = beta |
---|
[5162] | 294 | self.quantities['xmomentum'].beta = beta |
---|
[7276] | 295 | |
---|
| 296 | self.beta_vh = beta |
---|
[3847] | 297 | self.beta_vh_dry = beta |
---|
[5162] | 298 | self.quantities['ymomentum'].beta = beta |
---|
[3847] | 299 | |
---|
[7276] | 300 | ## |
---|
| 301 | # @brief |
---|
| 302 | # @param flag |
---|
| 303 | # @param reduction |
---|
[3804] | 304 | def set_store_vertices_uniquely(self, flag, reduction=None): |
---|
| 305 | """Decide whether vertex values should be stored uniquely as |
---|
[7312] | 306 | computed in the model (True) or whether they should be reduced to one |
---|
| 307 | value per vertex using self.reduction (False). |
---|
[3804] | 308 | """ |
---|
[3954] | 309 | |
---|
[7312] | 310 | # FIXME (Ole): how about using the word "continuous vertex values" or |
---|
| 311 | # "continuous stage surface" |
---|
[3804] | 312 | self.smooth = not flag |
---|
| 313 | |
---|
[4733] | 314 | # Reduction operation for get_vertex_values |
---|
[3804] | 315 | if reduction is None: |
---|
| 316 | self.reduction = mean |
---|
| 317 | #self.reduction = min #Looks better near steep slopes |
---|
| 318 | |
---|
[7276] | 319 | ## |
---|
| 320 | # @brief Set the minimum depth that will be written to an SWW file. |
---|
| 321 | # @param minimum_storable_height The minimum stored height (in m). |
---|
[3804] | 322 | def set_minimum_storable_height(self, minimum_storable_height): |
---|
[7276] | 323 | """Set the minimum depth that will be recognised when writing |
---|
[3804] | 324 | to an sww file. This is useful for removing thin water layers |
---|
| 325 | that seems to be caused by friction creep. |
---|
| 326 | |
---|
| 327 | The minimum allowed sww depth is in meters. |
---|
| 328 | """ |
---|
[7276] | 329 | |
---|
[3804] | 330 | self.minimum_storable_height = minimum_storable_height |
---|
[4258] | 331 | |
---|
[7276] | 332 | ## |
---|
| 333 | # @brief |
---|
| 334 | # @param minimum_allowed_height |
---|
[4258] | 335 | def set_minimum_allowed_height(self, minimum_allowed_height): |
---|
[7276] | 336 | """Set minimum depth that will be recognised in the numerical scheme. |
---|
[4258] | 337 | |
---|
| 338 | The minimum allowed depth is in meters. |
---|
| 339 | |
---|
| 340 | The parameter H0 (Minimal height for flux computation) |
---|
| 341 | is also set by this function |
---|
| 342 | """ |
---|
[4438] | 343 | |
---|
| 344 | #FIXME (Ole): rename H0 to minimum_allowed_height_in_flux_computation |
---|
[4701] | 345 | |
---|
| 346 | #FIXME (Ole): Maybe use histogram to identify isolated extreme speeds |
---|
| 347 | #and deal with them adaptively similarly to how we used to use 1 order |
---|
| 348 | #steps to recover. |
---|
[7276] | 349 | |
---|
[4258] | 350 | self.minimum_allowed_height = minimum_allowed_height |
---|
[7276] | 351 | self.H0 = minimum_allowed_height |
---|
[3804] | 352 | |
---|
[7276] | 353 | ## |
---|
| 354 | # @brief |
---|
| 355 | # @param maximum_allowed_speed |
---|
[3804] | 356 | def set_maximum_allowed_speed(self, maximum_allowed_speed): |
---|
[7276] | 357 | """Set the maximum particle speed that is allowed in water |
---|
[3804] | 358 | shallower than minimum_allowed_height. This is useful for |
---|
| 359 | controlling speeds in very thin layers of water and at the same time |
---|
| 360 | allow some movement avoiding pooling of water. |
---|
[7276] | 361 | """ |
---|
[3804] | 362 | |
---|
| 363 | self.maximum_allowed_speed = maximum_allowed_speed |
---|
| 364 | |
---|
[7276] | 365 | ## |
---|
| 366 | # @brief |
---|
| 367 | # @param points_file_block_line_size |
---|
| 368 | def set_points_file_block_line_size(self, points_file_block_line_size): |
---|
| 369 | """Set the minimum depth that will be recognised when writing |
---|
[4254] | 370 | to an sww file. This is useful for removing thin water layers |
---|
| 371 | that seems to be caused by friction creep. |
---|
| 372 | |
---|
| 373 | The minimum allowed sww depth is in meters. |
---|
| 374 | """ |
---|
| 375 | self.points_file_block_line_size = points_file_block_line_size |
---|
[7276] | 376 | |
---|
[7342] | 377 | |
---|
| 378 | # FIXME: Probably obsolete in its curren form |
---|
[7276] | 379 | ## |
---|
| 380 | # @brief Set the quantities that will be written to an SWW file. |
---|
| 381 | # @param q The quantities to be written. |
---|
| 382 | # @note Param 'q' may be None, single quantity or list of quantity strings. |
---|
| 383 | # @note If 'q' is None, no quantities will be stored in the SWW file. |
---|
[3804] | 384 | def set_quantities_to_be_stored(self, q): |
---|
[7342] | 385 | """Specify which quantities will be stored in the sww file |
---|
| 386 | |
---|
[3804] | 387 | q must be either: |
---|
[7342] | 388 | - a dictionary with quantity names |
---|
| 389 | - a list of quantity names (for backwards compatibility) |
---|
[3804] | 390 | - None |
---|
| 391 | |
---|
[7342] | 392 | The format of the dictionary is as follows |
---|
| 393 | |
---|
| 394 | quantity_name: flag where flag must be either 1 or 2. |
---|
| 395 | If flag is 1, the quantity is considered static and will be |
---|
| 396 | stored once at the beginning of the simulation in a 1D array. |
---|
| 397 | |
---|
| 398 | If flag is 2, the quantity is considered time dependent and |
---|
| 399 | it will be stored at each yieldstep by appending it to the |
---|
| 400 | appropriate 2D array in the sww file. |
---|
| 401 | |
---|
[3804] | 402 | If q is None, storage will be switched off altogether. |
---|
[7342] | 403 | |
---|
| 404 | Once the simulation has started and thw sww file opened, |
---|
| 405 | this function will have no effect. |
---|
| 406 | |
---|
| 407 | The format, where q is a list of names is for backwards compatibility only. |
---|
| 408 | It will take the specified quantities to be time dependent and assume |
---|
| 409 | 'elevation' to be static regardless. |
---|
[3804] | 410 | """ |
---|
| 411 | |
---|
| 412 | if q is None: |
---|
[7342] | 413 | self.quantities_to_be_stored = {} |
---|
[3804] | 414 | self.store = False |
---|
| 415 | return |
---|
| 416 | |
---|
[4701] | 417 | # Check correcness |
---|
[3804] | 418 | for quantity_name in q: |
---|
[7276] | 419 | msg = ('Quantity %s is not a valid conserved quantity' |
---|
| 420 | % quantity_name) |
---|
[7342] | 421 | assert quantity_name in self.quantities, msg |
---|
[3804] | 422 | |
---|
[7342] | 423 | if type(q) == types.ListType: |
---|
| 424 | |
---|
| 425 | msg = 'List arguments to set_quantities_to_be_stored ' |
---|
| 426 | msg += 'has been deprecated and will be removed in future ' |
---|
| 427 | msg += 'versions of ANUGA.' |
---|
| 428 | msg += 'Please use dictionary argument instead' |
---|
| 429 | warn(msg, DeprecationWarning) |
---|
| 430 | |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | # FIXME: Raise deprecation warning |
---|
| 434 | tmp = {} |
---|
| 435 | for x in q: |
---|
| 436 | tmp[x] = 2 |
---|
| 437 | tmp['elevation'] = 1 |
---|
| 438 | q = tmp |
---|
| 439 | |
---|
| 440 | assert type(q) == types.DictType |
---|
[3804] | 441 | self.quantities_to_be_stored = q |
---|
| 442 | |
---|
[7276] | 443 | ## |
---|
| 444 | # @brief |
---|
| 445 | # @param indices |
---|
[3804] | 446 | def get_wet_elements(self, indices=None): |
---|
| 447 | """Return indices for elements where h > minimum_allowed_height |
---|
| 448 | |
---|
| 449 | Optional argument: |
---|
| 450 | indices is the set of element ids that the operation applies to. |
---|
| 451 | |
---|
| 452 | Usage: |
---|
| 453 | indices = get_wet_elements() |
---|
| 454 | |
---|
[7276] | 455 | Note, centroid values are used for this operation |
---|
[3804] | 456 | """ |
---|
| 457 | |
---|
| 458 | # Water depth below which it is considered to be 0 in the model |
---|
| 459 | # FIXME (Ole): Allow this to be specified as a keyword argument as well |
---|
| 460 | from anuga.config import minimum_allowed_height |
---|
| 461 | |
---|
| 462 | elevation = self.get_quantity('elevation').\ |
---|
[7276] | 463 | get_values(location='centroids', indices=indices) |
---|
| 464 | stage = self.get_quantity('stage').\ |
---|
[3804] | 465 | get_values(location='centroids', indices=indices) |
---|
| 466 | depth = stage - elevation |
---|
| 467 | |
---|
| 468 | # Select indices for which depth > 0 |
---|
[6157] | 469 | wet_indices = num.compress(depth > minimum_allowed_height, |
---|
| 470 | num.arange(len(depth))) |
---|
[7276] | 471 | return wet_indices |
---|
[3804] | 472 | |
---|
[7276] | 473 | ## |
---|
| 474 | # @brief |
---|
| 475 | # @param indices |
---|
[3804] | 476 | def get_maximum_inundation_elevation(self, indices=None): |
---|
| 477 | """Return highest elevation where h > 0 |
---|
| 478 | |
---|
| 479 | Optional argument: |
---|
| 480 | indices is the set of element ids that the operation applies to. |
---|
| 481 | |
---|
| 482 | Usage: |
---|
| 483 | q = get_maximum_inundation_elevation() |
---|
| 484 | |
---|
[7276] | 485 | Note, centroid values are used for this operation |
---|
[3804] | 486 | """ |
---|
| 487 | |
---|
| 488 | wet_elements = self.get_wet_elements(indices) |
---|
| 489 | return self.get_quantity('elevation').\ |
---|
[7276] | 490 | get_maximum_value(indices=wet_elements) |
---|
[3804] | 491 | |
---|
[7276] | 492 | ## |
---|
| 493 | # @brief |
---|
| 494 | # @param indices |
---|
[3804] | 495 | def get_maximum_inundation_location(self, indices=None): |
---|
[4554] | 496 | """Return location of highest elevation where h > 0 |
---|
[3804] | 497 | |
---|
| 498 | Optional argument: |
---|
| 499 | indices is the set of element ids that the operation applies to. |
---|
| 500 | |
---|
| 501 | Usage: |
---|
[4554] | 502 | q = get_maximum_inundation_location() |
---|
[3804] | 503 | |
---|
[7276] | 504 | Note, centroid values are used for this operation |
---|
[3804] | 505 | """ |
---|
| 506 | |
---|
| 507 | wet_elements = self.get_wet_elements(indices) |
---|
| 508 | return self.get_quantity('elevation').\ |
---|
[7276] | 509 | get_maximum_location(indices=wet_elements) |
---|
| 510 | |
---|
[7350] | 511 | |
---|
| 512 | |
---|
[7276] | 513 | ## |
---|
| 514 | # @brief Get the total flow through an arbitrary poly line. |
---|
| 515 | # @param polyline Representation of desired cross section. |
---|
| 516 | # @param verbose True if this method is to be verbose. |
---|
| 517 | # @note 'polyline' may contain multiple sections allowing complex shapes. |
---|
| 518 | # @note Assume absolute UTM coordinates. |
---|
| 519 | def get_flow_through_cross_section(self, polyline, verbose=False): |
---|
| 520 | """Get the total flow through an arbitrary poly line. |
---|
| 521 | |
---|
| 522 | This is a run-time equivalent of the function with same name |
---|
[5736] | 523 | in data_manager.py |
---|
[7276] | 524 | |
---|
[5729] | 525 | Input: |
---|
[7276] | 526 | polyline: Representation of desired cross section - it may contain |
---|
| 527 | multiple sections allowing for complex shapes. Assume |
---|
[5729] | 528 | absolute UTM coordinates. |
---|
[7276] | 529 | Format [[x0, y0], [x1, y1], ...] |
---|
| 530 | |
---|
| 531 | Output: |
---|
[5729] | 532 | Q: Total flow [m^3/s] across given segments. |
---|
[7276] | 533 | """ |
---|
| 534 | |
---|
[7350] | 535 | |
---|
| 536 | cross_section = Cross_section(self, polyline, verbose) |
---|
| 537 | |
---|
| 538 | return cross_section.get_flow_through_cross_section() |
---|
| 539 | |
---|
| 540 | |
---|
| 541 | |
---|
| 542 | |
---|
| 543 | ## |
---|
[7276] | 544 | # @brief |
---|
| 545 | # @param polyline Representation of desired cross section. |
---|
| 546 | # @param kind Select energy type to compute ('specific' or 'total'). |
---|
| 547 | # @param verbose True if this method is to be verbose. |
---|
| 548 | # @note 'polyline' may contain multiple sections allowing complex shapes. |
---|
| 549 | # @note Assume absolute UTM coordinates. |
---|
[7452] | 550 | def get_energy_through_cross_section(self, polyline, |
---|
[7352] | 551 | kind='total', |
---|
| 552 | verbose=False): |
---|
| 553 | """Obtain average energy head [m] across specified cross section. |
---|
| 554 | |
---|
| 555 | Inputs: |
---|
| 556 | polyline: Representation of desired cross section - it may contain |
---|
| 557 | multiple sections allowing for complex shapes. Assume |
---|
| 558 | absolute UTM coordinates. |
---|
| 559 | Format [[x0, y0], [x1, y1], ...] |
---|
| 560 | kind: Select which energy to compute. |
---|
| 561 | Options are 'specific' and 'total' (default) |
---|
| 562 | |
---|
| 563 | Output: |
---|
| 564 | E: Average energy [m] across given segments for all stored times. |
---|
| 565 | |
---|
| 566 | The average velocity is computed for each triangle intersected by |
---|
| 567 | the polyline and averaged weighted by segment lengths. |
---|
| 568 | |
---|
| 569 | The typical usage of this function would be to get average energy of |
---|
| 570 | flow in a channel, and the polyline would then be a cross section |
---|
| 571 | perpendicular to the flow. |
---|
| 572 | |
---|
| 573 | #FIXME (Ole) - need name for this energy reflecting that its dimension |
---|
| 574 | is [m]. |
---|
| 575 | """ |
---|
| 576 | |
---|
| 577 | |
---|
| 578 | |
---|
| 579 | cross_section = Cross_section(self, polyline, verbose) |
---|
| 580 | |
---|
[7452] | 581 | return cross_section.get_energy_through_cross_section(kind) |
---|
[7352] | 582 | |
---|
| 583 | |
---|
| 584 | ## |
---|
[7276] | 585 | # @brief Run integrity checks on shallow water domain. |
---|
[3804] | 586 | def check_integrity(self): |
---|
| 587 | Generic_Domain.check_integrity(self) |
---|
| 588 | |
---|
| 589 | #Check that we are solving the shallow water wave equation |
---|
| 590 | msg = 'First conserved quantity must be "stage"' |
---|
| 591 | assert self.conserved_quantities[0] == 'stage', msg |
---|
| 592 | msg = 'Second conserved quantity must be "xmomentum"' |
---|
| 593 | assert self.conserved_quantities[1] == 'xmomentum', msg |
---|
| 594 | msg = 'Third conserved quantity must be "ymomentum"' |
---|
| 595 | assert self.conserved_quantities[2] == 'ymomentum', msg |
---|
| 596 | |
---|
[7276] | 597 | ## |
---|
| 598 | # @brief |
---|
[3804] | 599 | def extrapolate_second_order_sw(self): |
---|
[7276] | 600 | #Call correct module function (either from this module or C-extension) |
---|
[3804] | 601 | extrapolate_second_order_sw(self) |
---|
| 602 | |
---|
[7276] | 603 | ## |
---|
| 604 | # @brief |
---|
[3804] | 605 | def compute_fluxes(self): |
---|
[7276] | 606 | #Call correct module function (either from this module or C-extension) |
---|
[3804] | 607 | compute_fluxes(self) |
---|
| 608 | |
---|
[7276] | 609 | ## |
---|
| 610 | # @brief |
---|
[3804] | 611 | def distribute_to_vertices_and_edges(self): |
---|
[4769] | 612 | # Call correct module function |
---|
[5176] | 613 | if self.use_edge_limiter: |
---|
[7276] | 614 | distribute_using_edge_limiter(self) |
---|
[5175] | 615 | else: |
---|
[5306] | 616 | distribute_using_vertex_limiter(self) |
---|
[3804] | 617 | |
---|
[7352] | 618 | |
---|
| 619 | |
---|
[7276] | 620 | ## |
---|
| 621 | # @brief Evolve the model by one step. |
---|
| 622 | # @param yieldstep |
---|
| 623 | # @param finaltime |
---|
| 624 | # @param duration |
---|
| 625 | # @param skip_initial_step |
---|
[3804] | 626 | def evolve(self, |
---|
[7276] | 627 | yieldstep=None, |
---|
| 628 | finaltime=None, |
---|
| 629 | duration=None, |
---|
| 630 | skip_initial_step=False): |
---|
| 631 | """Specialisation of basic evolve method from parent class""" |
---|
[3804] | 632 | |
---|
[4769] | 633 | # Call check integrity here rather than from user scripts |
---|
| 634 | # self.check_integrity() |
---|
[3804] | 635 | |
---|
[7276] | 636 | msg = 'Attribute self.beta_w must be in the interval [0, 2]' |
---|
[5162] | 637 | assert 0 <= self.beta_w <= 2.0, msg |
---|
[3804] | 638 | |
---|
[4769] | 639 | # Initial update of vertex and edge values before any STORAGE |
---|
[7276] | 640 | # and or visualisation. |
---|
[4769] | 641 | # This is done again in the initialisation of the Generic_Domain |
---|
[7276] | 642 | # evolve loop but we do it here to ensure the values are ok for storage. |
---|
[3804] | 643 | self.distribute_to_vertices_and_edges() |
---|
| 644 | |
---|
| 645 | if self.store is True and self.time == 0.0: |
---|
| 646 | self.initialise_storage() |
---|
| 647 | |
---|
[4769] | 648 | # Call basic machinery from parent class |
---|
[7276] | 649 | for t in Generic_Domain.evolve(self, yieldstep=yieldstep, |
---|
| 650 | finaltime=finaltime, duration=duration, |
---|
[3804] | 651 | skip_initial_step=skip_initial_step): |
---|
[4769] | 652 | # Store model data, e.g. for subsequent visualisation |
---|
[3804] | 653 | if self.store is True: |
---|
[7340] | 654 | self.store_timestep() |
---|
[3804] | 655 | |
---|
[4769] | 656 | # Pass control on to outer loop for more specific actions |
---|
[3804] | 657 | yield(t) |
---|
| 658 | |
---|
[7276] | 659 | ## |
---|
| 660 | # @brief |
---|
[3804] | 661 | def initialise_storage(self): |
---|
| 662 | """Create and initialise self.writer object for storing data. |
---|
| 663 | Also, save x,y and bed elevation |
---|
| 664 | """ |
---|
| 665 | |
---|
[7340] | 666 | from anuga.shallow_water.data_manager import SWW_file |
---|
[7342] | 667 | |
---|
[4769] | 668 | # Initialise writer |
---|
[7340] | 669 | self.writer = SWW_file(self) |
---|
[3804] | 670 | |
---|
[4769] | 671 | # Store vertices and connectivity |
---|
[3804] | 672 | self.writer.store_connectivity() |
---|
| 673 | |
---|
[7276] | 674 | ## |
---|
| 675 | # @brief |
---|
| 676 | # @param name |
---|
[7340] | 677 | def store_timestep(self): |
---|
| 678 | """Store time dependent quantities and time. |
---|
[3804] | 679 | |
---|
| 680 | Precondition: |
---|
[7340] | 681 | self.writer has been initialised |
---|
[3804] | 682 | """ |
---|
[7276] | 683 | |
---|
[7340] | 684 | self.writer.store_timestep() |
---|
[3804] | 685 | |
---|
[7276] | 686 | ## |
---|
| 687 | # @brief Get time stepping statistics string for printing. |
---|
| 688 | # @param track_speeds |
---|
| 689 | # @param triangle_id |
---|
[4836] | 690 | def timestepping_statistics(self, |
---|
| 691 | track_speeds=False, |
---|
[7276] | 692 | triangle_id=None): |
---|
[4827] | 693 | """Return string with time stepping statistics for printing or logging |
---|
[3804] | 694 | |
---|
[4827] | 695 | Optional boolean keyword track_speeds decides whether to report |
---|
| 696 | location of smallest timestep as well as a histogram and percentile |
---|
| 697 | report. |
---|
| 698 | """ |
---|
| 699 | |
---|
[7276] | 700 | from anuga.config import epsilon, g |
---|
[4827] | 701 | |
---|
| 702 | # Call basic machinery from parent class |
---|
[7276] | 703 | msg = Generic_Domain.timestepping_statistics(self, track_speeds, |
---|
[4836] | 704 | triangle_id) |
---|
[4827] | 705 | |
---|
| 706 | if track_speeds is True: |
---|
| 707 | # qwidth determines the text field used for quantities |
---|
| 708 | qwidth = self.qwidth |
---|
[7276] | 709 | |
---|
[4836] | 710 | # Selected triangle |
---|
[4827] | 711 | k = self.k |
---|
| 712 | |
---|
| 713 | # Report some derived quantities at vertices, edges and centroid |
---|
| 714 | # specific to the shallow water wave equation |
---|
| 715 | z = self.quantities['elevation'] |
---|
[7276] | 716 | w = self.quantities['stage'] |
---|
[4827] | 717 | |
---|
| 718 | Vw = w.get_values(location='vertices', indices=[k])[0] |
---|
| 719 | Ew = w.get_values(location='edges', indices=[k])[0] |
---|
| 720 | Cw = w.get_values(location='centroids', indices=[k]) |
---|
| 721 | |
---|
| 722 | Vz = z.get_values(location='vertices', indices=[k])[0] |
---|
| 723 | Ez = z.get_values(location='edges', indices=[k])[0] |
---|
[7276] | 724 | Cz = z.get_values(location='centroids', indices=[k]) |
---|
[4827] | 725 | |
---|
| 726 | name = 'depth' |
---|
| 727 | Vh = Vw-Vz |
---|
| 728 | Eh = Ew-Ez |
---|
| 729 | Ch = Cw-Cz |
---|
[7276] | 730 | |
---|
[4827] | 731 | s = ' %s: vertex_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 732 | %(name.ljust(qwidth), Vh[0], Vh[1], Vh[2]) |
---|
[7276] | 733 | |
---|
[4827] | 734 | s += ' %s: edge_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 735 | %(name.ljust(qwidth), Eh[0], Eh[1], Eh[2]) |
---|
[7276] | 736 | |
---|
[4827] | 737 | s += ' %s: centroid_value = %.4f\n'\ |
---|
[7276] | 738 | %(name.ljust(qwidth), Ch[0]) |
---|
| 739 | |
---|
[4827] | 740 | msg += s |
---|
| 741 | |
---|
| 742 | uh = self.quantities['xmomentum'] |
---|
| 743 | vh = self.quantities['ymomentum'] |
---|
| 744 | |
---|
| 745 | Vuh = uh.get_values(location='vertices', indices=[k])[0] |
---|
| 746 | Euh = uh.get_values(location='edges', indices=[k])[0] |
---|
| 747 | Cuh = uh.get_values(location='centroids', indices=[k]) |
---|
[7276] | 748 | |
---|
[4827] | 749 | Vvh = vh.get_values(location='vertices', indices=[k])[0] |
---|
| 750 | Evh = vh.get_values(location='edges', indices=[k])[0] |
---|
| 751 | Cvh = vh.get_values(location='centroids', indices=[k]) |
---|
| 752 | |
---|
| 753 | # Speeds in each direction |
---|
| 754 | Vu = Vuh/(Vh + epsilon) |
---|
| 755 | Eu = Euh/(Eh + epsilon) |
---|
[7276] | 756 | Cu = Cuh/(Ch + epsilon) |
---|
[4827] | 757 | name = 'U' |
---|
| 758 | s = ' %s: vertex_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 759 | %(name.ljust(qwidth), Vu[0], Vu[1], Vu[2]) |
---|
[7276] | 760 | |
---|
[4827] | 761 | s += ' %s: edge_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 762 | %(name.ljust(qwidth), Eu[0], Eu[1], Eu[2]) |
---|
[7276] | 763 | |
---|
[4827] | 764 | s += ' %s: centroid_value = %.4f\n'\ |
---|
[7276] | 765 | %(name.ljust(qwidth), Cu[0]) |
---|
| 766 | |
---|
[4827] | 767 | msg += s |
---|
| 768 | |
---|
| 769 | Vv = Vvh/(Vh + epsilon) |
---|
| 770 | Ev = Evh/(Eh + epsilon) |
---|
[7276] | 771 | Cv = Cvh/(Ch + epsilon) |
---|
[4827] | 772 | name = 'V' |
---|
| 773 | s = ' %s: vertex_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 774 | %(name.ljust(qwidth), Vv[0], Vv[1], Vv[2]) |
---|
[7276] | 775 | |
---|
[4827] | 776 | s += ' %s: edge_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 777 | %(name.ljust(qwidth), Ev[0], Ev[1], Ev[2]) |
---|
[7276] | 778 | |
---|
[4827] | 779 | s += ' %s: centroid_value = %.4f\n'\ |
---|
[7276] | 780 | %(name.ljust(qwidth), Cv[0]) |
---|
| 781 | |
---|
[4827] | 782 | msg += s |
---|
| 783 | |
---|
| 784 | # Froude number in each direction |
---|
| 785 | name = 'Froude (x)' |
---|
[6157] | 786 | Vfx = Vu/(num.sqrt(g*Vh) + epsilon) |
---|
| 787 | Efx = Eu/(num.sqrt(g*Eh) + epsilon) |
---|
| 788 | Cfx = Cu/(num.sqrt(g*Ch) + epsilon) |
---|
[7276] | 789 | |
---|
[4827] | 790 | s = ' %s: vertex_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 791 | %(name.ljust(qwidth), Vfx[0], Vfx[1], Vfx[2]) |
---|
[7276] | 792 | |
---|
[4827] | 793 | s += ' %s: edge_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 794 | %(name.ljust(qwidth), Efx[0], Efx[1], Efx[2]) |
---|
[7276] | 795 | |
---|
[4827] | 796 | s += ' %s: centroid_value = %.4f\n'\ |
---|
[7276] | 797 | %(name.ljust(qwidth), Cfx[0]) |
---|
| 798 | |
---|
[4827] | 799 | msg += s |
---|
| 800 | |
---|
| 801 | name = 'Froude (y)' |
---|
[6157] | 802 | Vfy = Vv/(num.sqrt(g*Vh) + epsilon) |
---|
| 803 | Efy = Ev/(num.sqrt(g*Eh) + epsilon) |
---|
| 804 | Cfy = Cv/(num.sqrt(g*Ch) + epsilon) |
---|
[7276] | 805 | |
---|
[4827] | 806 | s = ' %s: vertex_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 807 | %(name.ljust(qwidth), Vfy[0], Vfy[1], Vfy[2]) |
---|
[7276] | 808 | |
---|
[4827] | 809 | s += ' %s: edge_values = %.4f,\t %.4f,\t %.4f\n'\ |
---|
| 810 | %(name.ljust(qwidth), Efy[0], Efy[1], Efy[2]) |
---|
[7276] | 811 | |
---|
[4827] | 812 | s += ' %s: centroid_value = %.4f\n'\ |
---|
[7276] | 813 | %(name.ljust(qwidth), Cfy[0]) |
---|
[4827] | 814 | |
---|
[7276] | 815 | msg += s |
---|
[4827] | 816 | |
---|
| 817 | return msg |
---|
[7276] | 818 | |
---|
[4827] | 819 | |
---|
| 820 | |
---|
[6654] | 821 | def compute_boundary_flows(self): |
---|
| 822 | """Compute boundary flows at current timestep. |
---|
[6647] | 823 | |
---|
[6648] | 824 | Quantities computed are: |
---|
| 825 | Total inflow across boundary |
---|
| 826 | Total outflow across boundary |
---|
[6654] | 827 | Flow across each tagged boundary segment |
---|
[6648] | 828 | """ |
---|
[6647] | 829 | |
---|
[6648] | 830 | # Run through boundary array and compute for each segment |
---|
| 831 | # the normal momentum ((uh, vh) dot normal) times segment length. |
---|
[6653] | 832 | # Based on sign accumulate this into boundary_inflow and boundary_outflow. |
---|
[6647] | 833 | |
---|
[6653] | 834 | # Compute flows along boundary |
---|
| 835 | |
---|
[6654] | 836 | uh = self.get_quantity('xmomentum').get_values(location='edges') |
---|
| 837 | vh = self.get_quantity('ymomentum').get_values(location='edges') |
---|
[6653] | 838 | |
---|
| 839 | # Loop through edges that lie on the boundary and calculate |
---|
| 840 | # flows |
---|
[6654] | 841 | boundary_flows = {} |
---|
| 842 | total_boundary_inflow = 0.0 |
---|
| 843 | total_boundary_outflow = 0.0 |
---|
[6653] | 844 | for vol_id, edge_id in self.boundary: |
---|
[6654] | 845 | # Compute normal flow across edge. Since normal vector points |
---|
| 846 | # away from triangle, a positive sign means that water |
---|
| 847 | # flows *out* from this triangle. |
---|
| 848 | |
---|
| 849 | momentum = [uh[vol_id, edge_id], vh[vol_id, edge_id]] |
---|
| 850 | normal = self.mesh.get_normal(vol_id, edge_id) |
---|
| 851 | length = self.mesh.get_edgelength(vol_id, edge_id) |
---|
| 852 | normal_flow = num.dot(momentum, normal)*length |
---|
| 853 | |
---|
| 854 | # Reverse sign so that + is taken to mean inflow |
---|
| 855 | # and - means outflow. This is more intuitive. |
---|
| 856 | edge_flow = -normal_flow |
---|
| 857 | |
---|
| 858 | # Tally up inflows and outflows separately |
---|
| 859 | if edge_flow > 0: |
---|
| 860 | # Flow is inflow |
---|
| 861 | total_boundary_inflow += edge_flow |
---|
| 862 | else: |
---|
| 863 | # Flow is outflow |
---|
| 864 | total_boundary_outflow += edge_flow |
---|
[6653] | 865 | |
---|
[6654] | 866 | # Tally up flows by boundary tag |
---|
| 867 | tag = self.boundary[(vol_id, edge_id)] |
---|
| 868 | |
---|
| 869 | if tag not in boundary_flows: |
---|
| 870 | boundary_flows[tag] = 0.0 |
---|
| 871 | boundary_flows[tag] += edge_flow |
---|
| 872 | |
---|
| 873 | |
---|
| 874 | return boundary_flows, total_boundary_inflow, total_boundary_outflow |
---|
[6653] | 875 | |
---|
[6654] | 876 | |
---|
| 877 | def compute_forcing_flows(self): |
---|
| 878 | """Compute flows in and out of domain due to forcing terms. |
---|
| 879 | |
---|
| 880 | Quantities computed are: |
---|
| 881 | |
---|
[6653] | 882 | |
---|
[6654] | 883 | Total inflow through forcing terms |
---|
| 884 | Total outflow through forcing terms |
---|
| 885 | Current total volume in domain |
---|
| 886 | |
---|
| 887 | """ |
---|
| 888 | |
---|
| 889 | #FIXME(Ole): We need to separate what part of explicit_update was |
---|
| 890 | # due to the normal flux calculations and what is due to forcing terms. |
---|
| 891 | |
---|
| 892 | pass |
---|
| 893 | |
---|
| 894 | |
---|
| 895 | def compute_total_volume(self): |
---|
| 896 | """Compute total volume (m^3) of water in entire domain |
---|
| 897 | """ |
---|
| 898 | |
---|
| 899 | area = self.mesh.get_areas() |
---|
| 900 | volume = 0.0 |
---|
| 901 | |
---|
| 902 | stage = self.get_quantity('stage').get_values(location='centroids') |
---|
| 903 | elevation = self.get_quantity('elevation').get_values(location='centroids') |
---|
| 904 | depth = stage-elevation |
---|
| 905 | |
---|
| 906 | return num.sum(depth*area) |
---|
| 907 | |
---|
| 908 | |
---|
| 909 | def volumetric_balance_statistics(self): |
---|
| 910 | """Create volumetric balance report suitable for printing or logging. |
---|
| 911 | """ |
---|
| 912 | |
---|
[7276] | 913 | (boundary_flows, total_boundary_inflow, |
---|
| 914 | total_boundary_outflow) = self.compute_boundary_flows() |
---|
| 915 | |
---|
[6654] | 916 | s = '---------------------------\n' |
---|
| 917 | s += 'Volumetric balance report:\n' |
---|
| 918 | s += '--------------------------\n' |
---|
[7276] | 919 | s += 'Total boundary inflow [m^3/s]: %.2f\n' % total_boundary_inflow |
---|
| 920 | s += 'Total boundary outflow [m^3/s]: %.2f\n' % total_boundary_outflow |
---|
[6654] | 921 | s += 'Net boundary flow by tags [m^3/s]\n' |
---|
| 922 | for tag in boundary_flows: |
---|
[7276] | 923 | s += ' %s [m^3/s]: %.2f\n' % (tag, boundary_flows[tag]) |
---|
[6654] | 924 | |
---|
[7276] | 925 | s += 'Total net boundary flow [m^3/s]: %.2f\n' % (total_boundary_inflow + total_boundary_outflow) |
---|
| 926 | s += 'Total volume in domain [m^3]: %.2f\n' % self.compute_total_volume() |
---|
[6654] | 927 | |
---|
| 928 | # The go through explicit forcing update and record the rate of change for stage and |
---|
| 929 | # record into forcing_inflow and forcing_outflow. Finally compute integral |
---|
| 930 | # of depth to obtain total volume of domain. |
---|
| 931 | |
---|
| 932 | # FIXME(Ole): This part is not yet done. |
---|
| 933 | |
---|
| 934 | return s |
---|
| 935 | |
---|
[7276] | 936 | ################################################################################ |
---|
| 937 | # End of class Shallow Water Domain |
---|
| 938 | ################################################################################ |
---|
[3804] | 939 | |
---|
[4769] | 940 | #----------------- |
---|
[3804] | 941 | # Flux computation |
---|
[4769] | 942 | #----------------- |
---|
[3804] | 943 | |
---|
[7276] | 944 | ## @brief Compute fluxes and timestep suitable for all volumes in domain. |
---|
| 945 | # @param domain The domain to calculate fluxes for. |
---|
[3804] | 946 | def compute_fluxes(domain): |
---|
[7276] | 947 | """Compute fluxes and timestep suitable for all volumes in domain. |
---|
[3804] | 948 | |
---|
| 949 | Compute total flux for each conserved quantity using "flux_function" |
---|
| 950 | |
---|
| 951 | Fluxes across each edge are scaled by edgelengths and summed up |
---|
| 952 | Resulting flux is then scaled by area and stored in |
---|
| 953 | explicit_update for each of the three conserved quantities |
---|
| 954 | stage, xmomentum and ymomentum |
---|
| 955 | |
---|
| 956 | The maximal allowable speed computed by the flux_function for each volume |
---|
| 957 | is converted to a timestep that must not be exceeded. The minimum of |
---|
| 958 | those is computed as the next overall timestep. |
---|
| 959 | |
---|
| 960 | Post conditions: |
---|
| 961 | domain.explicit_update is reset to computed flux values |
---|
| 962 | domain.timestep is set to the largest step satisfying all volumes. |
---|
[4769] | 963 | |
---|
| 964 | This wrapper calls the underlying C version of compute fluxes |
---|
[3804] | 965 | """ |
---|
| 966 | |
---|
| 967 | import sys |
---|
[7276] | 968 | from shallow_water_ext import compute_fluxes_ext_central \ |
---|
| 969 | as compute_fluxes_ext |
---|
[3804] | 970 | |
---|
[7276] | 971 | N = len(domain) # number_of_triangles |
---|
[3804] | 972 | |
---|
[4769] | 973 | # Shortcuts |
---|
[3804] | 974 | Stage = domain.quantities['stage'] |
---|
| 975 | Xmom = domain.quantities['xmomentum'] |
---|
| 976 | Ymom = domain.quantities['ymomentum'] |
---|
| 977 | Bed = domain.quantities['elevation'] |
---|
| 978 | |
---|
| 979 | timestep = float(sys.maxint) |
---|
| 980 | |
---|
[4769] | 981 | flux_timestep = compute_fluxes_ext(timestep, |
---|
| 982 | domain.epsilon, |
---|
| 983 | domain.H0, |
---|
| 984 | domain.g, |
---|
| 985 | domain.neighbours, |
---|
| 986 | domain.neighbour_edges, |
---|
| 987 | domain.normals, |
---|
| 988 | domain.edgelengths, |
---|
| 989 | domain.radii, |
---|
| 990 | domain.areas, |
---|
| 991 | domain.tri_full_flag, |
---|
| 992 | Stage.edge_values, |
---|
| 993 | Xmom.edge_values, |
---|
| 994 | Ymom.edge_values, |
---|
| 995 | Bed.edge_values, |
---|
| 996 | Stage.boundary_values, |
---|
| 997 | Xmom.boundary_values, |
---|
| 998 | Ymom.boundary_values, |
---|
| 999 | Stage.explicit_update, |
---|
| 1000 | Xmom.explicit_update, |
---|
| 1001 | Ymom.explicit_update, |
---|
| 1002 | domain.already_computed_flux, |
---|
| 1003 | domain.max_speed, |
---|
| 1004 | int(domain.optimise_dry_cells)) |
---|
[3804] | 1005 | |
---|
[4769] | 1006 | domain.flux_timestep = flux_timestep |
---|
[3804] | 1007 | |
---|
[7276] | 1008 | ################################################################################ |
---|
[4769] | 1009 | # Module functions for gradient limiting |
---|
[7276] | 1010 | ################################################################################ |
---|
[3804] | 1011 | |
---|
[7276] | 1012 | ## |
---|
| 1013 | # @brief Wrapper for C version of extrapolate_second_order_sw. |
---|
| 1014 | # @param domain The domain to operate on. |
---|
| 1015 | # @note MH090605 The following method belongs to the shallow_water domain class |
---|
| 1016 | # see comments in the corresponding method in shallow_water_ext.c |
---|
| 1017 | def extrapolate_second_order_sw(domain): |
---|
| 1018 | """Wrapper calling C version of extrapolate_second_order_sw""" |
---|
[3804] | 1019 | |
---|
| 1020 | import sys |
---|
[7276] | 1021 | from shallow_water_ext import extrapolate_second_order_sw as extrapol2 |
---|
[3804] | 1022 | |
---|
[3928] | 1023 | N = len(domain) # number_of_triangles |
---|
[3804] | 1024 | |
---|
[4710] | 1025 | # Shortcuts |
---|
[3804] | 1026 | Stage = domain.quantities['stage'] |
---|
| 1027 | Xmom = domain.quantities['xmomentum'] |
---|
| 1028 | Ymom = domain.quantities['ymomentum'] |
---|
| 1029 | Elevation = domain.quantities['elevation'] |
---|
[4710] | 1030 | |
---|
[4769] | 1031 | extrapol2(domain, |
---|
| 1032 | domain.surrogate_neighbours, |
---|
| 1033 | domain.number_of_boundaries, |
---|
| 1034 | domain.centroid_coordinates, |
---|
| 1035 | Stage.centroid_values, |
---|
| 1036 | Xmom.centroid_values, |
---|
| 1037 | Ymom.centroid_values, |
---|
| 1038 | Elevation.centroid_values, |
---|
| 1039 | domain.vertex_coordinates, |
---|
| 1040 | Stage.vertex_values, |
---|
| 1041 | Xmom.vertex_values, |
---|
| 1042 | Ymom.vertex_values, |
---|
| 1043 | Elevation.vertex_values, |
---|
[5315] | 1044 | int(domain.optimise_dry_cells)) |
---|
[3804] | 1045 | |
---|
[7276] | 1046 | ## |
---|
| 1047 | # @brief Distribution from centroids to vertices specific to the SWW eqn. |
---|
| 1048 | # @param domain The domain to operate on. |
---|
[5306] | 1049 | def distribute_using_vertex_limiter(domain): |
---|
[7276] | 1050 | """Distribution from centroids to vertices specific to the SWW equation. |
---|
[3804] | 1051 | |
---|
| 1052 | It will ensure that h (w-z) is always non-negative even in the |
---|
| 1053 | presence of steep bed-slopes by taking a weighted average between shallow |
---|
| 1054 | and deep cases. |
---|
| 1055 | |
---|
| 1056 | In addition, all conserved quantities get distributed as per either a |
---|
| 1057 | constant (order==1) or a piecewise linear function (order==2). |
---|
| 1058 | |
---|
| 1059 | FIXME: more explanation about removal of artificial variability etc |
---|
| 1060 | |
---|
| 1061 | Precondition: |
---|
| 1062 | All quantities defined at centroids and bed elevation defined at |
---|
| 1063 | vertices. |
---|
| 1064 | |
---|
| 1065 | Postcondition |
---|
| 1066 | Conserved quantities defined at vertices |
---|
| 1067 | """ |
---|
| 1068 | |
---|
[4769] | 1069 | # Remove very thin layers of water |
---|
[3804] | 1070 | protect_against_infinitesimal_and_negative_heights(domain) |
---|
| 1071 | |
---|
[4769] | 1072 | # Extrapolate all conserved quantities |
---|
[5162] | 1073 | if domain.optimised_gradient_limiter: |
---|
[4769] | 1074 | # MH090605 if second order, |
---|
| 1075 | # perform the extrapolation and limiting on |
---|
| 1076 | # all of the conserved quantities |
---|
[3804] | 1077 | |
---|
| 1078 | if (domain._order_ == 1): |
---|
| 1079 | for name in domain.conserved_quantities: |
---|
| 1080 | Q = domain.quantities[name] |
---|
| 1081 | Q.extrapolate_first_order() |
---|
| 1082 | elif domain._order_ == 2: |
---|
| 1083 | domain.extrapolate_second_order_sw() |
---|
| 1084 | else: |
---|
| 1085 | raise 'Unknown order' |
---|
| 1086 | else: |
---|
[4769] | 1087 | # Old code: |
---|
[3804] | 1088 | for name in domain.conserved_quantities: |
---|
| 1089 | Q = domain.quantities[name] |
---|
[4701] | 1090 | |
---|
[3804] | 1091 | if domain._order_ == 1: |
---|
| 1092 | Q.extrapolate_first_order() |
---|
| 1093 | elif domain._order_ == 2: |
---|
[5306] | 1094 | Q.extrapolate_second_order_and_limit_by_vertex() |
---|
[3804] | 1095 | else: |
---|
| 1096 | raise 'Unknown order' |
---|
| 1097 | |
---|
[5290] | 1098 | # Take bed elevation into account when water heights are small |
---|
[3804] | 1099 | balance_deep_and_shallow(domain) |
---|
| 1100 | |
---|
[5290] | 1101 | # Compute edge values by interpolation |
---|
[3804] | 1102 | for name in domain.conserved_quantities: |
---|
| 1103 | Q = domain.quantities[name] |
---|
| 1104 | Q.interpolate_from_vertices_to_edges() |
---|
| 1105 | |
---|
[7276] | 1106 | ## |
---|
| 1107 | # @brief Distribution from centroids to edges specific to the SWW eqn. |
---|
| 1108 | # @param domain The domain to operate on. |
---|
[5306] | 1109 | def distribute_using_edge_limiter(domain): |
---|
[7276] | 1110 | """Distribution from centroids to edges specific to the SWW eqn. |
---|
[5306] | 1111 | |
---|
| 1112 | It will ensure that h (w-z) is always non-negative even in the |
---|
| 1113 | presence of steep bed-slopes by taking a weighted average between shallow |
---|
| 1114 | and deep cases. |
---|
| 1115 | |
---|
| 1116 | In addition, all conserved quantities get distributed as per either a |
---|
| 1117 | constant (order==1) or a piecewise linear function (order==2). |
---|
| 1118 | |
---|
| 1119 | |
---|
| 1120 | Precondition: |
---|
| 1121 | All quantities defined at centroids and bed elevation defined at |
---|
| 1122 | vertices. |
---|
| 1123 | |
---|
| 1124 | Postcondition |
---|
| 1125 | Conserved quantities defined at vertices |
---|
| 1126 | """ |
---|
| 1127 | |
---|
| 1128 | # Remove very thin layers of water |
---|
| 1129 | protect_against_infinitesimal_and_negative_heights(domain) |
---|
| 1130 | |
---|
| 1131 | for name in domain.conserved_quantities: |
---|
| 1132 | Q = domain.quantities[name] |
---|
| 1133 | if domain._order_ == 1: |
---|
| 1134 | Q.extrapolate_first_order() |
---|
| 1135 | elif domain._order_ == 2: |
---|
| 1136 | Q.extrapolate_second_order_and_limit_by_edge() |
---|
| 1137 | else: |
---|
| 1138 | raise 'Unknown order' |
---|
| 1139 | |
---|
| 1140 | balance_deep_and_shallow(domain) |
---|
| 1141 | |
---|
| 1142 | # Compute edge values by interpolation |
---|
| 1143 | for name in domain.conserved_quantities: |
---|
| 1144 | Q = domain.quantities[name] |
---|
| 1145 | Q.interpolate_from_vertices_to_edges() |
---|
| 1146 | |
---|
[7276] | 1147 | ## |
---|
| 1148 | # @brief Protect against infinitesimal heights and associated high velocities. |
---|
| 1149 | # @param domain The domain to operate on. |
---|
[3804] | 1150 | def protect_against_infinitesimal_and_negative_heights(domain): |
---|
[7276] | 1151 | """Protect against infinitesimal heights and associated high velocities""" |
---|
[3804] | 1152 | |
---|
[7276] | 1153 | from shallow_water_ext import protect |
---|
| 1154 | |
---|
[4769] | 1155 | # Shortcuts |
---|
[3804] | 1156 | wc = domain.quantities['stage'].centroid_values |
---|
| 1157 | zc = domain.quantities['elevation'].centroid_values |
---|
| 1158 | xmomc = domain.quantities['xmomentum'].centroid_values |
---|
| 1159 | ymomc = domain.quantities['ymomentum'].centroid_values |
---|
| 1160 | |
---|
| 1161 | protect(domain.minimum_allowed_height, domain.maximum_allowed_speed, |
---|
| 1162 | domain.epsilon, wc, zc, xmomc, ymomc) |
---|
| 1163 | |
---|
[7276] | 1164 | ## |
---|
| 1165 | # @brief Wrapper for C function balance_deep_and_shallow_c(). |
---|
| 1166 | # @param domain The domain to operate on. |
---|
[3804] | 1167 | def balance_deep_and_shallow(domain): |
---|
| 1168 | """Compute linear combination between stage as computed by |
---|
| 1169 | gradient-limiters limiting using w, and stage computed by |
---|
| 1170 | gradient-limiters limiting using h (h-limiter). |
---|
| 1171 | The former takes precedence when heights are large compared to the |
---|
| 1172 | bed slope while the latter takes precedence when heights are |
---|
| 1173 | relatively small. Anything in between is computed as a balanced |
---|
| 1174 | linear combination in order to avoid numerical disturbances which |
---|
| 1175 | would otherwise appear as a result of hard switching between |
---|
| 1176 | modes. |
---|
| 1177 | |
---|
[4769] | 1178 | Wrapper for C implementation |
---|
[3804] | 1179 | """ |
---|
| 1180 | |
---|
[7276] | 1181 | from shallow_water_ext import balance_deep_and_shallow \ |
---|
| 1182 | as balance_deep_and_shallow_c |
---|
[5175] | 1183 | |
---|
[4733] | 1184 | # Shortcuts |
---|
[3804] | 1185 | wc = domain.quantities['stage'].centroid_values |
---|
| 1186 | zc = domain.quantities['elevation'].centroid_values |
---|
| 1187 | wv = domain.quantities['stage'].vertex_values |
---|
| 1188 | zv = domain.quantities['elevation'].vertex_values |
---|
| 1189 | |
---|
[4733] | 1190 | # Momentums at centroids |
---|
[3804] | 1191 | xmomc = domain.quantities['xmomentum'].centroid_values |
---|
| 1192 | ymomc = domain.quantities['ymomentum'].centroid_values |
---|
| 1193 | |
---|
[4733] | 1194 | # Momentums at vertices |
---|
[3804] | 1195 | xmomv = domain.quantities['xmomentum'].vertex_values |
---|
| 1196 | ymomv = domain.quantities['ymomentum'].vertex_values |
---|
| 1197 | |
---|
[5442] | 1198 | balance_deep_and_shallow_c(domain, |
---|
[7276] | 1199 | wc, zc, wv, zv, wc, |
---|
[5442] | 1200 | xmomc, ymomc, xmomv, ymomv) |
---|
[3804] | 1201 | |
---|
| 1202 | |
---|
| 1203 | |
---|
[7276] | 1204 | ################################################################################ |
---|
[4769] | 1205 | # Standard forcing terms |
---|
[7276] | 1206 | ################################################################################ |
---|
[4769] | 1207 | |
---|
[7276] | 1208 | ## |
---|
| 1209 | # @brief Apply gravitational pull in the presence of bed slope. |
---|
| 1210 | # @param domain The domain to apply gravity to. |
---|
| 1211 | # @note Wrapper for C function gravity_c(). |
---|
[3804] | 1212 | def gravity(domain): |
---|
| 1213 | """Apply gravitational pull in the presence of bed slope |
---|
[4769] | 1214 | Wrapper calls underlying C implementation |
---|
[3804] | 1215 | """ |
---|
| 1216 | |
---|
[7276] | 1217 | from shallow_water_ext import gravity as gravity_c |
---|
| 1218 | |
---|
[7519] | 1219 | xmom_update = domain.quantities['xmomentum'].explicit_update |
---|
| 1220 | ymom_update = domain.quantities['ymomentum'].explicit_update |
---|
[3804] | 1221 | |
---|
[4687] | 1222 | stage = domain.quantities['stage'] |
---|
| 1223 | elevation = domain.quantities['elevation'] |
---|
[3804] | 1224 | |
---|
[4687] | 1225 | h = stage.centroid_values - elevation.centroid_values |
---|
| 1226 | z = elevation.vertex_values |
---|
| 1227 | |
---|
[3804] | 1228 | x = domain.get_vertex_coordinates() |
---|
| 1229 | g = domain.g |
---|
| 1230 | |
---|
[7519] | 1231 | gravity_c(g, h, z, x, xmom_update, ymom_update) #, 1.0e-6) |
---|
[3804] | 1232 | |
---|
[7276] | 1233 | ## |
---|
| 1234 | # @brief Apply friction to a surface (implicit). |
---|
| 1235 | # @param domain The domain to apply Manning friction to. |
---|
| 1236 | # @note Wrapper for C function manning_friction_c(). |
---|
[4769] | 1237 | def manning_friction_implicit(domain): |
---|
[7276] | 1238 | """Apply (Manning) friction to water momentum |
---|
[4769] | 1239 | Wrapper for c version |
---|
[3804] | 1240 | """ |
---|
| 1241 | |
---|
[7519] | 1242 | from shallow_water_ext import manning_friction_old |
---|
| 1243 | from shallow_water_ext import manning_friction_new |
---|
[3804] | 1244 | |
---|
| 1245 | xmom = domain.quantities['xmomentum'] |
---|
| 1246 | ymom = domain.quantities['ymomentum'] |
---|
| 1247 | |
---|
[7519] | 1248 | x = domain.get_vertex_coordinates() |
---|
| 1249 | |
---|
[3804] | 1250 | w = domain.quantities['stage'].centroid_values |
---|
[7519] | 1251 | z = domain.quantities['elevation'].vertex_values |
---|
[3804] | 1252 | |
---|
| 1253 | uh = xmom.centroid_values |
---|
| 1254 | vh = ymom.centroid_values |
---|
| 1255 | eta = domain.quantities['friction'].centroid_values |
---|
| 1256 | |
---|
| 1257 | xmom_update = xmom.semi_implicit_update |
---|
| 1258 | ymom_update = ymom.semi_implicit_update |
---|
| 1259 | |
---|
[3928] | 1260 | N = len(domain) |
---|
[3804] | 1261 | eps = domain.minimum_allowed_height |
---|
| 1262 | g = domain.g |
---|
| 1263 | |
---|
[7519] | 1264 | if domain.use_new_mannings: |
---|
| 1265 | manning_friction_new(g, eps, x, w, uh, vh, z, eta, xmom_update, ymom_update) |
---|
| 1266 | else: |
---|
| 1267 | manning_friction_old(g, eps, w, uh, vh, z, eta, xmom_update, ymom_update) |
---|
| 1268 | |
---|
[3804] | 1269 | |
---|
[7276] | 1270 | ## |
---|
| 1271 | # @brief Apply friction to a surface (explicit). |
---|
| 1272 | # @param domain The domain to apply Manning friction to. |
---|
| 1273 | # @note Wrapper for C function manning_friction_c(). |
---|
[4769] | 1274 | def manning_friction_explicit(domain): |
---|
[7276] | 1275 | """Apply (Manning) friction to water momentum |
---|
[4769] | 1276 | Wrapper for c version |
---|
[3804] | 1277 | """ |
---|
| 1278 | |
---|
[7519] | 1279 | from shallow_water_ext import manning_friction_old |
---|
| 1280 | from shallow_water_ext import manning_friction_new |
---|
[3804] | 1281 | |
---|
| 1282 | xmom = domain.quantities['xmomentum'] |
---|
| 1283 | ymom = domain.quantities['ymomentum'] |
---|
| 1284 | |
---|
[7519] | 1285 | x = domain.get_vertex_coordinates() |
---|
| 1286 | |
---|
[3804] | 1287 | w = domain.quantities['stage'].centroid_values |
---|
[7519] | 1288 | z = domain.quantities['elevation'].vertex_values |
---|
[3804] | 1289 | |
---|
| 1290 | uh = xmom.centroid_values |
---|
| 1291 | vh = ymom.centroid_values |
---|
| 1292 | eta = domain.quantities['friction'].centroid_values |
---|
| 1293 | |
---|
| 1294 | xmom_update = xmom.explicit_update |
---|
| 1295 | ymom_update = ymom.explicit_update |
---|
| 1296 | |
---|
[3928] | 1297 | N = len(domain) |
---|
[3804] | 1298 | eps = domain.minimum_allowed_height |
---|
| 1299 | g = domain.g |
---|
| 1300 | |
---|
| 1301 | |
---|
[7519] | 1302 | if domain.use_new_mannings: |
---|
| 1303 | manning_friction_new(g, eps, x, w, uh, vh, z, eta, xmom_update, ymom_update) |
---|
| 1304 | else: |
---|
| 1305 | manning_friction_old(g, eps, w, uh, vh, z, eta, xmom_update, ymom_update) |
---|
[3804] | 1306 | |
---|
[7519] | 1307 | |
---|
| 1308 | |
---|
[4769] | 1309 | # FIXME (Ole): This was implemented for use with one of the analytical solutions (Sampson?) |
---|
[7276] | 1310 | ## |
---|
| 1311 | # @brief Apply linear friction to a surface. |
---|
| 1312 | # @param domain The domain to apply Manning friction to. |
---|
| 1313 | # @note Is this still used (30 Oct 2007)? |
---|
[3804] | 1314 | def linear_friction(domain): |
---|
| 1315 | """Apply linear friction to water momentum |
---|
| 1316 | |
---|
| 1317 | Assumes quantity: 'linear_friction' to be present |
---|
| 1318 | """ |
---|
| 1319 | |
---|
| 1320 | from math import sqrt |
---|
| 1321 | |
---|
| 1322 | w = domain.quantities['stage'].centroid_values |
---|
| 1323 | z = domain.quantities['elevation'].centroid_values |
---|
| 1324 | h = w-z |
---|
| 1325 | |
---|
| 1326 | uh = domain.quantities['xmomentum'].centroid_values |
---|
| 1327 | vh = domain.quantities['ymomentum'].centroid_values |
---|
| 1328 | tau = domain.quantities['linear_friction'].centroid_values |
---|
| 1329 | |
---|
| 1330 | xmom_update = domain.quantities['xmomentum'].semi_implicit_update |
---|
| 1331 | ymom_update = domain.quantities['ymomentum'].semi_implicit_update |
---|
| 1332 | |
---|
[3928] | 1333 | N = len(domain) # number_of_triangles |
---|
[3804] | 1334 | eps = domain.minimum_allowed_height |
---|
| 1335 | g = domain.g #Not necessary? Why was this added? |
---|
| 1336 | |
---|
| 1337 | for k in range(N): |
---|
| 1338 | if tau[k] >= eps: |
---|
| 1339 | if h[k] >= eps: |
---|
| 1340 | S = -tau[k]/h[k] |
---|
| 1341 | |
---|
| 1342 | #Update momentum |
---|
| 1343 | xmom_update[k] += S*uh[k] |
---|
| 1344 | ymom_update[k] += S*vh[k] |
---|
| 1345 | |
---|
[6644] | 1346 | def depth_dependent_friction(domain, default_friction, |
---|
| 1347 | surface_roughness_data, |
---|
| 1348 | verbose=False): |
---|
| 1349 | """Returns an array of friction values for each wet element adjusted for depth. |
---|
| 1350 | |
---|
| 1351 | Inputs: |
---|
| 1352 | domain - computational domain object |
---|
| 1353 | default_friction - depth independent bottom friction |
---|
| 1354 | surface_roughness_data - N x 5 array of n0, d1, n1, d2, n2 values for each |
---|
| 1355 | friction region. |
---|
| 1356 | |
---|
| 1357 | Outputs: |
---|
| 1358 | wet_friction - Array that can be used directly to update friction as follows: |
---|
| 1359 | domain.set_quantity('friction', wet_friction) |
---|
| 1360 | |
---|
| 1361 | |
---|
| 1362 | |
---|
| 1363 | """ |
---|
| 1364 | |
---|
[7276] | 1365 | import numpy as num |
---|
[6644] | 1366 | |
---|
| 1367 | # Create a temp array to store updated depth dependent friction for wet elements |
---|
| 1368 | # EHR this is outwardly inneficient but not obvious how to avoid recreating each call?????? |
---|
| 1369 | N=len(domain) |
---|
[7276] | 1370 | wet_friction = num.zeros(N, num.float) |
---|
[6644] | 1371 | wet_friction[:] = default_n0 # Initially assign default_n0 to all array so sure have no zeros values |
---|
| 1372 | |
---|
| 1373 | |
---|
| 1374 | depth = domain.create_quantity_from_expression('stage - elevation') # create depth instance for this timestep |
---|
| 1375 | # Recompute depth as vector |
---|
| 1376 | d = depth.get_values(location='centroids') |
---|
| 1377 | |
---|
| 1378 | # rebuild the 'friction' values adjusted for depth at this instant |
---|
| 1379 | for i in domain.get_wet_elements(): # loop for each wet element in domain |
---|
| 1380 | |
---|
| 1381 | # Get roughness data for each element |
---|
| 1382 | n0 = float(surface_roughness_data[i,0]) |
---|
| 1383 | d1 = float(surface_roughness_data[i,1]) |
---|
| 1384 | n1 = float(surface_roughness_data[i,2]) |
---|
| 1385 | d2 = float(surface_roughness_data[i,3]) |
---|
| 1386 | n2 = float(surface_roughness_data[i,4]) |
---|
| 1387 | |
---|
| 1388 | |
---|
| 1389 | # Recompute friction values from depth for this element |
---|
| 1390 | |
---|
| 1391 | if d[i] <= d1: |
---|
| 1392 | depth_dependent_friction = n1 |
---|
| 1393 | elif d[i] >= d2: |
---|
| 1394 | depth_dependent_friction = n2 |
---|
| 1395 | else: |
---|
| 1396 | depth_dependent_friction = n1+((n2-n1)/(d2-d1))*(d[i]-d1) |
---|
| 1397 | |
---|
| 1398 | # check sanity of result |
---|
| 1399 | if (depth_dependent_friction < 0.010 or depth_dependent_friction > 9999.0) : |
---|
[7317] | 1400 | log.critical('%s >>>> WARNING: computed depth_dependent friction ' |
---|
| 1401 | 'out of range, ddf%f, n1=%f, n2=%f' |
---|
| 1402 | % (model_data.basename, |
---|
| 1403 | depth_dependent_friction, n1, n2)) |
---|
[6644] | 1404 | |
---|
| 1405 | # update depth dependent friction for that wet element |
---|
| 1406 | wet_friction[i] = depth_dependent_friction |
---|
| 1407 | |
---|
| 1408 | # EHR add code to show range of 'friction across domain at this instant as sanity check????????? |
---|
| 1409 | |
---|
| 1410 | if verbose : |
---|
| 1411 | nvals=domain.get_quantity('friction').get_values(location='centroids') # return array of domain nvals |
---|
| 1412 | n_min=min(nvals) |
---|
| 1413 | n_max=max(nvals) |
---|
| 1414 | |
---|
[7317] | 1415 | log.critical(' ++++ calculate_depth_dependent_friction - ' |
---|
| 1416 | 'Updated friction - range %7.3f to %7.3f' |
---|
| 1417 | % (n_min, n_max)) |
---|
[6644] | 1418 | |
---|
| 1419 | return wet_friction |
---|
| 1420 | |
---|
| 1421 | |
---|
| 1422 | |
---|
[7276] | 1423 | ################################################################################ |
---|
[4733] | 1424 | # Initialise module |
---|
[7276] | 1425 | ################################################################################ |
---|
[3804] | 1426 | |
---|
| 1427 | from anuga.utilities import compile |
---|
| 1428 | if compile.can_use_C_extension('shallow_water_ext.c'): |
---|
[7276] | 1429 | # Underlying C implementations can be accessed |
---|
[7731] | 1430 | from shallow_water_ext import assign_windfield_values |
---|
[4769] | 1431 | else: |
---|
[7276] | 1432 | msg = 'C implementations could not be accessed by %s.\n ' % __file__ |
---|
[4769] | 1433 | msg += 'Make sure compile_all.py has been run as described in ' |
---|
| 1434 | msg += 'the ANUGA installation guide.' |
---|
| 1435 | raise Exception, msg |
---|
[3804] | 1436 | |
---|
[4733] | 1437 | # Optimisation with psyco |
---|
[3804] | 1438 | from anuga.config import use_psyco |
---|
| 1439 | if use_psyco: |
---|
| 1440 | try: |
---|
| 1441 | import psyco |
---|
| 1442 | except: |
---|
| 1443 | import os |
---|
[5920] | 1444 | if os.name == 'posix' and os.uname()[4] in ['x86_64', 'ia64']: |
---|
[3804] | 1445 | pass |
---|
| 1446 | #Psyco isn't supported on 64 bit systems, but it doesn't matter |
---|
| 1447 | else: |
---|
[7276] | 1448 | msg = ('WARNING: psyco (speedup) could not be imported, ' |
---|
| 1449 | 'you may want to consider installing it') |
---|
[7317] | 1450 | log.critical(msg) |
---|
[3804] | 1451 | else: |
---|
| 1452 | psyco.bind(Domain.distribute_to_vertices_and_edges) |
---|
| 1453 | psyco.bind(Domain.compute_fluxes) |
---|
| 1454 | |
---|
[7276] | 1455 | |
---|
[3804] | 1456 | if __name__ == "__main__": |
---|
| 1457 | pass |
---|