Rescale a Grid Solver Geometry File#
Contributor: Martin Diehl (https://martin-diehl.net) and Philip Eisenlohr (eisenlohr@egr.msu.edu)
DAMASK version: 3.0.0
Prerequisites (data): Grid file
Prerequisites (Python): pyvista
[1]:
import damask
import numpy as np
import pyvista as pv
pv.set_jupyter_backend('static')
[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.GeomGrid.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.ImageData(dimensions=grid.cells+1,
spacing=grid.size/grid.cells,
origin=grid.origin)
scl = pv.ImageData(dimensions=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()