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
file_name_in  = 'rescale_grid/20grains64x64x64.vti'
cells = [20,20,20]
file_name_out = f'20grains{cells[0]}x{cells[1]}x{cells[2]}.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  a b c: 64 x 64 x 64
size   x y z: 1.0 x 1.0 x 1.0
origin x y z: 0.0   0.0   0.0
# materials: 20

scaled grid:
cells  a b c: 20 x 20 x 20
size   x y z: 1.0 x 1.0 x 1.0
origin x y z: 0.0   0.0   0.0
# materials: 20

[4]:
org = pv.UniformGrid(grid.cells+1,grid.size/grid.cells,grid.origin)
scl = pv.UniformGrid(scaled.cells+1,scaled.size/scaled.cells,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