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