Add IPF of the inital microstructure to the grid file#

  • Contributor: Sharan Roongta ( and Philip Eisenlohr (

  • DAMASK version: 3.0.0-beta2

  • Prerequisites (data): Grid file with matching material.yaml

  • Postrequisites (software): ParaView or other VTK renderer

import damask
import numpy as np
geom = 'initial_IPF/20grains64x64x64.vti'        # path for geometry file
material_config = 'initial_IPF/material.yaml'    # path for material.yaml
v = damask.VTK.load(geom)
material_ID = v.get(label='material').flatten()

load the material file and assemble phase information#

It is tacitly assumed that there is only one (the first) constituent present at each grid point.

ma = damask.ConfigMaterial.load(material_config)

phases = list(ma['phase'].keys())
info = []

for m in ma['material']:
    c = m['constituents'][0]
    phase = c['phase']
    info.append({'phase':   phase,
                 'phaseID': phases.index(phase),
                 'lattice': ma['phase'][phase]['lattice'],
                 'O':       c['O'],
l = np.array([0,0,1])                            # lab frame direction for IPF

IPF = np.ones((len(material_ID),3),np.uint8)
for i,data in enumerate(info):
    IPF[np.where(material_ID==i)] = \

add IPF and phase information to grid file#

The resulting *.vti file can, for instance, be visualized with ParaView.

v = v.set(f'IPF_{l}',IPF)

p   = np.array([d['phase'] for d in info])
pid = np.array([d['phaseID'] for d in info])
v = v.set(label='phase',data=p[material_ID],info='phase name')
v = v.set(label='phaseID',data=pid[material_ID],info='phase ID')'20grains64x64x64_initial_IPF+phase')