Rescale a Grid Solver Geometry File#

[1]:
import damask
import numpy as np
import pyvista as pv

pv.set_jupyter_backend('pythreejs')
[2]:
# adjust to your situation, input file needs to exist
cells = [20,20,20]

file_name_in  = 'rescale_grid/20grains64x64x64.vti'
file_name_out = f'20grains{"x".join(map(str,cells))}.vti'

[3]:
grid = damask.Grid.load(file_name_in)
scaled = grid.scale(cells)
scaled.save(file_name_out)

print(f'original grid:\n{grid}\n')
print(f'scaled grid:\n{scaled}\n')

original grid:
cells:  64 × 64 × 64
size:   1.0 × 1.0 × 1.0 m³
origin: 0.0   0.0   0.0 m
# materials: 20

scaled grid:
cells:  20 × 20 × 20
size:   1.0 × 1.0 × 1.0 m³
origin: 0.0   0.0   0.0 m
# materials: 20

[4]:
org = pv.UniformGrid(dims=grid.cells+1,
                     spacing=grid.size/grid.cells,
                     origin=grid.origin)
scl = pv.UniformGrid(dims=scaled.cells+1,
                     spacing=scaled.size/scaled.cells,
                     origin=scaled.origin+np.array([-2,0,0]))
org['material'] =   grid.material.flatten('F')
scl['material'] = scaled.material.flatten('F')

pl = pv.Plotter()
pl.set_background('white')
pl.add_mesh(org)
pl.add_mesh(scl)
pl.show()
../../_images/documentation_examples_rescale_grid_4_0.png

Notes#

Installation of the prerequisites#

pyvista#

pip install pyvista

pythreejs#

pip install pythreejs
jupyter nbextension install --py --symlink --sys-prefix pythreejs
jupyter nbextension enable pythreejs --py --sys-prefix