\( \usepackage{euler} % must be loaded before fontspec for the whole doc (below); this must be kept for pngmath, however \usepackage{hyperref} \usepackage{amsmath} \usepackage{amsbsy} %\usepackage{mathabx} \usepackage{underscore} \usepackage[all]{xy} % Metadata of the pdf output \hypersetup{pdftitle={Yade Documentation}} \hypersetup{pdfauthor={Smilauer, V., et al.}} \hypersetup{pdfkeywords={Discrete element method, granular materials, contact law, hydromechanical coupling}} % symbols \renewcommand{\mat}{\boldsymbol} \renewcommand{\vec}{\boldsymbol} \renewcommand{\tens}{\boldsymbol} %normalized and locfram here \def\normalized#1{\widehat{#1}} \def\locframe#1{\widetilde{#1}} % timestep \def\Dt{\Delta t} \def\Dtcr{\Dt_{\rm cr}} % algorithm complexity \def\bigO#1{{\mathcal{O}(#1)}} % variants for greek symbols \let\epsilon\varepsilon \let\theta\vartheta \let\phi\varphi % shorthands \let\sig\sigma \let\eps\epsilon % variables at different points of time \def\prev#1{#1^-} \def\pprev#1{#1^\ominus} \def\curr#1{#1^{\circ}} \def\nnext#1{#1^\oplus} \def\next#1{#1^+} % shorthands for geometry \def\currn{\curr{\vec{n}}} \def\currC{\curr{\vec{C}}} \def\uT{\vec{u}_T} \def\curruT{\curr{\vec{u}}_T} \def\prevuT{\prev{\vec{u}}_T} \def\currn{\curr{\vec{n}}} \def\prevn{\prev{\vec{n}}} % motion \def\pprevvel{\pprev{\dot{\vec{u}}}} \def\nnextvel{\nnext{\dot{\vec{u}}}} \def\curraccel{\curr{\ddot{\vec{u}}}} \def\prevpos{\prev{\vec{u}}} \def\currpos{\curr{\vec{u}}} \def\nextpos{\next{\vec{u}}} \def\curraaccel{\curr{\dot{\vec{\omega}}}} \def\pprevangvel{\pprev{\vec{\omega}}} \def\nnextangvel{\nnext{\vec{\omega}}} \def\loccurr#1{\curr{\locframe{#1}}} \def\numCPU{n_{\rm cpu}} \DeclareMathOperator{\Align}{Align} \DeclareMathOperator{\sign}{sgn} % sorting algorithms \def\isleq#1{\currelem{#1}\ar@/^/[ll]^{\leq}} \def\isnleq#1{\currelem{#1}\ar@/^/[ll]^{\not\leq}} \def\currelem#1{\fbox{$#1$}} \def\sortSep{||} \def\sortInv{\hbox{\phantom{||}}} \def\sortlines#1{\xymatrix@=3pt{#1}} \def\crossBound{||\mkern-18mu<} \)

# yade.post2d module

Module for 2d postprocessing, containing classes to project points from 3d to 2d in various ways, providing basic but flexible framework for extracting arbitrary scalar values from bodies/interactions and plotting the results. There are 2 basic components: flatteners and extractors.

The algorithms operate on bodies (default) or interactions, depending on the `intr` parameter of post2d.data.

## Flatteners

Instance of classes that convert 3d (model) coordinates to 2d (plot) coordinates. Their interface is defined by the post2d.Flatten class (`__call__`, `planar`, `normal`).

## Extractors

Callable objects returning scalar or vector value, given a body/interaction object. If a 3d vector is returned, Flattener.planar is called, which should return only in-plane components of the vector.

## Example

This example can be found in examples/concrete/uniax-post.py

    from yade import post2d
    import pylab # the matlab-like interface of matplotlib

    O.load('/tmp/uniax-tension.xml.bz2')

    # 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))

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

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

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

    # show the figures
    pylab.show()

class yade.post2d.AxisFlatten(inherits Flatten → object)
  __init__(useRef=False, axis=2)
    Parameters:

      - useRef (bool) – use reference positions rather than actual positions (only meaningful when operating on Bodies)

      - axis ({0,1,2}) – axis normal to the plane; the return value will be simply position with this component dropped.

  normal(pos, vec)

    Given position and vector value, return lenght of the vector normal to the flat plane.

  planar(pos, vec)

    Given position and vector value, project the vector value to the flat plane and return its 2 in-plane components.

class yade.post2d.CylinderFlatten(inherits Flatten → object)

  Class for converting 3d point to 2d based on projection onto plane from circle. The y-axis in the projection corresponds to the rotation axis; the x-axis is distance form the axis.

  __init__(useRef, axis=2)
    Parameters:

      - useRef – (bool) use reference positions rather than actual positions

      - axis – axis of the cylinder, ∈{0,1,2}

  normal(b, vec)

    Given position and vector value, return lenght of the vector normal to the flat plane.

  planar(b, vec)

    Given position and vector value, project the vector value to the flat plane and return its 2 in-plane components.

class yade.post2d.Flatten(inherits object)

  Abstract class for converting 3d point into 2d. Used by post2d.data2d.

  normal(pos, vec)

    Given position and vector value, return lenght of the vector normal to the flat plane.

  planar(pos, vec)

    Given position and vector value, project the vector value to the flat plane and return its 2 in-plane components.

class yade.post2d.HelixFlatten(inherits Flatten → object)

  Class converting 3d point to 2d based on projection from helix. The y-axis in the projection corresponds to the rotation axis

  __init__(useRef, thetaRange, dH_dTheta, axis=2, periodStart=0)
    Parameters:

      - useRef (bool) – use reference positions rather than actual positions

      - thetaRange ((θmin,θmax)) – bodies outside this range will be discarded

      - dH_dTheta (float) – inclination of the spiral (per radian)

      - axis ({0,1,2}) – axis of rotation of the spiral

      - periodStart (float) – height of the spiral for zero angle

  normal(pos, vec)

    Given position and vector value, return lenght of the vector normal to the flat plane.

  planar(b, vec)

    Given position and vector value, project the vector value to the flat plane and return its 2 in-plane components.

yade.post2d.data(extractor, flattener, intr=False, onlyDynamic=True, stDev=None, relThreshold=3.0, perArea=0, div=(50, 50), margin=(0, 0), radius=1)

  Filter all bodies/interactions, project them to 2d and extract required scalar value; return either discrete array of positions and values, or smoothed data, depending on whether the stDev value is specified.

  The `intr` parameter determines whether we operate on bodies or interactions; the extractor provided should expect to receive body/interaction.

  Parameters:

    - extractor (callable) – receives Body (or Interaction, if `intr` is `True`) instance, should return scalar, a 2-tuple (vector fields) or None (to skip that body/interaction)

    - flattener (callable) – post2d.Flatten instance, receiving body/interaction, returns its 2d coordinates or `None` (to skip that body/interaction)

    - intr (bool) – operate on interactions rather than bodies

    - onlyDynamic (bool) – skip all non-dynamic bodies

    - stDev (float/None) – standard deviation for averaging, enables smoothing; `None` (default) means raw mode, where discrete points are returned

    - relThreshold (float) – threshold for the gaussian weight function relative to stDev (smooth mode only)

    - perArea (int) – if 1, compute weightedSum/weightedArea rather than weighted average (weightedSum/sumWeights); the first is useful to compute average stress; if 2, compute averages on subdivision elements, not using weight function

    - div ((int,int)) – number of cells for the gaussian grid (smooth mode only)

    - margin ((float,float)) – x,y margins around bounding box for data (smooth mode only)

    - radius (float/callable) – Fallback value for radius (for raw plotting) for non-spherical bodies or interactions; if a callable, receives body/interaction and returns radius

  Returns:

    dictionary

  Returned dictionary always containing keys ‘type’ (one of ‘rawScalar’,’rawVector’,’smoothScalar’,’smoothVector’, depending on value of smooth and on return value from extractor), ‘x’, ‘y’, ‘bbox’.

  Raw data further contains ‘radii’.

  Scalar fields contain ‘val’ (value from extractor), vector fields have ‘valX’ and ‘valY’ (2 components returned by the extractor).

yade.post2d.plot(data, axes=None, alpha=0.5, clabel=True, cbar=False, aspect='equal', **kw)

  Given output from post2d.data, plot the scalar as discrete or smooth plot.

  For raw discrete data, plot filled circles with radii of particles, colored by the scalar value.

  For smooth discrete data, plot image with optional contours and contour labels.

  For vector data (raw or smooth), plot quiver (vector field), with arrows colored by the magnitude.

  Parameters:

    - axes – matplotlib.axesinstance where the figure will be plotted; if None, will be created from scratch.

    - data – value returned by post2d.data

    - clabel (bool) – show contour labels (smooth mode only), or annotate cells with numbers inside (with perArea==2)

    - cbar (bool) – show colorbar (equivalent to calling pylab.colorbar(mappable) on the returned mappable)

  Returns:

    tuple of `(axes,mappable)`; mappable can be used in further calls to pylab.colorbar.