yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #07190
Re: [Question #223165]: How to save data into a file?
Question #223165 on Yade changed:
https://answers.launchpad.net/yade/+question/223165
Jan Stránský proposed the following answer:
Hello Alam
> 1. The code saves the initial position of the particle in the file. Is
> there any way I can save the position of particle at each iteration.
>
>
Yes :-) it depends on what you want:
- for each iteration to have separate file:
def savePos():
i = O.iter
pos = O.bodies[70].state.pos
f = open('%d.dat'%i,'w')
f.write('%s\n'%str(pos))
f.close()
O.engines = [
...
PyRunner(iterPeriod=100,command="savePos()") # specify iterPeriod as you
want
]
- store particle position for each iteration and than save it to one
file:
def plotAddData():
pos = b1.state.pos
plot.addData( i=O.iter, x=pos[0], y=pos[1], z=pos[2] )
O.engines = [
...
PyRunner(iterPeriod=100,command="plotAddData()") # specify iterPeriod as
you want
]
O.run(1000); O.wait() # change 1000 to what you want
plot.saveDataTxt('pos,dat')
> 2. The number of interactions are not saved in the file and is there a
> way I can save contact point of particle{70} interaction, normal etc?
>
if you want to save number of interactions, do it in the same way as in
previous step, just
intrs = b1.intrs()
plot.addData( ..., n=len(intrs) ) # or f.write('%d\n'%len(intrs))
to save anything else, you can do the same:
intrs = b1.intrs()
for i in intrs:
n = i.geom.normal
cp = i.geom.contactPoint
fn = i.phys.normalForce
f.write('%s\n'%str(n))
f.write('%s\n'%str(cp))
f.write('%s\n'%str(fn))
or instead of f.write(..) you use plot.addData function, depends on what
you want or prefere... Don't forget to add chosen command to PyRunner in
O.engines
cheers
Jan
--
You received this question notification because you are a member of
yade-users, which is an answer contact for Yade.