# how to get the body numbers who is contact with a sphere

Hi, all
I want to get the body numbers who is contact with a sphere i, when I try use len(O.interactions.withBody(i)), I get a num like 3,4,5, but in fact it is higher when inspect with inspector. why? I'm wrong?

if len(O.interactions.withBody(i))>=3:
print len(O.interactions.withBody(i))

## Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
Christian Jakob
Solved:
Last query:
 Revision history for this message Christian Jakob (jakob-ifgt) said on 2013-07-30: #1

did you try this?

count = 0
for i in O.interactions.withBody(i):
if i.isReal:
count += 1

print count

 Revision history for this message Jan Stránský (honzik) said on 2013-07-30: #2

Hello,

@Christian, withBody "Return list of real interactions of given body" [1]

@Liucheng, maybe the same reason, try to use also withBodyAll function
"Return list of all (real as well as non-real) interactions of given body"
[2]. Is now this number and the number from inspector same, or not?

2013/7/30 Christian Jakob <email address hidden>

> Question #233241 on Yade changed:
>
> Christian Jakob posted a new comment:
> did you try this?
>
> count = 0
> for i in O.interactions.withBody(i):
> if i.isReal:
> count += 1
>
> print count
>
> --
> You received this question notification because you are a member of
>
> _______________________________________________
> Post to : <email address hidden>
>

 Revision history for this message liucheng83 (lcheng83) said on 2013-07-30: #3

Hello,
I try this srcipts:
-----------------------------------------------------------
k=200
count = 0
for i in O.interactions.withBody(k):
if i.isReal:
count += 1

print count

len(O.interactions.withBody(k))

len(O.interactions.withBodyAll(k))
------------------------------------------------------------------
The result is the same as the inspector. Thank you all, Christian and Jan.

But how to caculate the coordination number wihin a box range, I just want to caculate the particle who is not moving. Is the following is true?

----------
for i in range(103,len(O.bodies)):
if O.bodies[i].state.vel.norm()<0.1 :
if len(O.interactions.withBody(i))>=3:
num_in_contact[0]=num_in_contact[0]+1
num_contact[0]=num_contact[0]+len(O.interactions.withBody(i))
num_coordination[0]=1.0*num_contact[0]/num_in_contact[0]
----------

 Revision history for this message liucheng83 (lcheng83) said on 2013-07-30: #4

----------
for i in range(103,len(O.bodies)):
if O.bodies[i].state.vel.norm()<0.1 :
if len(O.interactions.withBody(i))>=3:
num_in_contact[0]=num_in_contact[0]+1
num_contact[0]=num_contact[0]+len(O.interactions.withBody(i))
num_coordination[0]=1.0*num_contact[0]/num_in_contact[0]
----------

 Revision history for this message Christian Jakob (jakob-ifgt) said on 2013-07-30: #5

hm, personally I prefer using proofed and implemented methods:

#if you have clumps in the model:
coord_num = avgNumInteractions(considerClumps=True)

#else:
coord_num = avgNumInteractions(considerClumps=False)

 Revision history for this message liucheng83 (lcheng83) said on 2013-07-30: #6

Yes, a simple way to get the coordination numbers in whole, but is there something wrong with my script to get coordination numbers in a small regin.
Does avgNumInteractions(considerClumps=True) consider the contacts from the wall?

 Revision history for this message Christian Jakob (jakob-ifgt) said on 2013-07-30: #7

> Yes, a simple way to get the coordination numbers in whole, but is there something wrong with my script to get coordination numbers in a small regin.

So write your tool, and check out if it gives same result as avgNumInteractions(). If yes, it works fine ;)

> Does avgNumInteractions(considerClumps=True) consider the contacts from the wall?

Yes, once for sphere-wall contact, twice for sphere-sphere contacts.
There was a similar discussion about coordination number, see here:

cheers,

christian

 Revision history for this message liucheng83 (lcheng83) said on 2013-07-31: #8

Thanks Christian Jakob, that solved my question.

 Revision history for this message liucheng83 (lcheng83) said on 2013-07-31: #9

Thank you all, Christian and Jan. that solved my question.