[4837] | 1 | """Module where global ANUGA model parameters and default values are set |
---|
[4376] | 2 | """ |
---|
| 3 | |
---|
[6105] | 4 | import os |
---|
| 5 | import sys |
---|
| 6 | |
---|
[7276] | 7 | |
---|
[6086] | 8 | ################################################################################ |
---|
[4837] | 9 | # Numerical constants |
---|
[6086] | 10 | ################################################################################ |
---|
| 11 | |
---|
| 12 | epsilon = 1.0e-12 # Smallest number - used for safe division |
---|
| 13 | max_float = 1.0e36 # Largest number - used to initialise |
---|
| 14 | # (max, min) ranges |
---|
| 15 | default_smoothing_parameter = 0.001 # Default alpha for penalised |
---|
| 16 | # least squares fitting |
---|
| 17 | single_precision = 1.0e-6 # Smallest single precision number |
---|
[7055] | 18 | velocity_protection = 1.0e-6 # Used to compute velocity from momentum |
---|
| 19 | # See section 7.4 on Flux limiting |
---|
| 20 | # in the user manual |
---|
| 21 | |
---|
[5436] | 22 | |
---|
[6086] | 23 | ################################################################################ |
---|
| 24 | # Standard filenames, directories and system parameters used by ANUGA |
---|
| 25 | ################################################################################ |
---|
| 26 | |
---|
[4837] | 27 | pmesh_filename = '.\\pmesh' |
---|
| 28 | version_filename = 'stored_version_info.py' |
---|
| 29 | default_datadir = '.' |
---|
[7055] | 30 | time_format = '%d/%m/%y %H:%M:%S' # Used with timefile2netcdf |
---|
| 31 | umask = 002 # Controls file and directory permission created by anuga (UNIX) |
---|
[4837] | 32 | default_boundary_tag = 'exterior' |
---|
[4376] | 33 | |
---|
[4837] | 34 | # Major revision number for use with create_distribution |
---|
| 35 | # and update_anuga_user_guide |
---|
[8731] | 36 | major_revision = '1.3.0-beta' |
---|
[4376] | 37 | |
---|
[6086] | 38 | ################################################################################ |
---|
| 39 | # Physical constants |
---|
| 40 | ################################################################################ |
---|
[4376] | 41 | |
---|
[4837] | 42 | manning = 0.03 # Manning's friction coefficient |
---|
| 43 | #g = 9.80665 # Gravity - FIXME reinstate this and fix unit tests. |
---|
[4376] | 44 | g = 9.8 |
---|
[7865] | 45 | #g(phi) = 9780313 * (1 + 0.0053024 sin(phi)**2 - 0.000 0059 sin(2*phi)**2) |
---|
| 46 | # micro m/s**2, where phi is the latitude |
---|
[4376] | 47 | #The 'official' average is 9.80665 |
---|
| 48 | |
---|
[6086] | 49 | eta_w = 3.0e-3 # Wind stress coefficient |
---|
| 50 | rho_a = 1.2e-3 # Atmospheric density |
---|
| 51 | rho_w = 1023 # Fluid density [kg/m^3] (rho_w = 1023 for salt water) |
---|
[4376] | 52 | |
---|
[6086] | 53 | ################################################################################ |
---|
[4837] | 54 | # Limiters - used with linear reconstruction of vertex |
---|
| 55 | # values from centroid values |
---|
[6086] | 56 | ################################################################################ |
---|
[8404] | 57 | # Note the individual beta values are set in domain.set_flow_method which also sets |
---|
| 58 | # the timestepping method |
---|
[4837] | 59 | |
---|
[8404] | 60 | beta_w = 1.0 |
---|
[4768] | 61 | |
---|
[4376] | 62 | # Alpha_balance controls how limiters are balanced between deep and shallow. |
---|
[6086] | 63 | # A large value will favour the deep water limiters, allowing the a closer hug |
---|
| 64 | # to the coastline. This will minimise 'creep' but at the same time cause |
---|
| 65 | # smaller time steps |
---|
[4376] | 66 | # Range: |
---|
| 67 | alpha_balance = 2.0 |
---|
| 68 | |
---|
| 69 | # Flag use of new limiters. |
---|
[4631] | 70 | # tight_slope_limiters = 0 means use old limiters (e.g. for some tests) |
---|
| 71 | # tight_slope_limiters = 1 means use new limiters that hug the bathymetry closer |
---|
[5181] | 72 | tight_slope_limiters = True |
---|
[4376] | 73 | |
---|
[8353] | 74 | use_edge_limiter = False # The edge limiter is better, but most runs have been |
---|
| 75 | # using vertex limiting. Validations passed with this |
---|
| 76 | # one True 9th May 2008, but many unit tests need |
---|
| 77 | # backward compatibility flag set FIXME(Ole). |
---|
| 78 | |
---|
[5315] | 79 | # Use centroid velocities to reconstruct momentum at vertices in |
---|
| 80 | # very shallow water |
---|
[5313] | 81 | # This option has a first order flavour to it, but we still have second order |
---|
[5315] | 82 | # reconstruction of stage and this option only applies in |
---|
| 83 | # balance_deep_and_shallow when |
---|
[5313] | 84 | # alpha < 1 so in deeper water the full second order scheme is used. |
---|
[5290] | 85 | # |
---|
[5303] | 86 | # This option is good with tight_slope_limiters, especially for large domains. |
---|
[5313] | 87 | use_centroid_velocities = True |
---|
[5957] | 88 | |
---|
| 89 | # FIXME (Ole) Maybe get rid of order altogether and use beta_w |
---|
[6258] | 90 | default_order = 2 |
---|
[4376] | 91 | |
---|
[8308] | 92 | # Option to use velocity extrapolation instead of momentum extrapolation in the |
---|
| 93 | # routine domain.extrapolate_second_order_sw |
---|
[8402] | 94 | extrapolate_velocity_second_order=True |
---|
[8308] | 95 | |
---|
[8377] | 96 | # Option to setup compute_fluxes_method |
---|
[8538] | 97 | # Currently "original' and 'wb_1' to 'wb_3' and 'tsunami' |
---|
[8402] | 98 | compute_fluxes_method = 'wb_2' |
---|
[8377] | 99 | |
---|
[8538] | 100 | # Option to setup distribute_to_vertices_and_edges_method |
---|
| 101 | # Currently "original' and 'tsunami' |
---|
| 102 | distribute_to_vertices_and_edges_method = 'original' |
---|
| 103 | |
---|
[6086] | 104 | ################################################################################ |
---|
[8390] | 105 | # Friction Method |
---|
| 106 | ################################################################################ |
---|
| 107 | |
---|
[8406] | 108 | sloped_mannings_function = False |
---|
[8390] | 109 | |
---|
| 110 | ################################################################################ |
---|
[4837] | 111 | # Timestepping |
---|
[6086] | 112 | ################################################################################ |
---|
[4376] | 113 | |
---|
[4837] | 114 | CFL = 1.0 # CFL condition assigned to domain.CFL - controls timestep size |
---|
| 115 | |
---|
[8404] | 116 | # Choose type of timestepping and spatial reconstruction method |
---|
[4712] | 117 | |
---|
[8404] | 118 | timestepping_method = 1 |
---|
| 119 | |
---|
| 120 | # For shallow water we have a method that sets both timestepping and spatial reconstruction and |
---|
| 121 | # beta values. In this case the settings for timestepping_method will be overriden |
---|
| 122 | |
---|
[8418] | 123 | #flow_algorithm = '1_0' # 1st order euler and conservative piecewise constant spatial reconstruction |
---|
| 124 | flow_algorithm = '1_5' # 1st order euler and conservative piecewise linear spatial reconstruction |
---|
| 125 | #flow_algorithm = '1_75' # 1st order euler and more aggressive piecewise linear spatial reconstruction |
---|
| 126 | #flow_algorithm = '2_0' # 2nd order TVD scheme and more aggressive piecewise linear spatial reconstruction |
---|
| 127 | #flow_algorithm = '2.5' # 3rd order TVD scheme and more aggressive piecewise linear spatial reconstruction |
---|
[8404] | 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
[5162] | 132 | # rk2 is a little more stable than euler, so rk2 timestepping |
---|
| 133 | # can deal with a larger beta when slope limiting the reconstructed |
---|
| 134 | # solution. The large beta is needed if solving problems sensitive |
---|
| 135 | # to numerical diffusion, like a small forced wave in an ocean |
---|
| 136 | beta_euler = 1.0 |
---|
| 137 | beta_rk2 = 1.6 |
---|
| 138 | |
---|
[4677] | 139 | # Option to search for signatures where isolated triangles are |
---|
| 140 | # responsible for a small global timestep. |
---|
| 141 | # Treating these by limiting their momenta may help speed up the |
---|
| 142 | # overall computation. |
---|
| 143 | # This facility is experimental. |
---|
[4805] | 144 | # protect_against_isolated_degenerate_timesteps = False |
---|
[4677] | 145 | protect_against_isolated_degenerate_timesteps = False |
---|
[4376] | 146 | |
---|
[4837] | 147 | min_timestep = 1.0e-6 # Minimal timestep accepted in ANUGA |
---|
| 148 | max_timestep = 1.0e+3 |
---|
[6086] | 149 | max_smallsteps = 50 # Max number of degenerate steps allowed b4 |
---|
| 150 | # trying first order |
---|
[4376] | 151 | |
---|
[6086] | 152 | # Perhaps minimal timestep could be based on the geometry as follows: |
---|
| 153 | # Define maximal possible speed in open water v_max, e.g. 500m/s (soundspeed?) |
---|
| 154 | # Then work out minimal internal distance in mesh r_min and set |
---|
| 155 | # min_timestep = r_min/v_max |
---|
[4837] | 156 | # |
---|
[6086] | 157 | # Max speeds are calculated in the flux function as |
---|
[4837] | 158 | # |
---|
[6086] | 159 | # lambda = v +/- sqrt(gh) |
---|
[4837] | 160 | # |
---|
| 161 | # so with 500 m/s, h ~ 500^2/g = 2500 m well out of the domain of the |
---|
| 162 | # shallow water wave equation |
---|
| 163 | # |
---|
[6086] | 164 | # The actual soundspeed can be as high as 1530m/s |
---|
[7865] | 165 | # (see http://staff.washington.edu/aganse/public.projects/ |
---|
| 166 | # clustering/clustering.html), |
---|
[6086] | 167 | # but that would only happen with h>225000m in this equation. Why ? |
---|
| 168 | # The maximal speed we specify is really related to the max speed |
---|
| 169 | # of surface pertubation |
---|
[4837] | 170 | # |
---|
[6086] | 171 | # v_max = 100 #For use in domain_ext.c |
---|
| 172 | # sound_speed = 500 |
---|
[4376] | 173 | |
---|
[6086] | 174 | ################################################################################ |
---|
[4837] | 175 | # Ranges specific to the shallow water wave equation |
---|
[6086] | 176 | # These control maximal and minimal values of quantities |
---|
| 177 | ################################################################################ |
---|
[4376] | 178 | |
---|
[4837] | 179 | # Water depth below which it is considered to be 0 in the model |
---|
[8745] | 180 | minimum_allowed_height = 1.0e-03 |
---|
[4376] | 181 | |
---|
[4837] | 182 | # Water depth below which it is *stored* as 0 |
---|
[8353] | 183 | minimum_storable_height = 1.0e-05 |
---|
[4376] | 184 | |
---|
[4805] | 185 | # FIXME (Ole): Redefine this parameter to control maximal speeds in general |
---|
| 186 | # and associate it with protect_against_isolated_degenerate_timesteps = True |
---|
[4732] | 187 | maximum_allowed_speed = 0.0 # Maximal particle speed of water |
---|
| 188 | #maximum_allowed_speed = 1.0 # Maximal particle speed of water |
---|
[6086] | 189 | # Too large (100) creates 'flopping' water |
---|
| 190 | # Too small (0) creates 'creep' |
---|
[7276] | 191 | |
---|
[4837] | 192 | maximum_froude_number = 100.0 # To be used in limiters. |
---|
[4376] | 193 | |
---|
[6086] | 194 | ################################################################################ |
---|
[4837] | 195 | # Performance parameters used to invoke various optimisations |
---|
[6086] | 196 | ################################################################################ |
---|
[4815] | 197 | |
---|
[8404] | 198 | use_psyco = False # Use psyco optimisations |
---|
[4376] | 199 | |
---|
[4837] | 200 | optimise_dry_cells = True # Exclude dry and still cells from flux computation |
---|
| 201 | optimised_gradient_limiter = True # Use hardwired gradient limiter |
---|
| 202 | |
---|
[8808] | 203 | points_file_block_line_size = 5e7 # Number of lines read in from a points file |
---|
[4376] | 204 | # when blocking |
---|
[4502] | 205 | |
---|
[6086] | 206 | ################################################################################ |
---|
[7276] | 207 | # NetCDF-specific type constants. Used when defining NetCDF file variables. |
---|
| 208 | ################################################################################ |
---|
| 209 | |
---|
| 210 | netcdf_char = 'c' |
---|
| 211 | netcdf_byte = 'b' |
---|
| 212 | netcdf_int = 'i' |
---|
| 213 | netcdf_float = 'd' |
---|
| 214 | netcdf_float64 = 'd' |
---|
| 215 | netcdf_float32 = 'f' |
---|
| 216 | |
---|
| 217 | ################################################################################ |
---|
[6086] | 218 | # Dynamically-defined constants. |
---|
| 219 | ################################################################################ |
---|
[4685] | 220 | |
---|
[6086] | 221 | # Determine if we can read/write large NetCDF files |
---|
[8810] | 222 | netcdf_mode_w = 'wl' |
---|
| 223 | netcdf_mode_a = 'r+' |
---|
[6086] | 224 | netcdf_mode_r = 'r' |
---|
[4837] | 225 | |
---|
[6105] | 226 | # Code to set the write mode depending on |
---|
| 227 | # whether Scientific.IO supports large NetCDF files |
---|
[7276] | 228 | s = """ |
---|
[7454] | 229 | import os, tempfile |
---|
[8780] | 230 | from anuga.file.netcdf import NetCDFFile |
---|
[7454] | 231 | |
---|
| 232 | filename = tempfile.mktemp('.nc') |
---|
| 233 | |
---|
| 234 | fid = NetCDFFile(filename, 'wl') |
---|
[7276] | 235 | fid.close() |
---|
[7454] | 236 | os.remove(filename) |
---|
[7276] | 237 | """ |
---|
[4837] | 238 | |
---|
[8780] | 239 | """ |
---|
[6105] | 240 | # Need to run in a separate process due an |
---|
| 241 | # error with older versions of Scientific.IO |
---|
| 242 | if sys.platform == 'win32': |
---|
| 243 | null = 'NUL' |
---|
| 244 | else: |
---|
| 245 | null = '/dev/null' |
---|
[6106] | 246 | cmd = 'python -c "%s" 2> %s' % (s, null) |
---|
| 247 | err = os.system(cmd) |
---|
[6105] | 248 | |
---|
[6106] | 249 | if err != 0: |
---|
[6105] | 250 | # The Python script s failed e.g. with a segfault |
---|
| 251 | # which means that large file support is |
---|
| 252 | # definitely not supported |
---|
| 253 | pass |
---|
| 254 | else: |
---|
| 255 | # Try the import within this process |
---|
| 256 | try: |
---|
| 257 | exec(s) |
---|
| 258 | except IOError: |
---|
[6108] | 259 | # NetCDFFile does not segfault but it does not |
---|
| 260 | # support large file support |
---|
[6105] | 261 | pass |
---|
[6106] | 262 | else: |
---|
| 263 | # Set the default mode to large file support |
---|
[7277] | 264 | #netcdf_mode_w = 'w4' # Future use of HDF5 |
---|
| 265 | netcdf_mode_w = 'wl' # Large NetCDF (new default 30/6/2009) |
---|
| 266 | #netcdf_mode_w = 'w' # Old style NetCDF used by OSG viewer |
---|
| 267 | |
---|
[8780] | 268 | """ |
---|