Flumy [Free API]
Process based model for meandering chanelized systems
MCRCProgramming.hpp
1 #ifndef MCRC_PROGRAMMING_HH
2 #define MCRC_PROGRAMMING_HH
3 
4 #ifdef _WINDOWS
5 // Disable warning messages 4351
6 #pragma warning( disable : 4351 )
7 #endif
8 
9 // Export Macro
10 #include "flumy_export.hpp"
11 
12 #include <list>
13 #include <string>
14 #include <vector>
15 #include <map>
16 #include <new>
17 
18 #include <iomanip>
19 #include <algorithm>
20 #include <exception>
21 
22 #include <iostream>
23 #include <fstream>
24 #include <sstream>
25 #include <cstring>
26 #include <cmath>
27 
28 #include "MCRCDefines.h"
29 
30 // Type definitions
31 typedef double MP_real;
32 typedef int MP_int;
33 typedef unsigned int MP_uint;
34 typedef unsigned char MP_uchar;
35 typedef bool MP_bool;
36 typedef std::string MP_string;
37 typedef MP_int MP_tseed;
38 typedef MP_uint MP_age;
39 typedef MP_uchar MP_color;
40 typedef MP_uchar MP_stut;
41 typedef MP_uchar MP_agut;
42 
43 typedef std::vector<MP_stut> FaciesList;
44 typedef std::vector<MP_age> AgeList;
45 typedef std::vector<MP_real> RealList;
46 typedef std::vector<MP_int> IntList;
47 typedef std::vector<MP_string> StringList;
48 
49 // For facies storage
50 #define MP_FAMILY_MASK 0xf
51 #define MP_GRANULO_OFFSET 4
52 #define MP_STUT_SIZE 8
53 #define MP_AGUT_SIZE 8
54 
55 #define UNUSED(x) (void)(x)
56 
57 // Initial value for some parameters
58 #define MP_INIT_AGE 0
59 #define MP_INIT_SEED DEF_SIM_SEED
60 #define MP_INIT_FREQ FREQ_NEVER
61 #define MP_INIT_PERIOD_VAL 100
62 #define MP_INIT_POISSON_VAL 100
63 #define MP_INIT_DIST DIST_CONSTANT
64 #define MP_INIT_CONST 0.
65 #define MP_INIT_MIN 0.
66 #define MP_INIT_MAX 1.
67 #define MP_INIT_NORM_MEAN 0.
68 #define MP_INIT_NORM_STDEV 1.
69 #define MP_INIT_LOGNORM_MEAN 0.
70 #define MP_INIT_LOGNORM_STDEV 1.
71 
72 // Scour and secondary current factors
73 #define MP_CHANNEL_A_AFF 4.
74 #define MP_CHANNEL_A_SEC 3.
75 #define MP_CHANNEL_A (MP_CHANNEL_A_AFF + MP_CHANNEL_A_SEC)
76 
77 // Flow heights
78 #define MP_FLU_EFF_TO_MAX_HFLOW 1.5
79 #define MP_TUR_EFF_TO_MAX_HFLOW 3.
80 #define MP_FLU_HMAX_TO_MAX_HFLOW 1.
81 #define MP_TUR_HMAX_TO_MAX_HFLOW 3.
82 
83 // Universal constants
84 #define MP_PI 3.14159265
85 #define MP_2PI 2*MP_PI
86 #define MP_G 9.81
87 #define MP_YEAR_SECONDS 31557600
88 #define MP_PARAB_MEAN_TO_MAX_FACTOR 1.5
89 #define MP_PARAB_MAX_TO_MEAN_FACTOR 1/1.5
90 
91 // Flow and sediment constants
92 #define MP_DENSITY_SED 2.65
93 #define MP_R (MP_DENSITY_SED - 1)
94 #define MP_VISCO 0.000001
95 #define MP_K 0.4
96 #define MP_FRICTION_COEFF_SKIN 0.005
97 #define MP_FRICTION_COEFF_SKIN_SQRT sqrt(MP_FRICTION_COEFF_SKIN)
98 #define MP_Z0 0.01
99 #define MP_KSI (0.077 / MP_FRICTION_COEFF_SKIN_SQRT)
100 #define MP_TURBI_SCALE_FACTOR 14.
101 #define MP_LOC_SLOPE_ALPHA 3.
103 
104 // Turbidite velocity profile constants
105 // MP_VEL_TURB_POW currently not well calibrated. May be related to mud proportion : the muddier the higher (Stacey et al 88)
106 #define MP_VEL_TURB_POW 0.8
107 #define MP_POWER_FACTOR pow(2, MP_VEL_TURB_POW)
108 #define MP_INTEGRAL (MP_POWER_FACTOR / sqrt(MP_PI) * tgamma(alpha + 0.5) / tgamma(alpha + 1))
109 
110 // Miscellaneous Fluvial constants
111 #define MP_FLU_D2W_FACTOR 15.
112 #define MP_FLU_W2WL_FACTOR 12.5
113 #define MP_FLU_W2LOB_FACTOR 30.
114 #define MP_FLU_SINUO 2.71
115 #define MP_FLU_SINUO_ALLEN 1.5
116 #define MP_FLU_KOB 0.6
117 #define MP_FLU_KMIG /*DON'T*/ 0.65
118 #define MP_FLU_KMIG_OLD 0.75
119 #define MP_FLU_KVP 0.87
120 #define MP_FLU_TAU_CUT 2.53e-9
121 
122 // Miscellaneous Turbidites constants
123 #define MP_TUR_D2W_FACTOR 30.
124 #define MP_TUR_W2WL_FACTOR 5.0
125 #define MP_TUR_W2LOB_FACTOR 10.
126 #define MP_TUR_SINUO 2.05
127 #define MP_TUR_SINUO_ALLEN 1.5
128 #define MP_TUR_KOB 1.25
129 #define MP_TUR_KMIG /*DON'T*/ 0.4
130 #define MP_TUR_KMIG_OLD 0.95
131 #define MP_TUR_KVP 0.75
132 #define MP_TUR_TAU_CUT 4.85e-9
133 
134 // Computing constants
135 #define MP_MIN_SLOPE_WARN 0.0005
136 #define MP_MAX_SLOPE_WARN 0.016
137 #define MP_PEAT_COMPRESS_FACTOR 0.1
138 #define MP_DEFAULT_MIG_WELL_FACTOR 15
139 #define MP_UNDEFINED_ZUL MP_UNKNOWN_INT_VALUE
140 #define MP_DEFAULT_ZUL_TOL 0
141 #define MP_THICKNESS_RATIO 0.01
142 #define MP_INACTIVE_EP 100000.
143 #define MP_MAX_CS_CHANNEL 13
144 #define MP_MAX_MEANDER_DEFAULT_VALUES 4
145 #define MP_MAX_NB_NODES 25000000
146 #define MP_MAX_NB_NODES_WARN 1000000
147 #define MP_ERR_MAX_WELLS 100
148 #define MP_WARN_MAX_WELLS 55
149 #define MP_MAX_GRID_SIZE 5000
150 #define MP_ZOOM_TIFF 1
151 #define MP_REFRESH_LOOP 100
152 #define MP_DEFAULT_CELLS_ORDER "+Y +X +Z"
153 #define MP_DEFAULT_GSLIB_CELLS_ORDER "+X +Y +Z"
154 #define MP_DEFAULT_NA_VALUE "NA"
155 
156 // Constant definitions for Random Number (RN) generation
157 #define MP_RN_DEFAULT_SEED MP_INIT_SEED
158 #define MP_RN_DEFAULT_MODULUS 2147483647
159 #define MP_RN_DEFAULT_MULTIPLIER 16807
160 #define MP_RN_DEFAULT_QUOTIENT 127773
161 #define MP_RN_DEFAULT_REST 2836
162 #define MP_RN_SHUFFLING_TABLE_SIZE 32
163 
164 // System parameters
165 #define MP_EPSILON 0.000001
166 #define MP_UNKNOWN_STRING_VALUE "??"
167 #define MP_UNKNOWN_REAL_VALUE 1.e30
168 #define MP_MAX_REAL_VALUE 1.e30
169 #define MP_MIN_REAL_VALUE -1.e30
170 #define MP_UNKNOWN_INT_VALUE 2147483647
171 #define MP_MAX_INT_VALUE 2147483647
172 #define MP_MIN_INT_VALUE -2147483647
173 
174 
176 class FLUMY_EXPORT InferenceStats {
177 public:
178  MP_age age;
179  MP_real pb_prop;
180  MP_real sand_prop;
181  MP_real agg_rate;
182  MP_real mig_rate;
183  MP_real mean_vp;
184  MP_real infer_kob;
185  MP_real infer_kmig;
186  MP_real infer_kvp;
187  MP_real sinuo;
188  MP_real tortuo;
189  MP_real sinuo_allen;
190  MP_real sbext;
191  MP_real wl;
192  InferenceStats() : age(0),
193  pb_prop(0.),
194  sand_prop(0.),
195  agg_rate(0.),
196  mig_rate(0.),
197  mean_vp(0.),
198  infer_kob(0.),
199  infer_kmig(0.),
200  infer_kvp(0.),
201  sinuo(0.),
202  tortuo(0.),
203  sinuo_allen(0.),
204  sbext(0.),
205  wl(0.) {}
206 } ;
207 
209 class FLUMY_EXPORT TauCutStats {
210 public:
211  MP_age age;
212  MP_real tau_cut;
213  MP_real sinuo;
214  MP_real sinuo_allen;
215  MP_real tortuo;
216  MP_real wavelength;
217  MP_real mean_sbext;
218  TauCutStats() : age(0),
219  tau_cut(0.),
220  sinuo(0.),
221  sinuo_allen(0.),
222  tortuo(0.),
223  wavelength(0.),
224  mean_sbext(0.) {}
225 };
226 
227 // Usual Functions
228 #undef MIN
229 #define MIN(x,y) (( (x) > (y) ) ? (y) : (x))
230 #undef MAX
231 #define MAX(x,y) (( (x) < (y) ) ? (y) : (x))
232 #undef ABS
233 #define ABS(a) ((a) >= 0 ? (a) : -(a))
234 
235 // Portability
236 #ifdef _WINDOWS
237 #define round(x) ((MP_real)((x)>=0?(MP_int)((x)+0.5):(MP_int)((x)-0.5)))
238 #ifdef assert
239 #undef assert
240 #define assert(x) TRACE_ASSERT(x)
241 #endif
242 #endif
243 
244 // Iterator declaration (Y must inherits or be a typedef from std::vector<Z>)
245 #define DECLARE_ITERATOR(X,Y,Z) \
246  class FLUMY_EXPORT X { \
247  public : \
248  X() : _val() {} ; \
249  X( const X & ci ) : _val( ci._val ) {} ; \
250  X( const Y::const_iterator & ci ) : _val( ci ) {} ; \
251  X& operator=( const X & ci ) {if (*this != ci) _val = ci._val; return(*this);} \
252  bool operator<( const X & ci ) const {return(_val<ci._val);} \
253  bool operator>( const X & ci ) const {return(_val>ci._val);} \
254  bool operator<=( const X & ci ) const {return(_val<=ci._val);} \
255  bool operator>=( const X & ci ) const {return(_val>=ci._val);} \
256  bool operator==( const X & ci ) const {return(_val==ci._val);} \
257  bool operator!=( const X & ci ) const {return(_val!=ci._val);} \
258  X& operator++() {++_val;return(*this);} \
259  X& operator--() {--_val;return(*this);} \
260  const Z& operator*() const { return( *_val ); } \
261  const Z* operator->() const { return( &(*_val) ); } \
262  private : \
263  Y::const_iterator _val ; \
264  }; \
265 
266 // Reverse Iterator declaration (Y must inherits or be a typedef from std::vector<Z>)
267 #define DECLARE_REVERSE_ITERATOR(X,Y,Z) \
268  class FLUMY_EXPORT X { \
269  public : \
270  X() : _val() {} ; \
271  X( const X & ci ) : _val( ci._val ) {} ; \
272  X( const Y::const_reverse_iterator & ci ) : _val( ci ) {} ; \
273  X& operator=( const X & ci ) {if (*this != ci) _val = ci._val; return(*this);} \
274  bool operator<( const X & ci ) const {return(_val<ci._val);} \
275  bool operator>( const X & ci ) const {return(_val>ci._val);} \
276  bool operator<=( const X & ci ) const {return(_val<=ci._val);} \
277  bool operator>=( const X & ci ) const {return(_val>=ci._val);} \
278  bool operator==( const X & ci ) const {return(_val==ci._val);} \
279  bool operator!=( const X & ci ) const {return(_val!=ci._val);} \
280  X& operator++() {++_val;return(*this);} \
281  X& operator--() {--_val;return(*this);} \
282  const Z& operator*() const { return( *_val ); } \
283  const Z* operator->() const { return( &(*_val) ); } \
284  private : \
285  Y::const_reverse_iterator _val ; \
286  }; \
287 
288 #define SPACES " \t\r\n"
289 
290 inline MP_string trim_right (const MP_string & s,
291  const MP_string & t = SPACES)
292 {
293  MP_string d (s);
294  MP_string::size_type i (d.find_last_not_of (t));
295  if (i == MP_string::npos)
296  return "";
297  else
298  return d.erase (d.find_last_not_of (t) + 1) ;
299 }
300 
301 inline MP_string trim_left (const MP_string & s,
302  const MP_string & t = SPACES)
303 {
304  MP_string d (s);
305  return d.erase (0, s.find_first_not_of (t)) ;
306 }
307 
308 inline MP_string trim_all (const MP_string & s,
309  const MP_string & t = SPACES)
310 {
311  MP_string d (s);
312  return trim_left (trim_right (d, t), t) ;
313 }
314 
315 #endif // MCRC_PROGRAMMING_HH
316 
Definition: MCRCProgramming.hpp:176
MP_real infer_kmig
Kmig infered value (no unit)
Definition: MCRCProgramming.hpp:185
MP_real sand_prop
Sand proportion (Net-to-Gross) (i.e. PB+CL proportion) ([0,1])
Definition: MCRCProgramming.hpp:180
InferenceStats()
Definition: MCRCProgramming.hpp:192
MP_real sinuo_allen
Channel Allen (1984) sinuosity (no unit)
Definition: MCRCProgramming.hpp:189
MP_real agg_rate
Aggradation rate (m / it)
Definition: MCRCProgramming.hpp:181
MP_real wl
Mean wavelength (m)
Definition: MCRCProgramming.hpp:191
MP_age age
Age of statistics (it)
Definition: MCRCProgramming.hpp:178
MP_real infer_kob
Kob infered value (no unit)
Definition: MCRCProgramming.hpp:184
MP_real infer_kvp
Kvp infered value (no unit)
Definition: MCRCProgramming.hpp:186
MP_real mig_rate
Migration rate (m / it)
Definition: MCRCProgramming.hpp:182
MP_real sbext
Mean sand bodies extension (m)
Definition: MCRCProgramming.hpp:190
MP_real pb_prop
Pointbar / LAPs facies proportion ([0,1])
Definition: MCRCProgramming.hpp:179
MP_real tortuo
Channel tortuosity (no unit)
Definition: MCRCProgramming.hpp:188
MP_real mean_vp
Mean velocity perturbation (m/s)
Definition: MCRCProgramming.hpp:183
MP_real sinuo
Channel sinuosity (no unit)
Definition: MCRCProgramming.hpp:187
Definition: MCRCProgramming.hpp:209
MP_real sinuo_allen
Allen (1984) sinuosity before first cutoff (no unit)
Definition: MCRCProgramming.hpp:214
MP_age age
Age of first cutoff (it)
Definition: MCRCProgramming.hpp:211
TauCutStats()
Definition: MCRCProgramming.hpp:218
MP_real wavelength
Wavelength before first cutoff (m)
Definition: MCRCProgramming.hpp:216
MP_real mean_sbext
Mean sand body extension before first cutoff (m)
Definition: MCRCProgramming.hpp:217
MP_real tortuo
Tortuosity before first cutoff (no unit)
Definition: MCRCProgramming.hpp:215
MP_real sinuo
Sinuosity before first cutoff (no unit)
Definition: MCRCProgramming.hpp:213
MP_real tau_cut
Abstract time of first cutoff (no unit)
Definition: MCRCProgramming.hpp:212