← Back to team overview

yade-users team mailing list archive

Re: [Question #685237]: KeyError

 

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

    Status: Answered => Open

nobody is still having a problem:
Hi Jan,

I tried what you said, this works fine.

But if I load a sample, like this: O.load ('sample.yade.gz')

If I want to record several variables.

the sample is just the gravity deposition.[1]
and then I use the same code as I mention yesterday.
#######################################
O.load ('sample.yade.gz')
from yade import geom
import itertools
from numpy import *
import numpy as np
from yade import pack, plot, export, utils
import math
def checkUnbalanced():
	if unbalancedForce()<.001:
		O.pause()
O.engines=[
	ForceResetter(),
	InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
	InteractionLoop(
			[Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom()],
			[Ip2_FrictMat_FrictMat_FrictPhys(),Ip2_CohFrictMat_CohFrictMat_CohFrictPhys()],			[Law2_ScGeom_FrictPhys_CundallStrack(),Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,always_use_moment_law=True,label='cohesiveLaw')]
	),
	GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=10000,timestepSafetyCoefficient=0.8),
	NewtonIntegrator(gravity=(0,0,-9.81),damping=0.4),
	PyRunner(command='contact_info()',iterPeriod=1000),
]
d = 0		
def contact_info():
	global d
	fn_normals_cal_1 = []
	fn_normals_cal_2 = []
	fn_normals_cal_3 = []
	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_normal_cal_2 = i.phys.normalForce[1]
			fn_normal_cal_3 = i.phys.normalForce[2]
			fn_normals_cal_1.append(fn_normal_cal_1)
			fn_normals_cal_2.append(fn_normal_cal_2)
			fn_normals_cal_3.append(fn_normal_cal_3)
 	plot.reset()
 	h = 0
    n = len(fn_normals_cal_1)
    while h < n:
        plot.addData(x = fn_normals_cal_1[h],y = fn_normals_cal_2[h],z= fn_normals_cal_3[h])
        h = h+1
	plot.saveDataTxt('./contact_info'+str(d)+'.txt',vars = ('x','y','z'))
    d = d+1		
O.run(10000000,True)

I think this time the variables' format is correct.

but when I ran this code.

I still got the same problem.
#############################
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "rotation_awn.py", line 60, in contact_info
    plot.saveDataTxt('./contact_info'+str(d)+'.txt',vars = ('x','y','z'))
  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: 'x'
###############################

If I didn't save the sample and reload it.

I just run the gravity deposition and record the data, I didn't get any
errors.

##########
By the way, I did all these processes under same computer.  so this is not related to different versions of YADE and computer.

So, I'm thinking this is related to the O.save and O.load problem? or
because I did something wrong with the recorder?

best,
yong





[1] https://yade-dem.org/doc/tutorial-examples.html#gravity-deposition

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