From 5fb2d30ee4a9adc539ce071cbe2defe74fab5e11 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 23 Aug 2020 09:02:17 +0200 Subject: [PATCH] fast and for arbitrary type --- python/damask/_geom.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index de0b04c79..382ae4d32 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -6,6 +6,7 @@ from functools import partial import numpy as np from scipy import ndimage,spatial +from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np from . import environment from . import Rotation @@ -357,8 +358,6 @@ class Geom: """ g = VTK.from_file(fname).geom - N_cells = g.GetNumberOfCells() - microstructure = np.zeros(N_cells,'i') grid = np.array(g.GetDimensions())-1 bbox = np.array(g.GetBounds()).reshape(3,2).T size = bbox[1] - bbox[0] @@ -366,9 +365,7 @@ class Geom: celldata = g.GetCellData() for a in range(celldata.GetNumberOfArrays()): if celldata.GetArrayName(a) == 'microstructure': - array = celldata.GetArray(a) - for c in range(N_cells): - microstructure[c] = array.GetValue(c) + microstructure = vtk_to_np(celldata.GetArray(a)) return Geom(microstructure.reshape(grid,order='F'),size,bbox[0])