36 namespace ContinuumMechanics::CommonTensors {
57 template <
int sizeI,
int sizeJ >
79 Eigen::Matrix< double, sizeI * sizeJ, sizeI * sizeJ >
P;
81 auto d = [](
int a,
int b ) ->
double {
return a == b ? 1.0 : 0.0; };
83 for (
int i = 0; i < sizeI; i++ )
84 for (
int j = 0; j < sizeJ; j++ )
85 for (
int l = 0; l < sizeI; l++ )
86 for (
int k = 0; k < sizeJ; k++ )
87 P( i + j * sizeI, l * sizeJ + k ) =
d( i, l ) *
d( k, j );
99 if constexpr (
nDim == 2 )
107 namespace ContinuumMechanics::TensorUtility {
109 constexpr
int d(
int a,
int b )
111 return a == b ? 1 : 0;
117 typename = std::enable_if< !std::is_const< std::remove_reference< T > >::value > >
120 return Eigen::Map< Eigen::Matrix< typename T::Scalar, x, y > >( t.data() );
123 template <
int x,
int y,
typename T,
typename =
void >
124 auto as(
const T& t )
126 return Eigen::Map< const Eigen::Matrix< typename T::Scalar, x, y > >( t.data() );
129 template <
typename Derived,
130 typename = std::enable_if< !std::is_const< std::remove_reference< Derived > >::value > >
134 Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime * Derived::ColsAtCompileTime, 1 > >(
138 template <
typename Derived,
typename =
void >
142 const Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime * Derived::ColsAtCompileTime, 1 > >(
146 template <
int... Pairs >
149 static_assert(
sizeof...( Pairs ) % 2 == 0,
"Pairs must contain an even number of elements." );
151 constexpr
int numPairs =
sizeof...( Pairs ) / 2;
153 Eigen::array< Eigen::IndexPair< int >, numPairs > result{};
155 if constexpr ( numPairs > 0 ) {
156 constexpr
int values[] = { Pairs... };
159 for (
int i = 0; i < numPairs; ++i ) {
160 result[i] = { values[2 * i], values[2 * i + 1] };
168 namespace IndexNotation {
169 template <
int nDim >
172 if constexpr (
nDim == 1 )
173 return std::pair< int, int >( 0, 0 );
174 else if (
nDim == 2 )
176 case 0:
return std::pair< int, int >( 0, 0 );
177 case 1:
return std::pair< int, int >( 1, 1 );
178 case 2:
return std::pair< int, int >( 0, 1 );
181 else if (
nDim == 3 ) {
183 case 0:
return std::pair< int, int >( 0, 0 );
184 case 1:
return std::pair< int, int >( 1, 1 );
185 case 2:
return std::pair< int, int >( 2, 2 );
186 case 3:
return std::pair< int, int >( 0, 1 );
187 case 4:
return std::pair< int, int >( 0, 2 );
188 case 5:
return std::pair< int, int >( 1, 2 );
193 << __PRETTY_FUNCTION__ <<
": invalid dimension / voigt index specified" );
196 template <
int nDim >
199 if constexpr (
nDim == 1 )
201 else if (
nDim == 2 )
202 return ( i == j ) ? ( i == 0 ? 0 : 1 ) : 2;
204 else if (
nDim == 3 ) {
205 constexpr
int tensor2VoigtNotationIndicesMapping[3][3] = { { 0, 3, 4 }, { 3, 1, 5 }, { 4, 5, 2 } };
206 return tensor2VoigtNotationIndicesMapping[i][j];
209 throw std::invalid_argument(
MakeString() << __PRETTY_FUNCTION__ <<
": invalid dimension specified" );
212 template <
int nDim >
215 using namespace Eigen;
218 for (
int i = 0; i <
nDim; i++ )
219 for (
int j = 0; j <
nDim; j++ )
220 result( toVoigt< nDim >( i, j ), i, j ) = 1;