← Back to team overview

yade-users team mailing list archive

[Question #685237]: KeyError

 

New question #685237 on Yade:
https://answers.launchpad.net/yade/+question/685237

Hi All,

I'm trying to do a gravity deposit and record the contact information. For example, normal contact force for every particle.

I write the code like this:

###########################
import numpy as np
from yade import pack, plot, export, utils
import math
O.bodies.append(geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(1,1,1),rMean=.04,rRelFuzz=.5)
sp.toSimulation()
O.engines=[
	ForceResetter(),
	InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
	InteractionLoop(
		[Ig2_Sphere_Sphere_ScGeom(),Ig2_Facet_Sphere_ScGeom()],
		[Ip2_FrictMat_FrictMat_FrictPhys()],
		[Law2_ScGeom_FrictPhys_CundallStrack()]
	),
	PyRunner(command='checkUnbalanced()',realPeriod=1000),
	PyRunner(command='contact_info()',iterPeriod=1000),
	NewtonIntegrator(gravity=(0,0,-9.81),damping=0.4),
]
O.dt=.5*PWaveTimeStep()
print(len(O.bodies))
def checkUnbalanced():
	if unbalancedForce()<.001:
		O.pause()		
d = 0
def contact_info():
	global d
	fn_normals_cal_1 = []
	for i in O.interactions:
		if not i.isReal:continue
		if isinstance(O.bodies[i.id1].shape,Sphere) and isinstance(O.bodies[i.id2].shape,Sphere):
			fn_normal_cal_1 = i.phys.normalForce[0]
			fn_normals_cal_1.append(fn_normal_cal_1)			
 	plot.reset()
 	h = 0
    	n = len(fn_normals_cal_1)
    	while h < n:
        	plot.addData(e_e_e = fn_normals_cal_1[h])
       		h = h+1
	plot.saveDataTxt('./contact_info'+str(d)+'.txt',vars = ('e_e_e'))
    	d = d+1		
O.run(10000,True)
####################
the error is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "rotation_awn.py", line 40, in contact_info
    plot.saveDataTxt('./contact_info'+str(d)+'.txt',vars = ('e_e_e'))
  File "/packages/7x/yade/2018.02b/lib64/yade-2018.02b/py/yade/plot.py", line 642, in saveDataTxt
    for i in range(len(data[vars[0]])):
KeyError: 'e'


###############

when I changed these lines:

    	while h < n:
        	plot.addData(e = fn_normals_cal_1[h])
       		h = h+1
	plot.saveDataTxt('./contact_info'+str(d)+'.txt',vars = ('e'))
    	d = d+1	

###### the code works very well.

Is there any special format for vars or something wrong with the code?

best,
yong



-- 
You received this question notification because your team yade-users is
an answer contact for Yade.