yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #16589
[Question #662763]: How to save Data in a txt or Gnuplot file
New question #662763 on Yade:
https://answers.launchpad.net/yade/+question/662763
Dear all,
I am new to YADE and still have some difficulties. I have written a very simple script. However, I would like to save my plot data into a txt-file (I only wanna save the information about the Penetration Depth (PD) and the normal Stiffness (Kn2), so I can plot them later). I tried working with a PyRunner, but somehow it's not working. Can anybody please help me with that? Below you find my working example.
Thanks a lot,
Soje
!/usr/bin/env python
# encoding: utf-8
from yade import utils, plot, qt
o = Omega()
# Physical parameters
fr = 0.5;rho=2000
tc = 0.0001;
en = 0.7; et = 0.4;
cn = 0.186; cs = 0.186
kn =1000; ks =0.849e-3
tc = 0.0001;
o.dt = 0.1*tc
Rad = 2.0e-3
# Add material
mat1 = O.materials.append(ViscElMat(frictionAngle=fr,cn=cn,cs=cs,kn=kn,ks=ks))
mat2 = O.materials.append(ViscElMat(frictionAngle=fr,cn=cn,cs=cs,kn=10*kn,ks=ks))
# Add spheres
id1 = O.bodies.append(sphere(center=[0,0,0],radius=Rad,material=mat1,fixed=True))
id2 = O.bodies.append(sphere(center=[0,0,2*Rad],radius=Rad,material=mat1,fixed=False))
bodyList = []
for b in O.bodies:
bodyList.append(b.id)
id3 = O.bodies.append(sphere(center=[0,0.5*Rad,-1e-2+Rad],radius=Rad,material=mat2,fixed=True))
# Import box's geometry
O.bodies.append(geom.facetBox(center=(0,0,0), extents=(1e-2,1e-2,1e-2), wallMask=31, material=mat1))
# Add engines
o.engines = [
ForceResetter(),
InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Wall_Aabb(),Bo1_Facet_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
[Ip2_ViscElMat_ViscElMat_ViscElPhys(label='myPhysics')],
[Law2_ScGeom_ViscElPhys_Basic()],
),
NewtonIntegrator(damping=0,gravity=[0,0,-9.81]),
DeformControl(),
PyRunner(command='addPlotData()',iterPeriod=1),
PyRunner(command='ChangeKn()', virtPeriod=0.1,dead=False,label='changeK'),
PyRunner(command='CreateClumps()',iterPeriod=1000)
PyRunner(command='ExportPara()',iterPeriod=1000)
]
#Function change Kn
def ChangeKn():
pairs = [(i.id1,i.id2) for i in O.interactions]
for i in range(0,2,1):
kn2 = O.bodies[i].material.kn * 0.9
O.bodies[i].mat = ViscElMat(frictionAngle=fr,cn=cn,cs=cs,kn=kn2,ks=ks)
if kn2 <= 0.3:
changeK.dead = True
O.interactions.clear()
for id1,id2 in pairs: utils.createInteraction(id1,id2)
#Funtion create Clumps
def CreateClumps():
kn2 = O.bodies[0].mat.kn
if kn2 <= 0.3:
if not O.bodies[0].isClumpMember:
idClump = O.bodies.clump(bodyList)
# Data History and save for Gnuplot
def ExportPara():
plot.addData(PD=O.interactions[0,1].geom.penetrationDepth)
plot.addData(kn2 = O.bodies[0,1].mat.kn)
plot.saveDataTxt("Parameter.txt.bz2")
# Function to add data to plot
def addPlotData():
pos1 = (O.bodies[id2].state.pos[2]-O.bodies[id1].state.pos[2])-(Rad)
PD=O.interactions[0,1].geom.penetrationDepth
kn2 = O.bodies[0].mat.kn
plot.addData(PD=PD, kn2=-kn2)
plot.plots={'kn2':('PD')}; plot.plot()
plot.plot()
O.run(1)
qt.View()
--
You received this question notification because your team yade-users is
an answer contact for Yade.