yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #15859
Re: [Question #658870]: Export and import facets
Question #658870 on Yade changed:
https://answers.launchpad.net/yade/+question/658870
Status: Open => Answered
Jan Stránský proposed the following answer:
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)
#####
--
You received this question notification because your team yade-users is
an answer contact for Yade.