Question about i.phys.normalForce()

Asked by Henry

Dear all,
    I want to generate a sample with the average contact force lies in a range [Permit_Min_Force,Permit_Max_Force] throught the following code. However when I obtain the interaction force through "i.phys.normalForce()", some errors are listed during the calculations.
   Is the interaciton not update, after I change the radius of the spheres? if so, how can I update the incteraction properties during the simulaiton?

Errors:

File "PackInPolygon_new.py", line 229, in Cal_Interface
    F1=i.phys.normalForce[1]
AttributeError: 'NoneType' object has no attribute 'normalForce'

The codes:

Permit_Min_Force=500.0
Permit_Max_Force=2.0*Permit_Min_Force

def Cal_Interface():
    Rf=0.0
    Contact_Num=0
    aa=dict(O.energy.items())
    for i in O.interactions:
            if not i.isReal:continue
            F0=i.phys.normalForce[0]
            F1=i.phys.normalForce[1]
            F2=i.phys.normalForce[1]
            f=sqrt(F0*F0+F1*F1+F2*F2)
          # print('f:', f)
            Rf=Rf+f
            Contact_Num=Contact_Num+1
    return Rf, Contact_Num

while 1:
    Sign=0
    O.run(1000)
    (Rf, Contact_Num)=Cal_Interface()
    print("Rf=", Rf,"Contact_Num=", Contact_Num)
    if Contact_Num>0:
        Rf=Rf/Contact_Num
    else:
        Rf=0.0
    if Rf>Permit_Min_Force:
        Mult=0.99
    if Rf<Permit_Max_Force:
        Mult=1.01
    if Rf>Permit_Min_Force and Rf<Permit_Max_Force:
        Sign=1
        Mult=1
    for o in O.bodies:
        if isinstance(o.shape,Sphere):
            R=o.shape.radius
            o.shape.radius=R*Mult
    print("Contact_Num=", Contact_Num,"Sign=", Sign)
    if Sign==1:
        break

Thanks a lot!

Henry

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jérôme Duriez (jduriez) said :
#1

Hi,

The error says the i.phys you want to access is "NoneType", probably it does not exist. Did you run at least one iteration (with O.step(), or O.run() ) ?
It is necessary for the interactions to be detected and exist.

Jérôme

Revision history for this message
Jan Stránský (honzik) said :
#2

Hi Henry,

in your example, it is really veeeeery strange, that
F0 = i.phys.normalForce[0]
works without ok, but
F1 = i.phys.normalForce[1]
gives this error..

So a little investigation :-)
- is this the first error you get during the running of the program?
- could you please create a minimal working example (deleting all
unnecessary code not related to your problem) and send it to us?

cheers
Jan

2014-04-15 10:31 GMT+02:00 Henry <email address hidden>:

> New question #247021 on Yade:
> https://answers.launchpad.net/yade/+question/247021
>
> Dear all,
> I want to generate a sample with the average contact force lies in a
> range [Permit_Min_Force,Permit_Max_Force] throught the following code.
> However when I obtain the interaction force through "i.phys.normalForce()",
> some errors are listed during the calculations.
> Is the interaciton not update, after I change the radius of the
> spheres? if so, how can I update the incteraction properties during the
> simulaiton?
>
> Errors:
>
> File "PackInPolygon_new.py", line 229, in Cal_Interface
> F1=i.phys.normalForce[1]
> AttributeError: 'NoneType' object has no attribute 'normalForce'
>
>
> The codes:
>
> Permit_Min_Force=500.0
> Permit_Max_Force=2.0*Permit_Min_Force
>
> def Cal_Interface():
> Rf=0.0
> Contact_Num=0
> aa=dict(O.energy.items())
> for i in O.interactions:
> if not i.isReal:continue
> F0=i.phys.normalForce[0]
> F1=i.phys.normalForce[1]
> F2=i.phys.normalForce[1]
> f=sqrt(F0*F0+F1*F1+F2*F2)
> # print('f:', f)
> Rf=Rf+f
> Contact_Num=Contact_Num+1
> return Rf, Contact_Num
>
> while 1:
> Sign=0
> O.run(1000)
> (Rf, Contact_Num)=Cal_Interface()
> print("Rf=", Rf,"Contact_Num=", Contact_Num)
> if Contact_Num>0:
> Rf=Rf/Contact_Num
> else:
> Rf=0.0
> if Rf>Permit_Min_Force:
> Mult=0.99
> if Rf<Permit_Max_Force:
> Mult=1.01
> if Rf>Permit_Min_Force and Rf<Permit_Max_Force:
> Sign=1
> Mult=1
> for o in O.bodies:
> if isinstance(o.shape,Sphere):
> R=o.shape.radius
> o.shape.radius=R*Mult
> print("Contact_Num=", Contact_Num,"Sign=", Sign)
> if Sign==1:
> break
>
> Thanks a lot!
>
> Henry
>
>
> --
> 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
Henry (wenjiexu) said :
#3

Hi Jan,
    Many thanks for your help, and the script of my file, please check it. Thanks a lot!

# -*- coding: utf-8

from yade import utils,qt,export
from yade import plot
from yade.pack import *

mesh='Circle5cm' #name of gts mesh
surface=gts.read(open(mesh+'.gts'))

execfile('GenSPheresInSurface.py') #import a series of sphere in "surface"

O.materials.append(FrictMat(young=5.0e10,poisson=.1,density=3000000,frictionAngle=.0))

for b in O.bodies:

    if isinstance(b.shape,Sphere):
        b.state.blockedDOFs='zXY' # blocked movement along Z
        b.state.vel[1]=0.0
    if isinstance(b.shape,Clump):
        Clump_Num=Clump_Num+1
        b.state.blockedDOFs='yXYZ' # blocked movement along Y
        b.state.vel[1]=0.0

O.bodies.append(pack.gtsSurface2Facets(surface,color=(0.8,0.8,0.8),wire=True))

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()],label='collider'),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()],
 ),
 NewtonIntegrator(damping=0.9,gravity=(0,0.0,0.0)),
]

O.dt=1.0*utils.PWaveTimeStep()
O.timingEnabled=True;
O.run(2000)

Permit_Min_Force=500.0
Permit_Max_Force=2.0*Permit_Min_Force

def Cal_Interface():
    Rf=0.0
    Contact_Num=0
    for i in O.interactions:
            if not i.isReal:continue
            F0=i.phys.normalForce[0]
            F1=i.phys.normalForce[1]
            f=sqrt(F0*F0+F1*F1)#i.phys.normalForce().norm()
            Rf=Rf+f
            Contact_Num=Contact_Num+1
    return Rf, Contact_Num

def Gen_S():
    while 1:
        Sign=0
        O.run(1000)
        (Rf, Contact_Num)=Cal_Interface()
        print("Rf=", Rf,"Contact_Num=", Contact_Num)
        if Contact_Num>0:
            Rf=Rf/Contact_Num
        else:
            Rf=0.0
        if Rf>Permit_Min_Force:
            Mult=0.99
        if Rf<Permit_Max_Force:
            Mult=1.01
        if Rf>Permit_Min_Force and Rf<Permit_Max_Force:
            Sign=1
            Mult=1
        for o in O.bodies:
            if isinstance(o.shape,Sphere):
                R=o.shape.radius
                o.shape.radius=R*Mult
        print("Contact_Num=", Contact_Num,"Sign=", Sign)
        if Sign==1:
            break

Gen_S()

export.text(mesh+'.spheres')
print("Export the Spheres model successfuly!")

Henry

Revision history for this message
Henry (wenjiexu) said :
#4

However when I added the "Gen_S()" function in the Enginers as follows, its ok.

O.engines = O.engines+[PyRunner(command='Gen_S()',iterPeriod=10000,label='checker_Por')]

Thanks a lot!

Revision history for this message
Jan Stránský (honzik) said :
#5

I am really confused now :-) so your code is working now?
Jan

2014-04-15 11:56 GMT+02:00 Henry <email address hidden>:

> Question #247021 on Yade changed:
> https://answers.launchpad.net/yade/+question/247021
>
> Henry posted a new comment:
> However when I added the "Gen_S()" function in the Enginers as follows,
> its ok.
>
> O.engines =
>
> O.engines+[PyRunner(command='Gen_S()',iterPeriod=10000,label='checker_Por')]
>
> Thanks a lot!
>
> --
> 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
Henry (wenjiexu) said :
#6

The code is not working.
And I can't find the reason now.
Thanks!
Henry

Revision history for this message
Jan Stránský (honzik) said :
#7

ok :-)
to test your script, I will also need files:
- Circle5cm.gts
- GenSPheresInSurface.py

could you please place it somewhere on the internet so I can download them?
thanks
Jan

2014-04-17 2:51 GMT+02:00 Henry <email address hidden>:

> Question #247021 on Yade changed:
> https://answers.launchpad.net/yade/+question/247021
>
> Henry posted a new comment:
> The code is not working.
> And I can't find the reason now.
> Thanks!
> Henry
>
> --
> 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
>

Can you help with this problem?

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

To post a message you must log in.