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