No interactions after erasing body

Asked by Mark S. Bentley

Hi all,

I've got a fairly simple script to build some ballistic aggregates which I will use in later simulations. I basically started with a seed particle at the origin, which has dynamic=False and then create particles and fire them randomly towards the aggregate. When contact is detected (O.interactions.countReal() increases in my collision checking callback) I freeze that particle (setting dynamic = False) and create a new one.

This basically works OK. But I have to check for particles that miss the aggregate. So in my collision checking callback, if there has been no increase in interactions, and if I am far from the seed particle, I erase the particle with O.bodies.erase.

This is where things seem to behave unexpectedly. I erase the particle, and a few timesteps later create a new one. This takes the same ID as the deleted one. But now, no interactions are ever detected - even when the particles pass through each other! Does O.bodies.erase not do what I think it does?

Any suggestions welcome!

Thanks, Mark

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Anton Gladky
Solved:
Last query:
Last reply:
Revision history for this message
Mark S. Bentley (msbentley) said :
#1

OK, I've just discovered that when I create a new particle (using O.bodies.append) *after* having erased a previous particle, the bound seems to be uninitialised, which I guess explains why no collisions are detected...

Can anyone tell me why this is the case, and how I should get around it? All other bodies correctly have Aabb instances, but the particle created after I first erase one has uninitialised (other properties look OK, though)...

Revision history for this message
Anton Gladky (gladky-anton) said :
#2

It would be good to see a simple test-script, which demonstrates the problem.

Anton

Revision history for this message
Mark S. Bentley (msbentley) said :
#3

Sure, good idea :) This modified version of the bouncing ball script
shows either my problem, or what stupid mistake I'm making ;-) I am
running yade-daily on ubuntu from the PPA (version 2+3128+30~precise1,
from 2012-05-16) and the script below shows the dynamic particle
bouncing in the first case, and penetrating in the second, and that the
bound of the re-created body is not initialised.

Regards, Mark

-----

ids = O.bodies.append([
    utils.sphere(center=(0,0,0),radius=.5,fixed=True),
    utils.sphere((0,0,2),.5)
])

O.engines=[
    ForceResetter(),
    InsertionSortCollider([Bo1_Sphere_Aabb()]),
    InteractionLoop(
       [Ig2_Sphere_Sphere_L3Geom()],
       [Ip2_FrictMat_FrictMat_FrictPhys()],
       [Law2_L3Geom_FrictPhys_ElPerfPl()]
    ),
    GravityEngine(gravity=(0,0,-9.81)),
    NewtonIntegrator(damping=0.1),

VTKRecorder(fileName='vtk/test-',recorders=['spheres','id','velocity'],iterPeriod=1000)
]

O.dt=.5e-4*utils.PWaveTimeStep()

O.run(2100000, True)

print 'Particle IDs and boundings: ' + str(ids)
print str([pcle.bound for pcle in O.bodies])

O.bodies.erase(ids[1])

# Run a few timesteps to ensure interactions are cleared/updated etc.
O.run(10, True)

#Create new body
new_id = O.bodies.append([utils.sphere((0,0,2),.5)])

O.run(2100000, True)

print 'Particle IDs and boundings: ' + str(ids)
print str([pcle.bound for pcle in O.bodies])

On 16/05/12 16:15, Anton Gladky wrote:
> Question #197438 on Yade changed:
> https://answers.launchpad.net/yade/+question/197438
>
> Status: Open => Answered
>
> Anton Gladky proposed the following answer:
> It would be good to see a simple test-script, which demonstrates the
> problem.
>
> Anton
>

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

It is a bug I think. Thanks for pinpointing the bound problem and providing a script. It should not be too difficult to fix.
I wonder why Anton, who heavily delete/create bodies is not affected...

Revision history for this message
Best Anton Gladky (gladky-anton) said :
#5

Thanks, Mark, for the pointing this out.
It is fixed in last rev. b92389065

Anton

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

This is the new record for fixing a bug. ;)

Revision history for this message
Chiara Modenese (chiara-modenese) said :
#7

Hi,
It is not very clear to me how this was fixed. Could you please say something more about it, Anton (or Bruno)?
Thank you very much,
Chiara

On 18 May 2012, at 14:25, Chareyre wrote:

> Question #197438 on Yade changed:
> https://answers.launchpad.net/yade/+question/197438
>
> Chareyre proposed the following answer:
> This is the new record for fixing a bug. ;)
>
> --
> 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
Bruno Chareyre (bruno-chareyre) said :
#8

If interactions->dirty, then the collider runs at next iteration (including bounds dispatching).
Then the new bound will be defined immediatly (I guess it was defined only after N iterations before the fix).
Do you confirm Anton?

Revision history for this message
Anton Gladky (gladky-anton) said :
#9

2012/5/18 Chareyre <email address hidden>:
> Question #197438 on Yade changed:
> https://answers.launchpad.net/yade/+question/197438
>
> Chareyre posted a new comment:
> If interactions->dirty, then the collider runs at next iteration (including bounds dispatching).
> Then the new bound will be defined immediatly (I guess it was defined only after N iterations before the fix).
> Do you confirm Anton?

Yes. There are several conditions. when the collider should be rerun [1].
With this commit I force rerunning the function, if even the number of
bodies will not
change (for example, when the body was previously deleted and newly created).

https://github.com/yade/trunk/blob/master/pkg/common/InsertionSortCollider.cpp#L83

Anton

Revision history for this message
Anton Gladky (gladky-anton) said :
#10

I think, that this bug should not affect many users.

But I will backport the fix to 0.80 branch as well,

Anton

Revision history for this message
Chiara Modenese (chiara-modenese) said :
#11

Sounds good. Thanks!

On 18 May 2012, at 18:15, Chareyre <email address hidden> wrote:

> Question #197438 on Yade changed:
> https://answers.launchpad.net/yade/+question/197438
>
> Chareyre posted a new comment:
> If interactions->dirty, then the collider runs at next iteration (including bounds dispatching).
> Then the new bound will be defined immediatly (I guess it was defined only after N iterations before the fix).
> Do you confirm Anton?
>
> --
> 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
Mark S. Bentley (msbentley) said :
#12

Thanks for the fix and explanations! I'm not set up to build yade at the
moment, and the daily build for precise failed last night, but I'll give
it a try next time the build succeeds!

Thanks,

Mark

On 18/05/12 23:30, Chiara Modenese wrote:
> Question #197438 on Yade changed:
> https://answers.launchpad.net/yade/+question/197438
>
> Chiara Modenese proposed the following answer:
> Sounds good. Thanks!
>
>
> On 18 May 2012, at 18:15, Chareyre<email address hidden> wrote:
>
>> Question #197438 on Yade changed:
>> https://answers.launchpad.net/yade/+question/197438
>>
>> Chareyre posted a new comment:
>> If interactions->dirty, then the collider runs at next iteration (including bounds dispatching).
>> Then the new bound will be defined immediatly (I guess it was defined only after N iterations before the fix).
>> Do you confirm Anton?
>>
>> --
>> 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
Mark S. Bentley (msbentley) said :
#13

Tested and confirmed solved on lucid x64 - thanks! The build failed again for precise x64 on launchpad, but I guess that's a separate issue! Regards, Mark

Revision history for this message
Mark S. Bentley (msbentley) said :
#14

Thanks Anton Gladky, that solved my question.

Revision history for this message
Anton Gladky (gladky-anton) said :
#15

Hi Mark,

I have just committed a better fix for this bug (rev 1e50860). I would
recommend you to update, because the previous hurts performance.

> The build failed again for precise x64 on launchpad, but I guess that's a separate issue!

There are not enough RAM again on build-servers.

Anton

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

> I have just committed a better fix for this bug (rev 1e50860). I would
> recommend you to update, because the previous hurts performance.

Ah... I guess the problem is ISCOllider.cpp:162

        if(scene->interactions->dirty){
            doInitSort=true;
            scene->interactions->dirty=false;
        }

We don't need the doInitSort in this case, we just need to update the
sort like in a ordinary colliding (not initialize it, as for iteration 1).
One way to trigger a standard colliding is to set
Collider::fastestBodyMaxDist>1, as if one body moved too much (which is
in fact the case of that body that disappeared then popped up in a
different place...).

Bruno

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

Or maybe cleaner: add a flag "doSort" somewhere (Scene or Collider?) and turn it on when inserting bodies.

Revision history for this message
Anton Gladky (gladky-anton) said :
#18

2012/5/21 Chareyre <email address hidden>:
>
> Chareyre posted a new comment:
> Or maybe cleaner: add a flag "doSort" somewhere (Scene or Collider?) and
> turn it on when inserting bodies.

Maybe you are right, but I am not sure, whether this action will
create "bounds" for newly created bodies.

Anton.