From cfdf33e4b1e815b2df982563a3147a60ecbdd5ad Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 22 May 2023 17:32:39 +0200 Subject: [PATCH] don't change Neper material ID definition Neper material ID start at 0 if a buffer layer is added (run "neper -T -n 100 -tesrsize 320:320:320 -domain "cylinder(20,10)" -format vtk"), otherwise at 1. Hence, leave the IDs untouched and let the user change the numbering (either by a constant offset or by re-numbering): "explicit is better than implicit" --- python/damask/_grid.py | 9 +++++++-- python/tests/test_Grid.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 04a85f0f0..a0571279c 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -317,6 +317,11 @@ class Grid: loaded : damask.Grid Grid-based geometry from file. + Notes + ----- + Material indices in Neper usually start at 1 unless + a buffer material with index 0 is added. + Examples -------- Read a periodic polycrystal generated with Neper. @@ -325,7 +330,7 @@ class Grid: >>> N_grains = 20 >>> cells = (32,32,32) >>> damask.util.run(f'neper -T -n {N_grains} -tesrsize {cells[0]}:{cells[1]}:{cells[2]} -periodicity all -format vtk') - >>> damask.Grid.load_Neper(f'n{N_grains}-id1.vtk') + >>> damask.Grid.load_Neper(f'n{N_grains}-id1.vtk').renumber() cells: 32 × 32 × 32 size: 1.0 × 1.0 × 1.0 m³ origin: 0.0 0.0 0.0 m @@ -336,7 +341,7 @@ class Grid: cells = np.array(v.vtk_data.GetDimensions())-1 bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T - return Grid(material = v.get('MaterialId').reshape(cells,order='F').astype('int32',casting='unsafe') - 1, + return Grid(material = v.get('MaterialId').reshape(cells,order='F').astype('int32',casting='unsafe'), size = bbox[1] - bbox[0], origin = bbox[0], comments = util.execution_stamp('Grid','load_Neper'), diff --git a/python/tests/test_Grid.py b/python/tests/test_Grid.py index ff9ca412f..237ea32e5 100644 --- a/python/tests/test_Grid.py +++ b/python/tests/test_Grid.py @@ -501,7 +501,7 @@ class TestGrid: assert current == reference def test_load_Neper_reference(self,res_path,update): - current = Grid.load_Neper(res_path/'n10-id1_scaled.vtk') + current = Grid.load_Neper(res_path/'n10-id1_scaled.vtk').renumber() reference = Grid.load(res_path/'n10-id1_scaled.vti') if update: current.save(res_path/'n10-id1_scaled.vti')