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

Asked by liucheng83 on 2013-07-30

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:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Christian Jakob
Solved:
2013-07-31
Last query:
2013-07-31
Last reply:
2013-07-30
Christian Jakob (jakob-ifgt) said : #1

did you try this?

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

print count

Jan Stránský (honzik) said : #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?

cheers
Jan
[1]
https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.InteractionContainer.withBody
[2]
https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.InteractionContainer.withBodyAll

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

> Question #233241 on Yade changed:
> https://answers.launchpad.net/yade/+question/233241
>
> 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
> 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
>

liucheng83 (lcheng83) said : #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]
----------

liucheng83 (lcheng83) said : #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]
----------

Christian Jakob (jakob-ifgt) said : #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)

liucheng83 (lcheng83) said : #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?

Best Christian Jakob (jakob-ifgt) said : #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:

https://answers.launchpad.net/yade/+question/207350

cheers,

christian

liucheng83 (lcheng83) said : #8

Thanks Christian Jakob, that solved my question.

liucheng83 (lcheng83) said : #9

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