rotate all the simulation

Asked by jacopo

hi i'm new on yade. I have a little problem that i 'm not able to fix and a question:

i created a particles deposition in a Box and i saved the particles positions. I would like to save also the Box position (is built with facets (geom.facetbox) .In this way i should have a file where is texted the particles and box positions.

After this , i would like to rotate everything of 45° along Z axes in another script. Any idea of how can i do it? I mean , i want to paste box and particles positions rotate of 45° before the simulation starts. Does exist any function that allow me to do it?

this is the script, but i think you don't need it, becouse is only a particles deposition. From this script i want to save particles and box positions. These i 'll rotate after in another script.
Thanks for your time.

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

# create rectangular box from facets
O.bodies.append(geom.facetBox((0,0,0.6),(1.5,1.075,0.6),wallMask=31))

pred=pack.inAlignedBox((-1.5,-1.075,0),(1.5,1.075,1.2))

idSoil=FrictMat(density=1550,frictionAngle=radians(28),label='soil',young=10787315,poisson=0.2)

O.materials.append(idSoil)

spheres=pack.randomDensePack(pred,radius=0.08,color=(0,0,1),spheresInCell=500,material='soil',returnSpherePack=True)

spheres.toSimulation()

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()]
   ),
   NewtonIntegrator(gravity=(0,0,-9.81),damping=0),
   #PyRunner(command='checkUnbalanced()',iterPeriod=10),
]

############################################################################
######################### DEFINING FUNCTIONS ###############################
############################################################################

#def checkUnbalanced():
# if O.time > 2.5 :
# O.pause()
# export.textExt('cassone.txt',format='x_y_z_r',comment='Final state of the spheres')

O.dt=.8*PWaveTimeStep()
O.run()
#O.stopAtIter=maxIt;
O.saveTmp()

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
Best Jan Stránský (honzik) said :
#1

Hello,

> i'm new on yade

welcome :-)

> i created a particles deposition in a Box and i saved the particles positions. I would like to save also the Box position (is built with facets (geom.facetbox) .In this way i should have a file where is texted the particles and box positions.

I would save the facets in a separate file as for spheres there is pre-defined function for both save and load. But if you insist on a single file, it is possible (you can open the file with particles and write some more lines with facets position).

> After this , i would like to rotate everything of 45° along Z axes in another script. Any idea of how can i do it? I mean , i want to paste box and particles positions rotate of 45° before the simulation starts. Does exist any function that allow me to do it?

See below. You can also leave the geometry as it is and rotate the "rest" (like loading etc.)
a MWE for saving facets in a separate file. I inserted some comments, but if anything is not clear, do not hesitate to ask.

############################# script 1
from yade import pack, export

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)

O.bodies.append(geom.facetBox((0,0,0.6),(1.5,1.075,0.6),wallMask=31))

pred=pack.inAlignedBox((-1.5,-1.075,0),(1.5,1.075,1.2))
spheres=pack.randomDensePack(pred,radius=0.08,color=(0,0,1),spheresInCell=200,returnSpherePack=True)
spheres.toSimulation()

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()]
   ),
   NewtonIntegrator(gravity=(0,0,-9.81),damping=0),
]

O.dt=.8*PWaveTimeStep()
O.run(1000,True)
export.text("/tmp/jacopo-spheres.txt")
saveFacets("/tmp/jacopo-facets.txt")
############################# end of script 1

############################# script 2
from yade import ymport

def readFacet(line,**kw): # read one facet from line. kw might be material etc.
   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

# rotate on point around axis passing through center by angle
def rotatePoint(p,center=Vector3(1,2,3),axis=(0,0,1),angle=.25*pi):
   q = Quaternion(axis,angle)
   return center + q*(p-center)

def rotateSpheres(spheres):
   for s in spheres: # for all spheres
      p = s.state.pos
      p = rotatePoint(p) # rotate its center
      s.state.pos = s.state.refPos = p

def rotateFacets(facets):
   for f in facets: # for all facets
      vs = f.shape.vertices # vertices in local coord system
      vs = [f.state.pos + f.state.ori*v for v in vs] # vertices in global coord system
      vs = [rotatePoint(v) for v in vs] # rotated vertices
      v1,v2,v3 = vs
      # new facet pos (see definition of utils.facet function)
      cc = f.state.pos = f.state.refPos = utils.inscribedCircleCenter(v1,v2,v3)
      v1,v2,v3 = [v-cc for v in (v1,v2,v3)] # vertices in local coord system
      f.shape.setVertices(v1,v2,v3)

spheres = ymport.text("/tmp/jacopo-spheres.txt")
rotateSpheres(spheres)

facets = loadFacets("/tmp/jacopo-facets.txt")
rotateFacets(facets)

O.bodies.append(spheres+facets)
############################# end of script 2

cheers
Jan

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

really thanks Jan, this is exacly what i had to do.