36 namespace ContinuumMechanics::CommonTensors {
55 template <
int sizeI,
int sizeJ >
77 Eigen::Matrix< double, sizeI * sizeJ, sizeI * sizeJ >
P;
79 auto d = [](
int a,
int b ) ->
double {
return a == b ? 1.0 : 0.0; };
81 for (
int i = 0; i < sizeI; i++ )
82 for (
int j = 0; j < sizeJ; j++ )
83 for (
int l = 0; l < sizeI; l++ )
84 for (
int k = 0; k < sizeJ; k++ )
85 P( i + j * sizeI, l * sizeJ + k ) =
d( i, l ) *
d( k, j );
97 if constexpr (
nDim == 2 )
105 namespace ContinuumMechanics::TensorUtility {
107 constexpr
int d(
int a,
int b )
109 return a == b ? 1 : 0;
115 typename = std::enable_if< !std::is_const< std::remove_reference< T > >::value > >
118 return Eigen::Map< Eigen::Matrix< typename T::Scalar, x, y > >( t.data() );
121 template <
int x,
int y,
typename T,
typename =
void >
122 auto as(
const T& t )
124 return Eigen::Map< const Eigen::Matrix< typename T::Scalar, x, y > >( t.data() );
127 template <
typename Derived,
128 typename = std::enable_if< !std::is_const< std::remove_reference< Derived > >::value > >
132 Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime * Derived::ColsAtCompileTime, 1 > >(
136 template <
typename Derived,
typename =
void >
140 const Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime * Derived::ColsAtCompileTime, 1 > >(
146 namespace IndexNotation {
147 template <
int nDim >
150 if constexpr (
nDim == 1 )
151 return std::pair< int, int >( 0, 0 );
152 else if (
nDim == 2 )
154 case 0:
return std::pair< int, int >( 0, 0 );
155 case 1:
return std::pair< int, int >( 1, 1 );
156 case 2:
return std::pair< int, int >( 0, 1 );
159 else if (
nDim == 3 ) {
161 case 0:
return std::pair< int, int >( 0, 0 );
162 case 1:
return std::pair< int, int >( 1, 1 );
163 case 2:
return std::pair< int, int >( 2, 2 );
164 case 3:
return std::pair< int, int >( 0, 1 );
165 case 4:
return std::pair< int, int >( 0, 2 );
166 case 5:
return std::pair< int, int >( 1, 2 );
171 << __PRETTY_FUNCTION__ <<
": invalid dimension / voigt index specified" );
174 template <
int nDim >
177 if constexpr (
nDim == 1 )
179 else if (
nDim == 2 )
180 return ( i == j ) ? ( i == 0 ? 0 : 1 ) : 2;
182 else if (
nDim == 3 ) {
183 constexpr
int tensor2VoigtNotationIndicesMapping[3][3] = { { 0, 3, 4 }, { 3, 1, 5 }, { 4, 5, 2 } };
184 return tensor2VoigtNotationIndicesMapping[i][j];
187 throw std::invalid_argument(
MakeString() << __PRETTY_FUNCTION__ <<
": invalid dimension specified" );
190 template <
int nDim >
193 using namespace Eigen;
196 for (
int i = 0; i <
nDim; i++ )
197 for (
int j = 0; j <
nDim; j++ )
198 result( toVoigt< nDim >( i, j ), i, j ) = 1;