setting initial velocity

Asked by jacopo

hi i still need your help. Sorry for the time i will take.

i'm trying to move my surface (is built by facets). i tried with translation engine but i saw that this engine gives a costant velocity for all the simulation lenght. I would like to set only the initial velocity. I try to build a function to reach this goal :

def inizio():
     if O.iter < 2:
       for i in range(1,27459) :
           O.bodies[i].state.vel=(-18,0,0)

########################
i set O.iter < 2 in way to have this velocity (18 m/s) only for the first two iteractions, but even at 200 iters i still have the same velocity. I try to explain better: this surface must hit a soil and be stopped after some seconds (friction and dissipation). What happened is: the surface pass through the soil without changing his velocity. I see the soil's spheres moving due to the impact, but the surface doesn't "feel" it. I already set the contact sphere-sphere and Facet-sphere, so i think Yade is setting at each iteraction the same velocity.

IS it a problem with contacts? or is it a problem with the velocity definition?

i post my script :

#####################################
#####################################

from yade import pack, plot
from yade import export, ymport
from yade import utils

####################
#### LOAD FACETS ###
####################

def readFacet(line,**kw): # read one facet from line.
   nums = [float(w) for w in line.split()] # convert line to 9 numbers
   v1,v2,v3 = nums[0:3], nums[3:6], nums[6:9] # split them to 3 vertices
   return facet((v1,v2,v3),**kw) # creates and returns facet
def loadFacets(fName): # load facets from a file
   with open(fName) as f:
      lines = f.readlines()
   return [readFacet(line) for line in lines] # convert lines to facets

################################
#### SALVA POSIZIONE FACETS ####
################################

def saveFacet(f,facet): # save one facet as 9 coordinates (3 vertices)
   vs = facet.shape.vertices # vertices in local coord system
   vs = [facet.state.pos + facet.state.ori*v for v in vs] # vertices in global coord system
   line = " ".join(" ".join(str(e) for e in v) for v in vs)
   f.write(line+"\n")
def saveFacets(fName): # save all facets
   facets = [b for b in O.bodies if isinstance(b.shape,Facet)] # list of facets in simulation
   with open(fName,"w") as f: # save them to a file
      for facet in facets:
         saveFacet(f,facet)

#####################################
#####################################
#####################################

facets = loadFacets("./AEREO.txt")
lista=O.bodies.append(facets)

################
##box material#####
################

idCA=FrictMat(density=2227,frictionAngle=radians(0.5),label='CA',young=30e9,poisson=0.15)
O.materials.append(idCA)

############################

cassone = loadFacets("./posizione_cassone_finale.txt")
O.bodies.append(cassone)

############################

#################
##soil material##
#################

idSoil=FrictMat(density=1500,frictionAngle=radians(29),label='soil',young=11277647.5,poisson=0.21)
O.materials.append(idSoil)

############################

spheres = ymport.text("./POSIZIONE_FINALE_SFERE.txt",color=(0,0,1))
O.bodies.append(spheres)

###################
###################
###################

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
   InteractionLoop(
      [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()]
   ),
 #TranslationEngine(translationAxis=(-1,0,0),velocity=18,ids=lista,label='trans'),
 NewtonIntegrator(gravity=(0,0,-9.81),damping=0),
 PyRunner(command='inizio()',iterPeriod=1),
]

################
####funzioni####
################

def inizio():
     if O.iter < 2:
       for i in range(1,27459) :
           O.bodies[i].state.vel=(-18,0,0)

O.dt=0.8*PWaveTimeStep()
O.run()
#############################
#############################

thanks for your time.

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
Bruno Chareyre (bruno-chareyre) said :
#1

My religion is against answering questions not complying to https://yade-dem.org/wiki/Howtoask, sorry.

The question is just "how to move facets?" yet it needs a long script and not less than three external files.
None of them are provided, so the script just doesn't work... (but please read guidelines again before sending three links to dropbox...).
Or maybe consider comment #5 in [1]. What about impacting one single facet on one single sphere for a start?
Regards
Bruno

[1] https://answers.launchpad.net/yade/+question/672673

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

Hello,

> i set O.iter < 2 in way to have this velocity (18 m/s) only for the first two iteractions, but even at 200 iters i still have the same velocity.

if you set velocity and there is no need to change it (no contact or external force), it just remains constant (the case O.iter >= 2)
Also, the velocity remains constant in the case of contact if the body has blocked degrees of freedom or is not dynamic (default for facets)

> the surface pass through the soil without changing his velocity.
> I see the soil's spheres moving due to the impact, but the surface doesn't "feel" it. I already set the contact sphere-sphere and Facet-sphere, so i think Yade is setting at each iteraction the same velocity.
> IS it a problem with contacts? or is it a problem with the velocity definition?

Because facets in your simulation are not dynamic. To fix it, you have to do something like
###
f = facet(...,dynamic=True,fixed=False)
f.state.mass = 123 # (!)
f.state.inertia = (1,2,3) # (!)
###
I this case, each facet would move independently, so probably you should clump them together.
Also note that facet is considered as zero-thick element, so its mass and inertia is zero by default, you should assign a nonzero value.

Repeating Bruno, you could have find this behavior with a few spheres and a few facets. Consider first to build a very simplified simulation to understand all these Yade "gotchas"..
Also next time please try to provide a MINIMAL working example. E.g., saveFacets part of your script is not used at all..
Also next time please name your question according to your real problem, because "setting initial velocity" works ok according to your description :-)

cheers
Jan

Revision history for this message
jacopo (varrialeee) said :
#3

Hi jan, thanks for your help. I modified the script as you suggest me and it is working (when the box hits the soil, it decelerates and breaks). As you said i need to clump it, but i'm facing this error:

python: /build/yade-2_s9R0/yade-1.20.0/core/Clump.cpp:211: static void Clump::updateProperties(const boost::shared_ptr<Body>&, unsigned int): asserzione "M>0" non riuscita.
Annullato (core dump creato)

i provide a minimal script:

#####################################
########### BOX 1 ###################
#####################################

facets=geom.facetBox((4,0,0),(1.2,1.2,1.2),wallMask=63)
clumpID = O.bodies.appendClumped(facets)
clump = O.bodies[clumpID]

for b in O.bodies:
    b.dynamic=True
    b.state.mass=1
    b.state.inertia=(0.1,0.5,0.4)
    b.fixed=True

################
##box material##
################

idCA=FrictMat(density=2227,frictionAngle=radians(0.5),label='CA',young=30e9,poisson=0.15)
O.materials.append(idCA)

############################
####### BOX 2 ##############
############################

O.bodies.append(geom.facetBox((0,0,0),(2,2,2),wallMask=29))

#################
##soil material##
#################

idSoil=FrictMat(density=1500,frictionAngle=radians(29),label='soil',young=11277647.5,poisson=0.21)
O.materials.append(idSoil)

############################

pred=pack.inAlignedBox((-2,-2,-2),(2,2,2))
spheres=pack.regularHexa(pred,radius=0.1,gap=0)
O.bodies.append(spheres)

###################
###################
###################

O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
   InteractionLoop(
      [Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
      [Ip2_FrictMat_FrictMat_FrictPhys()],
      [Law2_ScGeom_FrictPhys_CundallStrack()]
   ),
 #TranslationEngine(translationAxis=(-1,0,0),velocity=18,ids=lista,label='trans'),
 NewtonIntegrator(gravity=(0,0,-9.81),damping=0),
 PyRunner(command='inizio()',iterPeriod=1),
]

################
####funzioni####
################

def inizio():
     if O.iter < 2:
       for i in range(0,12) :
           O.bodies[i].state.vel=(-18,0,0)

O.dt=0.8*PWaveTimeStep()
O.saveTmp()
########################################
########################################

->NOTE:
changing the first part of the script "BOX 1" with the following script you could see what i'm trying to do:

#####################################
########### BOX 1 ###################
#####################################

O.bodies.append(geom.facetBox((4,0,0),(1.2,1.2,1.2),wallMask=63))

for b in O.bodies:
    b.dynamic=True
    b.state.mass=10
    b.state.inertia=(0.1,0.5,0.4)
    b.fixed=True

In particular, in my project, i have a much more complicated shape then a box. If i use the same identical logic of the provided script i can observe that my object is still moving at the same velocity . I try to explain better: while the first part of my object hits the soil and starts to decelerate and break itself, the not in contact parts continue their movement with the same starting velocity. My question is :
-> clumping all my object facets, will they start to decelerate even if they aren't directly in contact with the soil?

I'm sorry for the last questions, i read the guidelines, i hope to not make any other mistakes.

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

> I modified the script

perfect, thanks :-)

> As you said i need to clump it, but i'm facing this error:

you need to set mass and inertia of facets before clumping them.
The clump-generating algorithm (computing center of mass, inertia etc. of the resulting clump) assumes nonzero mass and inertia.

> clumping all my object facets, will they start to decelerate even if they aren't directly in contact with the soil?

yes, all the facets will behave as a rigid body. So if the "nose" will contact the soil, the whole aircraft would deccalerate.

> i hope to not make any other mistakes.

well, a mistake is to ask questions unrelated to the original question [1] :-) so next time please open the new one concerning the new topic.

cheers
Jan

[1] https://yade-dem.org/wiki/Howtoask , point 5

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

> clumping all my object facets, will they start to decelerate even if they aren't directly in contact with the soil?

Yes they should.

The assertion failure (you are using a debug build are'nt you? else I think asserts would be removed)? is because the cumulated mass of the clumped facets is zero.
You need 1/ to assign mass and inertia to each facet before clumping or 2/ compile without debug features so that you can define mass/inertia of the clump after clumping.
Cheers
Bruno

Revision history for this message
jacopo (varrialeee) said :
#6

Ok thanks for the fast answers. Probably i don't understand in the right way. I change the script in this way but i'm still facing the same error:

#####################################
########### BOX 1 ###################
#####################################

facets=geom.facetBox((4,0,0),(1.2,1.2,1.2),wallMask=63)

for b in O.bodies:
    b.dynamic=True
    b.state.mass=10
    b.state.inertia=(0.1,0.5,0.4)
    b.fixed=True

clumpID = O.bodies.appendClumped(facets)
clump = O.bodies[clumpID]
#clump.state.mass = 10

##########################
############################
In this way i should have set the facets mass and inertia( using the cycle), and then clump them.
If i type O.bodies[2].state.mass from terminal i could see that its mass is set to 10 (deleting the clumping part). If i add at the of the cycle this:

clumpID = O.bodies.appendClumped(facets)
clump = O.bodies[clumpID]

it gives me the same error:

python: /build/yade-2_s9R0/yade-1.20.0/core/Clump.cpp:211: static void Clump::updateProperties(const boost::shared_ptr<Body>&, unsigned int): asserzione "M>0" non riuscita.
Annullato (core dump creato)

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

1) instant replay: "a mistake is to ask questions unrelated to the original question [1]". Please open a new question for a new question
2) please post complete scripts, not just changes

concerning your problem:
for b in O.bodies: ... O.bodies at this point contains no facets, you should do
for f in facets: ...
and then
O.bodies.appendClumped(...)

cheers
Jan

[1] https://yade-dem.org/wiki/Howtoask , point 5

Revision history for this message
jacopo (varrialeee) said :
#8

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