← Back to team overview

yade-users team mailing list archive

Re: [Question #699510]: How to get the resultant force on a particle

 

Question #699510 on Yade changed:
https://answers.launchpad.net/yade/+question/699510

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

there are two points:
1) NewtonInegrator.gravity. It is not included in O.forces.f
2) i.phys.normalForce and i.phys.shearForce are numbers/vectors SAME for both interacting bodies, but clearly they must be taken into account oppositely for each body (Newton's 3rd law of action and reaction)

Below is corrected code. For the second example, replace 0 with 20 (body id)
###
    NewtonIntegrator(...,label="integrator")
...

print O.forces.f(0) + newton.gravity * O.bodies[0].state.mass

a=[]
for i in O.bodies[0].intrs():
        f = i.phys.normalForce + i.phys.shearForce
        if O.bodies[0].id == i.id1: f = -f # HERE
        a.append(f)

resultF=Vector3(0,0,0)
for i in range(len(a)):
        resultF=resultF+a[i]
resultF += integrator.gravity * O.bodies[0].state.mass # HERE
###

Cheers
Jan


PS: Not important notes:

---
> for i in range(len(a)):
>         resultF=resultF+a[i]

a more readable would be:
for f in a:
        resultF=resultF+f

or even more "pythonic" without (explicit) loop:
resultF = sum(a, Vector3.Zero)

---
print O.forces.f(20)

a=[]
for i in O.bodies[20].intrs():

20 is repeated code/value, which is generally considered as bad practice (to change it, you need to be careful to change all occurrences, even more emphasized with the corrected code).
Better is to use a variable for this:
###
id = 20
print O.forces.f(id)
a=[]
for i in O.bodies[id].intrs():

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.