How to count number of interactions

Asked by Reza Housseini

I want to count the number of collisions between some spheres and a facet. I thought this could be achieved by using the InteractionContainer O.interactions. But for my simple baby example there are no countable interactions.

  tc = 0.001
  en = 0.8
  es = 0.2
  params = utils.getViscoelasticFromSpheresInteraction(tc, en, es)
  frictMatId = O.materials.append(NormalInelasticMat(density=300.0,poisson=0.5,young=1e9))

  ballId=O.bodies.append([
    utils.sphere(center=(0.5,0.5,0.5),radius=.05,material=frictMatId)
  ])

  floor = pack.sweptPolylines2gtsSurface(
    [[
      Vector3(0.0,0.0,0.0),
      Vector3(1.0,0.0,0.0),
      Vector3(1.0,1.0,0.0),
      Vector3(0.0,1.0,0.0),
    ]],
    capStart=True,capEnd=True
  )
  floorIds = O.bodies.append(pack.gtsSurface2Facets(floor))

  O.engines=[
     ForceResetter(),
     InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
     InteractionLoop(
        [Ig2_Facet_Sphere_L3Geom(),Ig2_Sphere_Sphere_L3Geom()], # collision geometry
        [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
        [Law2_L3Geom_FrictPhys_ElPerfPl()] # contact law -- apply forces
     ),
    HarmonicMotionEngine(A=(0.0,0.0,5.25e-3),f=(0.0,0.0,1000/60.0),ids=floorIds),
    NewtonIntegrator(damping=0.2,gravity=(0,0,-9.81))
  ]

  O.dt=0.01*tc
  O.run(2000000,True)

What is the cause of this? Do I interpret the InteractionContainer wrong?

Thanks for any advice

Cheers Reza

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Christian Jakob (jakob-ifgt) said :
#1

Maybe the problem is, that the material id can not be used for specify a material (not sure, if this is the problem)

instead of

frictMatId = O.materials.append(NormalInelasticMat(density=300.0,poisson=0.5,young=1e9))

try this

myMat = NormalInelasticMat(density=300.0,poisson=0.5,young=1e9)
frictMatId = O.materials.append(myMat)

Then you can set it to your sphere:

ballId=O.bodies.append([sphere(center=(0.5,0.5,0.5),radius=.05,material=myMat)])

Getting number of interactions can be done like this:

counter = 0
for i in O.interactions:
  if i.isReal:
    counter+=1

(did not check)

Revision history for this message
Reza Housseini (reza-housseini-3) said :
#2

Thanks Jakob
My actual problem is, that only 1 interaction does appear in the container O.interactions. But none of the collisions between the ball and the floor. Why is that?

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

Hello Christian,

> Maybe the problem is, that the material id can not be used for specify a
> material (not sure, if this is the problem)
>
 FYI, material id can be used to specify material [1]
[1] https://yade-dem.org/doc/yade.utils.html#yade.utils.sphere
cheers
Jan

Revision history for this message
Christian Jakob (jakob-ifgt) said :
#4

> My actual problem is, that only 1 interaction does appear in the container O.interactions.

How many interactions would you expect from a simple model with one sphere and facets?

> But none of the collisions between the ball and the floor. Why is that?

There are no interactions between facets, so your interaction must be between your sphere and one of the facets.

You can check which bodie ids are involved in interactions by:

for i in O.interactions:
  if i.isReal:
    print 'found interaction between ',i.id1,' and ',i.id2

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

Hello Reza,

how do you (what command do you use) to get the number of interactions? and
how often dou you use it? the interaction between the sphere and floor
would ocure in only a few time steps in total I would guess..
cheers
Jan

PS: btw, from where did you get the engines? L3Geom is not maintained
AFAIK, ScGeom is more standard.. anyway should not be related to your
problem

2013/9/6 Reza Housseini <email address hidden>

> New question #235259 on Yade:
> https://answers.launchpad.net/yade/+question/235259
>
> I want to count the number of collisions between some spheres and a facet.
> I thought this could be achieved by using the InteractionContainer
> O.interactions. But for my simple baby example there are no countable
> interactions.
>
> tc = 0.001
> en = 0.8
> es = 0.2
> params = utils.getViscoelasticFromSpheresInteraction(tc, en, es)
> frictMatId =
> O.materials.append(NormalInelasticMat(density=300.0,poisson=0.5,young=1e9))
>
> ballId=O.bodies.append([
> utils.sphere(center=(0.5,0.5,0.5),radius=.05,material=frictMatId)
> ])
>
> floor = pack.sweptPolylines2gtsSurface(
> [[
> Vector3(0.0,0.0,0.0),
> Vector3(1.0,0.0,0.0),
> Vector3(1.0,1.0,0.0),
> Vector3(0.0,1.0,0.0),
> ]],
> capStart=True,capEnd=True
> )
> floorIds = O.bodies.append(pack.gtsSurface2Facets(floor))
>
> O.engines=[
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
> InteractionLoop(
> [Ig2_Facet_Sphere_L3Geom(),Ig2_Sphere_Sphere_L3Geom()], #
> collision geometry
> [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
> [Law2_L3Geom_FrictPhys_ElPerfPl()] # contact law -- apply forces
> ),
>
> HarmonicMotionEngine(A=(0.0,0.0,5.25e-3),f=(0.0,0.0,1000/60.0),ids=floorIds),
> NewtonIntegrator(damping=0.2,gravity=(0,0,-9.81))
> ]
>
> O.dt=0.01*tc
> O.run(2000000,True)
>
> What is the cause of this? Do I interpret the InteractionContainer wrong?
>
> Thanks for any advice
>
> Cheers Reza
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Reza Housseini (reza-housseini-3) said :
#6

> How many interactions would you expect from a simple model with one sphere and facets?

The facet is driven by a HarmonicMotionEngine and the ball is therefore hopping.

> how do you (what command do you use) to get the number of interactions?

I just let the simulation run and then use len(O.interactions) to count the number of interactions. I also found out about utils.avgNumInteractions() but this too does not count any interactions.

Aren't all interactions loggend in the InteractionContainer?

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

Hi Reza,

the ball is hopping (regardless harmonic motion of facets), as you wrote
:-) so at the end of simulation, I would expect the sphere to be somewhere
"hopped" from the floor (the situation that you stop the simulation just at
the moment of interaction is very unlikely in my opinion). Can you check
the position of the floor and of the sphere at the moment you are
investigating number of interactions?

You can also use PyRunner to do something periodically in the simulation
(like checking number of interactions), so you can for example add one to
O.engines:

O.engines = [
  ...
  PyRunner(iterPeriod=1,command="getMaxNumIntrs()"),
]

maxNumIntrs=0
def getMaxNumIntrs():
  global maxNumIntrs
  maxNumIntrs = max(len(O.interactions),maxNumIntrs)

to get maximum number of interactions during the whole simulation time
(should be 1 or more if there is at least one sphere repulse from floor).

cheers
Jan

2013/9/9 Reza Housseini <email address hidden>

> Question #235259 on Yade changed:
> https://answers.launchpad.net/yade/+question/235259
>
> Status: Answered => Open
>
> Reza Housseini is still having a problem:
> > How many interactions would you expect from a simple model with one
> sphere and facets?
>
> The facet is driven by a HarmonicMotionEngine and the ball is therefore
> hopping.
>
> > how do you (what command do you use) to get the number of
> interactions?
>
> I just let the simulation run and then use len(O.interactions) to count
> the number of interactions. I also found out about
> utils.avgNumInteractions() but this too does not count any interactions.
>
> Aren't all interactions loggend in the InteractionContainer?
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Reza Housseini (reza-housseini-3) said :
#8

Hi Jan

Thanks for the clarification. There's only on problem, this approach is very slow it even slows my simulation with one ball down remarkably. Does anybody know a way to achieve the same with less performance drop?

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

Hi Reza,

Yes, it slows down. You can change it by increasing iterPeriod parameter
(but then you can miss the moment of interaction :-) it depends on what you
want to achieve..

For your simulation setup, you would have one (or possibly a few)
interaction at the moment of sphere/facet overlap (veeery short time) and
no interactions otherwise (most of the simulation). So the result you got
(no interaction at the end of simulation) is expected. The reason is
explained above and from this point of view you did not interpret the
interactionContainer wrong :-)

Do you plan to count interactions for different simulations, or only this
simple example? Or this simple example is only for testing?
cheers
Jan

2013/9/9 Reza Housseini <email address hidden>

> Question #235259 on Yade changed:
> https://answers.launchpad.net/yade/+question/235259
>
> Reza Housseini posted a new comment:
> Hi Jan
>
> Thanks for the clarification. There's only on problem, this approach is
> very slow it even slows my simulation with one ball down remarkably.
> Does anybody know a way to achieve the same with less performance drop?
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Reza Housseini (reza-housseini-3) said :
#10

Hi Jan

Yes this simple example is only for testing. Number of particles for the real simulation are about 1000. Do you think it's worth writing a Callback function for the InteractionLoop?

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

For 1000 particle I would expect that the number of interactions would be
higher. Of course it depends on what you simulate. But if the packing is
dense (e.g. particles falling by gravity to an open box) I would expect
that.

What is your goal with the number of interactions? Do you want to track it
during the simulation, or you just want one value at the end of the
simulation?

Jan

2013/9/9 Jan Stránský <email address hidden>

> Question #235259 on Yade changed:
> https://answers.launchpad.net/yade/+question/235259
>
> Jan Stránský proposed the following answer:
> Hi Reza,
>
> Yes, it slows down. You can change it by increasing iterPeriod parameter
> (but then you can miss the moment of interaction :-) it depends on what you
> want to achieve..
>
> For your simulation setup, you would have one (or possibly a few)
> interaction at the moment of sphere/facet overlap (veeery short time) and
> no interactions otherwise (most of the simulation). So the result you got
> (no interaction at the end of simulation) is expected. The reason is
> explained above and from this point of view you did not interpret the
> interactionContainer wrong :-)
>
> Do you plan to count interactions for different simulations, or only this
> simple example? Or this simple example is only for testing?
> cheers
> Jan
>
>
>
> 2013/9/9 Reza Housseini <email address hidden>
>
> > Question #235259 on Yade changed:
> > https://answers.launchpad.net/yade/+question/235259
> >
> > Reza Housseini posted a new comment:
> > Hi Jan
> >
> > Thanks for the clarification. There's only on problem, this approach is
> > very slow it even slows my simulation with one ball down remarkably.
> > Does anybody know a way to achieve the same with less performance drop?
> >
> > --
> > You received this question notification because you are a member of
> > yade-users, which is an answer contact for Yade.
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~yade-users
> > Post to : <email address hidden>
> > Unsubscribe : https://launchpad.net/~yade-users
> > More help : https://help.launchpad.net/ListHelp
> >
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Can you help with this problem?

Provide an answer of your own, or ask Reza Housseini for more information if necessary.

To post a message you must log in.