File: uniax-post.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 (55 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (3)
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
52
53
54
55
# -*- encoding=utf-8 -*-
#
# demonstration of the yade.post2d module (see its documentation for details)
#
from yade import post2d
import pylab  # the matlab-like interface of matplotlib

loadFile = '/tmp/uniax-tension.yade.gz'
if not os.path.exists(loadFile):
	raise RuntimeError("Run uniax.py first so that %s is created" % loadFile)
O.load(loadFile)

# flattener that project to the xz plane
flattener = post2d.AxisFlatten(useRef=False, axis=1)
# return scalar given a Body instance
extractDmg = lambda b: b.state.normDmg
# will call flattener.planar implicitly
# the same as: extractVelocity=lambda b: flattener.planar(b,b.state['vel'])
extractVelocity = lambda b: b.state.vel

# create new figure
pylab.figure()
# plot raw damage
post2d.plot(post2d.data(extractDmg, flattener))
pylab.suptitle('damage')

# plot smooth damage into new figure
pylab.figure()
ax, map = post2d.plot(post2d.data(extractDmg, flattener, stDev=2e-3))
pylab.suptitle('smooth damage')
# show color scale
pylab.colorbar(map, orientation='horizontal')

# shear stress		NOT WORKING (AttributeError: 'CpmState' object has no attribute 'tau' and no 'sigma'):
#pylab.figure()
#post2d.plot(post2d.data(lambda b: b.state.sigma,flattener))
#pylab.suptitle('sigma')
#pylab.figure()
#post2d.plot(post2d.data(lambda b: b.state.tau,flattener,stDev=2e-3))
#pylab.suptitle('smooth tau (in grid)')

# raw velocity (vector field) plot
pylab.figure()
post2d.plot(post2d.data(extractVelocity, flattener))
pylab.suptitle('velocity')

# smooth velocity plot; data are sampled at regular grid
pylab.figure()
ax, map = post2d.plot(post2d.data(extractVelocity, flattener, stDev=1e-3))
pylab.suptitle('smooth velocity')
# save last (current) figure to file
pylab.gcf().savefig('/tmp/foo.png')

# show the figures
pylab.show()