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
|
# -*- encoding=utf-8 -*-
#authors: katia.boschi@polimi.it, bruno.chareyre@3sr-grenoble.fr
# This script and features used in it are experimental. PLease wait stabilization before asking questions about it.
from yade import pack
from yade import export
from yade import timing
from yade import plot
import time
from math import *
num_spheres = 1000 # number of spheres
young = 1.e6
compFricDegree = 3 # initial contact friction during the confining phase
finalFricDegree = 30 # contact friction during the deviatoric loading
mn, mx = Vector3(0, 0, 0), Vector3(1., 1., 0.4) # corners of the initial packing
graindensity = 2600
errors = 0
toleranceWarning = 1.e-11
toleranceCritical = 1.e-6
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=radians(compFricDegree), density=graindensity, label='spheres'))
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=0, density=0, label='walls'))
walls = aabbWalls([mn, mx], thickness=0, material='walls')
wallIds = O.bodies.append(walls)
sp = pack.SpherePack()
sp.makeCloud(mn, mx, -1, 0.3333, num_spheres, False, 0.95, seed=1) #"seed" make the "random" generation always the same
sp.toSimulation(material='spheres')
triax = TriaxialStressController(
maxMultiplier=1. + 2e4 / young, # spheres growing factor (fast growth)
finalMaxMultiplier=1. + 2e3 / young, # spheres growing factor (slow growth)
thickness=0,
stressMask=7,
max_vel=0.005,
internalCompaction=True, # If true the confining pressure is generated by growing particles
)
newton = NewtonIntegrator(damping=0.2)
O.engines = [
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Box_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(), Ig2_Box_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()],
label="iloop"
),
TwoPhaseFlowEngine(dead=1, label="flow"), #introduced as a dead engine for the moment, see 2nd section
GlobalStiffnessTimeStepper(active=1, timeStepUpdateInterval=100, timestepSafetyCoefficient=0.8),
triax,
newton
]
triax.goal1 = triax.goal2 = triax.goal3 = -10000
while 1:
O.run(1000, True)
unb = unbalancedForce()
if unb < 0.001 and abs(-10000 - triax.meanStress) / 10000 < 0.001:
break
setContactFriction(radians(finalFricDegree))
radius = 0
for b in O.bodies:
if b.state.mass == 0:
b.state.blockedDOFs = 'xyzXYZ'
b.state.vel = (0, 0, 0)
b.state.angVel = (0, 0, 0)
if b.state.mass > 0:
radius += b.shape.radius
#b.state.blockedDOFs='xyz'
#b.state.vel=(0,0,0)
radius = radius / num_spheres
triax.dead = True
while 1:
O.run(1000, True)
unb = unbalancedForce()
if unb < 0.001:
break
press = 1000.
O.run(10, 1)
flow.dead = 0
flow.meshUpdateInterval = -1
flow.useSolver = 3
flow.permeabilityFactor = 1
flow.viscosity = 0.1
flow.bndCondIsWaterReservoir = [0, 0, 1, 0, 0, 0]
flow.bndCondIsPressure = [0, 0, 1, 0, 0, 0]
flow.bndCondValue = [0, 0, press, 0, 0, 0]
flow.boundaryUseMaxMin = [0, 0, 0, 0, 0, 0]
flow.iniVoidVolumes = True
GlobalStiffnessTimeStepper.dead = True
O.dt = min(0.8 * PWaveTimeStep(), 0.8 * 1. / 1200. * pi / flow.viscosity * graindensity * radius**2)
O.dynDt = False
newton.damping = 0.1
flow.surfaceTension = 0.0
flow.drainageFirst = False
flow.isDrainageActivated = False
flow.isImbibitionActivated = True
flow.isCellLabelActivated = True
flow.initialization()
cs = flow.getClusters()
c0 = cs[1]
voidvol = 0.0
voidvoltot = 0.0
nvoids = flow.nCells()
initialvol = [0.0] * (nvoids)
bar = [0.0] * (nvoids)
initiallevel = O.bodies[flow.wallIds[flow.ymin
]].state.pos[1] + (O.bodies[flow.wallIds[flow.ymax]].state.pos[1] - O.bodies[flow.wallIds[flow.ymin]].state.pos[1]) / 3
for ii in range(nvoids):
initialvol[ii] = 1. / flow.getCellInvVoidVolume(ii)
voidvoltot += initialvol[ii]
bar[ii] = flow.getCellBarycenter(ii)[1]
iniok = 0
while (iniok == 0):
celleini1 = [nvoids + 1] * (nvoids)
celleini0 = [0] * (nvoids)
getInt = c0.getInterfaces()
for ii in range(len(getInt)):
if bar[getInt[ii][1]] < initiallevel:
if celleini1[getInt[ii][1]] == nvoids + 1:
celleini1[getInt[ii][1]] = ii
celleini0[getInt[ii][1]] = getInt[ii][0]
for ii in range(nvoids):
if celleini1[ii] != nvoids + 1:
flow.clusterOutvadePore(celleini0[ii], ii)
no = 0
for ii in range(nvoids):
if bar[ii] < initiallevel:
if flow.getCellLabel(ii) == 0:
no = 1
break
if no == 0:
iniok = 1
for ii in range(len(c0.getInterfaces())):
c0.setCapVol(ii, 0.0)
c0.solvePressure()
flow.computeCapillaryForce(addForces=True, permanently=False)
O.run(1, 1)
newton.dead = True
flow.savePhaseVtk("./vtk", True)
timeini = O.time
ini = O.iter
Qin = 0.0
#Qout=0.0
totalflux = [0.0] * (nvoids)
#totalCellSat=0.0
for ii in range(nvoids):
if flow.getCellLabel(ii) == 0:
voidvol += initialvol[ii]
bubble = 0
dd = 0.0
deltabubble = 0
col0 = [0] * (nvoids)
neighK = [0.0] * (nvoids)
ints = c0.getInterfaces() #current interfaces
unsatPores = [] #short list of pores with incoming fluxes
invadedPores = [] #pores invaded in current step
incidentInterfaces = [[] for i in range(nvoids)] # map interfaces connected to an interfacial (dry) pore
def updateInterfaces():
ints = c0.getInterfaces() #current interfaces
unsatPores = [] #short list of pores with incoming fluxes
incidentInterfaces = [[] for i in range(nvoids)]
for idx in range(len(ints)):
intf = ints[idx]
if len(incidentInterfaces[intf[1]]) == 0:
unsatPores.append(intf[1])
incidentInterfaces[intf[1]].append(idx)
def pressureImbibition():
global Qin, total2, dd, deltabubble, bubble, unsatPores, incidentInterfaces, invadedPores, ints
start = time.time()
c0.updateCapVolList(O.dt)
Qin += -1 * (flow.getBoundaryFlux(flow.wallIds[flow.ymin])) * O.dt
#Qout+=(flow.getBoundaryFlux(flow.wallIds[flow.ymax]))*O.dt
#print "1",time.time()-start
#start=time.time()
delta = [0.0] * (nvoids)
ints = c0.getInterfaces()
if len(unsatPores) == 0 or len(invadedPores) > 0: #if not initialized or needs update
# reset all lists if invasion occured in previous iterations
# TODO: could be more atomic if they were updated after each local invasion
unsatPores = []
invadedPores = []
incidentInterfaces = [[] for i in range(nvoids)]
for idx in range(len(ints)):
intf = ints[idx]
if len(incidentInterfaces[intf[1]]) == 0:
unsatPores.append(intf[1])
incidentInterfaces[intf[1]].append(idx)
for ii in unsatPores:
totalflux[ii] = 0.0
for intf in incidentInterfaces[ii]:
totalflux[ii] += c0.getCapVol(intf)
if (totalflux[ii]) >= initialvol[ii]:
invadedPores.append(ii) #more efficient later than looping on nvoids to check ==1
delta[ii] = totalflux[ii] - initialvol[ii]
totalflux[ii] = initialvol[ii]
intf = incidentInterfaces[ii][0]
col0[ii] = ints[intf][0]
#if len(invadedPores)>0: print( "## invasion ##",len(invadedPores))
#print "2",time.time()-start
#start=time.time()
for jj in invadedPores:
flow.clusterOutvadePore(col0[jj], jj)
#print "4",time.time()-start
#start=time.time()
if len(invadedPores) > 0:
#updateInterfaces() #redefine interfaces if outvade() changed them
ints = c0.getInterfaces()
for ll in invadedPores:
if delta[ll] != 0.0:
intfs = c0.getInterfaces(cellId=ll)
for ii in intfs:
if flow.getCellLabel(ii[1]) == 0:
neighK[ll] += c0.getConductivity(ii[3])
if neighK[ll] == 0.0:
deltabubble += delta[ll]
bubble += 1
else:
for ii in intfs:
if flow.getCellLabel(ii[1]) == 0:
c0.setCapVol(ii[3], delta[ll] / neighK[ll] * c0.getConductivity(ii[3]))
totalflux[ii[1]] += delta[ll] / neighK[ll] * c0.getConductivity(ii[3])
#print "7",time.time()-start
#start=time.time()
if len(invadedPores) > 0:
# TODO: could be more atomic if they were updated after each local invasion
unsatPores = []
invadedPores = []
incidentInterfaces = [[] for i in range(nvoids)]
for idx in range(len(ints)):
intf = ints[idx]
if len(incidentInterfaces[intf[1]]) == 0:
unsatPores.append(intf[1])
incidentInterfaces[intf[1]].append(idx)
for ii in unsatPores:
if (totalflux[ii]) >= initialvol[ii]:
invadedPores.append(ii) #more efficient later than looping on nvoids to check ==1
delta[ii] = totalflux[ii] - initialvol[ii]
totalflux[ii] = initialvol[ii]
intf = incidentInterfaces[ii][0]
col0[ii] = ints[intf][0]
for jj in invadedPores:
flow.clusterOutvadePore(col0[jj], jj)
if len(invadedPores) > 0:
#updateInterfaces() #redefine interfaces if outvade() changed them
ints = c0.getInterfaces()
for ll in invadedPores:
if delta[ll] != 0.0:
intfs = c0.getInterfaces(cellId=ll)
for ii in intfs:
if flow.getCellLabel(ii[1]) == 0:
neighK[ll] += c0.getConductivity(ii[3])
if neighK[ll] == 0.0:
deltabubble += delta[ll]
bubble += 1
else:
for ii in intfs:
if flow.getCellLabel(ii[1]) == 0:
c0.setCapVol(ii[3], delta[ll] / neighK[ll] * c0.getConductivity(ii[3]))
totalflux[ii[1]] += delta[ll] / neighK[ll] * c0.getConductivity(ii[3])
unsatPores = []
invadedPores = []
incidentInterfaces = [[] for i in range(nvoids)]
for idx in range(len(ints)):
intf = ints[idx]
if len(incidentInterfaces[intf[1]]) == 0:
unsatPores.append(intf[1])
incidentInterfaces[intf[1]].append(idx)
for ii in unsatPores:
if (totalflux[ii]) >= initialvol[ii]:
invadedPores.append(ii) #more efficient later than looping on nvoids to check ==1
delta[ii] = totalflux[ii] - initialvol[ii]
totalflux[ii] = initialvol[ii]
intf = incidentInterfaces[ii][0]
col0[ii] = ints[intf][0]
dd += delta[ii]
print(O.iter, "waterloss", ii, delta[ii])
for jj in invadedPores:
flow.clusterOutvadePore(col0[jj], jj)
#print "8",time.time()-start
#start=time.time
total2 = 0.0
for ii in range(nvoids):
total2 += totalflux[ii]
#print "9",time.time()-start
#start=time.time()
start = time.time()
c0.solvePressure()
#print("10",time.time()-start)
#start=time.time()
flow.computeCapillaryForce(addForces=True, permanently=False)
#print( "11",time.time()-start)
#start=time.time()
#not needed with new version of computeCapillaryForce()
#for b in O.bodies:
#O.forces.setPermF(b.id, flow.fluidForce(b.id))
#print( "12",time.time()-start)
file = open('Test.txt', "w")
checkdifference = 0
def equilibriumtest():
global F33, F22, checkdifference, errors
#unbalanced=utils.unbalancedForce()
F33 = abs(O.forces.f(flow.wallIds[flow.ymax])[1])
F22 = abs(O.forces.f(flow.wallIds[flow.ymin])[1])
#F11 =abs(O.forces.f(flow.wallIds[flow.xmax])[0]),
#F00=abs(O.forces.f(flow.wallIds[flow.xmin])[0]),
#F44=abs(O.forces.f(flow.wallIds[flow.zmin])[2]),
#F55=abs(O.forces.f(flow.wallIds[flow.zmax])[2]),
deltaF = abs(F33 - F22)
file.write(str(O.iter) + " " + str(F33) + " " + str(F22) + " " + str(deltaF) + "\n")
if O.time >= timeini + 2.0:
if checkdifference == 0:
print('check F done')
if deltaF > 0.01 * press:
print('Error: too high difference between forces acting at the bottom and upper walls')
errors += 1
#O.pause()
checkdifference = 1
once = 0
def fluxtest():
global once, errors, QinOk
no = 0
QinOk = Qin - deltabubble
error = QinOk - total2
if error > toleranceWarning:
print(
"Warning: difference between total water volume flowing through bottom wall and water loss due to air bubble generations", QinOk,
" vs. total water volume flowing inside dry or partially saturated cells", total2
)
if error > toleranceCritical:
print("The difference is more, than the critical tolerance!")
errors += 1
file.write(str(O.time - timeini) + " " + str(total2) + " " + str(QinOk) + " " + str(error) + "\n")
for ii in range(nvoids):
if flow.getCellLabel(ii) == 0:
no = 1
break
if no == 0:
if once == 0:
imbtime = O.time - timeini
print(imbtime, voidvol, total2, QinOk)
if voidvol - total2 > toleranceWarning:
print(
"Warning: initial volume of dry voids", voidvol,
" vs. total water volume flowing inside dry or partially saturated cells", total2
)
if voidvol - total2 > toleranceCritical:
print("The difference is more, than the critical tolerance!")
errors += 1
print(errors)
file.write(str(imbtime) + " " + str(voidvol) + " " + str(total2) + " " + str(QinOk) + " " + str(errors) + "\n")
once = 1
timing.stats()
if (errors):
resultStatus += 1
def addPlotData():
plot.addData(i1=O.iter, t=O.time, Fupper=F33, Fbottom=F22, Q=QinOk, T=total2)
plot.live = True
plot.plots = {' t ': ('Fupper', 'Fbottom'), 't': ('Q', 'T')}
#plot.plot()
def pl():
flow.savePhaseVtk("./vtk", True)
O.engines = O.engines + [PyRunner(iterPeriod=100, command='pl()')]
#O.engines=O.engines+[VTKRecorder(iterPeriod=100,recorders=['spheres'],fileName='./exp')]
O.engines = O.engines + [PyRunner(iterPeriod=1, command='pressureImbibition()')]
O.engines = O.engines + [PyRunner(iterPeriod=1, command='equilibriumtest()')]
O.engines = O.engines + [PyRunner(iterPeriod=1, command='fluxtest()')]
O.engines = O.engines + [PyRunner(iterPeriod=1, command='addPlotData()')]
O.engines = O.engines + [NewtonIntegrator(damping=0.1)]
O.timingEnabled = True
#O.run(100,True)
#timing.stats()
#file.close()
#plot.saveDataTxt('plots.txt',vars=('i1','t','Fupper','Fbottom','Q','T'))
#O.run(1,1)
|