From 4cd84ab8ce80e38e594094bf8b0431414e10ebdd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 Feb 2023 12:54:51 +0100 Subject: [PATCH 1/5] return was missing --- python/damask/mechanics.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index 76c7ae13b..3c4a96d99 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -260,6 +260,11 @@ def _polar_decomposition(T: _np.ndarray, Requested outputs: ‘R’ for the rotation tensor, ‘V’ for left stretch tensor, and ‘U’ for right stretch tensor. + Returns + ------- + VRU : tuple of numpy.ndarray, shape (...,3,3) + Requested components of the singular value decomposition. + """ u, _, vh = _np.linalg.svd(T) R = _np.einsum('...ij,...jk',u,vh) @@ -290,6 +295,11 @@ def _equivalent_Mises(T_sym: _np.ndarray, s : float Scaling factor (2/3 for strain, 3/2 for stress). + Returns + ------- + eq : numpy.ndarray, shape (...) + Scaled second invariant of the deviatoric part of T_sym. + """ d = _tensor.deviatoric(T_sym) return _np.sqrt(s*_np.sum(d**2.0,axis=(-1,-2))) From 66b0b2e9dc4b1599e84350859ddc178eae5dbfd7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 Feb 2023 17:10:22 +0100 Subject: [PATCH 2/5] using latex to improve documentation --- python/damask/mechanics.py | 59 ++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index 3c4a96d99..4b4dfa2aa 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -50,7 +50,7 @@ def deformation_Cauchy_Green_right(F: _np.ndarray) -> _np.ndarray: def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate the Mises equivalent of a strain tensor. Parameters @@ -63,12 +63,20 @@ def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray: epsilon_vM : numpy.ndarray, shape (...) Von Mises equivalent strain of epsilon. + Notes + ----- + The von Mises equivalent of a strain tensor is defined as: + + .. math:: + + \epsilon_{\mathrm{vM}} = \sqrt{2/3 \epsilon_{ij}' \epsilon_{ij}'} + """ return _equivalent_Mises(epsilon,2.0/3.0) def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate the Mises equivalent of a stress tensor. Parameters @@ -81,6 +89,14 @@ def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray: sigma_vM : numpy.ndarray, shape (...) Von Mises equivalent stress of sigma. + Notes + ----- + The von Mises equivalent of a stress tensor is defined as: + + .. math:: + + \sigma_{\mathrm{vM}} = \sqrt{3/2 \sigma_{ij}' \sigma_{ij}'} + """ return _equivalent_Mises(sigma,3.0/2.0) @@ -105,7 +121,7 @@ def maximum_shear(T_sym: _np.ndarray) -> _np.ndarray: def rotation(T: _np.ndarray) -> _rotation.Rotation: - """ + r""" Calculate the rotational part of a tensor. Parameters @@ -118,6 +134,17 @@ def rotation(T: _np.ndarray) -> _rotation.Rotation: R : damask.Rotation, shape (...) Rotational part of the vector. + Notes + ----- + The rotational part is calculated from the polar decomposition: + + .. math:: + + \mathbf{R} = \mathbf{T} \mathbf{U}^{-1} = \mathbf{V}^{-1} \mathbf{T} + + where :math:`\mathbf{V}` and :math:`\mathbf{U}` are left + and right stretch tensor, respectively. + """ return _rotation.Rotation.from_matrix(_polar_decomposition(T,'R')[0]) @@ -212,7 +239,7 @@ def stress_second_Piola_Kirchhoff(P: _np.ndarray, def stretch_left(T: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate left stretch of a tensor. Parameters @@ -225,12 +252,23 @@ def stretch_left(T: _np.ndarray) -> _np.ndarray: V : numpy.ndarray, shape (...,3,3) Left stretch tensor from Polar decomposition of T. + Notes + ----- + The left stretch tensor is calculated from the + polar decomposition: + + .. math:: + + \mathbf{V} = \mathbf{T} \mathbf{R}^\mathrm{T} + + where :math:`\mathbf{R}` is a rotation. + """ return _polar_decomposition(T,'V')[0] def stretch_right(T: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate right stretch of a tensor. Parameters @@ -243,6 +281,17 @@ def stretch_right(T: _np.ndarray) -> _np.ndarray: U : numpy.ndarray, shape (...,3,3) Left stretch tensor from Polar decomposition of T. + Notes + ----- + The right stretch tensor is calculated from the + polar decomposition: + + .. math:: + + \mathbf{U} = \mathbf{R}^\mathrm{T} \mathbf{T} + + where :math:`\mathbf{R}` is a rotation. + """ return _polar_decomposition(T,'U')[0] From 61f2ae295b56133346427ac6e9f5627ed78a0a21 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 16 Feb 2023 11:59:19 -0500 Subject: [PATCH 3/5] switch to physics macros --- python/damask/mechanics.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index 4b4dfa2aa..1948aa2ce 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -65,11 +65,11 @@ def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray: Notes ----- - The von Mises equivalent of a strain tensor is defined as: + The von Mises equivalent of a deviatoric strain tensor is defined as: .. math:: - \epsilon_{\mathrm{vM}} = \sqrt{2/3 \epsilon_{ij}' \epsilon_{ij}'} + \epsilon_\text{vM} = \sqrt{2/3 \epsilon^\prime_{ij} \epsilon^\prime_{ij}} """ return _equivalent_Mises(epsilon,2.0/3.0) @@ -91,11 +91,11 @@ def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray: Notes ----- - The von Mises equivalent of a stress tensor is defined as: + The von Mises equivalent of a deviatoric stress tensor is defined as: .. math:: - \sigma_{\mathrm{vM}} = \sqrt{3/2 \sigma_{ij}' \sigma_{ij}'} + \sigma_\text{vM} = \sqrt{3/2 \sigma^\prime_{ij} \sigma^\prime_{ij}} """ return _equivalent_Mises(sigma,3.0/2.0) @@ -140,9 +140,9 @@ def rotation(T: _np.ndarray) -> _rotation.Rotation: .. math:: - \mathbf{R} = \mathbf{T} \mathbf{U}^{-1} = \mathbf{V}^{-1} \mathbf{T} + \vb{R} = \vb{T} \vb{U}^{-1} = \vb{V}^{-1} \vb{T} - where :math:`\mathbf{V}` and :math:`\mathbf{U}` are left + where :math:`\vb{V}` and :math:`\vb{U}` are left and right stretch tensor, respectively. """ @@ -259,9 +259,9 @@ def stretch_left(T: _np.ndarray) -> _np.ndarray: .. math:: - \mathbf{V} = \mathbf{T} \mathbf{R}^\mathrm{T} + \vb{V} = \vb{T} \vb{R}^\text{T} - where :math:`\mathbf{R}` is a rotation. + where :math:`\vb{R}` is a rotation. """ return _polar_decomposition(T,'V')[0] @@ -288,9 +288,9 @@ def stretch_right(T: _np.ndarray) -> _np.ndarray: .. math:: - \mathbf{U} = \mathbf{R}^\mathrm{T} \mathbf{T} + \vb{U} = \vb{R}^\text{T} \vb{T} - where :math:`\mathbf{R}` is a rotation. + where :math:`\vb{R}` is a rotation. """ return _polar_decomposition(T,'U')[0] From eefa2c29a21f12e0da41c9048790d9384e462889 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 Feb 2023 19:30:28 +0100 Subject: [PATCH 4/5] more details --- python/damask/mechanics.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index 1948aa2ce..7eabdccd3 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -14,7 +14,7 @@ from . import _rotation def deformation_Cauchy_Green_left(F: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate left Cauchy-Green deformation tensor (Finger deformation tensor). Parameters @@ -27,12 +27,18 @@ def deformation_Cauchy_Green_left(F: _np.ndarray) -> _np.ndarray: B : numpy.ndarray, shape (...,3,3) Left Cauchy-Green deformation tensor. + Notes + ----- + .. math:: + + \vb{B} = \vb{F} \vb{F}^{T} + """ return _np.matmul(F,_tensor.transpose(F)) def deformation_Cauchy_Green_right(F: _np.ndarray) -> _np.ndarray: - """ + r""" Calculate right Cauchy-Green deformation tensor. Parameters @@ -45,6 +51,12 @@ def deformation_Cauchy_Green_right(F: _np.ndarray) -> _np.ndarray: C : numpy.ndarray, shape (...,3,3) Right Cauchy-Green deformation tensor. + Notes + ----- + .. math:: + + \vb{C} = \vb{F}^{T} \vb{F} + """ return _np.matmul(_tensor.transpose(F),F) @@ -65,12 +77,15 @@ def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray: Notes ----- - The von Mises equivalent of a deviatoric strain tensor is defined as: + The von Mises equivalent of a strain tensor is defined as: .. math:: \epsilon_\text{vM} = \sqrt{2/3 \epsilon^\prime_{ij} \epsilon^\prime_{ij}} + where :math:`\vb{\epsilon}^\prime` is the deviatoric part + of the strain tensor. + """ return _equivalent_Mises(epsilon,2.0/3.0) @@ -91,12 +106,15 @@ def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray: Notes ----- - The von Mises equivalent of a deviatoric stress tensor is defined as: + The von Mises equivalent of a stress tensor is defined as: .. math:: \sigma_\text{vM} = \sqrt{3/2 \sigma^\prime_{ij} \sigma^\prime_{ij}} + where :math:`\vb{\sigma}^\prime` is the deviatoric part + of stress tensor. + """ return _equivalent_Mises(sigma,3.0/2.0) From 4485e1045c1cb809cd416f4a43e7037055aa3c9f Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 16 Feb 2023 15:12:10 -0500 Subject: [PATCH 5/5] proper indication of transpose; polish --- python/damask/mechanics.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/damask/mechanics.py b/python/damask/mechanics.py index 7eabdccd3..aef6b49ef 100644 --- a/python/damask/mechanics.py +++ b/python/damask/mechanics.py @@ -31,7 +31,7 @@ def deformation_Cauchy_Green_left(F: _np.ndarray) -> _np.ndarray: ----- .. math:: - \vb{B} = \vb{F} \vb{F}^{T} + \vb{B} = \vb{F} \vb{F}^\text{T} """ return _np.matmul(F,_tensor.transpose(F)) @@ -55,7 +55,7 @@ def deformation_Cauchy_Green_right(F: _np.ndarray) -> _np.ndarray: ----- .. math:: - \vb{C} = \vb{F}^{T} \vb{F} + \vb{C} = \vb{F}^\text{T} \vb{F} """ return _np.matmul(_tensor.transpose(F),F) @@ -83,7 +83,7 @@ def equivalent_strain_Mises(epsilon: _np.ndarray) -> _np.ndarray: \epsilon_\text{vM} = \sqrt{2/3 \epsilon^\prime_{ij} \epsilon^\prime_{ij}} - where :math:`\vb{\epsilon}^\prime` is the deviatoric part + where :math:`\vb*{\epsilon}^\prime` is the deviatoric part of the strain tensor. """ @@ -112,8 +112,8 @@ def equivalent_stress_Mises(sigma: _np.ndarray) -> _np.ndarray: \sigma_\text{vM} = \sqrt{3/2 \sigma^\prime_{ij} \sigma^\prime_{ij}} - where :math:`\vb{\sigma}^\prime` is the deviatoric part - of stress tensor. + where :math:`\vb*{\sigma}^\prime` is the deviatoric part + of the stress tensor. """ return _equivalent_Mises(sigma,3.0/2.0) @@ -160,7 +160,7 @@ def rotation(T: _np.ndarray) -> _rotation.Rotation: \vb{R} = \vb{T} \vb{U}^{-1} = \vb{V}^{-1} \vb{T} - where :math:`\vb{V}` and :math:`\vb{U}` are left + where :math:`\vb{V}` and :math:`\vb{U}` are the left and right stretch tensor, respectively. """