List spheres' diameters/radii

Asked by Hien Nguyen

Hello everybody,

I have a sphere pack (6 walls around a sphere pack) and I want to list all the spheres's ID + Radius into a file, how can I do it?

Here is what I'm imagining:

import numpy, os, math, pylab
from yade import utils, pack

a=open('radius.txt','w')
for i in O.bodies:
  a.write('%d %f \n'%(i.id, i.shape.radius))
a.close()

That gave me:
  AttributeError: 'Box' object has no attribute 'radius'
and I'm stuck here. Can you give me some advices?

Thanks in advance.

Ref:
https://yade-dem.org/doc/yade.wrapper.html?highlight=radius#yade.wrapper.Sphere.radius

Question information

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

Hello

The walls that you have in your problem have not a radius, so if you want to list all the radi of spheres in your simulation, you have to discard before the identities of the 6 walls (id from 0 to 5) by doing this:

a=open('radius.txt','w')
for i in O.bodies:
   if i.id>5:
      a.write('%d %f \n'%(i.id, i.shape.radius))
a.close()

Bests
Donia

Revision history for this message
Ricardo Pieralisi (ricpieralisi) said :
#2

If the spheres have different colors than the box, you can do something like this:

C1=Vector(0,0,1) #color of the sphere

for b in O.bodies:
  if b.shape.color==C1:
    c=str(b.state.pos)
    r=str(b.shape.radius)
    f.write(c)
    f.write(r)
    f.write('\n')

u can use with more color too

Revision history for this message
Hien Nguyen (giahien) said :
#3

Thanks Donia Marzougui, that solved my question.

Revision history for this message
Hien Nguyen (giahien) said :
#4

Thanks Ricardo too for your solution!

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

Hi Nguyen,

you have to exclude non-spherical particles from the loop:

a=open('radius.txt','w')
for i in O.bodies:
  if not isinstance(i.shape,Sphere): continue # after this line, only
spheres continue the loop and are written to the file
  a.write('%d %f \n'%(i.id, i.shape.radius))
a.close()

cheers
Jan

2013/10/31 Nguyen N.G. Hien <email address hidden>

> New question #238406 on Yade:
> https://answers.launchpad.net/yade/+question/238406
>
> Hello everybody,
>
> I have a sphere pack (6 walls around a sphere pack) and I want to list all
> the spheres's ID + Radius into a file, how can I do it?
>
> Here is what I'm imagining:
>
> import numpy, os, math, pylab
> from yade import utils, pack
>
> a=open('radius.txt','w')
> for i in O.bodies:
> a.write('%d %f \n'%(i.id, i.shape.radius))
> a.close()
>
> That gave me:
> AttributeError: 'Box' object has no attribute 'radius'
> and I'm stuck here. Can you give me some advices?
>
> Thanks in advance.
>
> Ref:
>
> https://yade-dem.org/doc/yade.wrapper.html?highlight=radius#yade.wrapper.Sphere.radius
>
>
> --
> 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
Hien Nguyen (giahien) said :
#6

Thanks Mr Jan Stránský , your solution is more general.

Revision history for this message
Hicham BENNIOU (benniou-hicham-deactivatedaccount) said :
#7

Hi Nguyen,

This examples works also, you can save the values in a file instead of printing them on screen ;)

from yade import pack,qt

sp=pack.SpherePack()
sp.makeCloud((0,0,0),(1,1,1),rMean=.05,rRelFuzz=.5)
sp.toSimulation()

yade.qt.View()

for i in O.bodies:
  if isinstance(i.shape,Sphere):
      r=i.shape.radius
      print ('radius = %f'%(r))