Remove Spheres Randomicaly from Pack

Asked by Luis Barbosa

Hi everyone,

After creating a packing of spheres, I would like to remove randomicaly some spheres from inside the pack.

Does anyone has some experience on this?

Thanks,
Luis

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
velimier
Solved:
Last query:
Last reply:
Revision history for this message
Best velimier (velimier) said :
#1

Hi,
maybe you can randomly append spheres from packing but excluding certain number of spheres.

from yade import pack
import random

sp = SpherePack()
sp = pack.regularOrtho(pack.inAlignedBox((0,0,0),(1,1,1)),radius=.05,gap=0)

n=350 #number of spheres to exclude

#randomly append spheres from packing
for i in range(0, len(sp)-n):
    b = sp[random.randint(0,len(sp)-1)]
    O.bodies.append(b)
    sp.remove(b)

Hope it suits your need,
Veljko

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

Hi Luis,
I like the approach of Veljko.
Aternativally you can implement something like removeRandom() method, but
it would need some c++ coding (as the core of SpherePack is implemented in
c++)
cheers
Jan

2016-06-06 12:58 GMT+02:00 velimier <email address hidden>:

> Question #294908 on Yade changed:
> https://answers.launchpad.net/yade/+question/294908
>
> Status: Open => Answered
>
> velimier proposed the following answer:
> Hi,
> maybe you can randomly append spheres from packing but excluding certain
> number of spheres.
>
> from yade import pack
> import random
>
> sp = SpherePack()
> sp = pack.regularOrtho(pack.inAlignedBox((0,0,0),(1,1,1)),radius=.05,gap=0)
>
> n=350 #number of spheres to exclude
>
> #randomly append spheres from packing
> for i in range(0, len(sp)-n):
> b = sp[random.randint(0,len(sp)-1)]
> O.bodies.append(b)
> sp.remove(b)
>
> Hope it suits your need,
> Veljko
>
> --
> You received this question notification because your team yade-users 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
Luis Barbosa (luis-pires-b) said :
#3

Thanks velimier, that solved my question.

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#4

Hi Jan,

Working on it!

Thanks.
Luis