#ifndef VOIGT_OPERATIONS_H #define VOIGT_OPERATIONS_H #include "MatrixDef.h" #include "MatrixLibrary.h" // Voigt indexing puts a symmetric 3x3 matrix into a // vector form: [0 1 2 3 4 5] // // matrix form: [[ 0 5 4 ] // [ 5 1 3 ] // [ 4 3 2 ]] // // unsymmetric version // vector form: [0 1 2 3 4 5 6 7 8] // // matrix form: [[ 0 5 4 ] // [ 8 1 3 ] // [ 7 6 2 ]] namespace voigt3 { //const int voigt_idx1_symm[] = {0,1,2,1,0,0}; // first packed voigt index //const int voigt_idx2_symm[] = {0,1,2,2,2,1}; // second packed voigt index const int voigt_idx1[] = {0,1,2,1,0,0,2,2,1}; // first packed voigt index const int voigt_idx2[] = {0,1,2,2,2,1,1,0,0}; // second packed voigt index // const int voigt_idx1[] = {0,1,2,0,0,1,1,2,2}; // first packed voigt index // const int voigt_idx2[] = {0,1,2,1,2,2,0,0,1}; // second packed voigt index //* Computes a symmetric matrix-matrix product //* Inputs 6-length vectors A, B inline DENS_VEC dsymm(const DENS_VEC &A, const DENS_VEC &B) { DENS_VEC C(6,false); C(0) = A(0)*B(0)+A(5)*B(5)+A(4)*B(4); C(1) = A(5)*B(5)+A(1)*B(1)+A(3)*B(3); C(2) = A(4)*B(4)+A(3)*B(3)+A(2)*B(2); C(3) = A(5)*B(4)+A(1)*B(3)+A(3)*B(2); C(4) = A(0)*B(4)+A(5)*B(3)+A(4)*B(2); C(5) = A(0)*B(5)+A(5)*B(1)+A(4)*B(3); return C; } //* Returns the trace of a 3x3 matrix in symmetric voigt form. inline double tr(const DENS_VEC &A) { return A(0) + A(1) + A(2); } //* Computes the determinant of a 3x3 matrix in symmetric voigt form. inline double det(const DENS_VEC &A) { return A(0) * (A(1)*A(2)-A(3)*A(3)) -A(5) * (A(5)*A(2)-A(3)*A(4)) +A(4) * (A(5)*A(3)-A(1)*A(4)); } //* Returns the derivative of C*C in voigt notation. inline DENS_MAT derivative_of_square(const DENS_VEC &C) { DENS_MAT D(6,6); D(0,0)=2.0*C(0); D(0,1)=0.0; D(0,2)=0.0; D(1,0)=0.0; D(1,1)=2.0*C(1); D(1,2)=0.0; D(2,0)=0.0; D(2,1)=0.0; D(2,2)=2.0*C(2); D(0,3)=0.0; D(0,4)=2.0*C(4); D(0,5)=2.0*C(5); D(1,3)=2.0*C(3); D(1,4)=0.0; D(1,5)=2.0*C(5); D(2,3)=2.0*C(3); D(2,4)=2.0*C(4); D(2,5)=0.0; D(3,0)=0.0; D(3,1)=C(3); D(3,2)=C(3); D(4,0)=C(4); D(4,1)=0.0; D(4,2)=C(4); D(5,0)=C(5); D(5,1)=C(5); D(5,2)=0.0; D(3,3)=C(1)+C(2); D(3,4)=C(5); D(3,5)=C(4); D(4,3)=C(5); D(4,4)=C(0)+C(2); D(4,5)=C(3); D(5,3)=C(4); D(5,4)=C(3); D(5,5)=C(0)+C(1); return D; } //* Computes the inverse of a 3x3 matrix in symmetric voigt form. inline DENS_VEC inv(const DENS_VEC &A) { DENS_VEC B(6,false); const double inv_det = 1.0/det(A); B(0) = (A(1)*A(2)-A(3)*A(3))*inv_det; B(1) = (A(0)*A(2)-A(4)*A(4))*inv_det; B(2) = (A(0)*A(1)-A(5)*A(5))*inv_det; B(3) = (A(4)*A(5)-A(0)*A(3))*inv_det; B(4) = (A(5)*A(3)-A(4)*A(1))*inv_det; B(5) = (A(4)*A(3)-A(5)*A(2))*inv_det; return B; } //* Returns the identify matrix in voigt form, optionally scaled by a factor. inline DENS_VEC eye(INDEX N=3, double scale=1.0) { const double dij[] = {0.0, scale}; const INDEX voigt_size = N*N-((N*N-N)>>1); // total - symmetric elements DENS_VEC I(voigt_size,false); for (INDEX i=0; i