# updating O.bodies

There's a problem in O,.bodies when we delete some particles during simulation. Or if we use replaceByClumps() (because in replaceByClumps also a ball is deleted and replaced by a clump).

In these case, if we then want to iterate over bodies we get an error because O.bodies() has not been updates and there're some ids with no physical body.

for example after using replaceByClumps(), I'd like to use calm() function in pyrunner as

def calm():
for ii in range(1,(len(O.bodies)-1)):
O.bodies[ii].state.vel=Vector3(0,0,0)

but the function crashes because some bodies are missing. This can be solved by:

1- if there's a function to check the existence of a body
2- if we can update O.bodies

Thanks

## Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
Solved:
2014-12-15
Last query:
2014-12-15
2014-12-14
 Jan Stránský (honzik) said on 2014-12-12: #1

In the loop, you can use a check

if not O.bodies[ii]: continue

or

b = O.bodies[ii]
if not b: continue

Or you can just simply use

for b in O.bodies:
Whatever

It will skip non-existent bodies

Cheers
Jan

napsal(a):

> New question #258987 on Yade:
>
>
> There's a problem in O,.bodies when we delete some particles during
> simulation. Or if we use replaceByClumps() (because in replaceByClumps also
> a ball is deleted and replaced by a clump).
>
> In these case, if we then want to iterate over bodies we get an error
> because O.bodies() has not been updates and there're some ids with no
> physical body.
>
> for example after using replaceByClumps(), I'd like to use calm() function
> in pyrunner as
>
> def calm():
> for ii in range(1,(len(O.bodies)-1)):
> O.bodies[ii].state.vel=Vector3(0,0,0)
>
> but the function crashes because some bodies are missing. This can be
> solved by:
>
> 1- if there's a function to check the existence of a body
> 2- if we can update O.bodies
>
>
> Thanks
>
> --
> You received this question notification because you are a member of
>
> _______________________________________________
> Post to : <email address hidden>
>

thank you, Jan

O.bodies problem is solved this way.
however, there is problem with calm() function. Although I call it at each time step by pyrunner it seems it's not able to reset the velocity of the balls.
I have created a orthogonal packing of spheres and so normally there shoulf not be overlaps.
But even if there are overlaps calm() is called at each time step. however, balls are having an explosive velocity. Any idea why tbis happen s?

thanks

 Christian Jakob (jakob-ifgt) said on 2014-12-13: #3

Hi,

There is already a calm function in yade, that you can use:

Regards,

Christian

Yes, I tried the built-in function. That's good.

However, in a regular packing we're supposed not to have overlaps!

 Jan Stránský (honzik) said on 2014-12-14: #5

There is probably some misconception in your script, could you send us a
minimal working example? As it is different topic, preferably in new
question/bug..
Cheers
Jan
napsal(a):

> Question #258987 on Yade changed:
>
> behzad posted a new comment:
> Yes, I tried the built-in function. That's good.
>
> However, in a regular packing we're supposed not to have overlaps!
>
> --
> You received this question notification because you are a member of
>
> _______________________________________________
> Post to : <email address hidden>