Plot Data per Grain with Scatter

  • Contributor: Martin Diehl (https://martin-diehl.net)

  • DAMASK version: 3.0.0-alpha4

  • Prerequisites (data): DADF5 results file with 1. Piola-Kirchhoff stress (‘P’) and deformation gradient (‘F’), geometry file used for the simulation.

  • Prerequisites (python): seaborn

[1]:
%pylab inline
%matplotlib inline
Populating the interactive namespace from numpy and matplotlib
[2]:
import damask
import numpy as np
import pandas as pd
import seaborn as sns
[3]:
# adjust to your situation, files need to exist
grid_file   = 'plot_per_grain_scatter/20grains16x16x16.vti'
result_file = 'plot_per_grain_scatter/20grains16x16x16_tensionX.hdf5'
grains = [1,4,19] # corresponds to the material ID in the vti file/material.yaml
[4]:
grid   = damask.Grid.load(grid_file)
result = damask.Result(result_file)
[5]:
# loop over all increments and store P(1,1) per grain and avg(F(1,1))
data = {g:pd.DataFrame() for g in grains}
for inc in result.get(['F','P']).values():
    P = inc['P']
    F = inc['F']
    for g in grains:
        points = np.where(grid.material.flatten()==g)
        P_11 = P[points,0,0].flatten()
        F_11 = np.broadcast_to(np.average(F[:,0,0]),P_11.shape)
        x = pd.DataFrame({'F_11':F_11,'P_11':P_11})
        data[g] = data[g].append(x)
 ██████████████████████████████████████████████████ 100% ETA 0:00:00
[6]:
for g in grains:
   plot = sns.lineplot(y='P_11',x='F_11',data=data[g])

fig = plot.get_figure()
../../../_images/documentation_examples_post-processing_plot_per_grain_scatter_6_0.png
[ ]: