Advertisement
Guest User

cpm_crash_test.py

a guest
Aug 21st, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.09 KB | None | 0 0
  1. import sys, time, random, os, gts, math
  2. from yade import ymport
  3. from yade import pack
  4. from yade import qt
  5.  
  6. #Simulation Parameters
  7. nbIter=100000000000
  8. iterPeriod = 100
  9. filename = "crash_test"
  10.  
  11. #define material properties:
  12. shearModulus            = 3.6e9
  13. poissonRatio            = 0.28
  14. youngModulus            = 2*shearModulus*(1+poissonRatio)
  15. angle                   = radians(36) #friction angle in radians
  16. rho_p                   = 917         #density of particles
  17. rho_f                   = 1029        #density of the fluid, rho_f > rho_p = floating particles
  18. v_iw                    = 0           #velocity of increasing water-level
  19. gravity                 = -9.80665    #m/s
  20. damping                 = 0.3         #ratio
  21.  
  22. #define water boundaries:
  23. boundaryMin = Vector3(-10, -10, -0.14)
  24. boundaryMax = Vector3(10, 10, 10)
  25. waterLevel = boundaryMin[2]
  26. t0 = O.time
  27.  
  28. #define colors:
  29. waterColor  = (.2,.2,.7)  #blue
  30.  
  31. #define materials:
  32. id_Mat=O.materials.append(CpmMat(young=youngModulus, poisson=poissonRatio, density=rho_p, frictionAngle=angle, sigmaT=5.5e3, relDuctility=30, epsCrackOnset=1e10, isoPrestress=0, damLaw=0) )
  33. Mat=O.materials[id_Mat]
  34.  
  35. # Create water level indicator
  36. idsWaterFacets =  []
  37. idsWaterFacets.append(O.bodies.append(facet( \
  38.             [ boundaryMin, [boundaryMax[0], boundaryMin[1], boundaryMin[2]], [boundaryMax[0], boundaryMax[1], boundaryMin[2]] ], \
  39.             fixed=True, material=FrictMat(young=0), color=waterColor, wire=False))) #no interactions will appear
  40. idsWaterFacets.append(O.bodies.append(facet( \
  41.             [ [boundaryMax[0], boundaryMax[1], boundaryMin[2]], [boundaryMin[0], boundaryMax[1], boundaryMin[2]], boundaryMin ], \
  42.             fixed=True, material=FrictMat(young=0), color=waterColor, wire=False))) #no interactions will appear
  43.  
  44. surface=gts.read(open('keel.gts'))
  45. volume=pack.inGtsSurface(surface)
  46.  
  47. O.bodies.append(pack.randomDensePack(predicate=volume, radius=0.05, material=Mat, cropLayers=0, rRelFuzz=0.6666, spheresInCell=5000, memoizeDb=None, useOBB=False, memoDbg=False, color=None, returnSpherePack=False))
  48.  
  49.  
  50. #Define timestep
  51. O.dt=0.5*PWaveTimeStep()
  52.  
  53. O.engines=[
  54.     ForceResetter(),
  55.  
  56.     InsertionSortCollider([ Bo1_Sphere_Aabb(), Bo1_Facet_Aabb()]),
  57.     InteractionLoop(
  58.         [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
  59.         [Ip2_CpmMat_CpmMat_CpmPhys(cohesiveThresholdIter=10000), Ip2_FrictMat_CpmMat_FrictPhys()],
  60.         [Law2_ScGeom_FrictPhys_CundallStrack(), Law2_ScGeom_CpmPhys_Cpm(omegaThreshold=1, yieldEllipseShift=0, yieldSurfType=0)]
  61.     ),
  62.  
  63.     NewtonIntegrator(damping=damping, gravity=[0, 0, gravity], label='integrator'),
  64.  
  65.     # Save data for Paraview
  66.     #VTKRecorder(fileName=filepath+'_vtk', recorders=['all', 'cpm'], iterPeriod=iterPeriod),
  67.  
  68.     PyRunner(command='O.pause()', iterPeriod=nbIter),
  69.     PyRunner(iterPeriod=25, command='applyBuoyancy()', label='buoLabel'),
  70.     PyRunner(iterPeriod=10000, command='print O.iter')
  71. ]
  72.  
  73. print "Start simulation: " + filename
  74. qt.View() # launch Yade with the 3D view
  75. O.pause() # launch Yade with the simulation paused
  76.  
  77. # Based on https://github.com/yade/trunk/blob/f50c914fd20b550e06512a774022653467b2e041/examples/clumps/apply-buoyancy-clumps.py
  78. def applyBuoyancy():
  79.     global waterLevel
  80.     waterLevel = (O.time-t0)*v_iw + boundaryMin[2]
  81.     for b in O.bodies:
  82.         zMin = 1e9
  83.         zMax = -1e9
  84.         if b.isStandalone and isinstance(b.shape,Sphere):
  85.             rad = b.shape.radius
  86.             zMin = b.state.pos[2] - rad
  87.             dh = min((waterLevel - zMin), 2*rad)    #to get sure, that dh is not bigger than 2*radius
  88.         elif b.isClump:             #determine rad, zMin and zMax for clumps:
  89.             for ii in b.shape.members.keys():
  90.                 pos = O.bodies[ii].state.pos
  91.                 zMin = min(zMin,pos[2]-O.bodies[ii].shape.radius)
  92.                 zMax = max(zMax,pos[2]+O.bodies[ii].shape.radius)
  93.             #get equivalent radius from clump mass:
  94.             rad = ( 3*b.state.mass/(4*pi*O.bodies[b.shape.members.keys()[0]].mat.density) )**(1./3.)       
  95.             #get dh relative to equivalent sphere, but acting when waterLevel is between clumps z-dimensions zMin and zMax:
  96.             dh = min((waterLevel - zMin)*2*rad/(zMax - zMin), 2*rad)       
  97.         else:
  98.             continue
  99.         if dh > 0:
  100.             F_buo = -1*(pi/3)*dh*dh*(3*rad - dh)*rho_f*integrator.gravity                                       # = -V*rho*g
  101.             O.forces.addF(b.id, F_buo, permanent=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement