← Back to team overview

yade-users team mailing list archive

Re: [Question #258987]: updating O.bodies

 

Question #258987 on Yade changed:
https://answers.launchpad.net/yade/+question/258987

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hi Behzad,

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

Dne 12.12.2014 21:01 "behzad" <question258987@xxxxxxxxxxxxxxxxxxxxx>
napsal(a):

> New question #258987 on Yade:
> https://answers.launchpad.net/yade/+question/258987
>
>
> 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
>
> Do you guys have any idea about this?
>
> Thanks
> Behzad
>
> --
> 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     : yade-users@xxxxxxxxxxxxxxxxxxx
> 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.