do not include origin into calculation

This commit is contained in:
Martin Diehl 2023-10-12 23:21:40 +02:00
parent c48cee1af2
commit 467638e952
2 changed files with 14 additions and 5 deletions

View File

@ -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.

View File

@ -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 \