62
63
* \param pos The position to be iterated.
64
65
template< std::size_t order, std::size_t dim >
65
inline void positionIterateOneStep( std::vector< std::size_t >& pos ) // NOLINT, need a reference here
66
inline void positionIterateOneStep( boost::array< std::size_t, order >& pos ) // NOLINT, need a reference here
67
68
WAssert( pos.size() >= order, "" );
97
98
* \param pos The sorted(!) position to be iterated.
99
100
template< std::size_t order, std::size_t dim >
100
inline void positionIterateSortedOneStep( std::vector< std::size_t >& pos ) // NOLINT, need a reference here
101
inline void positionIterateSortedOneStep( boost::array< std::size_t, order >& pos ) // NOLINT, need a reference here
102
103
WAssert( pos.size() >= order, "" );
289
290
bool operator != ( WTensorBase const& other ) const;
293
* Declare a compile-time constant as enum and not as static constant.
298
* The number of elements to store.
300
dataSize = WPower< dim, order >::value
293
305
* Calculate the position of the element in the data vector. The function
300
312
template< typename Index_T >
301
313
static inline std::size_t getPos( Index_T pos[] );
304
* Stores all elements.
306
std::vector< Data_T > m_data;
309
* Declare a compile-time constant as enum and not as static constant.
314
* The number of elements to store.
316
dataSize = WPower< dim, order >::value
315
//! Stores all elements.
316
//std::vector< Data_T > m_data;
317
boost::array< Data_T, dataSize > m_data;
320
320
template< std::size_t order, std::size_t dim, typename Data_T >
321
321
WTensorBase< order, dim, Data_T >::WTensorBase()
322
: m_data( dataSize, Data_T() )
323
m_data.assign( Data_T() );
326
326
template< std::size_t order, std::size_t dim, typename Data_T >
332
332
template< std::size_t order, std::size_t dim, typename Data_T >
333
333
WTensorBase< order, dim, Data_T >::WTensorBase( WTensorBaseSym< order, dim, Data_T > const& t )
346
345
template< std::size_t order, std::size_t dim, typename Data_T >
347
346
WTensorBase< order, dim, Data_T > const& WTensorBase< order, dim, Data_T >::operator = ( WTensorBaseSym< order, dim, Data_T > const& t )
349
std::vector< std::size_t > pos( order, 0 );
348
boost::array< std::size_t, order > pos;
351
351
for( std::size_t k = 0; k < dataSize; ++k )
353
( *this )[ pos ] = t[ pos ];
353
( *this )[ &pos[ 0 ] ] = t[ &pos[ 0 ] ];
354
354
positionIterateOneStep< order, dim >( pos );
656
* Declare a compile-time constant as enum and not as static constant.
661
* The number of elements to store.
663
dataSize = WBinom< order + dim - 1, order >::value
656
667
* Standard constructor.
658
669
* All elements are set to Data_T().
668
679
explicit WTensorBaseSym( const WValue< Data_T >& data );
682
* Constructs the symmetrical tensor and initialize with the given data.
684
* \param data The components of the symmetrical tensor: Take care of the
685
* ordering of the components to match the ordering in \see m_data.
687
explicit WTensorBaseSym( const boost::array< Data_T, dataSize >& data );
671
690
* Copy constructor.
673
692
* \param t The tensor to copy from.
698
717
std::size_t getOrder() const;
720
* Set internal data from a WValue.
722
* \param values The input values.
724
void setValues( WValue< Data_T > const& values );
727
* Set internal data from a boost array.
729
* \param values The input values.
731
void setValues( boost::array< Data_T, dataSize > const& values );
701
734
* Get the element at a specific position.
703
736
* \param indices A std::vector of indices that has a size of at least order.
760
793
bool operator != ( WTensorBaseSym const& other ) const;
764
797
* Stores the elements of this tensor lexicographical ordered on their
765
798
* indices, where for each set of permutations the lexicographical lowest
768
std::vector< Data_T > m_data;
771
* Declare a compile-time constant as enum and not as static constant.
776
* The number of elements to store.
778
dataSize = WBinom< order + dim - 1, order >::value
801
// std::vector< Data_T > m_data;
802
boost::array< Data_T, dataSize > m_data;
782
806
* A class that maps symmetric tensor indices to vector positions.
833
857
WTensorBaseSym< order, dim, Data_T >::PositionIndexer::PositionIndexer()
835
859
// the map uses lexical ordering of vectors
836
std::map< std::vector< std::size_t >, std::size_t > m;
860
std::map< boost::array< std::size_t, order >, std::size_t > m;
838
862
// fill the map with all possible combinations of indices, where
839
863
// every combination of indices appears in ascending order of indices
840
std::vector< std::size_t > pos( order, 0 );
864
boost::array< std::size_t, order > pos;
841
867
for( std::size_t k = 0; k < dataSize; ++k )
843
869
// enumerate the position
871
m.insert( std::make_pair( pos, k ) );
846
873
// get the next sorted combination
847
874
positionIterateSortedOneStep< order, dim >( pos );
850
877
// now iterate all possible sets of indices
851
pos = std::vector< std::size_t >( order, 0 );
852
std::vector< std::size_t > _p( order, 0 );
880
boost::array< std::size_t, order > _p;
853
883
for( std::size_t k = 0; k < WPower< dim, order >::value; ++k )
858
888
std::sort( _p.begin(), _p.end() );
860
890
// now map the arbitrary ordered indices to the position of the ordered set in m (and thus in m_data)
861
m_positions[ pos ] = m[ _p ];
891
m_positions[ &pos[ 0 ] ] = m[ _p ];
863
// the map should already know the sorted position,
893
// the map should already knows the sorted position,
864
894
// it should never be added by std::map::operator [] at this point
865
895
WAssert( m.size() == dataSize, "" );
881
911
template< std::size_t order, std::size_t dim, typename Data_T >
882
912
WTensorBaseSym< order, dim, Data_T >::WTensorBaseSym()
883
: m_data( dataSize, Data_T() )
914
m_data.assign( Data_T() );
887
917
template< std::size_t order, std::size_t dim, typename Data_T >
888
918
WTensorBaseSym< order, dim, Data_T >::WTensorBaseSym( const WValue< Data_T >& data )
889
: m_data( &data[0], &data[0] + data.size() )
891
920
WAssert( dataSize == m_data.size(), "Number of given components does not match the order and dimension of this symmetric tensor" );
921
std::copy( &data[ 0 ], &data[ 0 ] + data.size(), &m_data[ 0 ] );
924
template< std::size_t order, std::size_t dim, typename Data_T >
925
WTensorBaseSym< order, dim, Data_T >::WTensorBaseSym( const boost::array< Data_T, dataSize >& data )
927
std::copy( &data[ 0 ], &data[ 0 ] + dataSize, &m_data[ 0 ] );
894
930
template< std::size_t order, std::size_t dim, typename Data_T >
919
955
template< std::size_t order, std::size_t dim, typename Data_T >
956
void WTensorBaseSym< order, dim, Data_T >::setValues( WValue< Data_T > const& values )
958
WAssert( m_data.size() == values.size(), "Number of given components does not match the order and dimension of this symmetric tensor" );
959
std::copy( &values[ 0 ], &values[ 0 ] + values.size(), &m_data[ 0 ] );
962
template< std::size_t order, std::size_t dim, typename Data_T >
963
void WTensorBaseSym< order, dim, Data_T >::setValues( boost::array< Data_T, dataSize > const& values )
965
std::copy( &values[ 0 ], &values[ 0 ] + dataSize, &m_data[ 0 ] );
968
template< std::size_t order, std::size_t dim, typename Data_T >
920
969
template< typename Index_T >
921
970
Data_T& WTensorBaseSym< order, dim, Data_T >::operator[] ( std::vector< Index_T > const& indices )
1131
1182
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t order, std::size_t dim, typename Data_T > //NOLINT
1132
1183
class WTensorFunc : public TensorBase_T< order, dim, Data_T >
1187
* Default constructor.
1192
* Initializes the tensor with the given data.
1194
* \param data Components in same ordering as the components of the TensorBase class.
1196
explicit WTensorFunc( const WValue< Data_T >& data );
1199
* Initializes the tensor with the given data.
1201
* \param data Components in same ordering as the components of the TensorBase class.
1203
explicit WTensorFunc( const boost::array< Data_T, TensorBase_T< order, dim, Data_T >::dataSize >& data );
1206
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t order, std::size_t dim, typename Data_T >
1207
WTensorFunc< TensorBase_T, order, dim, Data_T >::WTensorFunc()
1208
: TensorBase_T< order, dim, Data_T >()
1212
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t order, std::size_t dim, typename Data_T >
1213
WTensorFunc< TensorBase_T, order, dim, Data_T >::WTensorFunc( const WValue< Data_T >& data )
1214
: TensorBase_T< order, dim, Data_T >( data )
1218
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t order, std::size_t dim, typename Data_T >
1219
WTensorFunc< TensorBase_T, order, dim, Data_T >::WTensorFunc( const boost::array< Data_T, TensorBase_T< order, dim, Data_T >::dataSize >& data )
1220
: TensorBase_T< order, dim, Data_T >( data )
1137
1226
* Implements the operator () for an order of 6.
1238
* Default constructor.
1243
* Initializes the tensor with the given data.
1245
* \param data Components in same ordering as the components of the TensorBase class.
1247
explicit WTensorFunc( const WValue< Data_T >& data );
1250
* Initializes the tensor with the given data.
1252
* \param data Components in same ordering as the components of the TensorBase class.
1254
explicit WTensorFunc( const boost::array< Data_T, TensorBase_T< 6, dim, Data_T >::dataSize >& data );
1149
1257
* Access operator.
1151
1259
* \param i0 An index.
1174
1282
Data_T const& operator() ( std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3, std::size_t i4, std::size_t i5 ) const;
1285
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1286
WTensorFunc< TensorBase_T, 6, dim, Data_T >::WTensorFunc()
1287
: TensorBase_T< 6, dim, Data_T >()
1291
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1292
WTensorFunc< TensorBase_T, 6, dim, Data_T >::WTensorFunc( const WValue< Data_T >& data )
1293
: TensorBase_T< 6, dim, Data_T >( data )
1297
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1298
WTensorFunc< TensorBase_T, 6, dim, Data_T >::WTensorFunc( const boost::array< Data_T, TensorBase_T< 6, dim, Data_T >::dataSize >& data )
1299
: TensorBase_T< 6, dim, Data_T >( data )
1177
1303
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T > //NOLINT
1178
1304
Data_T& WTensorFunc< TensorBase_T, 6, dim, Data_T >::operator() ( std::size_t i0, std::size_t i1, std::size_t i2,
1179
1305
std::size_t i3, std::size_t i4, std::size_t i5 )
1391
* Default constructor.
1396
* Initializes the tensor with the given data.
1398
* \param data Components in same ordering as the components of the TensorBase class.
1400
explicit WTensorFunc( const WValue< Data_T >& data );
1403
* Initializes the tensor with the given data.
1405
* \param data Components in same ordering as the components of the TensorBase class.
1407
explicit WTensorFunc( const boost::array< Data_T, TensorBase_T< 4, dim, Data_T >::dataSize >& data );
1265
1410
* Access operator.
1267
1412
* \param i0 An index.
1286
1431
Data_T const& operator() ( std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3 ) const;
1434
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1435
WTensorFunc< TensorBase_T, 4, dim, Data_T >::WTensorFunc()
1436
: TensorBase_T< 4, dim, Data_T >()
1440
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1441
WTensorFunc< TensorBase_T, 4, dim, Data_T >::WTensorFunc( const WValue< Data_T >& data )
1442
: TensorBase_T< 4, dim, Data_T >( data )
1446
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1447
WTensorFunc< TensorBase_T, 4, dim, Data_T >::WTensorFunc( const boost::array< Data_T, TensorBase_T< 4, dim, Data_T >::dataSize >& data )
1448
: TensorBase_T< 4, dim, Data_T >( data )
1289
1452
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T > //NOLINT
1290
1453
Data_T& WTensorFunc< TensorBase_T, 4, dim, Data_T >::operator() ( std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3 )
1374
1537
explicit WTensorFunc( const WValue< Data_T >& data );
1540
* Initializes the tensor with the given data.
1542
* \param data Components in same ordering as the components of the TensorBase class.
1544
explicit WTensorFunc( const boost::array< Data_T, TensorBase_T< 2, dim, Data_T >::dataSize >& data );
1377
1547
* Access operator.
1379
1549
* \param i0 An index.
1584
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T >
1585
WTensorFunc< TensorBase_T, 2, dim, Data_T >::WTensorFunc( const boost::array< Data_T, TensorBase_T< 2, dim, Data_T >::dataSize >& data )
1586
: TensorBase_T< 2, dim, Data_T >( data )
1414
1590
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T > //NOLINT
1415
1591
Data_T& WTensorFunc< TensorBase_T, 2, dim, Data_T >::operator() ( std::size_t i0, std::size_t i1 )
1541
1717
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T > //NOLINT
1542
1718
Data_T const& WTensorFunc< TensorBase_T, 0, dim, Data_T >::operator() () const
1545
return TensorBase_T< 0, dim, Data_T >::operator[]< std::size_t >( NULL );
1547
1720
return TensorBase_T< 0, dim, Data_T >::template operator[]< std::size_t >( NULL );
1551
1723
template< template< std::size_t, std::size_t, typename > class TensorBase_T, std::size_t dim, typename Data_T > //NOLINT
1552
1724
WTensorFunc< TensorBase_T, 0, dim, Data_T >::operator Data_T() const
1555
return TensorBase_T< 0, dim, Data_T >::operator[]< std::size_t >( NULL );
1557
1726
return TensorBase_T< 0, dim, Data_T >::template operator[]< std::size_t >( NULL );
1561
1729
#endif // WTENSORBASE_H