Plot Data per Grain with Scatter

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

  • DAMASK version: 3.0.0-alpha5

  • Prerequisites (data): DADF5 results file with 1. Piola-Kirchhoff stress (‘P’) and deformation gradient (‘F’)

  • 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
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]:
result = damask.Result(result_file)
[5]:
result.export_setup()
grid_file = '20grains16x16x16.vti'
grid   = damask.Grid.load(grid_file)
'20grains16x16x16.vti' exists, geometry definition (grid solver) not exported.
'material.yaml' exists, main configuration not exported.
'numerics.yaml' exists, numerics configuration not exported.
'tensionX.yaml' exists, load case definition (grid solver) not exported.
[6]:
# 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 = grid.material.flatten(order='F')==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,ignore_index=True)
 ██████████████████████████████████████████████████ 100% ETA 0:00:00
[7]:
for g in grains:
   plot = sns.lineplot(y='P_11',x='F_11',data=data[g])

fig = plot.get_figure()
../../_images/documentation_examples_plot_per_grain_scatter_7_0.png
[ ]: