How do I correspond to the coordinates of particles and particles?

Asked by 孙灿

I want to know, when I use b.state.pos to get the coordinates of the particles, is the coordinate order of the console output random?
How do I match the coordinates of the output to the particles in the simulation?

Question information

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

Hello,

please provide a MWE [1].
"I use b.state.pos" is too generic and ambiguous.

> I use b.state.pos to get the coordinates of the particles

by b.state.pos, you get the coordinates of one single particle denoted as "b" (not particles)

> is the coordinate order of the console output random?

please define "random" and "the output".
You can make it random, but it would need effort from the user's side.
"Normally", e.g. using "for b in O.bodies: print(b.state.pos)", you get always the same order.

For the "match", I guess b.id is the information you are looking for? Something like:
for b in O.bodies: print(b.id, b.state.pos)

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
孙灿 (suncan) said :
#2

My code is as follows:

from yade import pack,plot
O.bodies.append(geom.facetBox((0.05, 9, 10), (0.1, 9, 10), wallMask=63))
sp = pack.SpherePack()
sp.makeCloud(Vector3(0.05,0,0),Vector3(0.05,18,20), rMean=0.1, rRelFuzz=1/3)
sp.toSimulation()

(xdim,ydim,zdim)= aabbDim()
print("Height is ",zdim)

for b in O.bodies:
   if isinstance(b.shape,Sphere):
       b.state.blockedDOFs='ZxY'
       b.shape.color=(3.,2.,1.)

circleRadius=1.5
circleCenter = Vector3(0.05,6,6)
circleRadius1=1.5
circleCenter1 = Vector3(0.05,12,6)

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.4),
        PyRunner(command='checkUnbalanced()', realPeriod=2),
        PyRunner(command='addPlotData()', iterPeriod=100)
]
O.dt = 0.5 * PWaveTimeStep()
O.trackEnergy = True

def checkUnbalanced():
 if unbalancedForce() < .05:
  O.pause()
  plot.saveDataTxt('bbb.txt.bz2')
  zMax = max(b.state.pos[2] for b in O.bodies if isinstance(b.shape,Sphere))
  print("Z ",zMax)
  layer = zMax-0.25
                for b in O.bodies:
      if isinstance(b.shape,Sphere):
                        #b.state.blockedDOFs='zxy'
                        b.state.vel=(0,0,0)
                        b.state.angVel=(0,0,0)
                    d = (b.state.pos - circleCenter).norm()
                    d1 = (b.state.pos - circleCenter1).norm()
                    if d < circleRadius:
                       O.bodies.erase(b.id)
                    if d1 < circleRadius1:
                       O.bodies.erase(b.id)
                    #print(b.state.pos)
      if b.state.pos[2]>layer:
   print(b.id,b.state.pos)
   #zMax = max(b.state.pos[2] for b in O.bodies)

  #zMax = max(b.state.pos[2] for b in O.bodies)
  #print("Z ",zMax)
  (xdim,ydim,zdim)= aabbDim()

  print("Height is ",zdim)

def addPlotData():
 plot.addData(i=O.iter, unbalanced=unbalancedForce(), **O.energy)

O.saveTmp()

from yade import qt
#qt.Controller()
qt.View()

I use print (b.id, b.state.pos) to output the id and coordinates of the particle. For example, the id of a particle is 1, in the print (b.id, b.state.pos) I know its coordinates at this time, and then I run the code again, the coordinates of the particle will change, at this time I can directly call the particle with id 1, get the coordinates after running it?

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

b = O.bodies[1]
print("voila",b.state.pos)

According to your other questions, I strongly suggest you to study the tutorial [2] and user's manual [3].
Many of the concepts you are asking is explained there.

Cheers
Jan

[2] https://yade-dem.org/doc/tutorial.html
[3] https://yade-dem.org/doc/user.html

Revision history for this message
孙灿 (suncan) said :
#4

Thanks Jan Stránský, that solved my question.