-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLSDParticle.cpp
3071 lines (2594 loc) · 109 KB
/
LSDParticle.cpp
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// LSDParticle
// Land Surface Dynamics Particle
//
// An object within the University
// of Edinburgh Land Surface Dynamics group topographic toolbox
// for tracing particles and retaining geochemical information
//
// Developed by:
// Simon M. Mudd
// Martin D. Hurst
// David T. Milodowski
// Stuart W.D. Grieve
// Declan A. Valters
// Fiona Clubb
//
// Copyright (C) 2013 Simon M. Mudd 2013
//
// 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
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <fstream>
#include <math.h>
#include <iostream>
#include "LSDStatsTools.hpp"
#include "LSDParticle.hpp"
using namespace std;
#ifndef LSDParticle_CPP
#define LSDParticle_CPP
// Sorting compiling problems with MSVC
#ifdef _WIN32
#ifndef M_PI
extern double M_PI;
#endif
#endif
const double one_min_exp_neg_2 = 1-exp(-2);
const double one_min_exp_neg_5 = 1-exp(-5);
// default constructor
void LSDParticle::create()
{
Type = 0;
CellIndex = -1;
Age = 0;
OSLage = -9999;
}
// start with a specific type
void LSDParticle::create( int StartType )
{
Type = StartType;
CellIndex = -1;
Age = 0;
OSLage = -9999;
}
void LSDParticle::create( int StartType, double StartAge )
{
Type = StartType;
CellIndex = -1;
Age = StartAge;
}
void LSDParticle::create( int StartType, int StartCI, double StartAge, double StartOSLage, double StartxLoc, double StartdLoc)
{
Type = StartType;
CellIndex = StartCI;
Age = StartAge;
OSLage = StartOSLage;
xLoc = StartxLoc;
dLoc = StartdLoc;
}
void LSDParticle::create( int StartType, int StartCI, double StartAge,
double StartOSLage, double StartxLoc, double StartyLoc, double StartdLoc)
{
Type = StartType;
CellIndex = StartCI;
Age = StartAge;
OSLage = StartOSLage;
xLoc = StartxLoc;
yLoc = StartyLoc;
dLoc = StartdLoc;
}
void LSDParticle::create(int StartType, double StartxLoc, double StartdLoc)
{
Type = StartType;
CellIndex = -1;
Age = 0;
OSLage = -9999;
xLoc = StartxLoc;
dLoc = StartdLoc;
}
LSDParticle& LSDParticle::operator=(const LSDParticle& rhs)
{
if (&rhs != this)
{
create(rhs.getType(),rhs.getCellIndex(),rhs.getAge(),rhs.getOSLage(), rhs.getxLoc(),rhs.getyLoc(),rhs.getdLoc());
}
return *this;
}
std::ostream& operator<<(std::ostream& os, const LSDParticle& tP)
{
os << tP.getType() << " " << tP.getCellIndex() << " " << tP.getAge() << " "
<< tP.getOSLage() << " " << tP.getxLoc() << " " << tP.getyLoc()
<< " " << tP.getdLoc();
return os;
}
void LSDParticle::incrementAge(double dt)
{
if (Age < 0)
Age = dt;
else
Age += dt;
if (OSLage > 0)
OSLage += dt;
}
void LSDParticle::setCellIndex(int tempCI)
{
CellIndex = tempCI;
}
void LSDParticle::OSLexpose()
{
OSLage = 0;
}
void LSDParticle::SoilAgeExpose()
{
Age = 0;
}
// update the x location
void LSDParticle::update_xLoc(double new_xLoc)
{
xLoc = new_xLoc;
}
// update the y location
void LSDParticle::update_yLoc(double new_yLoc)
{
yLoc = new_yLoc;
}
void LSDParticle::displaceReflect(double dx,double dd,double h, double dt)
{
xLoc += dx;
//std::cout << "tPart.cpp LINE 77 dx is: " << dd << std::endl;
double dOld = dLoc;
double dNew = dLoc+dd;
if (dNew > h)
{
//std::cout << "tPart.cpp LINE 84 dNew is: " << dNew << " and dd is: " << dd
// << " and dOld is: "<< dOld << std::endl;
dLoc = 2*h - dd - dOld;
//std::cout << "tPart.cpp LINE 86 dLoc is: " << dLoc << std::endl;
}
else if (dNew <= 0)
{
dLoc = -(dd+dOld);
OSLage = (dd+dOld)*dt/dd;
}
else
dLoc = dNew;
//if (dLoc > h)
// std::cout << "tPart.cpp LINE 86 dLoc is: " << dLoc << std::endl;
}
// this test to see if the particle is still within the x location < lambda
int LSDParticle::test_domain(double lambda)
{
int td;
if (xLoc >= 0 && xLoc <= lambda)
td = 1;
else
{
td = -1;
OSLage = -9999;
Age = -9999;
xLoc = -9999;
dLoc = -9999;
}
return td;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// LSDCRNParticle object
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// functions for the CRN loaded tracer particle
void LSDCRNParticle::create()
{
double rho_r = 2650; // in kg/m^3
Type = 0;
CellIndex = -1;
Age = 0;
OSLage = 0;
xLoc = 0; // in metres
yLoc = 0; // in metres
dLoc = 5; // in metres
zetaLoc = 100;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = rho_r*dLoc*0.1; // the 0.1
// converts between kg/m^2
// to g/cm^2
}
void LSDCRNParticle::create(int startType, double startxLoc,
double startzLoc)
{
double rho_r = 2650; // in kg/m^3
Type = startType;
CellIndex = -1;
Age = 0;
OSLage = 0;
xLoc = startxLoc; // in meters
yLoc = 0;
dLoc = 0; // in meters
zetaLoc = startzLoc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = rho_r*dLoc*0.1; // the 0.1
// converts between kg/m^2
// to g/cm^2
}
void LSDCRNParticle::create(int startType, double startxLoc,
double startdLoc, double start_effdloc,
double startzLoc)
{
Type = startType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
yLoc = 0;
dLoc = startdLoc; // in meters
zetaLoc = startzLoc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = start_effdloc;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, double startxLoc, double startyLoc,
double startdLoc, double start_effdloc,
double startzLoc)
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
{
Type = startType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
yLoc = startyLoc;
dLoc = startdLoc; // in meters
zetaLoc = startzLoc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = start_effdloc;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// a create function for a volume particle
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, int startGSDType,
double startxLoc,
double startdLoc, double start_effdloc,
double startzLoc, double startMass,
double startSurfaceArea)
{
Mass = startMass; // in kg
StartingMass = startMass; // in kg
SurfaceArea = startSurfaceArea;
// in m^2/kg
Type = startType;
GSDType = startGSDType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
dLoc = startdLoc; // in meters
zetaLoc = startzLoc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = start_effdloc;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// a create function for a volume particle with y loc
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, int startGSDType, double startxLoc, double startyLoc,
double startdLoc, double start_effdloc,
double startzLoc, double startMass,
double startSurfaceArea)
{
Mass = startMass; // in kg
StartingMass = startMass; // in kg
SurfaceArea = startSurfaceArea;
// in m^2/kg
Type = startType;
GSDType = startGSDType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
yLoc = startyLoc; // in metres
dLoc = startdLoc; // in meters
zetaLoc = startzLoc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
effective_dLoc = start_effdloc;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// contains posiution and CRN information
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, double startxLoc,double startzeta_Loc,
double startdLoc, double start_effdLoc,
double start_C10Be,double start_C14C)
{
Type = startType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
dLoc = startdLoc; // in meters
effective_dLoc = start_effdLoc;
zetaLoc = startzeta_Loc;
Conc_10Be = 0.0;
Conc_26Al = 0.0;
Conc_36Cl = 0.0;
Conc_14C = 0.0;
Conc_21Ne = 0.0;
Conc_3He = 0.0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This includes some position and CRN information
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, double startxLoc,double startzeta_Loc,
double startdLoc, double start_effdLoc,
double start_C10Be,double start_C14C, double start_21Ne)
{
Type = startType;
CellIndex = -1;
Age = -99;
OSLage = -99;
xLoc = startxLoc; // in meters
dLoc = startdLoc; // in meters
effective_dLoc = start_effdLoc;
zetaLoc = startzeta_Loc;
Conc_10Be = start_C10Be;
Conc_26Al = 0;
Conc_36Cl = 0;
Conc_14C = start_C14C;
Conc_21Ne = start_21Ne;
Conc_3He = 0;
Conc_f7Be = 0.0;
Conc_f10Be = 0.0;
Conc_f210Pb = 0.0;
Conc_f137Cs = 0.0;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This includes all data members for copy constructor
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::create(int startType, int start_GSDType, int startCellIndex,
double startAge, double startOSLAge,
double startxLoc,double startyLoc,double startdLoc, double startefdLoc,
double startzLoc, double start_C10Be, double start_C26Al,
double start_C36Cl, double start_C14C,
double start_C21Ne, double start_C3He,
double start_Cf7Be, double start_Cf10Be,
double start_Cf210Pb, double start_Cf137Cs,
double start_Mass, double start_StartingMass,
double start_SurfaceArea)
{
Type = startType;
CellIndex = startCellIndex;
Age = startAge;
OSLage = startOSLAge;
xLoc = startxLoc; // in metres
yLoc = startyLoc; // in metres
dLoc = startdLoc; // in metres
effective_dLoc = startefdLoc;
zetaLoc = startzLoc;
Conc_10Be = start_C10Be;
Conc_26Al = start_C26Al;
Conc_36Cl = start_C36Cl;
Conc_14C = start_C14C;
Conc_21Ne = start_C21Ne;
Conc_3He = start_C3He;
Conc_f7Be = start_Cf7Be;
Conc_f10Be = start_Cf10Be;
Conc_f210Pb = start_Cf210Pb;
Conc_f137Cs = start_Cf137Cs;
Mass = start_Mass;
StartingMass = start_StartingMass;
SurfaceArea = start_SurfaceArea;
GSDType = start_GSDType;
}
LSDCRNParticle& LSDCRNParticle::operator=(const LSDCRNParticle& rhs)
{
if (&rhs != this)
{
create(rhs.getType(), rhs.getGSDType(), rhs.getCellIndex(),
rhs.getAge(),rhs.getOSLage(),
rhs.getxLoc(),rhs.getyLoc(),rhs.getdLoc(),
rhs.geteffective_dLoc(),rhs.get_zetaLoc(),rhs.getConc_10Be(),
rhs.getConc_26Al(), rhs.getConc_36Cl(), rhs.getConc_14C(),
rhs.getConc_21Ne(), rhs.getConc_3He(),
rhs.getConc_f7Be(), rhs.getConc_f10Be(),
rhs.getConc_f210Pb(), rhs.getConc_f137Cs(),
rhs.getMass(), rhs.getStartingMass(),
rhs.getSurfaceArea());
}
return *this;
}
LSDCRNParticle& LSDCRNParticle::operator=(LSDCRNParticle& rhs)
{
if (&rhs != this)
{
create(rhs.getType(), rhs.getGSDType(), rhs.getCellIndex(),
rhs.getAge(),rhs.getOSLage(),
rhs.getxLoc(),rhs.getyLoc(),rhs.getdLoc(),
rhs.geteffective_dLoc(),rhs.get_zetaLoc(),rhs.getConc_10Be(),
rhs.getConc_26Al(), rhs.getConc_36Cl(), rhs.getConc_14C(),
rhs.getConc_21Ne(), rhs.getConc_3He(),
rhs.getConc_f7Be(), rhs.getConc_f10Be(),
rhs.getConc_f210Pb(), rhs.getConc_f137Cs(),
rhs.getMass(), rhs.getStartingMass(),
rhs.getSurfaceArea());
}
return *this;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Unit conversion utilities
// length units are in metres or g/cm^2
// density is in kg/m^3
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
double LSDCRNParticle::convert_m_to_gpercm2(double l_in_m, double rho)
{
if(rho < 500)
{
cout << "Density should be in kg/m^3, your density is: " << rho << endl;
cout << "Are you sure you have the correct units?" << endl;
}
double l_in_gpercm2 = l_in_m*rho*0.1;
return l_in_gpercm2;
}
double LSDCRNParticle::convert_gpercm2_to_m(double l_in_gpercm2, double rho)
{
if(rho < 500)
{
cout << "Density should be in kg/m^3, your density is: " << rho << endl;
cout << "Are you sure you have the correct units?" << endl;
}
double l_in_m = l_in_gpercm2*10/rho;
return l_in_m;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// this function just sets the concentration of cosmogenic in situ nuclides
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::update_cosmo_conc_const(double C_10Be, double C_26Al, double C_36Cl,
double C_14C, double C_21Ne, double C_3He)
{
Conc_10Be = C_10Be;
Conc_26Al = C_26Al;
Conc_36Cl = C_36Cl;
Conc_14C = C_14C;
Conc_21Ne = C_21Ne;
Conc_3He = C_3He;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// this function updates the concentration of CRNs in a particle
// the model assumes that during the timestep the change in the
// 'depth' of the particle occurs ofver a constant rate.
// The depth in this case is an equvalent depth...it is linearly
// proportional to depth if overlying density is constant, but
// really represetnt the mass per area above a point in the subsurface
// thus the erosion rate represent a mass removal rate.
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::update_10Be_conc(double dt,double erosion_rate, LSDCRNParameters& CRNp)
{
// fist berillium
double Be_exp = exp(-dt*CRNp.lambda_10Be);
//double Be_depth_exp = exp(-d_0/Gamma_Be1);
//cout << "LINE 236 LSDParticle.cpp " << endl;
//cout << lambda_10Be << " " << Be_exp << endl;
//cout << "starting conc: " << Conc_10Be << endl;
//cout << "starting depth: " << effective_dLoc << endl;
//cout << "erosion_rate: "<< erosion_rate << endl;
double sum_term = 0;
for (int i = 0; i<4; i++)
{
sum_term+= (CRNp.F_10Be[i]*exp(-effective_dLoc/CRNp.Gamma[i])*CRNp.Gamma[i])*
(exp(dt*erosion_rate/CRNp.Gamma[i])-
exp(-dt*CRNp.lambda_10Be))/
(erosion_rate+CRNp.Gamma[i]*CRNp.lambda_10Be);
//cout << "F_10Be["<<i<<"]: " << CRNp.F_10Be[i] << " and sum_term: " << sum_term <<endl;
}
//cout << "and sum term is: " << sum_term << endl;
// Note: Scaling is either done by modifying S_t or by scaling the F factors
// for the basinwide cosmogenic tool S_t is set to 1 and the scaling is done
// with the F factors.
Conc_10Be = Conc_10Be*Be_exp + CRNp.S_t*CRNp.P0_10Be*sum_term;
//cout << "and ending 10Be conc is: " << Conc_10Be <<endl;
}
// this function updates the 10Be concentration if there is a linear
// increase (or decrease) in erosion rate.
void LSDCRNParticle::update_10Be_conc_linear_increase(double dt,double erosion_rate, double alpha, LSDCRNParameters& CRNp)
{
// fist berillium
double Be_exp = exp(-dt*CRNp.lambda_10Be);
//double Be_depth_exp = exp(-d_0/Gamma_Be1);
//cout << "LINE 236 LSDParticle.cpp " << endl;
//cout << lambda_10Be << " " << Be_exp << endl;
//cout << "starting conc: " << Conc_10Be << endl;
//cout << "starting depth: " << effective_dLoc << endl;
//cout << "erosion_rate: "<< erosion_rate << endl;
double sum_term = 0;
double L_j, M_j, A_j, B_j, D_j;
double erfi_arg1, erfi_arg2;
for (int j = 0; j<4; j++)
{
A_j = sqrt(0.5*CRNp.Gamma[j]/alpha);
B_j = sqrt(2*alpha*CRNp.Gamma[j]);
D_j = sqrt(0.5*alpha/CRNp.Gamma[j]);
L_j = exp(-( (erosion_rate+CRNp.Gamma[j]*CRNp.lambda_10Be)*(erosion_rate+CRNp.Gamma[j]*CRNp.lambda_10Be)+
2*alpha*(effective_dLoc+dt*CRNp.Gamma[j]*CRNp.lambda_10Be) )/(B_j*B_j) );
erfi_arg1 = erosion_rate/B_j + A_j*CRNp.lambda_10Be;
erfi_arg2 = D_j*dt + erfi_arg1;
M_j = erfi(erfi_arg2) - erfi(erfi_arg1);
sum_term+= (CRNp.F_10Be[j]*A_j*L_j*M_j);
}
//cout << "and sum term is: " << sum_term << endl;
Conc_10Be = Conc_10Be*Be_exp + CRNp.S_t*CRNp.P0_10Be*sum_term*sqrt(M_PI);
//cout << "and ending 10Be conc is: " << Conc_10Be <<endl;
}
void LSDCRNParticle::update_10Be_conc_neutron_only(double dt,double erosion_rate, LSDCRNParameters& CRNp)
{
double Gamma_neutron=CRNp.Gamma[0]; // in g/cm^2
double Be_exp = exp(-dt*CRNp.lambda_10Be);
double sum_term = 0;
sum_term+= (exp(-effective_dLoc/Gamma_neutron)*Gamma_neutron)*
(exp(dt*erosion_rate/Gamma_neutron)-
exp(-dt*CRNp.lambda_10Be))/
(erosion_rate+Gamma_neutron*CRNp.lambda_10Be);
Conc_10Be = Conc_10Be*Be_exp + CRNp.S_t*Be_exp*CRNp.P0_10Be*sum_term;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This updates the 10Be concentration if erosion is steady using the full
// 4 attenuation depth model of Vermeesch (2007)
// The erosion rate should be in g/cm^2/yr
//
// NOTE This produces far less muon production than CRONUS
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::update_10Be_SSfull(double erosion_rate, LSDCRNParameters& CRNp)
{
double this_term;
double sum_term1 = 0;
//double sum_term2 = 0;
double spall_tot = 0;
double muon_tot = 0;
for (int i = 0; i<4; i++)
{
//cout << "ThickSF: " << CRNp.F_10Be[i]*(1-exp(-effective_dLoc/CRNp.Gamma[i]))*
// (CRNp.Gamma[i]/effective_dLoc) << endl;
//cout << "A: " << (CRNp.lambda_10Be+erosion_rate/CRNp.Gamma[i]) << endl;
//sum_term1+= (CRNp.F_10Be[i]*exp(-effective_dLoc/CRNp.Gamma[i])*CRNp.Gamma[i])/
// (erosion_rate+CRNp.Gamma[i]*CRNp.lambda_10Be);
//sum_term1+= (CRNp.F_10Be[i]*(1-exp(-effective_dLoc/CRNp.Gamma[i]))*
// (CRNp.Gamma[i]/effective_dLoc))/
// (CRNp.lambda_10Be+erosion_rate/CRNp.Gamma[i]);
//cout << "Thick/A:" << (CRNp.F_10Be[i]*(1-exp(-effective_dLoc/CRNp.Gamma[i]))*
// (CRNp.Gamma[i]/effective_dLoc))/
// (CRNp.lambda_10Be+erosion_rate/CRNp.Gamma[i]) << endl;
this_term = (exp(-effective_dLoc/CRNp.Gamma[i])*CRNp.F_10Be[i]*CRNp.Gamma[i])/
(erosion_rate+CRNp.Gamma[i]*CRNp.lambda_10Be);
sum_term1 += this_term;
if(i == 0)
{
spall_tot+=this_term;
}
else
{
muon_tot+=this_term;
}
}
//cout << "effective_dLoc: " << effective_dLoc << endl;
//cout << "erosion rate: " << erosion_rate << endl;
//cout << "and sum term is: " << sum_term1 << " " << sum_term2 << endl;
//double Pref = CRNp.S_t*CRNp.P0_10Be;
//cout << "Pref is: " << Pref << endl;
//cout << "Scaling is: " << CRNp.S_t << " P0 is: " << CRNp.P0_10Be
// << " and Pref is: " << CRNp.S_t*CRNp.P0_10Be << endl;
Conc_10Be = CRNp.S_t*CRNp.P0_10Be*sum_term1;
spall_tot = CRNp.S_t*CRNp.P0_10Be*spall_tot;
muon_tot = CRNp.S_t*CRNp.P0_10Be*muon_tot;
//cout << "Line 717, Conc 10Be is: " << Conc_10Be << " from spallation: " << spall_tot
// << " and muons: " << muon_tot << endl;
//cout << "and ending 10Be conc is: " << Conc_10Be <<endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// A depth integrated version of the steady state equation.
// This is really only appropriate for basinwide calculations because
// it doens't really represent the CRN concentration of an individual particle
// The arguments also override the effective depth of the particle
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::update_10Be_SSfull_depth_integrated(double erosion_rate,
LSDCRNParameters& CRNp,
double top_eff_depth, double bottom_eff_depth)
{
//cout << "LINE 748, doing full depth integration" << endl;
// first, check if the inputs are working properly
if (top_eff_depth > bottom_eff_depth)
{
cout << "LSDParticle line 753, your effective depths for integration are reversed" << endl;
cout << "Reversing the two depths. Check your inputs!" << endl;
double temp_eff_depth = bottom_eff_depth;
bottom_eff_depth = top_eff_depth;
top_eff_depth = temp_eff_depth;
}
// If the top effective depth and the bottom effective depth are the same, then run the standard
// concentration for particles eroding from the top of this pixel
if (top_eff_depth == bottom_eff_depth)
{
effective_dLoc = top_eff_depth;
update_10Be_SSfull(erosion_rate, CRNp);
}
else // If they arent the same, this calculates the depth average concentrations of particles between the top and bottom effective depths.
{
double this_term;
double sum_term1 = 0;
double spall_tot = 0;
double muon_tot = 0;
for (int i = 0; i<4; i++)
{
// get the individual terms
this_term = ( ( exp(-top_eff_depth/CRNp.Gamma[i])
-exp(-bottom_eff_depth/CRNp.Gamma[i]) )*
CRNp.F_10Be[i]*CRNp.Gamma[i]*CRNp.Gamma[i])/
(erosion_rate+CRNp.Gamma[i]*CRNp.lambda_10Be);
sum_term1 += this_term;
// add the terms to track muon and spalling production
if(i == 0)
{
spall_tot+=this_term;
}
else
{
muon_tot+=this_term;
}
}
// get the concentration
Conc_10Be = (1/(bottom_eff_depth-top_eff_depth))*CRNp.S_t*CRNp.P0_10Be*sum_term1;
spall_tot = (1/(bottom_eff_depth-top_eff_depth))*CRNp.S_t*CRNp.P0_10Be*spall_tot;
muon_tot = (1/(bottom_eff_depth-top_eff_depth))*CRNp.S_t*CRNp.P0_10Be*muon_tot;
}
// print some stuff to screen for bug checking
vector<bool> cosmo_flags(4,false);
cosmo_flags[0] = true;
//cout << "\n\n\nLSDParticle line 797, getting cosmo for erosion rate: " << erosion_rate <<endl;
//cout << "Top depth: " << top_eff_depth << " bottom depth: " << bottom_eff_depth << endl;
//cout << "The parameter values are: " << endl;
//CRNp.print_parameters_to_screen(cosmo_flags);
//cout << "Conc 10Be: " << Conc_10Be << endl << endl << endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This function uses newton iteration to get an apparent erosion rate
// for full muons.
// It is intended to mimic the cosmocalc erosion rate finder
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
vector<double> LSDCRNParticle::apparent_erosion_10Be_COSMOCALC(double rho, LSDCRNParameters& CRNp,
double scaling_factor, string Muon_scaling,
double top_eff_depth, double bottom_eff_depth)
{
double Target_conc = Conc_10Be;
// get the initial guess
effective_dLoc = top_eff_depth;
double erate_guess = apparent_erosion_10Be_neutron_only(rho, CRNp);
double eff_erate_guess = convert_m_to_gpercm2(erate_guess,rho);
//cout << "Concentration: " << Conc_10Be << " rho: " << rho << " neutron erate "
// << erate_guess << "m/yr, effective: " << eff_erate_guess << " g/cm^2/yr" << endl;
// set the scaling
// reset scaling parameters. This is necessary since the F values are
// reset for local scaling
if (Muon_scaling == "Schaller" )
{
CRNp.set_Schaller_parameters();
}
else if (Muon_scaling == "Braucher" )
{
CRNp.set_Braucher_parameters();
}
else if (Muon_scaling == "Granger" )
{
CRNp.set_Granger_parameters();
}
else if (Muon_scaling == "newCRONUS" )
{
CRNp.set_newCRONUS_parameters();
}
else
{
cout << "You didn't set the muon scaling." << endl
<< "Options are Schaller, Braucher, newCRONUS, and Granger." << endl
<< "You chose: " << Muon_scaling << endl
<< "Defaulting to Braucher et al (2009) scaling" << endl;
CRNp.set_Braucher_parameters();
}
// scale the F values
vector<bool> nuclide_scaling_switches(4,false);
nuclide_scaling_switches[0] = true; // this scales for 10Be
CRNp.scale_F_values(scaling_factor,nuclide_scaling_switches);
// now do Newton Iteration to find the correct erosion rate
// convert to g/cm^2/yr
eff_erate_guess = 0.1*erate_guess*rho;
// now using this as the initial guess, use Newton-Raphson to zero in on the
// correct erosion rate
double eff_e_new = eff_erate_guess; // the erosion rate upon which we iterate
double eff_e_change; // the change in erosion rate between iterations
double tolerance = 1e-10; // tolerance for a change in the erosion rate
// between Newton-Raphson iterations
double eff_e_displace = 1e-6; // A small displacment in the erosion rate used
// to calculate the derivative
double N_this_step; // the concentration of the nuclide reported this step
double N_displace; // the concentration at the displaced erosion rate
double N_derivative; // dN/de derivative for Newton-Raphson
double f_x; // the function being tested by newton raphson
double f_x_displace; // the displaced function (for calculating the derivative)
do
{
update_10Be_SSfull_depth_integrated(eff_e_new, CRNp,
top_eff_depth, bottom_eff_depth);
N_this_step = Conc_10Be;
update_10Be_SSfull_depth_integrated(eff_e_new+eff_e_displace, CRNp,
top_eff_depth, bottom_eff_depth);
N_displace = Conc_10Be;
// print to screen:
//cout << "eff_e_new = " << eff_e_new << " in cm/kyr: " << eff_e_new*1e6/rho
// << " 10Be: " << N_this_step << " atoms/yr" << endl;
f_x = N_this_step-Target_conc;
f_x_displace = N_displace-Target_conc;
N_derivative = (f_x_displace-f_x)/eff_e_displace;
if(N_derivative != 0)
{
eff_e_new = eff_e_new-f_x/N_derivative;
// check to see if the difference in erosion rates meet a tolerance
eff_e_change = f_x/N_derivative;
//cout << "Change is: " << eff_e_change << " and erosion rate is: " << eff_e_new << endl;
}
else
{
eff_e_change = 0;
}
} while(fabs(eff_e_change) > tolerance);
vector<double> erosion_rate_vec;
erosion_rate_vec.push_back(eff_e_new);
erosion_rate_vec.push_back(eff_e_new*10/rho);
Conc_10Be = Target_conc;
return erosion_rate_vec;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This gets the apparent erosion rate.
// if rho is in kg/m^3 this returns erosion in m/yr
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
double LSDCRNParticle::apparent_erosion_10Be_neutron_only(double rho, LSDCRNParameters& CRNp)
{
// a few constants, all computed from Vermeesh 2007
double Gamma_neutron=CRNp.Gamma[0]; // in g/cm^2
double app_eff_eros; // in g/cm2/yr
double app_eros; // in m/yr
double exp_term = exp(-effective_dLoc/Gamma_neutron);
//cout << "LSDCRNParticle line 741, S_t: " << CRNp.neutron_S_t << " P0: " << CRNp.P0_10Be
// << " total spallation: " << CRNp.neutron_S_t*CRNp.P0_10Be << endl
// << " and the F_0: " << CRNp.F_10Be[0] << endl;
app_eff_eros = Gamma_neutron*(exp_term*CRNp.neutron_S_t*CRNp.P0_10Be
/Conc_10Be-CRNp.lambda_10Be);
app_eros = app_eff_eros*10/rho;
return app_eros;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void LSDCRNParticle::update_26Al_conc(double dt,double erosion_rate, LSDCRNParameters& CRNp)
{
double Al_exp = exp(-dt*CRNp.lambda_26Al);
double sum_term = 0;
for (int i = 0; i<4; i++)
{
sum_term+= (CRNp.F_26Al[i]*exp(-effective_dLoc/CRNp.Gamma[i])*CRNp.Gamma[i])*
(exp(dt*erosion_rate/CRNp.Gamma[i])-
exp(-dt*CRNp.lambda_26Al))/
(erosion_rate+CRNp.Gamma[i]*CRNp.lambda_26Al);
}
Conc_26Al = Conc_26Al*Al_exp + CRNp.S_t*Al_exp*CRNp.P0_26Al*sum_term;
}
void LSDCRNParticle::update_26Al_conc_neutron_only(double dt,double erosion_rate, LSDCRNParameters& CRNp)
{
double Gamma_neutron = CRNp.Gamma[0]; // in g/cm^2
double Al_exp = exp(-dt*CRNp.lambda_26Al);
double sum_term = 0;
sum_term+= (exp(-effective_dLoc/Gamma_neutron)*Gamma_neutron)*
(exp(dt*erosion_rate/Gamma_neutron)-
exp(-dt*CRNp.lambda_26Al))/
(erosion_rate+Gamma_neutron*CRNp.lambda_26Al);
Conc_26Al = Conc_26Al*Al_exp + CRNp.S_t*Al_exp*CRNp.P0_26Al*sum_term;