-
Notifications
You must be signed in to change notification settings - Fork 4
/
2D_backend_analysis.py
1995 lines (1612 loc) · 71 KB
/
2D_backend_analysis.py
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
'''
Created on Wed 07/11/2018
@author: Enok C., Yuming, Anthony
'''
'''make_list_with_floats.py'''
def csv2txtlistSlide3(fileName):
import csv
with open(fileName, 'r') as f:
reader = csv.reader(f)
csvListTxt = list(reader)
csvList = []
tempList = []
for idR in range(len(csvListTxt)):
csvListTxt[idR] = [x for x in csvListTxt[idR] if x != '']
for i in range(len(csvListTxt[idR])):
if csvListTxt[idR][i] == '':
continue
elif i==0 and (idR==0 or idR%22 ==0):
indList = list(csvListTxt[idR][i])
blankInx = indList.index(' ')
columnID = ''.join(csvListTxt[idR][i][(blankInx+1):])
tempList.append(int(columnID))
elif i!=0 and csvListTxt[idR][i].find(',') == -1:
tempList.append(float(csvListTxt[idR][i]))
elif i!=0 and csvListTxt[idR][i].find(',') != -1:
commaIdx = csvListTxt[idR][i].index(',')
tempList.append(float(csvListTxt[idR][i][0:commaIdx]))
tempList.append(float(csvListTxt[idR][i][(commaIdx+2):]))
if idR!=0 and len(tempList)==22:
csvList.append(tempList)
tempList = []
return csvList
def csv2list(fileName):
import csv
with open(fileName, 'r') as f:
reader = csv.reader(f)
csvListTxt = list(reader)
csvListNum = []
for idR in range(len(csvListTxt)):
csvListTxt[idR] = [x for x in csvListTxt[idR] if x != '']
tempList = [float(i) for i in csvListTxt[idR]]
csvListNum.append(tempList)
return csvListNum
def making_float_list(startNum, endNum, spacing):
result = []
length = 1 + abs(startNum - endNum)/abs(spacing)
for i in range(int(length)):
x = startNum + spacing*i
result.append(float(x))
return result
def concatenate_lists(parentList, addingList):
result = parentList[:]
for i in range(len(addingList)):
result.append(float(addingList[i]))
return result
def listAtColNum(listName,colNum):
result = []
for i in range(len(listName)):
result.append(float(listName[i][colNum]))
return result
def listAtColNumTxt(listName,colNum):
result = []
for i in range(len(listName)):
result.append(listName[i][colNum])
return result
def arrayAtColNum(arrayName,colNum):
import numpy as np
result = []
for i in range(len(arrayName)):
result.append(float(arrayName[i][colNum]))
result = np.array(result)
return result
# csv_file = filename of csv exported from list
# csv_column = column titles
# data_list = list data
def exportList2CSV(csv_file,data_list,csv_columns=None):
# export files
import csv
with open(csv_file, 'w',newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',')
if csv_columns != None:
writer.writerow(csv_columns)
for data in data_list:
writer.writerow(data)
'''
purpose: create slices with information at sides
Input: DEM surface, slice parameters, slip surfaces
Output: slices points
Interpolation methods used:
1. scipy interpolation interp1d
> linear - a1
2. kriging ordinary
> linear - b1
> power - b2
> gaussian - b3
> spherical - b4
> exponentail - b5
> hole-effect - b6
3. kriging universal
> linear - c1
> power - c2
> gaussian - c3
> spherical - c4
> exponentail - c5
> hole-effect - c6
'''
# interpolation method
def interpolation2D(interpolType, edgeXCoords, DEMname, stdMax, exportOption=0):
import numpy as np
tempArrayX, tempArrayY = np.array(csv2list(DEMname)).T
csvXY = []
''' interpolation method '''
#library import
if interpolType[0] == 'a':
from scipy.interpolate import interp1d
elif interpolType[0] == 'b':
from pykrige.ok import OrdinaryKriging
elif interpolType[0] == 'c':
from pykrige.uk import UniversalKriging
# scipy interpol1d
if interpolType == 'a1':
tempInterpolated = interp1d(tempArrayX, tempArrayY, bounds_error=False)
interpolY = tempInterpolated(edgeXCoords)
# pykrige ordinary kriging
elif interpolType == 'b1':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='linear')
interpolY, stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'b2':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='power')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'b3':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='gaussian')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'b4':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='spherical')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'b5':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='exponential')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'b6':
tempInterpolated = OrdinaryKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='hole-effect')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
# pykrige universal kriging
elif interpolType == 'c1':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='linear')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'c2':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='power')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'c3':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='gaussian')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'c4':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='spherical')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'c5':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='exponential')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
elif interpolType == 'c6':
tempInterpolated = UniversalKriging(tempArrayX, np.zeros(tempArrayX.shape), tempArrayY, variogram_model='hole-effect')
interpolY,stdY = tempInterpolated.execute('grid', edgeXCoords, np.array([0.]))
interpolY = interpolY[0]
stdY = stdY[0]
# for pykrige, eliminate points that has a large standard deviation
#print(interpolY)
#print(stdY)
if interpolType[0] in ['b','c']:
for loopYPred in range(len(interpolY)):
if stdY[loopYPred] > stdMax:
interpolY[loopYPred] = np.nan
#print(interpolY)
#print(stdY)
interpolY = interpolY.tolist()
for loopXY in range(len(interpolY)):
csvXY.append([edgeXCoords[loopXY], interpolY[loopXY]])
# export the interpolated data into csv file
if exportOption==0:
exportList2CSV('interpolated_'+DEMname, csvXY)
return csvXY
# function that will calculate y-coordinates (from csv files) for given x-coordinates of slice edges
def DEM_2D_slices(DEMNameList, DEMTypeList, DEMInterpolTypeList, canvasRange, sliceNumberMax, stdMax=10):
# import python libraries
import numpy as np
#import scipy
#import matplotlib.pyplot as plt
# slice X coordinates
edgeXCoords = np.linspace(canvasRange[0], canvasRange[1], sliceNumberMax+1)
#print(edgeXCoords)
'''Input file sorting'''
Y_pred = []
for loopFile in range(len(DEMNameList)):
Y_pred.append(interpolation2D(DEMInterpolTypeList[loopFile], edgeXCoords, DEMNameList[loopFile], stdMax, exportOption=0))
#print(Y_pred)
edgesX = {}
sliceN = {}
for loopX in range(len(edgeXCoords)):
tempPtY = [float(canvasRange[2])]
tempPtM = ['bb']
# input information to dictionary of edgesX
for loopFile in range(len(DEMNameList)):
interpolY_edge = Y_pred[loopFile][loopX][1]
#print(interpolY_edge)
if not(np.isnan(interpolY_edge)):
if DEMTypeList[loopFile] == 'tt' and interpolY_edge > canvasRange[3]:
tempPtY.append(float(canvasRange[3]))
tempPtM.append('tt')
elif DEMTypeList[loopFile] == 'tt' and interpolY_edge <= canvasRange[3]:
tempPtY.append(interpolY_edge)
tempPtM.append('tt')
elif DEMTypeList[loopFile] == 'rr' and interpolY_edge > canvasRange[2]:
tempPtY[0] = interpolY_edge
tempPtM[0] = 'rr'
else:
tempPtY.append(interpolY_edge)
tempPtM.append(DEMTypeList[loopFile])
edgesX[edgeXCoords[loopX]] = [tempPtY, tempPtM]
if loopX >= 1:
sliceN[loopX] = [edgeXCoords[loopX-1], edgesX[edgeXCoords[loopX-1]], edgeXCoords[loopX], edgesX[edgeXCoords[loopX]]]
#print(edgesX[36])
#print(sliceN[20])
return sliceN
''' DEM points of 2D slip surface '''
'''
SSTypeList = 1 -> user-defined surface
SSTypeList = 2 -> grid circular search
'''
# find base y-coordinates for a given slip surface
def SS_2D_slices(SSTypeList, inputPara, canvasRange, sliceNumberMax, sliceN, stdMax=10):
# import python libraries
import numpy as np
#import scipy
#from scipy.interpolate import interp1d
#from pykrige.ok import OrdinaryKriging
#from pykrige.uk import UniversalKriging
#import matplotlib.pyplot as plt
newSliceN = {}
ss_csv = []
# slice X coordinates
edgeXCoords = np.linspace(canvasRange[0], canvasRange[1], sliceNumberMax+1)
#print(edgeXCoords)
'''Input SS for each slice X coordiantes'''
ss_Y_pred = {}
if SSTypeList == 2: # circular grid search
# extract inputPara
pt0X = inputPara[0]
pt0Y = inputPara[1]
R = inputPara[2]
for loopX in range(len(edgeXCoords)):
if (R**2 - (edgeXCoords[loopX] - pt0X)**2) >= 0:
#tempPtYSS1 = pt0Y + np.sqrt(R**2 - (edgeXCoords[loopX] - pt0X)**2)
tempPtYSS = pt0Y - np.sqrt(R**2 - (edgeXCoords[loopX] - pt0X)**2)
else:
tempPtYSS = np.nan
ss_Y_pred[loopX] = [edgeXCoords[loopX], tempPtYSS]
elif SSTypeList == 1: # user-defined surface
# extract inputPara
DEMNameList = inputPara[0]
interpolType = inputPara[1]
tempPtYSS = interpolation2D(interpolType, edgeXCoords, DEMNameList, stdMax, exportOption=0)
for loopX in range(len(edgeXCoords)):
ss_Y_pred[loopX] = tempPtYSS[loopX]
#print(ss_Y_pred)
firstLeft = np.nan
lastRight = np.nan
for loopSlice in range(1,sliceNumberMax+1):
ssLY = ss_Y_pred[loopSlice-1][1]
ssRY = ss_Y_pred[loopSlice][1]
sliceLedgeY = sliceN[loopSlice]
sliceLedgeY = sliceLedgeY[1][0]
sliceRedgeY = sliceN[loopSlice]
sliceRedgeY = sliceRedgeY[3][0]
#print(ssLY, ssRY, max(sliceLedgeY), max(sliceRedgeY))
#print(loopSlice)
#print(np.isnan(ssLY) or np.isnan(ssRY) or ssLY >= max(sliceLedgeY) or ssRY >= max(sliceRedgeY) or ssLY < min(sliceLedgeY) or ssRY < min(sliceRedgeY))
if np.isnan(ssLY) or np.isnan(ssRY) or ssLY >= max(sliceLedgeY) or ssRY >= max(sliceRedgeY) or ssLY < min(sliceLedgeY) or ssRY < min(sliceRedgeY):
#if (np.isnan(ssLY) and not(np.isnan(ssRY))) or (not(np.isnan(ssLY)) and (np.isnan(ssRY)))
if np.isnan(ssLY) or np.isnan(ssRY) or ssLY >= max(sliceLedgeY) or ssRY >= max(sliceRedgeY):
if loopSlice == 1:
ss_csv.append([ss_Y_pred[loopSlice-1][0], np.nan])
ss_csv.append([ss_Y_pred[loopSlice][0], np.nan])
elif ssLY < min(sliceLedgeY) or ssRY < min(sliceRedgeY):
if loopSlice == 1:
ss_csv.append([ss_Y_pred[loopSlice-1][0], min(sliceLedgeY)])
ss_csv.append([ss_Y_pred[loopSlice][0], min(sliceRedgeY)])
elif not(np.isnan(ssLY)) and not(np.isnan(ssRY)) and (min(sliceLedgeY) <= ssLY < max(sliceLedgeY)) and (min(sliceRedgeY) <= ssRY < max(sliceRedgeY)):
if firstLeft == 0:
firstLeft = loopSlice-1
elif lastRight == 0 and firstLeft != 0:
lastRight = loopSlice+1
# add slip surface to slice edges - left
nsliceLedgeY = [0]
nsliceLedgeYtype = [0]
sliceLedgeYtype = sliceN[loopSlice]
sliceLedgeYtype = sliceLedgeYtype[1][1]
tempYss = []
tempYssType = []
for loopLayer in range(len(sliceLedgeYtype)):
if sliceLedgeYtype[loopLayer][0] in ['t','m','g']:
nsliceLedgeY.append(sliceLedgeY[loopLayer])
nsliceLedgeYtype.append(sliceLedgeYtype[loopLayer])
elif sliceLedgeYtype[loopLayer][0] in ['r','w','b']:
if loopLayer == 0:
tempYss.append(ssLY)
tempYssType.append('ss')
if ssLY <= sliceLedgeY[loopLayer]:
tempYss.append(sliceLedgeY[loopLayer])
tempYssType.append(sliceLedgeYtype[loopLayer])
#print(tempYss)
#print(tempYssType)
maxEdgeBottom = max(tempYss)
maxEdgeBottomIDX = tempYss.index(maxEdgeBottom)
maxEdgeBottomType = tempYssType[maxEdgeBottomIDX]
nsliceLedgeY[0] = maxEdgeBottom
nsliceLedgeYtype[0] = maxEdgeBottomType
if loopSlice == 1:
ss_csv.append([ss_Y_pred[loopSlice-1][0], maxEdgeBottom])
# add slip surface to slice edges - right
nsliceRedgeY = [0]
nsliceRedgeYtype = [0]
sliceRedgeYtype = sliceN[loopSlice]
sliceRedgeYtype = sliceRedgeYtype[3][1]
tempYss = []
tempYssType = []
for loopLayer in range(len(sliceRedgeYtype)):
if sliceRedgeYtype[loopLayer][0] in ['t','m','g']:
nsliceRedgeY.append(sliceRedgeY[loopLayer])
nsliceRedgeYtype.append(sliceRedgeYtype[loopLayer])
elif sliceRedgeYtype[loopLayer][0] in ['r','w','b']:
if loopLayer == 0:
tempYss.append(ssRY)
tempYssType.append('ss')
if ssLY <= sliceRedgeY[loopLayer]:
tempYss.append(sliceRedgeY[loopLayer])
tempYssType.append(sliceRedgeYtype[loopLayer])
#print(tempYss)
#print(tempYssType)
maxEdgeBottom = max(tempYss)
maxEdgeBottomIDX = tempYss.index(maxEdgeBottom)
maxEdgeBottomType = tempYssType[maxEdgeBottomIDX]
nsliceRedgeY[0] = maxEdgeBottom
nsliceRedgeYtype[0] = maxEdgeBottomType
ss_csv.append([ss_Y_pred[loopSlice][0], maxEdgeBottom])
newSliceN[loopSlice] = [ss_Y_pred[loopSlice-1][0], [nsliceLedgeY, nsliceLedgeYtype], ss_Y_pred[loopSlice][0], [nsliceRedgeY, nsliceRedgeYtype]]
if not np.isnan(firstLeft):
sliceLedge = sliceN[firstLeft]
sliceLedgeX = sliceLedge[0]
sliceLedgeY = sliceLedge[1][0]
sliceLedgeYtype = sliceLedge[1][1]
sliceRedge = sliceN[firstLeft]
sliceRedgeX = sliceRedge[2]
sliceRedgeY = sliceRedge[3][0]
sliceRedgeYtype = sliceRedge[3][1]
# add slip surface to slice edges - left
nsliceLedgeY = [0]
nsliceLedgeYtype = [0]
tt_sliceLedgeY_idx = sliceRedgeYtype.index('tt')
if SSTypeList == 2: # circular grid search
# extract inputPara
pt0X = inputPara[0]
pt0Y = inputPara[1]
R = inputPara[2]
tempPtXSS1 = pt0X + np.sqrt(R**2 - (sliceLedgeY[tt_sliceLedgeY_idx] - pt0Y)**2)
tempPtXSS2 = pt0X - np.sqrt(R**2 - (sliceLedgeY[tt_sliceLedgeY_idx] - pt0Y)**2)
if tempPtXSS1 > sliceLedgeX and tempPtXSS1 < sliceRedgeX:
ss_csv.append([tempPtXSS1, sliceLedgeY[tt_sliceLedgeY_idx]])
nsliceLedgeY[0] = sliceLedgeY[tt_sliceLedgeY_idx]
nsliceLedgeYtype[0] = 'tt'
elif tempPtXSS2 > sliceLedgeX and tempPtXSS2 < sliceRedgeX:
ss_csv.append([tempPtXSS2, sliceLedgeY[tt_sliceLedgeY_idx]])
nsliceLedgeY[0] = sliceLedgeY[tt_sliceLedgeY_idx]
nsliceLedgeYtype[0] = 'tt'
elif SSTypeList == 1: # user defined
DEMNameList = inputPara[0]
interpolType = inputPara[1]
tempPtYSS = interpolation2D(interpolType, (sliceLedgeX+sliceRedgeX)/2, DEMNameList, stdMax, exportOption=0)
ss_csv.append([(sliceLedgeX+sliceRedgeX)/2, tempPtYSS])
nsliceLedgeY[0] = tempPtYSS
nsliceLedgeYtype[0] = 'tt'
# add slip surface to slice edges - right
edgeRinfo = newSliceN[firstLeft+1]
edgeRinfo = edgeRinfo[1]
newSliceN[firstLeft] = [sliceLedgeX, [nsliceLedgeY, nsliceLedgeYtype], sliceRedgeX, edgeRinfo]
if not np.isnan(lastRight):
sliceLedge = sliceN[lastRight]
sliceLedgeX = sliceLedge[0]
sliceLedgeY = sliceLedge[1][0]
sliceLedgeYtype = sliceLedge[1][1]
sliceRedge = sliceN[lastRight]
sliceRedgeX = sliceRedge[2]
sliceRedgeY = sliceRedge[3][0]
sliceRedgeYtype = sliceRedge[3][1]
# add slip surface to slice edges - left
edgeLinfo = newSliceN[lastRight-1]
edgeLinfo = edgeLinfo[3]
# add slip surface to slice edges - right
nsliceRedgeY = [0]
nsliceRedgeYtype = [0]
tt_sliceRedgeYtype_idx = sliceRedgeYtype.index('tt')
if SSTypeList == 2: # circular grid search
# extract inputPara
pt0X = inputPara[0]
pt0Y = inputPara[1]
R = inputPara[2]
tempPtXSS1 = pt0X + np.sqrt(R**2 - (sliceRedgeY[tt_sliceRedgeYtype_idx] - pt0Y)**2)
tempPtXSS2 = pt0X - np.sqrt(R**2 - (sliceRedgeY[tt_sliceRedgeYtype_idx] - pt0Y)**2)
if tempPtXSS1 > sliceLedgeX and tempPtXSS1 < sliceRedgeX:
ss_csv.append([tempPtXSS1, sliceRedgeY[tt_sliceRedgeYtype_idx]])
nsliceRedgeY[0] = sliceRedgeY[tt_sliceRedgeYtype_idx]
nsliceRedgeYtype[0] = 'tt'
elif tempPtXSS2 > sliceLedgeX and tempPtXSS2 < sliceRedgeX:
ss_csv.append([tempPtXSS2, sliceRedgeY[tt_sliceRedgeYtype_idx]])
nsliceRedgeY[0] = sliceRedgeY[tt_sliceRedgeYtype_idx]
nsliceRedgeYtype[0] = 'tt'
elif SSTypeList == 1: # user defined
DEMNameList = inputPara[0]
interpolType = inputPara[1]
tempPtYSS = interpolation2D(interpolType, (sliceLedgeX+sliceRedgeX)/2, DEMNameList, stdMax, exportOption=0)
ss_csv.append([(sliceLedgeX+sliceRedgeX)/2, tempPtYSS])
nsliceRedgeY[0] = tempPtYSS
nsliceRedgeYtype[0] = 'tt'
newSliceN[lastRight] = [sliceLedgeX, edgeLinfo, sliceRedgeX, [nsliceRedgeY, nsliceRedgeYtype]]
#print(ss_csv)
if len(newSliceN.keys()) == 0:
return None
else:
exportList2CSV('interpolated_ss_type'+str(SSTypeList)+'.csv', ss_csv)
return newSliceN, ss_csv
# find center of rotation and radius of user-defined slip surface
def findpt0nR_2D(ss_csv):
import numpy as np
# starting and ending index
startID = 0
endID = 0
for loopID in range(len(ss_csv)):
if np.isnan(ss_csv[loopID][1]):
if startID != 0 and endID == 0 and not(np.isnan(ss_csv[loopID-1][1])):
endID = loopID-1
break
else:
continue
else:
if startID == 0:
startID = loopID
else:
continue
#print(ss_csv[startID])
#print(ss_csv[startID+3])
#print(ss_csv[endID])
P1x = ss_csv[startID][0]
P1y = ss_csv[startID][1]
P2x = ss_csv[startID+3][0]
P2y = ss_csv[startID+3][1]
P3x = ss_csv[endID][0]
P3y = ss_csv[endID][1]
DistSq1 = P1x**2 + P1y**2
DistSq2 = P2x**2 + P2y**2
DistSq3 = P3x**2 + P3y**2
M11 = np.array([[P1x, P1y, 1],[P2x, P2y, 1],[P3x, P3y, 1]])
M12 = np.array([[DistSq1, P1y, 1],[DistSq2, P2y, 1],[DistSq3, P3y, 1]])
M13 = np.array([[DistSq1, P1x, 1],[DistSq2, P2x, 1],[DistSq3, P3x, 1]])
M14 = np.array([[DistSq1, P1x, P1y],[DistSq2, P2x, P2y],[DistSq3, P3x, P3y]])
pt0X = 0.5*np.linalg.det(M12)/np.linalg.det(M11)
pt0Y = -0.5*np.linalg.det(M13)/np.linalg.det(M11)
R = np.sqrt(pt0X**2 + pt0Y**2 + (np.linalg.det(M14)/np.linalg.det(M11)))
return [round(pt0X,3), round(pt0Y,3), round(R,3)]
'''calculate area using shoelace theorem'''
def area_np(x, y):
import numpy as np
x = np.asanyarray(x)
y = np.asanyarray(y)
n = len(x)
shift_up = np.arange(-n+1, 1)
shift_down = np.arange(-1, n-1)
return abs((x * (y.take(shift_up) - y.take(shift_down))).sum() / 2.0)
'''2D LEM Slope Analysis - compute R, f, x and e for moment arm for moment equilibrium '''
'''
Input - X,Y coordinate of each slices, central point of rotation
Output - moment arm of R, f, x and e for corresponding Sm, N, W and k*W
## Input file column legend of inputSlice
0(A) - slice number
1(B) - central coordinate X
2(C) - central coordinate Y at top
3(D) - central coordinate Y at base
4(E) - slice horizontal width
5(F) - slice base angle from horizontal (alpha)
## output file column legend
0(A) - slice number
1(B) - radius (R)
2(C) - perpendicular offset from center of rotation(f)
3(D) - horizontal distance from slice to the center of rotation (x)
4(E) - vertical distance from C.G. of slice to the center of rotation (e)
'''
def computeRfxe_2D(inputSlice, cenPt0):
# import functions python libraries
#import numpy as np
import math
# compute horizontal moment arm (x)
xi = abs(inputSlice[1] - cenPt0[0])
# compute vertical moment arm for horizontal seismic (e)
ei = abs(cenPt0[1] - 0.5*(inputSlice[2]+inputSlice[3]))
# compute moment arm of Ri and fi
RY = abs(cenPt0[1] - inputSlice[3])
RR = math.sqrt(xi**2 + RY**2)
deltaRangleY = round(90 - (abs(inputSlice[5]) + abs(math.degrees(math.atan(RY/xi)))),2)
if deltaRangleY == 0:
Ri = RR
fi = 0
elif deltaRangleY != 0:
Ri = RR*math.cos(math.radians(deltaRangleY))
fi = RR*math.sin(math.radians(deltaRangleY))
return [Ri, fi, xi, ei]
# GW level, pwp
def GW_2D(inputFile, baseZ, water_unitWeight):
import math
dictKeys = inputFile.keys()
output = {}
for loopSlice in dictKeys:
# check presence of GW level
checkGW_left = 0
if 'gw' in inputFile[loopSlice][1][1]:
gwLindex = inputFile[loopSlice][1][1]
gwLindex = gwLindex.index('gw')
gwyL = inputFile[loopSlice][1][0][gwLindex]
xL = inputFile[loopSlice][0]
ytL = inputFile[loopSlice][1][0][-1]
ybL = inputFile[loopSlice][1][0][0]
checkGW_left = 1
checkGW_right = 0
if 'gw' in inputFile[loopSlice][3][1]:
gwRindex = inputFile[loopSlice][3][1]
gwRindex = gwRindex.index('gw')
gwyR = inputFile[loopSlice][3][0][gwLindex]
xR = inputFile[loopSlice][2]
ytR = inputFile[loopSlice][3][0][-1]
ybR = inputFile[loopSlice][3][0][0]
checkGW_right = 1
if checkGW_left == 0 and checkGW_right == 0:
continue
elif checkGW_left != 0 and checkGW_right == 0:
gwyR = baseZ
xR = inputFile[loopSlice][2]
ytR = inputFile[loopSlice][3][0][-1]
ybR = inputFile[loopSlice][3][0][0]
elif checkGW_left == 0 and checkGW_right != 0:
gwyL = baseZ
xL = inputFile[loopSlice][0]
ytL = inputFile[loopSlice][1][0][-1]
ybL = inputFile[loopSlice][1][0][0]
# calculate angle of GW inclination
GWangle = abs(math.atan((gwyR-gwyL)/(xR-xL)))
# define l
lb_l = gwyL - ybL
lb_r = gwyR - ybR
lt_l = max([gwyL - ytL, 0])
lt_r = max([gwyR - ytR, 0])
# for top, take only positive hw
# calculate hw for left, right, base, top
hw_l = lb_l*(math.cos(GWangle))**2
hw_r = lb_r*(math.cos(GWangle))**2
hw_b = (hw_l+hw_r)/2
hw_t = 0.5*(lt_l*((math.cos(GWangle))**2)+lt_r*((math.cos(GWangle))**2))
# calculate net hw for side and base
hw_b_net = hw_b - hw_t
if hw_b_net < 0:
hw_s_net = 0
else:
hw_s_net = abs(hw_l-hw_r)
output[loopSlice] = [hw_l*water_unitWeight, hw_r*water_unitWeight, hw_t*water_unitWeight, hw_b*water_unitWeight, hw_s_net*water_unitWeight, hw_b_net*water_unitWeight]
return output
# main function - slope stability base shear parameters with class input
## Input file column legend
'''
1 = Mohr-Coulomb - [phi', c']
2 = undrained - depth - [shear_max, shear_min, Su_top, diff_Su]
3 = undrained - datum - [shear_max, shear_min, Su_datum, diff_Su, z_datum]
4 = power curve - [P_atm, a, b]
5 = shear-normal user defined function - [fileName]
unsaturated - [phi_b, aev, us_max]
'''
def shearModel2cphi(materialClass, materialName, Z, Ztop, eff_normal_stress, matricSuction):
#import math
import making_list_with_floats as makelist
import numpy as np
# materialClass takes input
# class[name] = [modelType, inputPara]
material = materialClass[materialName]
modelType = material[0]
inputPara = material[1][0]
unsaturatedPara = material[1][1]
calcPhiC=[]
#userShearNormal_mc=[]
# Mohr-Coulomb Model
if modelType in [1,10]:
calcPhiC.append([inputPara[0], inputPara[1]])
# undrained - depth
elif modelType in [2,20]:
calcShear = inputPara[2] + inputPara[3]*(Ztop - Z)
if calcShear < inputPara[1]: # lower than min shear
calcShear = inputPara[1]
if calcShear > inputPara[0]: # higher than max shear
calcShear = inputPara[0]
calcPhiC.append([0, calcShear])
# undrained - datum
elif modelType in [3,30]:
calcShear = inputPara[2] + inputPara[3]*abs(inputPara[4] - Z)
if calcShear < inputPara[1]: # lower than min shear
calcShear = inputPara[1]
if calcShear > inputPara[0]: # higher than max shear
calcShear = inputPara[0]
calcPhiC.append([0, calcShear])
# power curve
elif modelType in [4,40]:
calcShear = inputPara[0]*inputPara[1]*(eff_normal_stress/inputPara[0])**inputPara[2]
calcPhiC.append([0, calcShear])
# user defined shear-normal force
elif modelType in [5,50]:
userShearNormal = makelist.csv2list(inputPara[0])
for loopSN in range(len(userShearNormal)-1):
if inputPara[1] <= userShearNormal[loopSN+1][0] and inputPara[1] >= userShearNormal[loopSN][0]:
gradient = (userShearNormal[loopSN+1][1] - userShearNormal[loopSN][1])/(userShearNormal[loopSN+1][0] - userShearNormal[loopSN][0])
intercept = userShearNormal[loopSN][1] - gradient*userShearNormal[loopSN][0]
#userShearNormal_mc.append([gradient, intercept])
calcShear = gradient*eff_normal_stress + intercept
break
elif inputPara[1] >= userShearNormal[len(userShearNormal)][0]:
#print('out of range of nonlinear curve')
calcShear = userShearNormal[len(userShearNormal)][1]
break
else:
continue
calcPhiC.append([0, calcShear])
# adding unsaturated strength
if round(modelType/10) in [1,2,3,4,5]:
if matricSuction >= unsaturatedPara[1]:
unsatShearStrength = min([matricSuction, unsaturatedPara[2]])*np.tan(np.radians(unsaturatedPara[0]))
calcPhiC[1] += unsatShearStrength
return calcPhiC
''' main function - 2D slope stability support forces calculations from class of support type '''
'''
0 = User Defined Support - [type, F(0), d1, d2, d]
1 = End Anchored - [type, T]
2 = GeoTextile - [type, A(%), phi, a, T, anchorage_setting]
3 = Grouted Tieback - [type, T, P, B]
4 = Grouted Tieback with Friction - [type, T, P, phi, a, D]
5 = Micro Pile - [type, T]
6 = Soil Nail - [type, T, P, B]
'''
'''
def support_analysis(supportClass, supportName, Ana2D3D=2, Li=None, Lo=None, spacing2D=1, eff_normal_stress=None):
import math
import making_list_with_floats as makelist
# converting the input csv file into a list
supportInput = supportClass[supportName]
F_applied=[]
# for 3D analysis, set S to 1
if Ana2D3D==3:
Spacing=1
elif Ana2D3D==2:
Spacing=spacing2D
# End Anchored - 1 = End Anchored - [type, T]
if supportInput[0] == 1:
F=supportInput[1]/Spacing
F_applied.append(F)
# GeoTextile - #2 = GeoTextile - [type, A(%), phi, a, T, anchorage_setting]
# For GeoTextile Anchorage, 0 = not applicable, 1 = None, 2 = slope face, 3 = embedded end, 4 = both ends
elif supportInput[0] == 2:
# F=[F1:Pullout, F2:Tensile Failure, F3:Stripping]
F=[2*Lo*supportInput[1]*(supportInput[3] + eff_normal_stress*math.tan(math.radians(supportInput[2])))/100, supportInput[4]*Lo/100, 2*Li*supportInput[1]*(supportInput[3] + eff_normal_stress*math.tan(math.radians(supportInput[2])))/100]
if supportInput[5] == 1:
F_applied.append(min(F))
elif supportInput[5]== 2:
F_applied.append(min(F[1],F[2]))
elif supportInput[5] == 3:
F_applied.append(min(F[2],F[3]))
elif supportInput[5] == 4:
F_applied.append(F[2])
# Grouted Tieback - [type, T, P, B]
elif supportInput[0] == 3:
# F=[F1:Pullout, F2:Tensile Failure, F3:Stripping]
F=[supportInput[3]*Lo/Spacing, supportInput[1]/Spacing, (supportInput[2]+supportInput[3]*Li)/Spacing]
F_applied.append(min(F))
# Grouted Tieback with Friction - [type, T, P, phi, a, D]
elif supportInput[0] == 4:
# F=[F1:Pullout, F2:Tensile Failure, F3:Stripping]
strengthModel = supportInput[4] + eff_normal_stress*np.tan(np.radians(supportInput[3]))
F=[math.pi*supportInput[5]*Lo*strengthModel/Spacing, supportInput[1]/Spacing, (supportInput[2] + math.pi*supportInput[5]*Li*strengthModel)/Spacing]
F_applied.append(min(F))
# Micro Pile - [type, T]
elif supportInput[0] == 5:
F=supportInput[1]/Spacing
F_applied.append(F)
# Soil Nail - [type, T, P, B]
elif supportInput[0] == 6:
F=[supportInput[3]*Lo/Spacing, supportInput[1]/Spacing, (supportInput[2]+supportInput[3]*Li)/Spacing]
F_applied.append(min(F))
# User Defined Support - [type, T, F(0), d1, d2] - 6,10,11,12,13
elif supportInput[0] == 0:
if Li < supportInput[d1]:
slope1 = (supportInput[1]-supportInput[2])/supportInput[3]
F = slope1*Li + supportInput[2]
F_applied.append(F)
elif Li >= supportInput[3] and Li <= (supportInput[3]+supportInput[4]):
F=supportInput[1]
F_applied.append(F)
elif Li > (supportInput[3]+supportInput[4]):
slope2=(0-supportInput[1])/((Lo+Li)-supportInput[3]-supportInput[4])
F=slope2*(Li-supportInput[3]-supportInput[4])+supportInput[1]
F_applied.append(F)
return F_applied[0]
'''
# find geometric data (area, base, width) for each slice
def createInputfile4Analysis_2D_slices(newSliceN, L2R_or_R2L, seismicK, pt0, sliceNumberMax, materialClass, canvasRange, water_unitWeight, tensionCrackAngle=None):
# import python libraries
import numpy as np
#import scipy
#import matplotlib.pyplot as plt
analysisInputFile = [[2,0,1]]
analysisInputFile.append([2, 0, 1, len(newSliceN), L2R_or_R2L, pt0[0], pt0[1], seismicK, 0, 0, 0])
sliceKeyList = newSliceN.keys()
# width, base length, inclination (base, top), side left length, side right length
sliceInfo_bAlalphaBeta = {}
sliceInfo_W = {} # weight
for sliceN in sliceKeyList:
tempList = []
# slice width (b) and base length (l)
b = abs(newSliceN[sliceN][0] - newSliceN[sliceN][2])
l = np.sqrt((newSliceN[sliceN][1][0][0] - newSliceN[sliceN][3][0][0])**2 + (newSliceN[sliceN][0] - newSliceN[sliceN][2])**2)
tempList.append(b)
tempList.append(l)
# base angle and top angle (alpha and beta)
alpha = abs((newSliceN[sliceN][1][0][0] - newSliceN[sliceN][3][0][0])/(newSliceN[sliceN][0] - newSliceN[sliceN][2]))
beta = abs((newSliceN[sliceN][1][0][-1] - newSliceN[sliceN][3][0][-1])/(newSliceN[sliceN][0] - newSliceN[sliceN][2]))
tempList.append(alpha)
tempList.append(beta)
# side left length, side right length
sideL = abs((newSliceN[sliceN][1][0][0] - newSliceN[sliceN][1][0][-1]))
sideR = abs((newSliceN[sliceN][3][0][0] - newSliceN[sliceN][3][0][-1]))
tempList.append(sideL)
tempList.append(sideR)
# individual areas and their unit weights
tempArea = []
tempUnitWeight = []
if sliceN == min(sliceKeyList):
numDiffAreasL = 0
numDiffAreasR = len(newSliceN[sliceN][3][1])-2
for loopArea in range(numDiffAreasR):
xList = [newSliceN[sliceN][0], newSliceN[sliceN][2], newSliceN[sliceN][2]]
yList = [newSliceN[sliceN][1][0][0], newSliceN[sliceN][3][0][loopArea], newSliceN[sliceN][3][0][loopArea+1]]
tempType=[newSliceN[sliceN][1][1][0], newSliceN[sliceN][3][1][loopArea], newSliceN[sliceN][3][1][loopArea+1]]
tempArea.append(area_np(xList, yList))
if 'gw' in tempType:
for loopAtype in range(loopArea+1, len(newSliceN[sliceN][3][1])):
if newSliceN[sliceN][3][1][loopAtype][0] in ['m']:
tempUnitWeight.append(materialClass[newSliceN[sliceN][3][1][loopAtype]][3])
break
else:
continue
#elif tempType[0][0] in ['r','w']:
# tempAreaType.append(tempType[1])
else:
tempUnitWeight.append(materialClass[newSliceN[sliceN][3][1][loopAtype]][2])
elif sliceN == max(sliceKeyList):
numDiffAreasL = len(newSliceN[sliceN][1][1])-2
numDiffAreasR = 0
for loopArea in range(numDiffAreasL):
xList = [newSliceN[sliceN][2], newSliceN[sliceN][2], newSliceN[sliceN][0]]
yList = [newSliceN[sliceN][1][0][loopArea], newSliceN[sliceN][1][0][loopArea+1], newSliceN[sliceN][3][0][0]]
tempType=[newSliceN[sliceN][1][1][loopArea], newSliceN[sliceN][1][1][loopArea+1], newSliceN[sliceN][3][1][0]]
tempArea.append(area_np(xList, yList))
if 'gw' in tempType:
for loopAtype in range(loopArea+1, len(newSliceN[sliceN][1][1])):
if newSliceN[sliceN][1][1][loopAtype][0] in ['m']:
tempUnitWeight.append(materialClass[newSliceN[sliceN][1][1][loopAtype]][3])
break
else:
continue
#elif tempType[0][0] in ['r','w']:
# tempAreaType.append(tempType[1])
else:
tempUnitWeight.append(materialClass[newSliceN[sliceN][1][1][loopAtype]][2])
else:
numDiffAreasL = len(newSliceN[sliceN][1][1])-2
numDiffAreasR = len(newSliceN[sliceN][3][1])-2
for loopArea in range(min([numDiffAreasL, numDiffAreasR])):
xList = [newSliceN[sliceN][0], newSliceN[sliceN][0], newSliceN[sliceN][2], newSliceN[sliceN][2]]
yList = [newSliceN[sliceN][1][0][loopArea], newSliceN[sliceN][1][0][loopArea+1], newSliceN[sliceN][3][0][loopArea+1], newSliceN[sliceN][3][0][loopArea]]