Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.29 KB | None | 0 0
  1. ##Import Libraries
  2.  
  3. from yade import pack,plot,qt
  4. import math
  5. import random as rand
  6. import numpy as np
  7.  
  8.  
  9. servermode=False
  10. if servermode:
  11.     qt.View()
  12. O.dt=1e-6
  13.  
  14. ##############################
  15. ## PARAMETERS OF SIMULATION ##
  16. ##############################
  17.  
  18.  
  19.  
  20. ### Configuration: inclined channel
  21. slope = math.radians(31)    #Slope of the channe, in radian
  22. length = 0.3    #Length of the channe, in m
  23. width = 0.01    #Width of the channel, in m
  24. height = 0.1    #Height of the channel, in m
  25. gravityVector = Vector3(9.81*sin(slope),0.0,-9.81*cos(slope))   #Gravity vector to consider a channel inclined with slope angle 'slope'
  26.  
  27. ### Materials
  28. # Channel
  29.  
  30. #Fluid
  31. fluidDensity= 1200. #Density of the fluid, in kg/m3
  32.  
  33. # Debris
  34. diameterPart = 0.001    #Diameter of the particles, in m
  35. O.materials.append(
  36.         FrictViscoMat(
  37.             betan=0.5,  #(not defined yet)
  38.             density=1800.,  #entre 1800 et 2300 si densite apparente
  39.             frictionAngle=math.radians(35.),
  40.             poisson=.5,#Ratio between kn and ks (not defined yet)
  41.             young=1e8,#Not the real young but contact stiffnesse kn (not defined yet)
  42.             label='DebrisMat'
  43.         ))
  44.  
  45. ########################
  46. ## FRAMEWORK CREATION ##
  47. ########################
  48. #
  49. # Channel creation
  50. O.bodies.append(
  51.     geom.facetBox(
  52.     (length/2.,width/2.,height/2.),
  53.     (length/2.,width/2.,height/2.),
  54.     Quaternion((1,0,0),0),
  55.     wallMask=63,
  56.     material='DebrisMat'))
  57. O.bodies.append(
  58.     geom.facetBox(
  59.     (0,width/2.,height/2.),
  60.     (3./100,width/2.,height/2.),
  61.     Quaternion((1,0,0),0),
  62.     wallMask=2,
  63.     material='DebrisMat'))
  64.  
  65. rigWall=O.bodies.append(
  66.         aabbWalls(
  67.         [(0.9*length,0,0),(0.9*length,width,0.015)],
  68.         thickness=0.001,
  69.         material='DebrisMat',
  70.         oversizeFactor=1.0,
  71.         color=(204, 0, 0)))
  72. for i in rigWall[1:]:
  73.         O.bodies.erase(i)
  74.  
  75. # Creation of a pack of sphere
  76. setclump=False
  77.  
  78. partCloud = pack.SpherePack()
  79. partNumber = 5000
  80. partCloud.makeCloud(minCorner=(0.01,0,0),maxCorner=(3./100,width,0.01),rRelFuzz=diameterPart/10, rMean=diameterPart/2.0)
  81. spIds=partCloud.toSimulation(material='DebrisMat',color=[205./255,175./255,149./255])
  82.  
  83. if setclump:
  84.     templates= []
  85.     relRadList1=[diameterPart/2,diameterPart/2]
  86.     relPosList1=[[diameterPart/2,0,0],[diameterPart,0,0]]
  87.     templates.append(clumpTemplate(relRadii=relRadList1,relPositions=relPosList1))
  88.     ClIds=O.bodies.replaceByClumps(templates,[1])
  89.  
  90.  
  91. #####################
  92. ## SIMULATION LOOP ##
  93. #####################
  94. Factor=2.  #(test value)
  95. O.engines=[
  96.     ForceResetter(),
  97.     InsertionSortCollider(
  98.     [
  99.     Bo1_Sphere_Aabb(aabbEnlargeFactor=Factor),
  100.     Bo1_Facet_Aabb(),
  101.     Bo1_Box_Aabb(),
  102.     Bo1_Wall_Aabb()
  103.     ],
  104.     label="ISC"
  105.     ),
  106.     InteractionLoop(
  107.     # Geometries
  108.     [
  109.     Ig2_Sphere_Sphere_ScGeom(interactionDetectionFactor=Factor),
  110.     Ig2_Facet_Sphere_ScGeom(),
  111.     Ig2_Box_Sphere_ScGeom()
  112.     ],
  113.  
  114.     # Physics
  115.     [
  116. #   Ip2_FrictMat_FrictMat_FrictPhys()
  117.     Ip2_FrictViscoMat_FrictViscoMat_FrictViscoPhys()
  118. #   Ip2_FrictMat_FrictViscoMat_FrictViscoPhys()
  119.     ],
  120.  
  121.     # Laws
  122.     [
  123.     Law2_ScGeom_FrictViscoPhys_CundallStrackVisco(),
  124.     ]
  125.     ),
  126.  
  127. #   GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
  128.     NewtonIntegrator(gravity=gravityVector, damping = 0., label='newton'),
  129.     VTKRecorder(fileName='Results/test/test-',iterPeriod=10000),
  130.     # Launching Pyhton functions inside the loop
  131.     PyRunner(command='stopme()', iterPeriod=100),
  132. #   PyRunner(command='print(unbalancedForce())',iterPeriod=500),
  133.     PyRunner(command='addPlotData()',iterPeriod=500),
  134.     PyRunner(command='gravityDeposit()',iterPeriod=500,label='gravDep',dead=False),
  135.     ]
  136.  
  137.  
  138. #########################
  139. ## FUNCTION DEFINITION ##
  140. #########################
  141.  
  142. def gravityDeposit():
  143.    if (O.iter>100000 and kineticEnergy()<.05):
  144.     if servermode:
  145.         O.pause()
  146.     O.bodies.erase(12)
  147.     O.bodies.erase(13)
  148.     gravDep.dead=True
  149.     newton.damping=0
  150.     print "Gravity deposit finished & gate opened"
  151.  
  152. #and unbalancedForce()<.06 and O.energy.items()[0][1]<0.005
  153. def checkUnbalanced():
  154.    if (max([b.state.vel.norm() for b in O.bodies])<0.01 and unbalancedForce()<.05):
  155.     O.pause();plot.saveDataTxt('bbb1.txt.bz2');
  156.     print "stab cond satisf"
  157.  
  158. def addPlotData():
  159.    plot.addData(i=O.iter, unbalanced=unbalancedForce(), **O.energy)
  160.  
  161.  
  162. O.trackEnergy=True
  163. #O.dt=PWaveTimeStep()
  164.  
  165. plot.plots={'i':('unbalanced',None,O.energy.keys)}
  166. plot.plot()
  167.  
  168.  
  169. O.saveTmp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement