Error in saveDataTxt

Asked by ehsan benabbas

Hi everyone,

I hope you all are safe and healthy.

I run a triaxial code for the following input data:

print ('============ DEFINING VARIABLES ============')
nRead=readParamsFromTable(
 num_spheres=20000,
 compFricDegree = 10,
 key='_triax_',
 unknownOk=True
)
from yade.params import table
num_spheres=table.num_spheres
key=table.key
targetPorosity = 0.4
compFricDegree = table.compFricDegree
finalFricDegree = 29
damp=0.2
thick=0.01
stabilityThreshold=0.01
r_min=0.1*1e-3 # m
d_min=2*r_min # m
r_max=0.3*1e-3 # m
d_max=2*r_max # m
r_avr=(r_min+r_max)/2 # m
d_avr=2*r_avr # m
r_fuz=(r_max/r_avr)-1 # m
young=10e8 # Kn = 2 (E r1 E r2 / E r1 + E r2) >>> E = Kn/r_avr
Kn=young*(d_avr)
Kt=Kn
poisson=Kt/Kn # Kt/Kn
Ls=0.02 # m
mn,mx=Vector3(0,0,0),Vector3(Ls,Ls,Ls)
volume = (mx[0]-mn[0])*(mx[1]-mn[1])*(mx[2]-mn[2])
strainRate=-0.5 # %/sec
target_strain=0.25
sigmaIso=-5e5 # Pa
particleDensity=2000 #kg/m3

at the end of the computation, I want to save data on a text file with the following command:
plot.saveDataTxt('Macro_results')

knowing that I have defined the history function as follows:
from yade import plot
def history():
    plot.addData(
  e11 = -triax.strain[0],
  e22 = -triax.strain[1],
  e33 = -triax.strain[2],
  ev = -triax.strain[0]-triax.strain[1]-triax.strain[2],
  s11 = -triax.stress(triax.wall_right_id)[0],
  s22 = -triax.stress(triax.wall_top_id)[1],
  s33 = -triax.stress(triax.wall_front_id)[2],
  i = O.iter,
        t = O.time, # virtual (yade) time --- time of simulation
        fab = utils.fabricTensor()[0])

The code runs with no problem until the end of the code, for line:
plot.saveDataTxt('Macro_results')

And I get this error:
============ RECORD AND PLOT DATA ============
Traceback (most recent call last):
  File "/home/ehsan/yade/install/bin/yade-2019-08-08.git-775ae74", line 336, in runScript
    execfile(script,globals())
  File "/usr/lib/python3/dist-packages/past/builtins/misc.py", line 82, in execfile
    exec_(code, myglobals, mylocals)
  File "Final.py", line 437, in <module>
  File "/home/ehsan/yade/install/lib/x86_64-linux-gnu/yade-2019-08-08.git-775ae74/py/yade/plot.py", line 660, in saveDataTxt
    for i in range(len(data[vars[0]])):
IndexError: list index out of range
[[ ^L clears screen, ^U kills line. F12 controller, F11 3D view (press "h" in 3D view for help), F10 both, F9 generator, F8 plot. ]]

I want to know if should I use hd5 format file instead of txt file?

Thank you all.

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
ehsan benabbas
Solved:
Last query:
Last reply:
Revision history for this message
Robert Caulk (rcaulk) said :
#1

Hello,

thanks for reviewing the documentation [1], fixing the offedning line accordingly, and letting us know if your problem is corrected or not :-).

Cheers,

Robert

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

Revision history for this message
Jan Stránský (honzik) said :
#2

Hello,

> And I get this error:

this typically happens if you try to "save nothing", i.e. empty plot.data:
###
from yade import plot
print(plot.data) # returns empty dict, {}
plot.saveDataTxt("/tmp/test.txt") # the error you got
###
check how plot.data looks like at the time of saving

> I want to know if should I use hd5 format file instead of txt file?

it depends on you. After all, it is "just data" and both formats are interchangeable.

cheers
Jan

Revision history for this message
ehsan benabbas (ehsanben) said :
#3

Thanks, Robert and Jan,

This is why I did not understand it because the output file was empty. I have already used 'plot.addData' in the 'history' function of my code (find it on my question please) and have never had a problem. Accordingly, all the 'Macro_result' files (from different runs) have never been empty at the end. This time I just changed some properties such as the number of particles and did not expect to face this error as I think it should have nothing to do with those properties. Now, base on your comments, I just changed the line to the following to see if I get the error again or not.

plot.saveDataTxt('Macro_results.txt',vars=('e11','e22','e33','ev','s11','s22','s33','i','t','fab'))

It takes 3 days to be run and then I let you know the result.

Revision history for this message
Jan Stránský (honzik) said :
#4

> because the output file was empty.

the output file was empty because there was the error

> I have already used 'plot.addData' in the 'history' function of my code (find it on my question please)

you have defined 'history' function and used 'plot.addData', but we have no idea what you do with 'history' without a MWE (find it on [1] please). One option is that it is never called (or even not used in the code at all in an extreme case).

> and have never had a problem ... have never been empty at the end. This time I just changed some properties such as the number of particles and did not expect to face this error as I think it should have nothing to do with those properties.

again, without MWE we can just guess..
The parameters certainly influences the simulation, maybe stop conditions, maybe simulation time etc. Maybe also influencing the history function calls.

> I just changed the line to the following to see if I get the error again or not.
> plot.saveDataTxt('Macro_results.txt',vars=('e11','e22','e33','ev','s11','s22','s33','i','t','fab'))

plot.saveDataTxt saves all variables by default, so I doubt this change would make it better..
I really suggest also printing the plot.data value (to be sure if the problem is because of empty plot.data or other problem).

One simple solution is to save the data directly in 'history' function, then you do not need to save it at the end and you have at least something in case something went wrong during the run.
(Assuming that the frequency and amount of saved data does not take significant time of the simulation)

cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
ehsan benabbas (ehsanben) said :
#5

Thank you, Jan,

You always read the questions perfectly and point the solution. As we discussed, the problem had nothing to do with the documentation and the command I wrote in my code. The problem was a frequency to save data I get from the code. I had changed it to a big number to avoid recording a huge amount of numbers (and use less memory) which causes a problem with saveDataTxt. So, again I changed it to a lower number and it works now.

Bests,
Ehsan