i.geom.incidentVel is not a vector

Asked by Rioual on 2020-04-24


This is a very basic question
I want to use i.geom.incidentVel as the incident velocity of an interaction (https://yade-dem.org/doc/yade.wrapper.html?highlight=geom%20incidentvel#yade.wrapper.ScGeom.incidentVel).
But, unfortunately, when i print it in my script, the output is not a vector but is:
<bound method ScGeom.incidentVel of <ScGeom instance at 0x7ff930003690>>

Can you explain me what's happening ??

My very simple script is below



# basic simulation showing sphere falling ball gravity,
# bouncing against another sphere


# add 2 particles to the simulation
# they the default material (utils.defaultMat)


# simulation loop -- see presentation for the explanation
  [Ig2_Sphere_Sphere_ScGeom()], # collision geometry
  [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
  ), # contact law -- apply forces
 # Apply gravity force to particles. damf ing: numerical dissipation of energy.

# set timestep to a fraction of the critical timestep

# save the simulation, so that it can be reloaded later, for experimentation

def contactp():

 for i in O.interactions:

  particle1= O.bodies[i.id1]
  particle2= O.bodies[i.id2]

  cp = i.geom.contactPoint
  R1=i.geom.refR1; R2=i.geom.refR2

  v = i.geom.incidentVel

  print 'id1=', i.id1,'id2=', i.id2
  print 'R1=',R1,'R2=',R2
  print 'cp=', i.geom.contactPoint
  print 'pdepth=', i.geom.penetrationDepth
  print 'incidentVel=', v

Question information

English Edit question
Yade Edit question
No assignee Edit question
Last query:
Last reply:

This question was reopened

Jérôme Duriez (jduriez) said : #1

You forgot the parentheses: geom.incidentVel() is the correct syntax since it is a function (see the "error" message)


Rioual (francois-rioual-v) said : #3

Hi Jerome,

No, this is not an error message I get.
Instead of having a vector (velocity) at output for i.geom.incidentVel , i get =<bound method ScGeom.incidentVel of <ScGeom instance at 0x55e2957905f0>>



ps: the error message appears when I add ()

Jan Stránský (honzik) said : #4


> ps: the error message appears

please always try to be as specific as possible (in this case providing the complete error message)

In these cases, please first consult the documentation [1]. You should pass Interaction instance as an argument:
v = i.geom.incidentVel(i)


[1] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.ScGeom.incidentVel

Jérôme Duriez (jduriez) said : #5

Because I previously overlooked that necessary Interaction attribute (thanks Jan), let me try to add more explanations:

Your initial output message (more than an "error" message, indeed) was some "..method..". In the framework of object-oriented programming (like Python, C++, and YADE, where everything is an instance (= an item, one may say) of some given Class), method means function, and parentheses are then mandatory.
At least, as soon as you're interested more in the return value than in the function itself.. That was your case: you wanted to have the Vector3 returned by that method incidentVel, and not the method itself.

Then the question is, what do you have to put inside those parentheses ?

Most often, nothing. You can call directly eg i.geom.dict() even though the doc would mention one attribute "arg1" [*]. This arg1 attribute actually refers to the object whose method you're calling, so it's not necessary to pass it as an attribute.

On the other hand, incidentVel doc here mentions other attributes than arg1: an Interaction instance in particular => this one is necessary, see Jan's syntax.

There also is a bracket-delimited attribute, here avoidGranularRatcheting, with an equal sign. This one is an optional attribute, it has some default value = the right hand side of the equality. You do not need to pass this attribute as long as you're happy with that default value.

Further reading could be found in Python documentation about Python functions and their docstrings.

[*] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.ScGeom.dict

Rioual (francois-rioual-v) said : #6

...Thank you very much you all, it works now but I don't really see the logic for precising (i): i.geom already precises that you are referring to interaction "i", no ??
hence, i.geom.penetrationDepth works
i.geom.contactPoint works



Jérôme Duriez (jduriez) said : #7

penetrationDepth and contactPoint are attributes of the ScGeom class, not methods, so you can anyway not compare with the behavior for a method like incidentVel()

I otherwise agree it's a little deceiving to have to type i.geom.incidentVel(i)..

But I personally understand it thinking to i.geom.incidentVel(i), as (i.geom).incidentVel(i), where (i.geom) is just a ScGeom object, with all its attributes and methods, but with no more connection to the interaction i itself.

So, when calling the incidentVel() method of that ScGeom object, you have to pass again the interaction object that is "behind" (because the computations behind incidentVel() require data that are in i itself, and that are not contained in the ScGeom object i.geom)

Can you help with this problem?

Provide an answer of your own, or ask Rioual for more information if necessary.

To post a message you must log in.