About saving data

Asked by Lei Hang on 2020-07-13

Dear all,

I practice to save the data of the example "bouncing sphere", some problems confuse me.
First, I want to get the displacement plot of 'sphere1' in the whole bouncing process. And then, saving the data about the test. The code of mine is as follows:

#
from yade import plot

O.bodies.append([
 # fixed: particle's position in space will not change (support)
 sphere(center=(0,0,0),radius=.5,fixed=True),
 # this particles is free, subject to dynamics
 sphere((0,0,2),.5)
])

sphere1=O.bodies[-1]
z=sphere1.state.pos[2]-sphere1.state.refPos[2]

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom()], # collision geometry
  [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
  [Law2_ScGeom_FrictPhys_CundallStrack()] # contact law -- apply forces
 ),
 # Apply gravity force to particles. damping: numerical dissipation of energy.
 NewtonIntegrator(gravity=(0,0,-9.81),damping=0.1),
 PyRunner(command='addPlotData()',iterPeriod=100)
]

O.dt=.5e-4*PWaveTimeStep()

O.trackEnergy=True

def addPlotData():
                plot.addData(i=O.iter,z=sphere1.state.pos[2]-sphere1.state.refPos[2],**O.energy)

O.run(1000000,True)

plot.saveDataTxt('bounce.txt')

plot.plots={'i':('z',None,O.energy.keys)}

plot.plot()

O.saveTmp()
#

After running the code,there is no displacement data saved and it comes the error warning:
#
Exception ignored in thread started by: <function liveUpdate at 0x7f9be8a40790>
Traceback (most recent call last):
  File "/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py", line 514, in liveUpdate
    ax.relim() # recompute axes limits
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 2051, in relim
    self._update_line_limits(line)
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 1924, in _update_line_limits
    path = line.get_path()
  File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 1027, in get_path
    self.recache()
  File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 679, in recache
    self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
  File "<__array_function__ internals>", line 5, in broadcast_arrays
  File "/usr/lib/python3/dist-packages/numpy/lib/stride_tricks.py", line 264, in broadcast_arrays
    shape = _broadcast_shape(*args)
  File "/usr/lib/python3/dist-packages/numpy/lib/stride_tricks.py", line 191, in _broadcast_shape
    b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape
#

Many thanks in advance

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Lei Hang
Solved:
2020-07-14
Last query:
2020-07-14
Last reply:
Jan Stránský (honzik) said : #1

Hello,
I was not able to reproduce the problems.
I got both the file and the plot without any problem using both 2018.02b and 2020-06-23.git-f03a37c (on ubuntu 18.04)
cheers
Jan

Lei Hang (h-stone) said : #2

Thank you, Jan!

 I have solved my problem. The error is caused by the small iterperiod. After I enlarge the iterperiod to 1000, the error is solved.