File: simple-scene-plot.py

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (47 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- encoding=utf-8 -*-
import matplotlib

matplotlib.use('Qt5Agg')

O.engines = [
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Box_Aabb()]),
        InteractionLoop([Ig2_Sphere_Sphere_ScGeom(), Ig2_Box_Sphere_ScGeom()], [Ip2_FrictMat_FrictMat_FrictPhys()], [Law2_ScGeom_FrictPhys_CundallStrack()]),
        NewtonIntegrator(damping=.2, gravity=(0, 0, -9.81)),
        ###
        ### NOTE this extra engine:
        ###
        ### You want snapshot to be taken every 1 sec (realTimeLim) or every 50 iterations (iterLim),
        ### whichever comes soones. virtTimeLim attribute is unset, hence virtual time period is not taken into account.
        PyRunner(iterPeriod=20, command='myAddPlotData()')
]
O.bodies.append(box(center=[0, 0, 0], extents=[.5, .5, .5], fixed=True, color=[1, 0, 0]))
O.bodies.append(sphere([0, 0, 2], 1, color=[0, 1, 0]))
O.dt = .002 * PWaveTimeStep()

############################################
##### now the part pertaining to plots #####
############################################

from yade import plot
## we will have 2 plots:
## 1. t as function of i (joke test function)
## 2. i as function of t on left y-axis ('|||' makes the separation) and z_sph, v_sph (as green circles connected with line) and z_sph_half again as function of t
plot.plots = {'i': ('t'), 't': ('z_sph', None, ('v_sph', 'go-'), 'z_sph_half')}


## this function is called by plotDataCollector
## it should add data with the labels that we will plot
## if a datum is not specified (but exists), it will be NaN and will not be plotted
def myAddPlotData():
	sph = O.bodies[1]
	## store some numbers under some labels
	plot.addData(t=O.time, i=O.iter, z_sph=sph.state.pos[2], z_sph_half=.5 * sph.state.pos[2], v_sph=sph.state.vel.norm())


print("Now calling plot.plot() to show the figures. The timestep is artificially low so that you can watch graphs being updated live.")
plot.liveInterval = .2
plot.plot(subPlots=False)
O.run(int(2. / O.dt))
#plot.saveGnuplot('/tmp/a')
## you can also access the data in plot.data['i'], plot.data['t'] etc, under the labels they were saved.