-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLSDPorewaterColumn.cpp
More file actions
530 lines (431 loc) · 15.2 KB
/
Copy pathLSDPorewaterColumn.cpp
File metadata and controls
530 lines (431 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSDPorewaterColumn
// Land Surface Dynamics PorewterColumn object
//
// An object within the University
// of Edinburgh Land Surface Dynamics group topographic tools
// This object calculates porewater pressure based on the Iverson 2000 WRR
// model
//
// Developed by:
// Simon M. Mudd
// Stuart W.D. Grieve
//
// Copyright (C) 2016 Simon M. Mudd 2013 6
//
// Developer can be contacted by simon.m.mudd _at_ ed.ac.uk
//
// Simon Mudd
// University of Edinburgh
// School of GeoSciences
// Drummond Street
// Edinburgh, EH8 9XP
// Scotland
// United Kingdom
//
// This program is free software;
// you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation;
// either version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;
// without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the
// GNU General Public License along with this program;
// if not, write to:
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301
// USA
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/** @file LSDPorewaterColumn.hpp
@author Simon M. Mudd, University of Edinburgh
@author Stuart W. D. Grieve, University of Edinburgh
**/
#ifndef LSDPorewaterColumn_CPP
#define LSDPorewaterColumn_CPP
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include "LSDPorewaterColumn.hpp"
#include "LSDPorewaterParams.hpp"
#include "LSDStatsTools.hpp"
#include "TNT/tnt.h"
using namespace std;
using namespace TNT;
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Empty create function
// Starts with some defaults.
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::create()
{
row = 0;
col = 0;
node_index = 0;
cout << "I am an empty LSDPorewaterColumn object." <<endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This create function just uses an initial Psi
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::create(vector<float> Initial_Psi)
{
row = 0;
col = 0;
node_index = 0;
Psi = Initial_Psi;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This create function takes a porewater parameter object and uses the
// steady infiltration rate to set psi
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::create(LSDPorewaterParams LSDPP)
{
row = 0;
col = 0;
node_index = 0;
Psi = LSDPP.calculate_steady_psi();
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This prints the Psi values to screen
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::PrintPsiToScreen()
{
for(int i = 0; i<int(Psi.size()); i++)
{
cout << "Psi["<<i<<"]: " << Psi[i] << endl;
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This caluclates the response function
// THis comes from iverson's equation 27e
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
float LSDPorewaterColumn::CalculateResponseFunction(float t_star)
{
float R;
float sqrt_term = sqrt(t_star/M_PI);
float exp_term = exp(-1/t_star);
float multiple_bit = sqrt_term*exp_term;
if (t_star != 0)
{
R = multiple_bit- erfcf(1/ (sqrt(t_star)));
}
else // If t_star is 0, then 1/sqrt(t_star) is infinity, meaning erfc is 0)
{
R = 0;
}
return R;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This caluclates the Psi value based on iverson's equation 27
// Has only the transient component of psi
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<float> LSDPorewaterColumn::CalcualtePsiTransient(LSDPorewaterParams& LSDPP, float Iz_over_Kz,
float t_star, float T_star)
{
vector<float> Depths = LSDPP.get_Depths();
vector<float> transient_Psi(Depths.size());
float R;
if (t_star < T_star)
{
R = CalculateResponseFunction(t_star);
}
else
{
R = CalculateResponseFunction(t_star-T_star);
}
// This solves the equation, based on the response function (R_fn),
// which is equation 27e
for (int i = 0; i< int(Depths.size()) ; i++)
{
transient_Psi[i] = Depths[i]*Iz_over_Kz*R;
}
return transient_Psi;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Compute psi from equation 27a and b, but using dimensional time
// A bit slow since I haven't vectorised the calculations.
// Only calculates the transient component of psi for use with
// time series of rainfall
// times need to be in seconds
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<float> LSDPorewaterColumn::CalculatePsiDimensionalTimeTransient(LSDPorewaterParams& LSDPP, float t, float T, float Iz_over_Kz)
{
vector<float> Depths = LSDPP.get_Depths();
vector<float> transient_Psi(Depths.size());
float t_star;
float T_star;
float zsquare;
float D_hat = LSDPP.get_D_hat();
float R;
// loop through depths: each depth has a different t_star and T_star since
// these depend on depth
for(int i = 0; i< int(Depths.size()) ; i++)
{
// first get the nondimensional time. Note that according to
// equations 27c,d the dimensionless time is a function of depth,
// so each point below the surface has a different t_star and T_star
zsquare = Depths[i]*Depths[i];
t_star = t * D_hat / zsquare;
T_star = T * D_hat / zsquare;
if (t_star < T_star)
{
R = CalculateResponseFunction(t_star);
}
else
{
R = CalculateResponseFunction(t_star)-CalculateResponseFunction(t_star-T_star);
}
transient_Psi[i] =Depths[i]*Iz_over_Kz*R;
//cout << "depth: " << Depths[i] << " t_star: " << t_star << " T_star: " << T_star << endl;
}
return transient_Psi;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This caluclates the Psi value based on iverson's equation 27
// It parses a time series
// The durations and time are in seconds.
// The intensities are in Iz_over_Kz
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::CalculatePsiFromTimeSeries(vector<float> durations, vector<float> intensities,
LSDPorewaterParams& LSDPP, float t)
{
// Get the steady state time
vector<float> steady_psi = LSDPP.calculate_steady_psi();
vector<float> cumulative_psi = steady_psi;
// see what the result is:
//cout << endl << "======================" << endl << "Steady psi: " << endl;
//for(int i = 0; i<int(cumulative_psi.size()); i++)
//{
// cout << "Psi["<<i<<"]: " << cumulative_psi[i] << endl;
//}
//cout << "======================" << endl << endl << endl;
// Now we try to construct the transient pressure.
// loop through the record getting cumulative times
vector<float> starting_times;
starting_times.push_back(0);
float cumulative_time = 0;
int count = 0;
bool end_count_found = false;
int end_count = 0;
for (int i = 0; i< int(durations.size()); i++)
{
cumulative_time += durations[i];
//cout << "t: " << t << " cumulative time: " << cumulative_time << endl;
// the cumulative time is the time at the end of this timestep.
// if the cumulative time is less than the time of simulation,
// then we need to acount for this pulse of rainfall
if (t < cumulative_time)
{
if (end_count_found == false)
{
end_count_found = true;
end_count = count;
}
}
count++;
starting_times.push_back(cumulative_time);
}
// we don't need the last element
starting_times.pop_back();
//cout << "N starting times: " << starting_times.size() << endl;
// If we didn't find the end count it means the rainfall records have ended and we need
// all of the data
if (end_count_found == false)
{
// The minus one is needed since we have counted past the end of the index
end_count = count-1;
}
//cout << "end count is: " << end_count << endl;
// check starting times, etc
//for(int i = 0; i< int(starting_times.size()); i++)
//{
// cout << "st: " << starting_times[i] << " i: " << intensities[i] << " d: " << durations[i] << endl;
//
//}
// okay, now get the transients from superposition
// First we need to figure out how many of these we will need
float eff_t, this_intensity, this_duration;
vector<float> this_transient_Psi;
for(int i = 0; i< int(starting_times.size()); i++)
{
if(i<= end_count)
{
eff_t = t-starting_times[i];
this_intensity = intensities[i];
this_duration = durations[i];
//cout << "Eff t: " << eff_t << " and intensity: " << this_intensity << " dur: " << this_duration << endl;
// get this steps Psi value
this_transient_Psi = CalculatePsiDimensionalTimeTransient(LSDPP, eff_t, this_duration, this_intensity);
// check values
//cout << "Transient psi is:"<< endl;
//for(int i = 0; i<int(cumulative_psi.size()); i++)
//{
// cout << this_transient_Psi[i] << endl;
//}
// add this step's transient Psi values.
for(int i = 0; i<int(cumulative_psi.size()); i++)
{
cumulative_psi[i]+=this_transient_Psi[i];
}
}
}
// see what the result is:
for(int i = 0; i<int(cumulative_psi.size()); i++)
{
cout << "Psi["<<i<<"]: " << cumulative_psi[i] << endl;
}
Psi = cumulative_psi;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Factor of safety calculations
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This is the friction
float LSDPorewaterColumn::F_f(LSDPorewaterParams& LSDPP)
{
float alpha = LSDPP.get_alpha();
float friction_angle = LSDPP.get_friction_angle();
float tan_alpha = tan(alpha);
float tan_friction_angle = tan(friction_angle);
return tan_friction_angle/tan_alpha;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This is from the cohesion
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<float> LSDPorewaterColumn::F_c(LSDPorewaterParams& LSDPP)
{
float cohesion = LSDPP.get_cohesion();
float alpha = LSDPP.get_alpha();
float weight_of_soil = LSDPP.get_weight_of_soil();
vector<float> Depths = LSDPP.get_Depths();
float denom;
float denom2 = sin(alpha)*cos(alpha);
vector<float> F_c_vec;
for(int i = 0; i< int(Depths.size()); i++)
{
denom = Depths[i]*weight_of_soil;
F_c_vec.push_back( cohesion/(denom*denom2) );
}
return F_c_vec;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This is from the water
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<float> LSDPorewaterColumn::F_w(LSDPorewaterParams& LSDPP)
{
vector<float> Depths = LSDPP.get_Depths();
float alpha = LSDPP.get_alpha();
float friction_angle = LSDPP.get_friction_angle();
float weight_of_soil = LSDPP.get_weight_of_soil();
float weight_of_water = LSDPP.get_weight_of_water();
float denom, num1, num2;
float denom2 = sin(alpha)*cos(alpha);
float denom_tot;
vector<float> F_w_vec;
for(int i = 0; i< int(Depths.size()); i++)
{
num1 = Psi[i]*weight_of_water;
num2 = -num1*tan(friction_angle);
denom = Depths[i]*weight_of_soil;
denom_tot = denom*denom2;
F_w_vec.push_back( num2/denom_tot );
}
return F_w_vec;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This is the total factor of safety
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<float> LSDPorewaterColumn::FS(LSDPorewaterParams& LSDPP)
{
// get the components of the factor of safety
float F_f_float = F_f(LSDPP);
vector<float> F_c_vec = F_c(LSDPP);
vector<float> F_w_vec = F_w(LSDPP);
// get the
vector<float> FS = F_c_vec;
for(int i = 0; i< int(F_c_vec.size()); i++)
{
FS[i] = F_f_float+F_c_vec[i]+F_w_vec[i];
cout << "FS["<<i<<"]: " << FS[i] << endl;
}
return FS;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This checks to see a failure depth
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
float LSDPorewaterColumn::DepthOfFailure(LSDPorewaterParams& LSDPP, float minimum_depth)
{
float depth_of_failure = -9999;
// get the factor of safety vector
vector<float> FoS = FS(LSDPP);
// get the depth vector
vector<float> Depths = LSDPP.get_Depths();
int N_depths = int(Depths.size());
for(int i = 0; i< N_depths; i++)
{
// only check FS if above minimum depth
if(Depths[i]>= minimum_depth)
{
if(FoS[i] < 1.0)
{
depth_of_failure = Depths[i];
i = N_depths;
}
}
}
return depth_of_failure;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This checks to see a failure depth
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::GetMinFS(LSDPorewaterParams& LSDPP, float minimum_depth, float& depth_of_minFS, float& minFS)
{
depth_of_minFS = minimum_depth;
float min_FS = 9999;
// get the factor of safety vector
vector<float> FoS = FS(LSDPP);
// get the depth vector
vector<float> Depths = LSDPP.get_Depths();
int N_depths = int(Depths.size());
for(int i = 0; i< N_depths; i++)
{
// only check FS if above minimum depth
if(Depths[i]>= minimum_depth)
{
if(FoS[i] < min_FS)
{
depth_of_minFS = Depths[i];
min_FS = FoS[i];
}
}
}
minFS = min_FS;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This scans a timeseries for a failure
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDPorewaterColumn::ScanTimeseriesForFailure(vector<float> durations, vector<float> intensities,
LSDPorewaterParams& LSDPP, float minimum_depth,
vector<float> times)
{
// loop through times
int n_times = int(times.size());
float depth_of_minFS;
float min_FS;
for(int i = 0; i< n_times; i++)
{
// get the pore pressure
CalculatePsiFromTimeSeries(durations, intensities, LSDPP, times[i]);
// get the min
GetMinFS(LSDPP, minimum_depth, depth_of_minFS, min_FS);
cout << "Time in weeks is: " << LSDPP.seconds_to_weeks(times[i]) << " d min FS: "
<< depth_of_minFS << " min FS: " << min_FS << endl;
}
}
#endif