Apply force only once

Asked by rayolau

Hi guys!

I try to study the displacement of various spheres ( with different weight ) when they apply the same force, on a surface which previously has been created and is composed of other spheres.

My problem is the IterPeriod of the PyRunner function that I create for apply the force on the sphere that I want, in this case, green spheres.

If I put the period = 1 , the force is constantly applied .How I can apply the force only once? PyRunner(command='force()',
  ¿?¿?¿?iterPeriod=¿?¿?¿,initRun=True,label='checker'),

My first choice was to put a high period (100000000 for example), but this way , the green sphere falls on the surface of spheres before the force was applied . What I need is to apply a force on green particle when it is "in the air " to describe a parabolic movement to fall on the surface and stop.

The second PyRunner is to store the position data ( x , y, z) and the green particle velocity .

Thanks in advance =)

the code:

O.load('/path/spheresurface.yade')

#/////////////////////////////////////////////////////
#////////////////// materials \\\\\\\\\\\\\\\\\\\\\\\
#/////////////////////////////////////////////////////

MatBal=O.materials.append(FrictMat(
 young=27e9,poisson=0.30,density=1000,
 frictionAngle=0.7,label='mat1'))

#/////////////////////////////////////////////////////
#////////////////// green sphere\\\\\\\\\\\\\\\\\\\\
#/////////////////////////////////////////////////////

### green sphere

O.bodies.append(utils.sphere((0.108,0.2289647116,0.7175),0.0199647116,color=(0,1,0),material='mat1'))

#/////////////////////////////////////////////////////
#//////////////// force on green sphere\\\\\\\\\\\\
#/////////////////////////////////////////////////////

def force():
 piedraensayo=[]

###force on green sphere
 for i in range(0,len(O.bodies)):
  b=O.bodies[i]
  if O.bodies[i].shape.color==(0,1,0):
   piedraensayo.append([i])
   id_ball=i
   fx=1
   fy=0
   fz=0
   O.forces.addF(id_ball, (fx, fy, fz))

#/////////////////////////////////////////////////////
#///////save position and velocity \\\\\\\\\\\\\\\\\
#/////////////////////////////////////////////////////
def guardar():
 if O.iter==0:
  global paso
  matriz1=[]
  for i in range(0,len(O.bodies)):
   b=O.bodies[i]
   if O.bodies[i].shape.color==(0,1,0):
    matriz1.append([i,b.state.pos[1],b.state.pos[1],b.state.pos[2],b.state.vel.norm()])
    np.savetxt('pruebaVERDE.out',matriz1,delimiter=',')

  paso=1

 if paso==1 and O.time>0.2:

  matriz2=[]
  for i in range(0,len(O.bodies)):
   b=O.bodies[i]
   if O.bodies[i].shape.color==(0,1,0):
    matriz2.append([i,b.state.pos[0],b.state.pos[1],b.state.pos[2],b.state.vel.norm()])
    np.savetxt('pruebaVERDE2.out',matriz2,delimiter=',')

  paso=paso+1

 if paso==2 and O.time>0.4:

  matriz3=[]
  for i in range(0,len(O.bodies)):
   b=O.bodies[i]
   if O.bodies[i].shape.color==(0,1,0):
    matriz3.append([i,b.state.pos[0],b.state.pos[1],b.state.pos[2],b.state.vel.norm()])
    np.savetxt('pruebaVERDE3.out',matriz3,delimiter=',')

  paso=paso+1

#/////////////////////////////////////////////////////
#///////////////////// engines \\\\\\\\\\\\\\\\\\\\\\\
#/////////////////////////////////////////////////////

O.engines=[
 ForceResetter(),
 InsertionSortCollider(
  [Bo1_Sphere_Aabb(),
   Bo1_Facet_Aabb(),
   Bo1_Box_Aabb(),
   Bo1_Wall_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),
   Ig2_Facet_Sphere_ScGeom(),
   Ig2_Wall_Sphere_ScGeom(),
   Ig2_Box_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 PyRunner(command='force()',
  iterPeriod=1,initRun=True,label='checker'),
 PyRunner(command='guardar()',
  iterPeriod=1,initRun=True,label='checker'),
 NewtonIntegrator(damping=0.5,gravity=(0,-9.81,0),label='newton'),
 yade.qt.SnapshotEngine(fileBase='3d-',iterPeriod=1000,label='snapshot')
]
O.dt=utils.PWaveTimeStep()

Question information

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

Hi Laura

> My first choice was to put a high period (100000000 for example), but
> this way , the green sphere falls on the surface of spheres before the
> force was applied .

I think that the force was applied correctly. The only problem is that the
force was was applied for one time step (I assume very short time), so it
has almost no effect..

> What I need is to apply a force on green particle
> when it is "in the air " to describe a parabolic movement to fall on the
> surface and stop.
>

From this sentence, I am not sure if applied force is really what you are
looking for.. Wouldn't setting initial velocity in x direction be OK? The
resulting trajectory would be parabola..

cheers
Jan

Revision history for this message
rayolau (rayolau88) said :
#2

Hi Jan, thanks for your reply!

Respect "I think that the force was applied correctly. The only problem is that the
force was was applied for one time step (I assume very short time), so it
has almost no effect.." You were right . I've changed the IterPeriod and the value of O.force, and works ok.

PyRunner(command='force()',
  iterPeriod=1000000,initRun=True,label='checker'),

def force():
 piedraensayo=[]
 for i in range(0,len(O.bodies)):
  b=O.bodies[i]
  if O.bodies[i].shape.color==(0,1,0):
   piedraensayo.append([i])
   id_ball=i
   fx=10000
   fy=0
   fz=0
   O.forces.addF(id_ball, (fx, fy, fz))

However, maybe I should apply a velocity in x direction. In this sense, I tried this, and not working. The problem is I don't know how putting the identity of the green sphere to apply the velocity vector only on her.

def force():
 piedraensayo=[]
 for i in range(0,len(O.bodies)):
  b=O.bodies[i]
  if O.bodies[i].shape.color==(0,1,0):
   piedraensayo.append([i])
   id_ball=i
   b.state.vel(id_ball,(1,0,0))

Error: b.state.vel(id_ball, (10,0,0))
TypeError: 'Vector3' object is not callable

Thanks for your help , as always! =)

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

Hi Laura,

> I've changed the IterPeriod and the value of O.force, and works ok.
>

I believe it works, but I would not use it this way :-)

                        b.state.vel(id_ball,(1,0,0))
> Error: b.state.vel(id_ball, (10,0,0))
> TypeError: 'Vector3' object is not callable

the syntax should be:

b.state.vel = (1,0,0)

use this line only once in the beginning of the simulation (preferably do
not use PyRunner). Otherwise it would overwrite the vertical component of
the motion. (To test it, you can use PyRunner as you have it now with
initRun=True and iterPeriod=someVeryBigNumber)

cheers
Jan

Revision history for this message
rayolau (rayolau88) said :
#4

Hi Jan, thanks again!

I don't understand what do you say about put the b.state.vel at the begin of the simulation without use PyRunner. What type of function should I write in the script for identify the green sphere and then apply the vector velocity in this sphere? Sorry for question, could be a own mistake in my way of do the script.

cheers,

Laura

Revision history for this message
rayolau (rayolau88) said :
#5

Hi Jan,

Solved!!
 I made the identification of waiting in the terminal , apply the rate in the field , and then start the simulation , which saves the position and speed of the stone with the PyRunner for storing data.

Thanks for the help. Regards =)

Laura

Revision history for this message
rayolau (rayolau88) said :
#6

Hi Jan,

Solved!!
 I made the identification of waiting in the terminal , apply the rate in the field , and then start the simulation , which saves the position and speed of the stone with the PyRunner for storing data.

Thanks for the help. Regards =)

Laura

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

Hi Laura

I mean something like this:

#########################################
O.load('/path/spheresurface.yade')

MatBal=O.materials.append(FrictMat(...))

### green sphere
greenSphere = sphere((0.108,0.2289647116,0.7175),0.0199647116,color=(0,1,0),material='mat1')
# no need of utils.sphere
greenSphereId = O.bodies.append(greenSphere)

def guardar():
        ...

O.engines=[
        ForceResetter(),
        InsertionSortCollider(
                [Bo1_Sphere_Aabb(),
                        Bo1_Facet_Aabb(),
                        Bo1_Box_Aabb(),
                        Bo1_Wall_Aabb()]),
        InteractionLoop(
                [Ig2_Sphere_Sphere_ScGeom(),
                        Ig2_Facet_Sphere_ScGeom(),
                        Ig2_Wall_Sphere_ScGeom(),
                        Ig2_Box_Sphere_ScGeom()],
                [Ip2_FrictMat_FrictMat_FrictPhys()],
                [Law2_ScGeom_FrictPhys_CundallStrack()]
        ),
        # PyRunner(command='force()',
        # iterPeriod=1,initRun=True,label='checker'), # this
PyRunner will not be used
        PyRunner(command='guardar()',
                iterPeriod=1,initRun=True,label='checker'),
        NewtonIntegrator(damping=0.5,gravity=(0,-9.81,0),label='newton'),
        yade.qt.SnapshotEngine(fileBase='3d-',iterPeriod=
1000,label='snapshot')
]
O.dt=utils.PWaveTimeStep()

greenSphere.state.vel = (1,0,0) # this :-)
#################################################3

cheers
Jan

2015-06-30 15:31 GMT+02:00 rayolau <email address hidden>:

> Question #268691 on Yade changed:
> https://answers.launchpad.net/yade/+question/268691
>
> rayolau posted a new comment:
> Hi Jan, thanks again!
>
> I don't understand what do you say about put the b.state.vel at the
> begin of the simulation without use PyRunner. What type of function
> should I write in the script for identify the green sphere and then
> apply the vector velocity in this sphere? Sorry for question, could be a
> own mistake in my way of do the script.
>
> cheers,
>
> Laura
>
> --
> 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
Bruno Chareyre (bruno-chareyre) said :
#8

I don't understand the details but for the record:

- applying a force for one step is: O.forces.addF(id_ball, f)
- applying a force permanently is: O.forces.addF(id_ball, f,permanent=True)