Export and import facets

Asked by Alessandro Crema

Hi,

i have a problem with my simulation.
In particular i am searching a command in order to save a complex object with its position (which is composed by facets and initially imported in the simulation as a mesh file) after its motion in which there are interactions with other objects.
Then, i need to reload the object in the final configuration in a different simulation, but it is essential that it keeps exactly the same position of the final configuration of the previous simulation.

But unfortunately i don't find this couple of commands in the literature, compatible with a object composed by facets.

thanks in advance

Alessandro

Question information

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

Hello Alessandro,
one possible solution is to create your own functions saving / loading facets, see below.
cheers
Jan

#####
def saveFacets(fName):
   lines = []
   for b in O.bodies: # iterate over all bodies
      if not isinstance(b.shape,Facet): # consider only facets
         continue
      # append space separated 9 floats (9 coordinates)
      # repr() is used for exact string representation
      vs = [b.state.pos + b.state.ori*v for v in b.shape.vertices] # vertices in global coord system
      line = " ".join(" ".join(repr(v[i]) for i in (0,1,2)) for v in vs)
      lines.append(line)
   with open(fName,'w') as f: # save lines
      f.writelines(l+"\n" for l in lines)

def loadFacets(fName,**kw):
   with open(fName) as f: # read file
      lines = f.readlines()
   ret = []
   for line in lines: # for each line, reconstruc the facet
      fs = [float(v) for v in line.split()] # read floats
      v1,v2,v3 = [Vector3(fs[i],fs[i+1],fs[i+2]) for i in (0,3,6)] # make 3 Vector3
      f = facet((v1,v2,v3),**kw) # create facet
      ret.append(f)
   return ret

# test
facets = (
   facet(((1,0,0),(0,1,0),(0,0,1))),
   facet(((1,0,0),(0,1,0),(1,1,1))),
)
O.bodies.append((
   sphere((0,0,0),.1),
   sphere((2,2,2),.1),
))
O.bodies.append(facets)
for f in facets:
   f.state.vel = (1e2,0,0)
   f.state.angVel = (0,0,1e2)
O.run(10,True)
saveFacets('/tmp/fff')

O.reset()
O.bodies.append((
   sphere((0,0,0),.1),
   sphere((2,2,2),.1),
))
facets = loadFacets('/tmp/fff')
O.bodies.append(facets)
#####

Can you help with this problem?

Provide an answer of your own, or ask Alessandro Crema for more information if necessary.

To post a message you must log in.