Body' state change

Asked by Daniela

Hi,
If I have a body represented by a gts surface, I would like to know if it is possible to move this body.
During the simulation I would like to change the states of the body (position, rotation, velocity and angular velocity). Is it possible? Besides that, could I obtain the forces and torques acting on this body?
Thanks a lot.
Daniela

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Bruno Chareyre
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Anton Gladky (gladky-anton) said :
#1
Revision history for this message
Daniela (dmaionchi) said :
#2

Thansk agian Anton for the answer.

Revision history for this message
Daniela (dmaionchi) said :
#3

Hi Anton,
I took a look in the example that you sent me and tried to change it. My goal is that I can change for example the angular velocity of the RotationEngine at each iterPeriod. I tried it:

rotvel=0
O.engines=[
 #SubdomainBalancer(colorize=True,initRun=True,iterPeriod=100),
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Wall_Aabb()],label='collider'),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom(),Ig2_Wall_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()],
 ),
 GravityEngine(gravity=(1e-2,1e-2,-1000)),
 NewtonIntegrator(damping=.1,exactAsphericalRot=True),
 RotationEngine(
  ids=rotateIDs,
  angularVelocity=rotvel,
  rotationAxis=[0,-1,0],
  rotateAroundZero=1,
  zeroPoint=[-7.0,-6.0,-5.0]),
 HarmonicMotionEngine(A=[0,0,0.5], f=[0,0,20.0], fi = [0.0,0.0,pi], ids = vibrationPlate),
 HarmonicRotationEngine(A=0.2, f=100.0, fi = pi, rotationAxis=[1.0,0.0,0.0], rotateAroundZero = True, zeroPoint = [-15.0,3.0,-7.0], ids = vibrationRotationPlate),
     PyRunner(command='rotation()',iterPeriod=100)
]
def rotation():
    global rotvel
    rotvel = 100

but the value of rotvel seems to be always 0. How can I change then a variable located inside of the Engine?
Thanks, Daniela

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

I think that you can use labels:

O.engines = [
...
SomeEngine(...,label='sEngine')
...
]

sEngine.someParameter = value

good luck
Jan

______________________________________________________________
> Od: "Daniela" <email address hidden>
> Komu: <email address hidden>
> Datum: 06.07.2011 15:11
> Předmět: Re: [Yade-users] [Question #163736]: Body' state change
>
>Question #163736 on Yade changed:
>https://answers.launchpad.net/yade/+question/163736
>
> Status: Solved => Open
>
>Daniela is still having a problem:
>Hi Anton,
>I took a look in the example that you sent me and tried to change it. My goal is that I can change for example the angular velocity of the RotationEngine at each iterPeriod. I tried it:
>
>rotvel=0
>O.engines=[
> #SubdomainBalancer(colorize=True,initRun=True,iterPeriod=100),
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb(),Bo1_Wall_Aabb()],label='collider'),
> InteractionLoop(
> [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom(),Ig2_Wall_Sphere_ScGeom()],
> [Ip2_FrictMat_FrictMat_FrictPhys()],
> [Law2_ScGeom_FrictPhys_CundallStrack()],
> ),
> GravityEngine(gravity=(1e-2,1e-2,-1000)),
> NewtonIntegrator(damping=.1,exactAsphericalRot=True),
> RotationEngine(
> ids=rotateIDs,
> angularVelocity=rotvel,
> rotationAxis=[0,-1,0],
> rotateAroundZero=1,
> zeroPoint=[-7.0,-6.0,-5.0]),
> HarmonicMotionEngine(A=[0,0,0.5], f=[0,0,20.0], fi = [0.0,0.0,pi], ids = vibrationPlate),
> HarmonicRotationEngine(A=0.2, f=100.0, fi = pi, rotationAxis=[1.0,0.0,0.0], rotateAroundZero = True, zeroPoint = [-15.0,3.0,-7.0], ids = vibrationRotationPlate),
> PyRunner(command='rotation()',iterPeriod=100)
>]
>def rotation():
> global rotvel
> rotvel = 100
>
>but the value of rotvel seems to be always 0. How can I change then a variable located inside of the Engine?
>Thanks, Daniela
>
>--
>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
Daniela (dmaionchi) said :
#5

Hi Jan, it works with labels. Thanks!
I still have two questions:

1. I created a RotationEngine and a TranslationEngine, both with the same id, as want that a body (obtained from a mesh for example) has translational and rotational movement. But I see that just the one that is defined in the second place affects the body in the simulation. I saw that there is a CombinedKinematicEngine, but I am not sure if I should use it for this case. Anyway, how should I proceed in order to have the rotation and translation engines acting on the body?

2. I want to change the position and orientation of the body at some iterations. Can I do it using some Engine? I cannot imagine that I can do this using the TranslationEngine, as with this Engine I can define just the velocity.
When I include the body with O.bodies.append(YMPORT.GMSH("file.mesh",shift=,orientation=), I can define the orientation using Quaternion and the position using shift. I though that I could may bechange these variables, but I am also not sure because then I would need to reload the mesh every time that I change their values.

So, I would be grateful if you could help me with these questions.
Thanks in advance, Daniela

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

>1. I created a RotationEngine and a TranslationEngine, both with the
>same id, as want that a body (obtained from a mesh for example) has
>translational and rotational movement. But I see that just the one that
>is defined in the second place affects the body in the simulation. I saw
>that there is a CombinedKinematicEngine, but I am not sure if I should
>use it for this case. Anyway, how should I proceed in order to have the
>rotation and translation engines acting on the body?
O.engines = [
...
RotationEngine(...) + TranslationalEngine(...)
...
]

>
>2. I want to change the position and orientation of the body at some iterations. Can I do it using some Engine? I cannot imagine that I can do this using the TranslationEngine, as with this Engine I can define just the velocity.
O.bodies[...].state.pos = vector3(a,b,c)
but I am not sure if this works or not...

Jan

Revision history for this message
Daniela (dmaionchi) said :
#7

Hi Jan, thanks again for the help.
It works what you suggested, but I still have some problems:

1. As I don't want to load the mesh in the begin of the simulation, I wrote a PyRunner that checks the unbalancedForce and loads the mesh. Inside of the def function I defined the new engine using O.engines = O.engine+[RotationEngine(...,label='rotEng') + TranslationalEngine(...,label='transEng')] . But the problem now is that when I use the label to change some parameter from this engine, I receive the message: NameError: global name 'rotEng' is not defined. I tried to define the both labels as global, but it did not work. Any idea what I am doing wrong?

2.I also created a PyRunner to change the position of the body. The body is for example defined as:
body1=O.bodies.append(geom.facetCylinder((0,3,2),...)
It tried to make this
for b in O.bodies:
        if (b in body1):b.state.pos = Vector3(1,1,1)
but it does not work. If I write body1.id, the message that I receive says that list don't have ids.
How could I then change the position of the body1?

Thansk a lot. Daniela

Revision history for this message
Daniela (dmaionchi) said :
#8

Hi, the second problem I got to solve: if (b.id in body1):b.state.pos = Vector3(1,1,1)

Revision history for this message
Best Bruno Chareyre (bruno-chareyre) said :
#9

> 1. I created a RotationEngine and a TranslationEngine, both with the
> same id, as want that a body (obtained from a mesh for example) has
> translational and rotational movement. But I see that just the one that
> is defined in the second place affects the body in the simulation. I saw
> that there is a CombinedKinematicEngine, but I am not sure if I should
> use it for this case. Anyway, how should I proceed in order to have the
> rotation and translation engines acting on the body?
Note that if your motion is not too complicated, e.g. constant velocity
or spin, you can do something like:

b=O.bodies[100]
b.state.blockedDOFs='xyz' #block translational DOFs
b.state.vel=(1,0,0) #impose a velocity

> 2. I want to change the position and orientation of the body at some iterations. Can I do it using some Engine? I cannot imagine that I can do this using the TranslationEngine, as with this Engine I can define just the velocity.
> When I include the body with O.bodies.append(YMPORT.GMSH("file.mesh",shift=,orientation=), I can define the orientation using Quaternion and the position using shift. I though that I could may bechange these variables, but I am also not sure because then I would need to reload the mesh every time that I change their values.
>
Basically, the chance that you break something by imposing position
shifts is high, because many DEM algorithms are based on velocity
(updating bounds, contact kinematics, viscous and/or incremental contact
laws, post-processing,...). If you want to move b from p1 to p2,
consider this method:

b.state.blockedDOFs='xyz'
b.state.vel=(p2-p1)/O.dt
O.run(1)
Then maybe release the body:
b.state.blockedDOFs=''
b.state.vel=(0,0,0)

This is compatible with 100% of Yade algorithms.

Bruno

Revision history for this message
Daniela (dmaionchi) said :
#10

Hi,
actually I have a file containing information about position, velocity, orientation and angular velocity for a body for many time steps. In this sense, what I need is to "tell" the body in yade these values during the simulation. I suppose that I could do it using the RotationEngine and the TranslationEngine, because then I could already define at least the velocity and the angular velocity. But I have 2 problems here:
1. when I make RotationEngine(...,label='rotEng')+TranslationEngine(...,label='transEng') and try to define for example rotEng.angularVelocity=10, I receive the message: NameError: global name 'rotEng' is not defined. The same with transEng. It seems to be a problem with the + sign. But why?
2. the zeroPoint must change, as the body also has a translation movement. Actually I could just give it the value of the position, but I still have the problem described above when I write rotEng.zeroPoint.
I hoppe someone can help me.
Thanks. Daniela

Revision history for this message
Daniela (dmaionchi) said :
#11

Hi,
I have tried to solve my problem about moving bodies using to steps. At first I give the values of the new position and orientation (mantaining velocity and angular velocity zero) and then the values of the velocity and angular velocity (this one, using a RotationEngine), something like this:

def changeValues():
    for i in idArray:
        O.bodies[int(i)].state.pos += Vector3(0.1,0,0)
        O.bodies[int(i)].state.vel = Vector3(0.,0,0)
        O.bodies[int(i)].state.angVel = Vector3(0,0,0)
    checker.command='changeValues2()'
    checker.iterPeriod=1

def changeValues2():
    for i in idArray:
        O.bodies[int(i)].state.vel = Vector3(10,0,0)
    rotEng.angularVelocity=100
    rotEng.rotationAxis=[0,1,0]
    rotEng.zeroPoint += (0.01,0,0)
    checker.command='changeValues()'
    checker.iterPeriod=1

I have tested it and it seems to work ok. Can you confirm if this is really compatible with the Yade algorithms?
Thansk in advance, Daniela.

Revision history for this message
Daniela (dmaionchi) said :
#12

Problem solved.

Revision history for this message
Daniela (dmaionchi) said :
#13

Thanks Chareyre, that solved my question.