File: WedgeYADE.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (563 lines) | stat: -rwxr-xr-x 17,780 bytes parent folder | download | duplicates (2)
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
# -*- encoding=utf-8 -*-
#CW BOON 2018
# Use the following algorithms:
# CW Boon, GT Houlsby, S Utili (2012).  A new algorithm for contact detection between convex polygonal and polyhedral particles in the discrete element method.  Computers and Geotechnics 44, 73-82.
# CW Boon, GT Houlsby, S Utili (2015).  A new rock slicing method based on linear programming.  Computers and Geotechnics 65, 12-29.

#The code runs some steps to stabilise.  After that a vertical cut is carried out.  And the simulations shows the failure mechanism of the slope.
#Display is saved to a vtk file in the "vtk" folder and the user is required to load it using ParaView.  Control the frequency of printing a vtk file using vtkRecorder.iterPeriod in python

#Disclaimer: This script is just for illustration to demonstrate the function of Block Gen and PotentialBlock Code, and not for other purpose outside for this intended use

#To use this script:
#Compile with
#ENABLE_POTENTIAL_BLOCKS=ON, and add  sudo apt-get install
#coinor-clp,
#coinor-libclp-dev,
#coinor-libclp1,
#coinor-libosi1v5

import os
import errno
try:
	os.mkdir('./vtk/')
except OSError as exc:
	if exc.errno != errno.EEXIST:
		raise
	pass

name = 'BlockGeneration'

p = BlockGen()
p.maxRatio = 10000.0
p.minSize = 7.0
p.density = 2700  # 23.6/9.81*1000.0 	#kg/m3
p.dampingMomentum = 0.8
p.viscousDamping = 0.0
p.Kn = 2.0e8  #
p.Ks = 0.1e8  #
p.frictionDeg = 50.0  #degrees
p.traceEnergy = False
p.defaultDt = 1e-4
p.rForPP = 0.2  #0.04
p.kForPP = 0.0
p.RForPP = 1800.0
p.gravity = [0, 0, 9.81]
#p.inertiaFactor = 1.0
p.initialOverlap = 1e-6
p.exactRotation = True
#p.shrinkFactor = 1.0
p.boundarySizeXmin = 20.0
#South
p.boundarySizeXmax = 20.0
#North
p.boundarySizeYmin = 20.0
#West
p.boundarySizeYmax = 20
#East 4100
p.boundarySizeZmin = 0.0
#Up
p.boundarySizeZmax = 40.0
#Down
p.persistentPlanes = False
p.jointProbabilistic = True
p.opening = False
p.boundaries = True
p.slopeFace = False
p.calContactArea = True
p.twoDimension = False
p.unitWidth2D = 9.0
p.intactRockDegradation = True
#p.useFaceProperties = False
p.neverErase = False  # Must be used when tension is on
p.sliceBoundaries = True
p.filenamePersistentPlanes = ''
p.filenameProbabilistic = './joints/jointC.csv'  #  PLEASE CHEK THIS
p.filenameOpening = ''  #'./joints/opening.csv'
p.filenameBoundaries = ''
p.filenameSlopeFace = ''
p.filenameSliceBoundaries = ''
p.directionA = Vector3(1, 0, 0)
p.directionB = Vector3(0, 1, 0)
p.directionC = Vector3(0, 0, 1)

p.saveBlockGenData = True  #if True, data of the BlockGen are written in a file; if False, they are displayed on the terminal
p.outputFile = "BlockGen_Output.txt"  #if empty, the block generation data are not written at all

p.load()
O.engines[1].avoidSelfInteractionMask = 2
O.engines[2].lawDispatcher.functors[0].initialOverlapDistance = p.initialOverlap - 1e-6
O.engines[2].lawDispatcher.functors[0].allowBreakage = False
O.engines[2].lawDispatcher.functors[0].allowViscousAttraction = True
O.engines[2].lawDispatcher.functors[0].traceEnergy = False

O.engines[2].physDispatcher.functors[0].kn_i = 2e9
O.engines[2].physDispatcher.functors[0].ks_i = 0.1e9

from yade import plot

rockFriction = 40.0
boundaryFriction = 40.0
targetFriction = 40.0
waterHeight = 460.0  # PLEASE CHEK THIS 460.0 #
startCountingBrokenBonds = False
minTimeStep = 1000000.0
westBodyId = 10  #PLEASE CHEK THIS
midBodyId = 10  #PLEASE CHEK THIS
eastBodyId = 10  #PLEASE CHEK THIS
originalPositionW = O.bodies[westBodyId].state.pos
originalPositionE = O.bodies[eastBodyId].state.pos
originalPositionM = O.bodies[midBodyId].state.pos
velocityDependency = False

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Engines
O.engines[3].label = 'integration'
O.dt = 10.0e-5  #10e-4
O.engines = O.engines + [
        PotentialBlockVTKRecorder(
                fileName='./vtk/Wedge',
                iterPeriod=2000,
                twoDimension=False,
                sampleX=70,
                sampleY=70,
                sampleZ=70,
                maxDimension=100.0,
                REC_INTERACTION=True,
                REC_VELOCITY=True,
                label='vtkRecorder'
        )
]
O.engines = O.engines + [PyRunner(iterPeriod=2000, command='calTimeStep()')]
O.engines = O.engines + [PyRunner(iterPeriod=200, command='myAddPlotData()')]
O.engines = O.engines + [PyRunner(iterPeriod=200, command='goToNextStage2()', label='dispChecker')]

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Material
O.materials.append(FrictMat(young=-1, poisson=-1, density=p.density, frictionAngle=radians(0.0), label='frictionless'))

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Boundary Plates
thickness = 0.1 * p.boundarySizeZmax
wire = False
highlight = False
kPP = p.kForPP
rPP = p.rForPP

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Bottom plate
bbb = Body()
bbb.mask = 3
color = [0, 0.5, 1]
aPP = [1, -1, 0, 0, 0, 0]
bPP = [0, 0, 1, -1, 0, 0]
cPP = [0, 0, 0, 0, 1, -1]
dPP = [p.boundarySizeXmax - rPP, p.boundarySizeXmax - rPP, p.boundarySizeYmax - rPP, p.boundarySizeYmax - rPP, thickness - rPP, thickness - rPP]
minmaxAabb = 1.05 * Vector3(dPP[0], dPP[2], dPP[4])
bbb.shape = PotentialBlock(
        k=kPP,
        r=rPP,
        R=0.0,
        a=aPP,
        b=bPP,
        c=cPP,
        d=dPP,
        id=len(O.bodies),
        isBoundary=True,
        color=color,
        wire=wire,
        highlight=highlight,
        AabbMinMax=True,
        minAabb=minmaxAabb,
        maxAabb=minmaxAabb,
        fixedNormal=True,
        boundaryNormal=Vector3(0, 0, -1)
)
utils._commonBodySetup(bbb, bbb.shape.volume, bbb.shape.inertia, material='frictionless', pos=[0, 0, p.boundarySizeZmax + thickness], fixed=True)
bbb.state.ori = bbb.shape.orientation
O.bodies.append(bbb)

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Lateral plate A
bA = Body()
bA.mask = 3
color = [0, 0.5, 1]
aPP = [1, -1, 0, 0, 0, 0]
bPP = [0, 0, 1, -1, 0, 0]
cPP = [0, 0, 0, 0, 1, -1]
dPP = [p.boundarySizeXmax - rPP, p.boundarySizeXmax - rPP, thickness - rPP, thickness - rPP, 0.5 * p.boundarySizeZmax - rPP, 0.5 * p.boundarySizeZmax - rPP]
minmaxAabb = 1.05 * Vector3(dPP[0], dPP[2], dPP[4])
bA.shape = PotentialBlock(
        k=kPP,
        r=rPP,
        R=0.0,
        a=aPP,
        b=bPP,
        c=cPP,
        d=dPP,
        id=len(O.bodies),
        isBoundary=True,
        color=color,
        wire=wire,
        highlight=highlight,
        AabbMinMax=True,
        minAabb=minmaxAabb,
        maxAabb=minmaxAabb,
        fixedNormal=True,
        boundaryNormal=Vector3(0, -1, 0)
)
utils._commonBodySetup(
        bA, bA.shape.volume, bA.shape.inertia, material='frictionless', pos=[0, p.boundarySizeYmax + thickness, 0.5 * p.boundarySizeZmax], fixed=True
)
bA.state.ori = bA.shape.orientation
O.bodies.append(bA)

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Lateral plate B
bB = Body()
bB.mask = 3
color = [0, 0.5, 1]
aPP = [1, -1, 0, 0, 0, 0]
bPP = [0, 0, 1, -1, 0, 0]
cPP = [0, 0, 0, 0, 1, -1]
dPP = [p.boundarySizeXmax - rPP, p.boundarySizeXmax - rPP, thickness - rPP, thickness - rPP, 0.5 * p.boundarySizeZmax - rPP, 0.5 * p.boundarySizeZmax - rPP]
minmaxAabb = 1.05 * Vector3(dPP[0], dPP[2], dPP[4])
bB.shape = PotentialBlock(
        k=kPP,
        r=rPP,
        R=0.0,
        a=aPP,
        b=bPP,
        c=cPP,
        d=dPP,
        id=len(O.bodies),
        isBoundary=True,
        color=color,
        wire=wire,
        highlight=highlight,
        AabbMinMax=True,
        minAabb=minmaxAabb,
        maxAabb=minmaxAabb,
        fixedNormal=True,
        boundaryNormal=Vector3(0, 1, 0)
)
utils._commonBodySetup(
        bB, bB.shape.volume, bB.shape.inertia, material='frictionless', pos=[0, -p.boundarySizeYmax - thickness, 0.5 * p.boundarySizeZmax], fixed=True
)
bB.state.ori = bB.shape.orientation
O.bodies.append(bB)

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Lateral plate C
bC = Body()
bC.mask = 3
color = [0, 0.5, 1]
aPP = [1, -1, 0, 0, 0, 0]
bPP = [0, 0, 1, -1, 0, 0]
cPP = [0, 0, 0, 0, 1, -1]
dPP = [thickness - rPP, thickness - rPP, p.boundarySizeYmax - rPP, p.boundarySizeYmax - rPP, 0.5 * p.boundarySizeZmax - rPP, 0.5 * p.boundarySizeZmax - rPP]
minmaxAabb = 1.05 * Vector3(dPP[0], dPP[2], dPP[4])
bC.shape = PotentialBlock(
        k=kPP,
        r=rPP,
        R=0.0,
        a=aPP,
        b=bPP,
        c=cPP,
        d=dPP,
        id=len(O.bodies),
        isBoundary=True,
        color=color,
        wire=wire,
        highlight=highlight,
        AabbMinMax=True,
        minAabb=minmaxAabb,
        maxAabb=minmaxAabb,
        fixedNormal=True,
        boundaryNormal=Vector3(1, 0, 0)
)
utils._commonBodySetup(
        bC, bC.shape.volume, bC.shape.inertia, material='frictionless', pos=[-p.boundarySizeXmax - thickness, 0, 0.5 * p.boundarySizeZmax], fixed=True
)
bC.state.ori = bC.shape.orientation
O.bodies.append(bC)

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
# Lateral plate D
bD = Body()
bD.mask = 3
color = [0, 0.5, 1]
aPP = [1, -1, 0, 0, 0, 0]
bPP = [0, 0, 1, -1, 0, 0]
cPP = [0, 0, 0, 0, 1, -1]
dPP = [thickness - rPP, thickness - rPP, p.boundarySizeYmax - rPP, p.boundarySizeYmax - rPP, 0.5 * p.boundarySizeZmax - rPP, 0.5 * p.boundarySizeZmax - rPP]
minmaxAabb = 1.05 * Vector3(dPP[0], dPP[2], dPP[4])
bD.shape = PotentialBlock(
        k=kPP,
        r=rPP,
        R=0.0,
        a=aPP,
        b=bPP,
        c=cPP,
        d=dPP,
        id=len(O.bodies),
        isBoundary=True,
        color=color,
        wire=wire,
        highlight=highlight,
        AabbMinMax=True,
        minAabb=minmaxAabb,
        maxAabb=minmaxAabb,
        fixedNormal=True,
        boundaryNormal=Vector3(-1, 0, 0)
)
utils._commonBodySetup(
        bD, bD.shape.volume, bD.shape.inertia, material='frictionless', pos=[p.boundarySizeXmax + thickness, 0, 0.5 * p.boundarySizeZmax], fixed=True
)
bD.state.ori = bD.shape.orientation
O.bodies.append(bD)


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def calTimeStep():
	global minTimeStep
	mkratio = 99999999.9
	maxK = 0.0
	minMass = 1.0e15
	for i in O.interactions:
		if i.isReal == True:
			dt1 = O.bodies[i.id1].state.mass / i.phys.kn
			dt2 = O.bodies[i.id2].state.mass / i.phys.kn
			if dt1 < dt2:
				presentDt = 0.15 * sqrt(dt1)
				if minTimeStep > presentDt:
					minTimeStep = presentDt
					O.dt = minTimeStep
			else:
				presentDt = 0.15 * sqrt(dt2)
				if minTimeStep > presentDt:
					minTimeStep = presentDt
					O.dt = minTimeStep


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def excavate():
	for b in O.bodies:
		if NorthWall(b.state.pos[0], b.state.pos[1], b.state.pos[2]) < 0.001:
			if b.isClumpMember == True and b.shape.isBoundary == False:
				O.bodies.deleteClumpMember(O.bodies[b.clumpId], b)
			elif b.isClump == False and b.shape.isBoundary == False:
				O.bodies.erase(b.id)
				continue
	O.bodies.erase(bA.id)
	O.bodies.erase(bC.id)


prevDistance = O.bodies[westBodyId].state.pos[0]
tolDistance = 0.003  #0.1
tolDistance2 = 0.05
SRinProgress = False
SRcounter = 0
checkIter = 0
prevKE = 0.0
currentKE = 0.0
tolKE = 10e10
initBondedContacts = 0
initDispRate = -1.0
prevDispRate = 0


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def changeKE(newKE):
	global tolKE
	tolKE = newKE


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def changeTolDist(newTol):
	global tolDistance
	tolDistance = newTol


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
removeDampingBool = False


def goToNextStage2():
	global startCountingBrokenBonds
	global velocityDependency
	global waterHeight
	global boundaryFriction
	global rockFriction
	global targetFriction
	global prevDistance
	global originalPositionW
	global tolDistance
	global tolDistance2
	global checkIter
	global SRinProgress
	global SRcounter
	global prevKE
	global currentKE
	global tolKE
	global initDispRate
	global prevDispRate
	global removeDampingBool
	prevKE = currentKE
	KE = utils.kineticEnergy()
	currentKE = KE
	uf = utils.unbalancedForce()
	if O.iter > 500 and removeDampingBool == False:
		removeDamping()
		removeDampingBool = True
	if O.iter > 2000 and SRcounter == 0:  # and uf<0.005:
		print(O.iter)
		O.pause()
		vtkRecorder.iterPeriod = 1
		for b in O.bodies:
			b.state.vel = Vector3(0.0, 0.0, 0.0)
			b.state.angVel = Vector3(0.0, 0.0, 0.0)
		calTimeStep()
		excavate()
		dispChecker.iterPeriod = 1
		SRcounter = 1
		O.step()
		vtkRecorder.iterPeriod = 500
		O.run(20000)
		return


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def SouthWall(x, y, z):
	Xcentre1 = 0.0
	Ycentre1 = 0.0
	Zcentre1 = -0.0
	dip = 90.0
	dipdir = 315.0
	dipdirN = 0.0
	dipN = 90.0 - dip
	if dipdir > 180.0:
		dipdirN = dipdir - 180.0
	else:
		dipdirN = dipdir + 180.0
	dipRad = dipN / 180.0 * pi
	dipdirRad = dipdirN / 180.0 * pi
	a = cos(dipdirRad) * cos(dipRad)
	b = sin(dipdirRad) * cos(dipRad)
	c = sin(dipRad)
	l = sqrt(a * a + b * b + c * c)
	a = a / l
	b = b / l
	c = c / l
	d = a * Xcentre1 + b * Ycentre1 + c * Zcentre1
	plane = a * x + b * y + c * z - d
	if plane < 0.0:
		plane = 0.0
	return plane


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def NorthWall(x, y, z):
	Xcentre1 = 0.0
	Ycentre1 = 0.0
	Zcentre1 = -0.0
	dip = 90.0
	dipdir = 315.0
	dipdirN = 0.0
	dipN = 90.0 - dip
	if dipdir > 180.0:
		dipdirN = dipdir - 180.0
	else:
		dipdirN = dipdir + 180.0
	dipRad = dipN / 180.0 * pi
	dipdirRad = dipdirN / 180.0 * pi
	a = cos(dipdirRad) * cos(dipRad)
	b = sin(dipdirRad) * cos(dipRad)
	c = sin(dipRad)
	l = sqrt(a * a + b * b + c * c)
	a = -a / l
	b = -b / l
	c = -c / l
	d = a * Xcentre1 + b * Ycentre1 + c * Zcentre1
	plane = a * x + b * y + c * z - d
	if plane < 0.0:
		plane = 0.0
	return plane


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def removeDamping():
	for i in O.interactions:
		i.phys.viscousDamping = 0.5
		i.phys.cumulative_us = 0.0
	O.engines[2].physDispatcher.functors[0].viscousDamping = 0.5
	integration.damping = 0.0


# ----------------------------------------------------------------------------------------------------------------------------------------------- #
def myAddPlotData():
	global westBodyId
	global midBodyId
	global eastBodyId
	global originalPositionW
	global originalPositionM
	global originalPositionE
	global boundaryFriction
	KE = utils.kineticEnergy()
	uf = utils.unbalancedForce()
	displacementWx = O.bodies[westBodyId].state.pos[0] - originalPositionW[0]
	displacementW = (O.bodies[westBodyId].state.pos - originalPositionW).norm()
	displacementMx = O.bodies[midBodyId].state.pos[0] - originalPositionM[0]
	displacementM = (O.bodies[midBodyId].state.pos - originalPositionM).norm()
	displacementEx = O.bodies[eastBodyId].state.pos[0] - originalPositionE[0]
	displacementE = (O.bodies[eastBodyId].state.pos - originalPositionE).norm()
	plot.addData(
	        timeStep=O.iter,
	        timeStep1=O.iter,
	        timeStep2=O.iter,
	        timeStep3=O.iter,
	        timeStep4=O.iter,
	        timeStep5=O.iter,
	        kineticEn=KE,
	        unbalancedForce=uf,
	        waterLevel=waterHeight,
	        boundary_phi=boundaryFriction,
	        displacement=displacementW,
	        displacementWest=displacementW,
	        dispWx=displacementWx,
	        displacementMid=displacementM,
	        dispMx=displacementMx,
	        displacementEast=displacementE,
	        dispEx=displacementEx
	)


plot.plots = {
        'timeStep2': ('kineticEn'),
        'timeStep3': (('displacementWest', 'ro-'), ('dispWx', 'go-')),
        'timeStep1': (('displacementMid', 'ro-'), ('dispMx', 'go-')),
        'timeStep5': (('displacementEast', 'ro-'), ('dispEx', 'go-')),
        'timeStep4': ('unbalancedForce')
}  #PLEASE CHECK
plot.plot()  #Uncomment to view plots

# ----------------------------------------------------------------------------------------------------------------------------------------------- #
from yade import qt
try:
	v = qt.View()
	vaxes = True
	v.viewDir = Vector3(0, -1, 0)
	v.eyePosition = Vector3(0, 200, 0)

	v.eyePosition = Vector3(-77.42657409847706, 84.2619166834641, -17.41745783023423)
	v.upVector = Vector3(0.1913254208509842, -0.25732151742252396, -0.9471959776136951)
	v.viewDir = Vector3(0.6412359985709529, -0.697845344639707, 0.3191054200439123)
except:
	pass

O.step()
O.step()
#excavate()
O.step()
calTimeStep()
#O.run(20000)