Detect newly appeared interactions between two states of the same model

Asked by Hien Nguyen

Hello everybody,
I want to ask a question about contact detection of two different states of the same specimen. Here is my problem:
I have a saved model, named 'begin.xml', from this specimen, I apply a force and after certain number of iterations, I have the specimen named 'end.xml'.
I want to detect the different interactions in 'begin.xml' and 'end.xml', I sort them into 3 types:
1. Permanent interactions: interaction that stays the same from 'begin' to 'end'
2. Newly formed interactions: interaction that is not available in 'begin', but appears in 'end'
3. Lost interactions: interaction that once was in 'begin' but in 'end' it's no longer available.

And based on that sorting method, I want to extract information from those bodies like positions and forces of the both 'base' and 'end' state. (position as x1, x2 and force as f, if interaction is not available, f=0)

Here is what I drafted for my idea:

O.load('end')
for i in O.interactions:
  x_1_end=O.bodies[i.id1].state.pos
  x_2_end=O.bodies[i.id2].state.pos
  f_end=i.phys.normalForce+i.phys.shearForce
  O.load('begin')
  for j in O.interactions:
    if j.id1==i.id1 and j.id2==i.id2: # condition of the permanent interaction
      x_1_begin=O.bodies[j.id1].state.pos
      x_2_begin=O.bodies[j.id2].state.pos
      f_begin=j.phys.nomalForce + j.phys.shearForce

Till this point, this certainly handles the permanent interactions but I don't know how to continue with the lost and new interactions between 'begin' and 'end'. Maybe I might continue my script as:

  elif j.id1==i.id1 and j.id2!=i.id2:
      x_1_begin=O.bodies[j.id1].state.pos
      x_2_begin=O.bodies[j.id2].state.pos
      f_begin=j.phys.normalForce+i.phys.shearForce # of f=0 depends on 'new' or 'lost' conception
  elif j.id1!=i.id1 and j.id2==i.id2:...
  else:
    continue

But I'm not sure this should work (the condition seems silly but I haven't found another better one). So I have questions:

1. How to effectively discriminate those three types of interaction between two states I mentioned above. Most of all the *newly formed interaction* and the *lost interaction*.
2. In which manner YADE sorts the interactions when we loop all over them, I do:
for i in O.interactions:
  print i.id1, i.id2
and I see the list is quite in random order, but I do the script again and list is still the same so I convince myself that YADE is using certain sorting method for such looping, is that true? Can you enlighten me on this point?

Thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Best Jan Stránský (honzik) said :
#1

Hello Hien,

for efficient extraction of 'old', 'new' and 'permamnent' interactions have
a look at python set [1]. Something like:

idsBegin = set((i.id1,i.id2) for i in interactionsBegin)
idsEnd = set((i.id1,i.id2) for i in interactionsEnd)
permanent = idsEnd & idsBegin # or idsEnd.intersection(idsBegin)
new = idsEnd - permanent # or idsEnd.difference(permanent)
lost = idsBegin - permanent # or idsBegin.difference(permanent)

cheers
Jan

[1] http://docs.python.org/2/library/sets.html

2014-03-12 15:01 GMT+01:00 Hien Nguyen <<email address hidden>
>:

> New question #245380 on Yade:
> https://answers.launchpad.net/yade/+question/245380
>
> Hello everybody,
> I want to ask a question about contact detection of two different states
> of the same specimen. Here is my problem:
> I have a saved model, named 'begin.xml', from this specimen, I apply a
> force and after certain number of iterations, I have the specimen named
> 'end.xml'.
> I want to detect the different interactions in 'begin.xml' and 'end.xml',
> I sort them into 3 types:
> 1. Permanent interactions: interaction that stays the same from 'begin' to
> 'end'
> 2. Newly formed interactions: interaction that is not available in
> 'begin', but appears in 'end'
> 3. Lost interactions: interaction that once was in 'begin' but in 'end'
> it's no longer available.
>
> And based on that sorting method, I want to extract information from those
> bodies like positions and forces of the both 'base' and 'end' state.
> (position as x1, x2 and force as f, if interaction is not available, f=0)
>
>
> Here is what I drafted for my idea:
>
> O.load('end')
> for i in O.interactions:
> x_1_end=O.bodies[i.id1].state.pos
> x_2_end=O.bodies[i.id2].state.pos
> f_end=i.phys.normalForce+i.phys.shearForce
> O.load('begin')
> for j in O.interactions:
> if j.id1==i.id1 and j.id2==i.id2: # condition of the permanent
> interaction
> x_1_begin=O.bodies[j.id1].state.pos
> x_2_begin=O.bodies[j.id2].state.pos
> f_begin=j.phys.nomalForce + j.phys.shearForce
>
>
> Till this point, this certainly handles the permanent interactions but I
> don't know how to continue with the lost and new interactions between
> 'begin' and 'end'. Maybe I might continue my script as:
>
> elif j.id1==i.id1 and j.id2!=i.id2:
> x_1_begin=O.bodies[j.id1].state.pos
> x_2_begin=O.bodies[j.id2].state.pos
> f_begin=j.phys.normalForce+i.phys.shearForce # of f=0 depends on
> 'new' or 'lost' conception
> elif j.id1!=i.id1 and j.id2==i.id2:...
> else:
> continue
>
> But I'm not sure this should work (the condition seems silly but I haven't
> found another better one). So I have questions:
>
> 1. How to effectively discriminate those three types of interaction
> between two states I mentioned above. Most of all the *newly formed
> interaction* and the *lost interaction*.
> 2. In which manner YADE sorts the interactions when we loop all over them,
> I do:
> for i in O.interactions:
> print i.id1, i.id2
> and I see the list is quite in random order, but I do the script again and
> list is still the same so I convince myself that YADE is using certain
> sorting method for such looping, is that true? Can you enlighten me on this
> point?
>
> Thanks in advance!
>
>
>
>
> --
> 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 :
#2

Thanks Jan Stránský, that solved my question.

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#3

This one deserves the "Best Answer Prize"!