# How to count number of interactions

Asked by Reza Housseini on 2013-09-06

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([
])

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?

Cheers Reza

## Question information

Language:
English Edit question
Status:
For:
Assignee:
No assignee Edit question
Last query:
2013-09-09
2013-09-09
 Christian Jakob (jakob-ifgt) said on 2013-09-06: #1

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

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:

Getting number of interactions can be done like this:

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

(did not check)

 Reza Housseini (reza-housseini-3) said on 2013-09-06: #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?

 Jan Stránský (honzik) said on 2013-09-06: #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]
cheers
Jan

 Christian Jakob (jakob-ifgt) said on 2013-09-06: #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

 Jan Stránský (honzik) said on 2013-09-06: #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:
>
> 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([
> ])
>
> 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?
>
>
> Cheers Reza
>
> --
> You received this question notification because you are a member of
>
> _______________________________________________
> Post to : <email address hidden>
>

 Reza Housseini (reza-housseini-3) said on 2013-09-09: #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?

 Jan Stránský (honzik) said on 2013-09-09: #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:
>
>
> 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
>
> _______________________________________________
> Post to : <email address hidden>
>

 Reza Housseini (reza-housseini-3) said on 2013-09-09: #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?

 Jan Stránský (honzik) said on 2013-09-09: #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:
>
> 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
>
> _______________________________________________
> Post to : <email address hidden>
>

 Reza Housseini (reza-housseini-3) said on 2013-09-09: #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?

 Jan Stránský (honzik) said on 2013-09-09: #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:
>
> 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:
> >
> > 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
> >
> > _______________________________________________
> > Post to : <email address hidden>
> > More help : https://help.launchpad.net/ListHelp
> >
>
> --
> You received this question notification because you are a member of
>
> _______________________________________________