File: make-simulation-video.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (51 lines) | stat: -rw-r--r-- 1,650 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
48
49
50
51
# encoding: utf-8

# use another simulation script, create 3d output and graphs
#
# the simulation must not run by itself (no O.run() at the end of the script)
# when run, must stop by itself (without exiting)
#
# plotting should be set up as usual

from yade.yexecfile import execfile

import matplotlib

matplotlib.use('Agg')  # headless backend, makes rendering plots after the simulation _much_ faster (and more reliable)

from yade import qt, plot

simulations = [
        ('01-bouncing-sphere.py', u'Bouncing sphere', 100000), ('02-gravity-deposition.py', u'Gravity deposition', 100),
        ('03-oedometric-test.py', u'Oedometric test', 500), ('04-periodic-simple-shear.py', u'Simple shear\nwith\nperiodic boundary', 100),
        ('06-periodic-triaxial-test.py', u'Periodic triaxal test\nwith clumps', 200)
]


#for script,title in simulations:
def do(n):
	global script, title
	script, title, freq = simulations[n]
	O.reset()
	plot.reset()
	execfile(script, globals())
	# add output engines
	O.engines = O.engines + [qt.SnapshotEngine(fileBase=O.tmpFilename(), iterPeriod=freq, plot='snapshot')]
	# add the snapshot subplot
	plot.plots.update({'snapshot': None})
	# open the view so that it can be set up
	qt.View()


def done():
	utils.makeVideo(
	        plot.savePlotSequence(O.tmpFilename(), title=title + u'\n\n\nVáclav Šmilauer\neu@doxos.eu\nhttp://www.yade-dem.org'),
	        script + '.mpeg',
	        fps=10,
	        kbps=5000
	)


# FIXME: it seems that this script works now only with 03-oedometric-test.py, start it with: yade make-simulation-video.py, then type:
#	do(2)  # simulations[2]=='03-oedometric-test.py'
#	done()