Stop conditions failed

Asked by Diego Sotro

hi brothers,
i tried imposed a stop condition that is K_i -K_(i+1)<1e-5 for example, and i need obtain this K_i and K_(i+1), but with my scrypt i can't to get k_i calculated in def of my PyRunner. i can't to define ki variable as global and then i can't read this variable in parar() PyRunner. this is scrypt

from yade import geom, utils, export, pack
global rmean, D, h, load, Sd, mu, Pi, rhoh, ki
rmean=0.003
D=rmean*38.
h=rmean*60.
load=5e-4

Sd=0.17
mu=0.001
Pi=1/6.
g=9.81
rhoh=1000

R=D/2.
H=2.*h
mn,mx=Vector3(0,0,0),Vector3(D,D,H)
young=1e6
compFricDegree = 3 #ojo con este parametro
finalFricDegree = 30

O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='sph'))

walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

cuadr=pack.inAlignedBox((0,0,0),(D,D,H))
spheres=pack.randomDensePack(cuadr,spheresInCell=3000,radius=rmean,rRelFuzz=Sd,returnSpherePack=True)

spheres.toSimulation(material='sph')

newton=NewtonIntegrator(damping=0.2,gravity=(0,0,-9.81))
O.bodies[5].state.vel[2]=-0.05

def parar():
   carga=O.forces.f(5)[2]
   if O.bodies[5].state.vel[2]==0: muro.dead=1
   else:
    if carga>5e-4:
     O.bodies[5].state.vel[2]=0
     O.pause()
     flow.dead=0
     flow.defTolerance=0.03
     flow.useSolver=3
     flow.permeabilityFactor=1
     flow.viscosity=mu
     flow.bndCondIsPressure=[0,0,0,0,1,1]
     flow.bndCondValue=[0,0,0,0,0,Pi]
     flow.boundaryUseMaxMin=[0,0,0,0,0,0]
     O.run()

def flujest():
   if flow.getBoundaryFlux(4)==0: Err=100
   else: Err=(flow.getBoundaryFlux(5)+flow.getBoundaryFlux(4))/flow.getBoundaryFlux(4)*100
   if abs(Err)<0.1:
     Qout=flow.getBoundaryFlux(5)
     Qin=flow.getBoundaryFlux(4)
     dh=O.bodies[5].bound.refPos[2]
     k1=mu*Qin*1./Pi/(D*D)*dh
     k2=g*rhoh*Qin*1./Pi/(D*D)*dh*100
     n=flow.porosity
     print "Qin=",Qin," k1=",k1 ,"k2=",k2 ," Porosity=",n

def kant():
   Qin=flow.getBoundaryFlux(4)
   dh=O.bodies[5].bound.refPos[2]
   if Qin==0: ki=1000
   else: ki=mu*Qin*1./Pi/(D*D)*dh

#globals(ki)['kant']=locals(ki)['kant']

def final():
   Qin=flow.getBoundaryFlux(4)
   dh=O.bodies[5].bound.refPos[2]
   kf=mu*Qin*1./Pi/(D*D)*dh
   if abs(kf-ki)<1e-5: O.pause()

O.engines=[
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_ScGeom_FrictPhys_CundallStrack()],
),
FlowEngine(dead=1, label="flow"),
GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
PyRunner(command='flujest()', iterPeriod=500, initRun=8000, label="agua"),
newton,
PyRunner(command='parar()', iterPeriod=50, label="muro"),
PyRunner(command='kant()', iterPeriod=200, initRun=8000, label="kini"),
PyRunner(command='final()', iterPeriod=200, initRun=8300, label="kfin")
]

O.run()

thanks

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
Diego Sotro (horusdnsr) said :
#1

** this variable in final()

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

Hello Diego,
there are two options. Either proper use of 'global' keyword in Python (use
it *in* the function, not in the beginning of the script), or you can use
__builtin__ module (be careful not to overwrite some other important
variables).
Let us know if it works
cheers
Jan

###########################
import __builtin__

someGlobalVariable = 1
someOtherGlobalVariable = 1
__builtin__.someGlobalVariable = someGlobalVariable

def increment():
  __builtin__.someGlobalVariable += 1
    #
  global someOtherGlobalVariable
  someOtherGlobalVariable += 1
    #
  print 'builtin',__builtin__.someGlobalVariable
  print 'global ',__builtin__.someGlobalVariable

O.engines = [PyRunner(iterPeriod=1,command="increment()"),]
O.run(10)
#############################

2015-05-15 1:36 GMT+02:00 Diego Sotro <email address hidden>
:

> Question #266939 on Yade changed:
> https://answers.launchpad.net/yade/+question/266939
>
> Diego Sotro posted a new comment:
> ** this variable in final()
>
> --
> 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
Diego Sotro (horusdnsr) said :
#3

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

Revision history for this message
Diego Sotro (horusdnsr) said :
#4

Thank Jan you solved my problem.