Export plot data issues

Asked by Marco Previtali on 2019-05-13

I am running a simple script that generates a ball and drops it on a plane, while tracking position and kinetic energy.
I have problems exporting the simulation data, stored using plot.addData. The issue is that only a small portion of the data is exported. I have tried alternative ways to export the data (numpy), to no avail.

I have run the example files that utilize plot.saveDataTxt and they behave as expected (i.e. https://gitlab.com/yade-dev/trunk/blob/master/doc/sphinx/tutorial/02-gravity-deposition.py), however mine does not and I would rather solve this issue before moving onto more complex simulations.

It is not a problem caused by plot.addData as the plot.data dictionary contains the correct number of entries (9999) and plot.plot() displays the correct data. https://i.imgur.com/8IcBu46.png

This is the script I am using: https://pastebin.com/QmM9AyG0

Using plot.saveDataTxt, the output contains 232 timesteps.
Using numpy.savetxt for lists, the output contains 272 timesteps.
Using numpy.savetxt for arrays, the output contains 246 timesteps.
Using python's write, the output contains 303 timesteps.

I believe the problem is due to yade-python interactions during runtime, as typing str(len(myDict["t"]))) into the console or using np.savetxt('test.txt',myDict["t"]) provides the correct number of timesteps (9999).

Is this a bug or am I doing something wrong?

Question information

English Edit question
Yade Edit question
No assignee Edit question
Solved by:
Jan Stránský
Last query:
Last reply:
Best Jan Stránský (honzik) said : #1


> O.run(100000)
> plot.saveDataTxt('Plot_data.txt',vars=('t'))

Yade / Python reads the script line by line and executes it. In this case, O.run(100000) starts the running for 100000 time steps, but in the meantime the next lines are directly executed, so you save a state shortly after starting running.

O.run(100000,True) # True makes Yade wait until defined number of steps is finished
O.wait() # similar as above

Also please have a look at [1], section "Please, no external links!"


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

Marco Previtali (mprev) said : #2

The problem was indeed caused by python going off before run() terminated. Both solutions proposed work.

Thank you for the quick reply and I apologize for the external links.

Marco Previtali (mprev) said : #3

Thanks Jan Stránský, that solved my question.