Advertisement
Guest User

Untitled

a guest
May 13th, 2019
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. from yade import plot          
  2. import numpy as np
  3.  
  4.  
  5.  
  6. def exportStuffFunction(Omega,mySphere):   
  7.     plot.addData(t=Omega.time,Ek=utils.kineticEnergy(),posz=mySphere.state.pos[2])
  8.  
  9.  
  10.  
  11. def main():
  12.     global mySphere1
  13.     plot.reset()
  14.     O.materials.append(FrictMat(young=10e9, poisson=0.11, density=2700, frictionAngle=90, label='Gomma'))
  15.     mySphere1 = utils.sphere((0,0,0),radius=0.2,material='Gomma')
  16.     O.bodies.append(mySphere1)
  17.     O.bodies.append(utils.wall(-1,axis=2,material='Gomma'))
  18.  
  19.     O.engines=[
  20.     ForceResetter(),
  21.     InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Wall_Aabb()]),
  22.     InteractionLoop(                   
  23.         [Ig2_Wall_Sphere_ScGeom()],            
  24.         [Ip2_FrictMat_FrictMat_FrictPhys()],       
  25.         [Law2_ScGeom_FrictPhys_CundallStrack()]),  
  26.         NewtonIntegrator(damping=0.0,gravity=(0,0,-9.81)),
  27.         PyRunner(command='exportStuffFunction(O,mySphere1)',iterPeriod=10)
  28.        
  29.     ]
  30.  
  31.  
  32.     O.dt = 0.25*utils.PWaveTimeStep()  
  33.  
  34.  
  35.     plot.plots={'t':('posz',None,'Ek')}
  36.     O.trackEnergy=True         
  37.  
  38.     O.run(100000)              
  39.  
  40.     plot.plot()                
  41.     plot.saveDataTxt('Plot_data.txt',vars=('t'))
  42.  
  43.  
  44. #----------------------
  45.  
  46.  
  47. main()
  48.  
  49.  
  50.  
  51. myDict = plot.data
  52. t_array = np.array(myDict["t"])
  53. t_list = myDict["t"]
  54.  
  55.  
  56. np.savetxt('np_array.txt', t_array,newline='\n')
  57. np.savetxt('np_list.txt', t_list,newline='\n')
  58.  
  59.  
  60. fid = open('write_data.txt','w')
  61. for i in range (0,len(t_list)):
  62.     fid.write(str(t_list[i])+'\n')
  63. fid.close()
  64.  
  65. print('------------------------------------------------')
  66. print(str(len(t_list))+" "+str(len(t_array))+" "+str(len(myDict["t"])))
  67. print('------------------------------------------------')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement