yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #23325
Re: [Question #691285]: Extract Normals and Shears/tangentials forces on a ballMill
Question #691285 on Yade changed:
https://answers.launchpad.net/yade/+question/691285
Jan Stránský proposed the following answer:
Hello,
thanks for the code, but next time please try to create a MWE, where M stands for "minimal" - a few facets, no external mesh, just a few balls, no VTKRecoder... (sometimes, but very seldom, the full original code is needed).
Just focusing on your problem, which is saving same specific data.
> to extract and save at each time step
of course it is possible, but I would consider a longer period
> i need to save in the Txt format, which can be used with other
softwares.
please be more specific what "Txt format" and "other softwares" are.
**I personally** prefer to save data in some "structured" format like JSON or YAML. Creating "plain text" from them is easy, the other way not.
I think the plot module is not suitable for this kind of exporting. I
would save it "manually", see below.
### not tested, I am only willing to test it on a MWE :-)
import json
...
def exportForces():
data = [] # list of data for each interaction
for i in O.interactions:
b1,b2 = [O.bodies[i] for i in (i.id1,i.id2)]
# skip interactions not containing facets
if not (isinstance(b1.shape,Facet) or isinstance(b2.shape,Facet)):
continue
# gather desired values
fn = i.phys.normalForce
fs = i.phys.
cp = i.geom.contactPoint
pd = i.geom.penetrationDepth
# add it to the data collection
d = dict(normalForce=fn,shearForce=fs,contactPoint=cp,penetrationDepth=pd,id1=i.id1,id2=i.id2)
data.push(d)
# save
fName = "data{:06d}.json".format(O.iter)
with open(fName,"w") as f:
json.dump(data,f,indent=2)
...
O.engines = [
...
PyRunner(iterPeriod=1,command="exportForces()"),
]
...
###
cheers
Jan
--
You received this question notification because your team yade-users is
an answer contact for Yade.