← Back to team overview

yade-users team mailing list archive

Re: [Question #670608]: rotate all the simulation

 

Question #670608 on Yade changed:
https://answers.launchpad.net/yade/+question/670608

    Status: Open => Answered

Jan Stránský proposed the following answer:
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

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.