kenetic Energy of particles

Asked by hafsa

hi everyone ,
i wrote code about falling spheres in cylinder and now i want to know the average kinetic energy of all spheres .
this is what i obtain :

AttributeError Traceback (most recent call last)
/usr/bin/yade in <module>()

/usr/bin/yade in plotAddData()
     41 for b in O.bodies:
     42 if (type(b.shape)==Sphere):
---> 43 Ek = b. O.energy['kinetic']
     44 plot.addData(i=O.iter,Ek=Ek,**O.energy)
     45

AttributeError: 'Body' object has no attribute 'O'
In [1]: exit

my code is :
from yade import pack,plot

#material of cylinder
Mat1 = O.materials.append(ViscElMat(kn=10.0e4,ks=10.0e4,frictionAngle=0.455,density=2650.0))

# create the big sphere
big_sphr=O.bodies.append(utils.sphere((0,0,.3),1.,fixed=False,color=(1,0,0),highlight=True))

# create sphere packing
sp=pack.SpherePack()
sp.makeCloud((-7.2,-7.2,1.),(7.2,7.2,58.7),rMean=.5,rRelFuzz=0,num=6000)
sp.toSimulation(color=(0,1,0))

# create Cylinder
Cylinder=O.bodies.append(geom.facetCylinder((0,0,1.),10.0,height=60.0,wallMask=6,segmentsNumber=64,material=Mat1))

# interactions
O.engines=[
    ForceResetter(),
    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
    InteractionLoop(

        [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
        [Ip2_FrictMat_FrictMat_FrictPhys()],
        [Law2_ScGeom_FrictPhys_CundallStrack()]
    ),
    NewtonIntegrator(gravity=(0,0,-9.81),damping=0.3),
    PyRunner(iterPeriod=10,command="plotAddData()",label='energy'),
 ]

O.dt=utils.PWaveTimeStep()
O.saveTmp()

#energy kenetic
O.trackEnergy=True

def plotAddData():
   for b in O.bodies:
      if (type(b.shape)==Sphere):
         Ek = b. O.energy['kinetic']
         plot.addData(i=O.iter,Ek=Ek,**O.energy)

plot.plots={'time':('energy')}
plot.plot()

yade.qt.View()

any suggestions ? thank's in advance.
cordially
Any suggestions ?

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
hafsa
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

sometimes the Python error messages are self-explanatory, like in this case

> Ek = b. O.energy['kinetic']

should be
Ek = O.energy['kinetic'] # without b., b being Body instance

also have a look at kineticEnergy function [1]

cheers
Jan

[1] https://yade-dev.gitlab.io/trunk/yade.utils.html#yade._utils.kineticEnergy

Revision history for this message
hafsa (sebbah.hafsa) said :
#2

hi Jan,
thank you for your answer
but i obtain another error :

oadcast_arrays(*args, **kwargs)
    250 args = [np.array(_m, copy=False, subok=subok) for _m in args]
    251
--> 252 shape = _broadcast_shape(*args)
    253
    254 if all(array.shape == shape for array in args):

/home/hafsa/.local/lib/python2.7/site-packages/numpy/lib/stride_tricks.pyc in _broadcast_shape(*args)
    185 # use the old-iterator because np.nditer does not handle size 0 arrays
    186 # consistently
--> 187 b = np.broadcast(*args[:32])
    188 # unfortunately, it cannot handle 32 or more arguments directly
    189 for pos in range(32, len(args), 31):

 how can i obtain the overage kenetic energy of spheres
#energy kenetic
O.trackEnergy=True

def plotAddData():
   for b in O.bodies:
      if (type(b.shape)==Sphere):
         Ek = O.energy['kinetic']
         plot.addData(i=O.iter,Ek=Ek,**O.energy)

Revision history for this message
Jan Stránský (honzik) said :
#3

Hello,

I could not reproduce your error.

concerning your addPlotData function, it does not make much sense to me.. Ek is the same value all the time, so there is no need for the for loop over bodies. Calling plot.addData inside the loop also does not make sense.

To get average kinetic energy, you can do something like this:
###
e = O.energy["kinetic"] # or something like that
n = len([b for b in O.bodies if isinstance(b.shape,Sphere)])
eAvg = e/n
###

cheers
Jan

Revision history for this message
hafsa (sebbah.hafsa) said :
#4

hi Jan ,
i tried like you said but there's no plot

#energy kenetic
O.trackEnergy=True

def plotAddData():
   n = len([b for b in O.bodies if isinstance(b.shape,Sphere)])
   e = kineticEnergy()
   plot.addData(i=O.iter,eAvg = e/n)

plot.plots={'time':('energy')}
plot.plot()

Revision history for this message
Jan Stránský (honzik) said :
#5

plot.plots = {'i':'eAvg'}
Jan

Revision history for this message
hafsa (sebbah.hafsa) said :
#6

thank you Jan ,
for the person who want to plot average kinetic energy of spheres there's code :
from yade import pack,plot

#material of cylinder
Mat1 = O.materials.append(ViscElMat(kn=10.0e4,ks=10.0e4,frictionAngle=0.455,density=2650.0))

# create the big sphere
big_sphr=O.bodies.append(utils.sphere((0,0,.3),1.,fixed=False,color=(1,0,0),highlight=True))

# create sphere packing
sp=pack.SpherePack()
sp.makeCloud((-7.2,-7.2,1.),(7.2,7.2,58.7),rMean=.5,rRelFuzz=0,num=6000)
sp.toSimulation(color=(0,1,0))

# create Cylinder
Cylinder=O.bodies.append(geom.facetCylinder((0,0,1.),10.0,height=60.0,wallMask=6,segmentsNumber=64,material=Mat1))

# interactions
O.engines=[
    ForceResetter(),
    InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
    InteractionLoop(

        [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
        [Ip2_FrictMat_FrictMat_FrictPhys()],
        [Law2_ScGeom_FrictPhys_CundallStrack()]
    ),
    NewtonIntegrator(gravity=(0,0,-9.81),damping=0.3),
    PyRunner(iterPeriod=100,command='plotAddData()')

 ]

O.dt=utils.PWaveTimeStep()
O.saveTmp()

#energy kenetic
O.trackEnergy=True
n = len([b for b in O.bodies if isinstance(b.shape,Sphere)])
print(n)
def plotAddData():
   #e = kineticEnergy()
   plot.addData(i=O.iter,e =kineticEnergy()/n,**O.energy)

plot.plots={'i':['e']+O.energy.keys()}
plot.plot()
plot.live=True

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#7

For just the kinetic energy there is no need for: O.trackEnergy=True, and this energy tracking is rather slow.
Bruno

Revision history for this message
hafsa (sebbah.hafsa) said :
#8

hi Bruno ,
thanks for response if there is faster method i really want to know.

Revision history for this message
Jan Stránský (honzik) said :
#9

just read carefully the answers ;-) in this case the very first one
Jan

https://yade-dev.gitlab.io/trunk/yade.utils.html#yade._utils.kineticEnergy