From 467638e95216de761fd89b73b70db1ae7cfdb15e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 12 Oct 2023 23:21:40 +0200 Subject: [PATCH] do not include origin into calculation --- python/damask/_grid.py | 9 ++++++--- python/damask/seeds.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index a8df4f877..935a7f767 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -487,9 +487,11 @@ class Grid: size : sequence of float, len (3) Edge lengths of the grid in meter. seeds : numpy.ndarray of float, shape (:,3) - Position of the seed points in meter. All points need to lay within the box. + Position of the seed points in meter. All points need + to lay within the box [(0,0,0),size]. weights : sequence of float, len (seeds.shape[0]) - Weights of the seeds. Setting all weights to 1.0 gives a standard Voronoi tessellation. + Weights of the seeds. Setting all weights to 1.0 gives a + standard Voronoi tessellation. material : sequence of int, len (seeds.shape[0]), optional Material ID of the seeds. Defaults to None, in which case materials are consecutively numbered. @@ -544,7 +546,8 @@ class Grid: size : sequence of float, len (3) Edge lengths of the grid in meter. seeds : numpy.ndarray of float, shape (:,3) - Position of the seed points in meter. All points need to lay within the box. + Position of the seed points in meter. All points need + to lay within the box [(0,0,0),size]. material : sequence of int, len (seeds.shape[0]), optional Material ID of the seeds. Defaults to None, in which case materials are consecutively numbered. diff --git a/python/damask/seeds.py b/python/damask/seeds.py index 808ad3c1b..e80425a29 100644 --- a/python/damask/seeds.py +++ b/python/damask/seeds.py @@ -134,6 +134,12 @@ def from_grid(grid, coords, materials : numpy.ndarray, shape (:,3); numpy.ndarray, shape (:) Seed coordinates in 3D space, material IDs. + Notes + ----- + The origin is not considered in order to obtain coordinates + in a coordinate system located at the origin. This is expected + by damask.Grid.from_Voronoi_tessellation. + Examples -------- Recreate seeds from Voronoi tessellation. @@ -166,8 +172,8 @@ def from_grid(grid, materials = _np.unique(material[mask]) coords_ = _np.zeros((materials.size,3),dtype=float) for i,mat in enumerate(materials): - pc = (2*_np.pi*coords[material[:,0]==mat,:]-grid.origin)/grid.size - coords_[i] = grid.origin + grid.size / 2 / _np.pi * (_np.pi + + pc = 2*_np.pi*coords[material[:,0]==mat,:]/grid.size + coords_[i] = grid.size / 2 / _np.pi * (_np.pi + _np.arctan2(-_np.average(_np.sin(pc),axis=0), -_np.average(_np.cos(pc),axis=0))) \ if periodic else \