proper spacing
This commit is contained in:
parent
ab88ffd28e
commit
a670ab269f
|
@ -1,7 +1,7 @@
|
||||||
from scipy import spatial
|
from scipy import spatial
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
def __ks(size,grid,first_order=False):
|
def _ks(size,grid,first_order=False):
|
||||||
"""
|
"""
|
||||||
Get wave numbers operator.
|
Get wave numbers operator.
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ def curl(size,field):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
n = np.prod(field.shape[3:])
|
n = np.prod(field.shape[3:])
|
||||||
k_s = __ks(size,field.shape[:3],True)
|
k_s = _ks(size,field.shape[:3],True)
|
||||||
|
|
||||||
e = np.zeros((3, 3, 3))
|
e = np.zeros((3, 3, 3))
|
||||||
e[0, 1, 2] = e[1, 2, 0] = e[2, 0, 1] = +1.0 # Levi-Civita symbol
|
e[0, 1, 2] = e[1, 2, 0] = e[2, 0, 1] = +1.0 # Levi-Civita symbol
|
||||||
|
@ -58,7 +58,7 @@ def divergence(size,field):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
n = np.prod(field.shape[3:])
|
n = np.prod(field.shape[3:])
|
||||||
k_s = __ks(size,field.shape[:3],True)
|
k_s = _ks(size,field.shape[:3],True)
|
||||||
|
|
||||||
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
||||||
divergence = (np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 1
|
divergence = (np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 1
|
||||||
|
@ -78,7 +78,7 @@ def gradient(size,field):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
n = np.prod(field.shape[3:])
|
n = np.prod(field.shape[3:])
|
||||||
k_s = __ks(size,field.shape[:3],True)
|
k_s = _ks(size,field.shape[:3],True)
|
||||||
|
|
||||||
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
||||||
gradient = (np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*np.pi if n == 1 else # scalar, 1 -> 3
|
gradient = (np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*np.pi if n == 1 else # scalar, 1 -> 3
|
||||||
|
@ -110,6 +110,7 @@ def cell_coord0(grid,size,origin=np.zeros(3)):
|
||||||
|
|
||||||
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
||||||
|
|
||||||
|
|
||||||
def cell_displacement_fluct(size,F):
|
def cell_displacement_fluct(size,F):
|
||||||
"""
|
"""
|
||||||
Cell center displacement field from fluctuation part of the deformation gradient field.
|
Cell center displacement field from fluctuation part of the deformation gradient field.
|
||||||
|
@ -124,7 +125,7 @@ def cell_displacement_fluct(size,F):
|
||||||
"""
|
"""
|
||||||
integrator = 0.5j*size/np.pi
|
integrator = 0.5j*size/np.pi
|
||||||
|
|
||||||
k_s = __ks(size,F.shape[:3],False)
|
k_s = _ks(size,F.shape[:3],False)
|
||||||
k_s_squared = np.einsum('...l,...l',k_s,k_s)
|
k_s_squared = np.einsum('...l,...l',k_s,k_s)
|
||||||
k_s_squared[0,0,0] = 1.0
|
k_s_squared[0,0,0] = 1.0
|
||||||
|
|
||||||
|
@ -136,6 +137,7 @@ def cell_displacement_fluct(size,F):
|
||||||
|
|
||||||
return np.fft.irfftn(displacement,axes=(0,1,2),s=F.shape[:3])
|
return np.fft.irfftn(displacement,axes=(0,1,2),s=F.shape[:3])
|
||||||
|
|
||||||
|
|
||||||
def cell_displacement_avg(size,F):
|
def cell_displacement_avg(size,F):
|
||||||
"""
|
"""
|
||||||
Cell center displacement field from average part of the deformation gradient field.
|
Cell center displacement field from average part of the deformation gradient field.
|
||||||
|
@ -151,6 +153,7 @@ def cell_displacement_avg(size,F):
|
||||||
F_avg = np.average(F,axis=(0,1,2))
|
F_avg = np.average(F,axis=(0,1,2))
|
||||||
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),cell_coord0(F.shape[:3][::-1],size))
|
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),cell_coord0(F.shape[:3][::-1],size))
|
||||||
|
|
||||||
|
|
||||||
def cell_displacement(size,F):
|
def cell_displacement(size,F):
|
||||||
"""
|
"""
|
||||||
Cell center displacement field from deformation gradient field.
|
Cell center displacement field from deformation gradient field.
|
||||||
|
@ -165,6 +168,7 @@ def cell_displacement(size,F):
|
||||||
"""
|
"""
|
||||||
return cell_displacement_avg(size,F) + cell_displacement_fluct(size,F)
|
return cell_displacement_avg(size,F) + cell_displacement_fluct(size,F)
|
||||||
|
|
||||||
|
|
||||||
def cell_coord(size,F,origin=np.zeros(3)):
|
def cell_coord(size,F,origin=np.zeros(3)):
|
||||||
"""
|
"""
|
||||||
Cell center positions.
|
Cell center positions.
|
||||||
|
@ -181,6 +185,7 @@ def cell_coord(size,F,origin=np.zeros(3)):
|
||||||
"""
|
"""
|
||||||
return cell_coord0(F.shape[:3][::-1],size,origin) + cell_displacement(size,F)
|
return cell_coord0(F.shape[:3][::-1],size,origin) + cell_displacement(size,F)
|
||||||
|
|
||||||
|
|
||||||
def cell_coord0_gridSizeOrigin(coord0,ordered=True):
|
def cell_coord0_gridSizeOrigin(coord0,ordered=True):
|
||||||
"""
|
"""
|
||||||
Return grid 'DNA', i.e. grid, size, and origin from array of cell positions.
|
Return grid 'DNA', i.e. grid, size, and origin from array of cell positions.
|
||||||
|
@ -221,6 +226,7 @@ def cell_coord0_gridSizeOrigin(coord0,ordered=True):
|
||||||
|
|
||||||
return (grid,size,origin)
|
return (grid,size,origin)
|
||||||
|
|
||||||
|
|
||||||
def coord0_check(coord0):
|
def coord0_check(coord0):
|
||||||
"""
|
"""
|
||||||
Check whether coordinates lie on a regular grid.
|
Check whether coordinates lie on a regular grid.
|
||||||
|
@ -234,7 +240,6 @@ def coord0_check(coord0):
|
||||||
cell_coord0_gridSizeOrigin(coord0,ordered=True)
|
cell_coord0_gridSizeOrigin(coord0,ordered=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def node_coord0(grid,size,origin=np.zeros(3)):
|
def node_coord0(grid,size,origin=np.zeros(3)):
|
||||||
"""
|
"""
|
||||||
Nodal positions (undeformed).
|
Nodal positions (undeformed).
|
||||||
|
@ -256,6 +261,7 @@ def node_coord0(grid,size,origin=np.zeros(3)):
|
||||||
|
|
||||||
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
return np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
||||||
|
|
||||||
|
|
||||||
def node_displacement_fluct(size,F):
|
def node_displacement_fluct(size,F):
|
||||||
"""
|
"""
|
||||||
Nodal displacement field from fluctuation part of the deformation gradient field.
|
Nodal displacement field from fluctuation part of the deformation gradient field.
|
||||||
|
@ -270,6 +276,7 @@ def node_displacement_fluct(size,F):
|
||||||
"""
|
"""
|
||||||
return cell_2_node(cell_displacement_fluct(size,F))
|
return cell_2_node(cell_displacement_fluct(size,F))
|
||||||
|
|
||||||
|
|
||||||
def node_displacement_avg(size,F):
|
def node_displacement_avg(size,F):
|
||||||
"""
|
"""
|
||||||
Nodal displacement field from average part of the deformation gradient field.
|
Nodal displacement field from average part of the deformation gradient field.
|
||||||
|
@ -285,6 +292,7 @@ def node_displacement_avg(size,F):
|
||||||
F_avg = np.average(F,axis=(0,1,2))
|
F_avg = np.average(F,axis=(0,1,2))
|
||||||
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),node_coord0(F.shape[:3][::-1],size))
|
return np.einsum('ml,ijkl->ijkm',F_avg-np.eye(3),node_coord0(F.shape[:3][::-1],size))
|
||||||
|
|
||||||
|
|
||||||
def node_displacement(size,F):
|
def node_displacement(size,F):
|
||||||
"""
|
"""
|
||||||
Nodal displacement field from deformation gradient field.
|
Nodal displacement field from deformation gradient field.
|
||||||
|
@ -299,6 +307,7 @@ def node_displacement(size,F):
|
||||||
"""
|
"""
|
||||||
return node_displacement_avg(size,F) + node_displacement_fluct(size,F)
|
return node_displacement_avg(size,F) + node_displacement_fluct(size,F)
|
||||||
|
|
||||||
|
|
||||||
def node_coord(size,F,origin=np.zeros(3)):
|
def node_coord(size,F,origin=np.zeros(3)):
|
||||||
"""
|
"""
|
||||||
Nodal positions.
|
Nodal positions.
|
||||||
|
@ -315,6 +324,7 @@ def node_coord(size,F,origin=np.zeros(3)):
|
||||||
"""
|
"""
|
||||||
return node_coord0(F.shape[:3][::-1],size,origin) + node_displacement(size,F)
|
return node_coord0(F.shape[:3][::-1],size,origin) + node_displacement(size,F)
|
||||||
|
|
||||||
|
|
||||||
def cell_2_node(cell_data):
|
def cell_2_node(cell_data):
|
||||||
"""Interpolate periodic cell data to nodal data."""
|
"""Interpolate periodic cell data to nodal data."""
|
||||||
n = ( cell_data + np.roll(cell_data,1,(0,1,2))
|
n = ( cell_data + np.roll(cell_data,1,(0,1,2))
|
||||||
|
@ -323,6 +333,7 @@ def cell_2_node(cell_data):
|
||||||
|
|
||||||
return np.pad(n,((0,1),(0,1),(0,1))+((0,0),)*len(cell_data.shape[3:]),mode='wrap')
|
return np.pad(n,((0,1),(0,1),(0,1))+((0,0),)*len(cell_data.shape[3:]),mode='wrap')
|
||||||
|
|
||||||
|
|
||||||
def node_2_cell(node_data):
|
def node_2_cell(node_data):
|
||||||
"""Interpolate periodic nodal data to cell data."""
|
"""Interpolate periodic nodal data to cell data."""
|
||||||
c = ( node_data + np.roll(node_data,1,(0,1,2))
|
c = ( node_data + np.roll(node_data,1,(0,1,2))
|
||||||
|
@ -331,6 +342,7 @@ def node_2_cell(node_data):
|
||||||
|
|
||||||
return c[:-1,:-1,:-1]
|
return c[:-1,:-1,:-1]
|
||||||
|
|
||||||
|
|
||||||
def node_coord0_gridSizeOrigin(coord0,ordered=False):
|
def node_coord0_gridSizeOrigin(coord0,ordered=False):
|
||||||
"""
|
"""
|
||||||
Return grid 'DNA', i.e. grid, size, and origin from array of nodal positions.
|
Return grid 'DNA', i.e. grid, size, and origin from array of nodal positions.
|
||||||
|
|
Loading…
Reference in New Issue