list index out of range for plot.saveDataTxt ?

Asked by Luc OGER on 2018-12-07

I am trying to setup a double set of loose packing on on top of the other as prelimnary condition for simulations.
Os I have made a first program to make the fixed first packing and save the xyzr coodinates thne generate a second one on top which fall down on the first one without ny problem ... but the command plot.saveDataTxt generate an error message "list index out of range"

i don't understand why?

%%%%%%%%%%%%%%%%%%
here the output of the code :
Running script gravity-2-3rd-step-2packs.py
len-load-O.bodies = 7649
len-O.bodies = 7649
nombre_moving= 282
len-tot-O.bodies = 7931

then part of my code :
%%%%%%%%%%%%%%%%%%%%%%%%%
O.load("1st-step.yade")
print "len-load-O.bodies = ",len(O.bodies)

O.materials[0].frictionAngle=radians(15.0)

sp=pack.SpherePack()

for c,r in sp:
 O.bodies.append(sphere(c,r,fixed=True))
 O.bodies[0].mask = 0b01 # 1
num_small = len(O.bodies)
print "len-O.bodies = ",num_small

sp.toSimulation()

nombre_moving = int(cover_pack_fraction*(box_size*box_size)/(ratio*rayon*ratio*rayon*3.14159) )
print "nombre_moving=", nombre_moving
# generate randomly spheres with uniform radius distribution
sp.makeCloud((0,0,2.2*rayon),(box_size,box_size,(3.2+.2)*rayon*ratio),rMean=rayon*ratio,rRelFuzz=.005*ratio,num= nombre_moving)
for c,r in sp:
 if O.bodies[0].mask == 0b01: continue # 1
 O.bodies[0].mask == 0b10 # 2
# add the sphere pack to the simulation
sp.toSimulation()

num_tot = len(O.bodies)
print "len-tot-O.bodies = ",num_tot
collider.avoidSelfInteractionMask = 0b10

# simulation loop
O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
 InteractionLoop(
  # handle sphere+sphere and facet+sphere collisions
  [Ig2_Sphere_Sphere_L3Geom(),Ig2_Facet_Sphere_L3Geom()],
  [Ip2_FrictMat_FrictMat_FrictPhys(frictAngle=0.0)],
  [Law2_L3Geom_FrictPhys_ElPerfPl()]
 ),
# GravityEngine(gravity=(0,0,-9.81)),
# NewtonIntegrator(damping=0.4),
#
 NewtonIntegrator(damping=0.4,gravity=(0,-gravity_y,-gravity_z),label='Newton_integrator'),
 # call the checkUnbalanced function (defined below) every 2 seconds
 PyRunner(command='checkUnbalanced()',realPeriod=2,label='checker'),
]

#without friction
O.materials[0].frictionAngle=0

# timesteps
O.dt=.5*utils.PWaveTimeStep()

# enable energy tracking; any simulation parts supporting it
# can create and update arbitrary energy types, which can be
# accessed as O.energy['energyName'] subsequently
O.trackEnergy=True

def checkUnbalanced():
 global converg_min,iter_max,step1
# if step1>0: PyRunner(command='add_moving_sphere()')
 if utils.unbalancedForce()<converg_min:
  O.pause()
  plot.saveDataTxt('bbb.txt.bz2')

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Luc OGER
Solved:
2018-12-10
Last query:
2018-12-10
Last reply:
2018-12-08
Robert Caulk (rcaulk) said : #1

Hello,

As shown in [1], if you want to use plot.saveDataTxt('',vars=()), you need to add some variable data with plot.addData()[2]. Copied here for clarity:

>>> from yade import plot
>>> from pprint import pprint
>>> plot.reset()
>>> plot.addData(a=1,b=11,c=21,d=31) # add some data here
>>> plot.addData(a=2,b=12,c=22,d=32)
>>> pprint(plot.data)
{'a': [1, 2], 'b': [11, 12], 'c': [21, 22], 'd': [31, 32]}
>>> plot.saveDataTxt('/tmp/dataFile.txt.bz2',vars=('a','b','c'))
>>> import numpy
>>> d=numpy.genfromtxt('/tmp/dataFile.txt.bz2',dtype=None,names=True)
>>> d['a']
array([1, 2])
>>> d['b']
array([11, 12])

Cheers,

Robert

[1]https://yade-dem.org/doc/yade.plot.html#yade.plot.saveDataTxt
[2]https://yade-dem.org/doc/yade.plot.html#yade.plot.addData

Luc OGER (luc-oger) said : #2

Thanks Robert for the reply.

I catch my problem:
I was using this command without any argument before to save all data as pointed out in the variables explanaition "If None (default), all variables in plot.plot are saved."
but to speed up this new code i have commented out all the other plot functions!!

so I will try other option