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