GEOSX
genericTensorOps.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // Source includes
16 #include "ArraySlice.hpp"
17 #include "math.hpp"
18 
43 
49 #define LVARRAY_TENSOROPS_INIT_LOCAL_2( EXP ) { EXP[ 0 ], EXP[ 1 ] }
50 
57 #define LVARRAY_TENSOROPS_ASSIGN_2( var, exp0, exp1 ) \
58  var[ 0 ] = exp0; var[ 1 ] = exp1
59 
64 #define LVARRAY_TENSOROPS_INIT_LOCAL_3( EXP ) { EXP[ 0 ], EXP[ 1 ], EXP[ 2 ] }
65 
73 #define LVARRAY_TENSOROPS_ASSIGN_3( var, exp0, exp1, exp2 ) \
74  var[ 0 ] = exp0; var[ 1 ] = exp1; var[ 2 ] = exp2
75 
80 #define LVARRAY_TENSOROPS_INIT_LOCAL_6( EXP ) { EXP[ 0 ], EXP[ 1 ], EXP[ 2 ], EXP[ 3 ], EXP[ 4 ], EXP[ 5 ] }
81 
92 #define LVARRAY_TENSOROPS_ASSIGN_6( var, exp0, exp1, exp2, exp3, exp4, exp5 ) \
93  var[ 0 ] = exp0; var[ 1 ] = exp1; var[ 2 ] = exp2; var[ 3 ] = exp3; var[ 4 ] = exp4; var[ 5 ] = exp5
94 
99 #define LVARRAY_TENSOROPS_INIT_LOCAL_2x2( EXP ) \
100  { { EXP[ 0 ][ 0 ], EXP[ 0 ][ 1 ] }, \
101  { EXP[ 1 ][ 0 ], EXP[ 1 ][ 1 ] } }
102 
111 #define LVARRAY_TENSOROPS_ASSIGN_2x2( var, exp00, exp01, exp10, exp11 ) \
112  var[ 0 ][ 0 ] = exp00; var[ 0 ][ 1 ] = exp01; \
113  var[ 1 ][ 0 ] = exp10; var[ 1 ][ 1 ] = exp11
114 
119 #define LVARRAY_TENSOROPS_INIT_LOCAL_3x3( EXP ) \
120  { { EXP[ 0 ][ 0 ], EXP[ 0 ][ 1 ], EXP[ 0 ][ 2 ] }, \
121  { EXP[ 1 ][ 0 ], EXP[ 1 ][ 1 ], EXP[ 1 ][ 2 ] }, \
122  { EXP[ 2 ][ 0 ], EXP[ 2 ][ 1 ], EXP[ 2 ][ 2 ] } }
123 
137 #define LVARRAY_TENSOROPS_ASSIGN_3x3( var, exp00, exp01, exp02, exp10, exp11, exp12, exp20, exp21, exp22 ) \
138  var[ 0 ][ 0 ] = exp00; var[ 0 ][ 1 ] = exp01; var[ 0 ][ 2 ] = exp02; \
139  var[ 1 ][ 0 ] = exp10; var[ 1 ][ 1 ] = exp11; var[ 1 ][ 2 ] = exp12; \
140  var[ 2 ][ 0 ] = exp20; var[ 2 ][ 1 ] = exp21; var[ 2 ][ 2 ] = exp22
141 
143 
144 
145 namespace LvArray
146 {
147 namespace tensorOps
148 {
149 namespace internal
150 {
151 
152 HAS_STATIC_MEMBER( SIZE );
153 HAS_STATIC_MEMBER( NDIM );
154 
163 template< std::ptrdiff_t ISIZE, typename T >
164 LVARRAY_HOST_DEVICE inline constexpr
165 std::enable_if_t< HasStaticMember_SIZE< T > >
166 checkSizes( T const & src )
167 {
168  static_assert( ISIZE == T::SIZE,
169  "Expected the first dimension of size ISIZE, got an type of size T::SIZE." );
171 }
172 
180 template< std::ptrdiff_t PROVIDED_SIZE, typename T, std::ptrdiff_t INFERRED_SIZE >
181 LVARRAY_HOST_DEVICE inline constexpr
182 void checkSizes( T const ( &src )[ INFERRED_SIZE ] )
183 {
184  static_assert( PROVIDED_SIZE == INFERRED_SIZE,
185  "Expected the first dimension of size PROVIDED_N, got an array of size INFERRED_N." );
187 }
188 
198 template< std::ptrdiff_t PROVIDED_M,
199  std::ptrdiff_t PROVIDED_N,
200  typename T,
201  std::ptrdiff_t INFERRED_M,
202  std::ptrdiff_t INFERRED_N >
203 LVARRAY_HOST_DEVICE inline constexpr
204 void checkSizes( T const ( &src )[ INFERRED_M ][ INFERRED_N ] )
205 {
206  static_assert( PROVIDED_M == INFERRED_M, "Expected the first dimension of size PROVIDED_M, got an array of size INFERRED_M." );
207  static_assert( PROVIDED_N == INFERRED_N, "Expected the second dimension of size PROVIDED_N, got an array of size INFERRED_N." );
209 }
210 
217 template< std::ptrdiff_t ISIZE, typename ARRAY >
219 std::enable_if_t< HasStaticMember_NDIM< ARRAY > >
220 checkSizes( ARRAY const & array )
221 {
222  static_assert( ARRAY::NDIM == 1, "Must be a 1D array." );
223  #ifdef LVARRAY_BOUNDS_CHECK
224  LVARRAY_ERROR_IF_NE( array.size( 0 ), ISIZE );
225  #else
226  LVARRAY_UNUSED_VARIABLE( array );
227  #endif
228 }
229 
237 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename ARRAY >
239 std::enable_if_t< HasStaticMember_NDIM< ARRAY > >
240 checkSizes( ARRAY const & array )
241 {
242  static_assert( ARRAY::NDIM == 2, "Must be a 1D array." );
243 #ifdef LVARRAY_BOUNDS_CHECK
244  LVARRAY_ERROR_IF_NE( array.size( 0 ), ISIZE );
245  LVARRAY_ERROR_IF_NE( array.size( 1 ), JSIZE );
246 #else
247  LVARRAY_UNUSED_VARIABLE( array );
248 #endif
249 }
250 
251 } // namespace internal
252 
254 template< std::ptrdiff_t ISIZE >
255 constexpr std::ptrdiff_t SYM_SIZE = ( ISIZE * ( ISIZE + 1 ) ) / 2;
256 
263 
271 template< std::ptrdiff_t ISIZE, typename VECTOR >
273 auto maxAbsoluteEntry( VECTOR && vector )
274 {
275  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
276  internal::checkSizes< ISIZE >( vector );
277 
278  auto maxVal = math::abs( vector[ 0 ] );
279  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
280  {
281  maxVal = math::max( maxVal, math::abs( vector[ i ] ) );
282  }
283 
284  return maxVal;
285 }
286 
295 template< std::ptrdiff_t ISIZE, typename VECTOR >
297 void fill( VECTOR && vector, std::remove_reference_t< decltype( vector[ 0 ] ) > const value )
298 {
299  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
300  internal::checkSizes< ISIZE >( vector );
301 
302  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
303  {
304  vector[ i ] = value;
305  }
306 }
307 
317 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename MATRIX >
319 void fill( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) > const value )
320 {
321  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
322  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
323  internal::checkSizes< ISIZE, JSIZE >( matrix );
324 
325  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
326  {
327  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
328  {
329  matrix[ i ][ j ] = value;
330  }
331  }
332 }
333 
343 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename SRC_VECTOR >
345 void copy( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
346  SRC_VECTOR const & LVARRAY_RESTRICT_REF srcVector )
347 {
348  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
349  internal::checkSizes< ISIZE >( dstVector );
350  internal::checkSizes< ISIZE >( srcVector );
351 
352  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
353  {
354  dstVector[ i ] = srcVector[ i ];
355  }
356 }
357 
368 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_MATRIX, typename SRC_MATRIX >
370 void copy( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
371  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix )
372 {
373  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
374  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
375  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
376  internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
377 
378  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
379  {
380  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
381  {
382  dstMatrix[ i ][ j ] = srcMatrix[ i ][ j ];
383  }
384  }
385 }
386 
395 template< std::ptrdiff_t ISIZE, typename VECTOR >
397 void scale( VECTOR && vector, std::remove_reference_t< decltype( vector[ 0 ] ) > const scale )
398 {
399  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
400  internal::checkSizes< ISIZE >( vector );
401 
402  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
403  {
404  vector[ i ] *= scale;
405  }
406 }
407 
417 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename MATRIX >
419 void scale( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) > const scale )
420 {
421  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
422  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
423  internal::checkSizes< ISIZE, JSIZE >( matrix );
424 
425  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
426  {
427  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
428  {
429  matrix[ i ][ j ] *= scale;
430  }
431  }
432 }
433 
444 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename SRC_VECTOR >
446 void scaledCopy( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
447  SRC_VECTOR const & LVARRAY_RESTRICT_REF srcVector,
448  std::remove_reference_t< decltype( srcVector[ 0 ] ) > const scale )
449 {
450  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
451  internal::checkSizes< ISIZE >( dstVector );
452  internal::checkSizes< ISIZE >( srcVector );
453 
454  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
455  {
456  dstVector[ i ] = scale * srcVector[ i ];
457  }
458 }
459 
471 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_MATRIX, typename SRC_MATRIX >
473 void scaledCopy( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
474  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix,
475  std::remove_reference_t< decltype( srcMatrix[ 0 ][ 0 ] ) > const scale )
476 {
477  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
478  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
479  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
480  internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
481 
482  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
483  {
484  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
485  {
486  dstMatrix[ i ][ j ] = scale * srcMatrix[ i ][ j ];
487  }
488  }
489 }
490 
499 template< std::ptrdiff_t M, typename DST_VECTOR >
501 void addScalar( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
502  std::remove_reference_t< decltype( dstVector[0] ) > const value )
503 {
504  static_assert( M > 0, "M must be greater than zero." );
505  internal::checkSizes< M >( dstVector );
506 
507  for( std::ptrdiff_t i = 0; i < M; ++i )
508  {
509  dstVector[ i ] += value;
510  }
511 }
512 
522 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename SRC_VECTOR >
524 void add( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
525  SRC_VECTOR const & LVARRAY_RESTRICT_REF srcVector )
526 {
527  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
528  internal::checkSizes< ISIZE >( dstVector );
529  internal::checkSizes< ISIZE >( srcVector );
530 
531  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
532  {
533  dstVector[ i ] += srcVector[ i ];
534  }
535 }
536 
547 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_MATRIX, typename SRC_MATRIX >
549 void add( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
550  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix )
551 {
552  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
553  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
554  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
555  internal::checkSizes< ISIZE, JSIZE >( srcMatrix );
556 
557  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
558  {
559  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
560  {
561  dstMatrix[ i ][ j ] += srcMatrix[ i ][ j ];
562  }
563  }
564 }
565 
575 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename SRC_VECTOR >
577 void subtract( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
578  SRC_VECTOR const & LVARRAY_RESTRICT_REF srcVector )
579 {
580  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
581  internal::checkSizes< ISIZE >( dstVector );
582  internal::checkSizes< ISIZE >( srcVector );
583 
584  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
585  {
586  dstVector[ i ] -= srcVector[ i ];
587  }
588 }
589 
600 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename SRC_VECTOR >
602 void scaledAdd( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
603  SRC_VECTOR const & LVARRAY_RESTRICT_REF srcVector,
604  std::remove_reference_t< decltype( srcVector[ 0 ] ) > const scale )
605 {
606  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
607  internal::checkSizes< ISIZE >( dstVector );
608  internal::checkSizes< ISIZE >( srcVector );
609 
610  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
611  {
612  dstVector[ i ] = dstVector[ i ] + scale * srcVector[ i ];
613  }
614 }
615 
626 template< std::ptrdiff_t ISIZE, typename DST_VECTOR, typename VECTOR_A, typename VECTOR_B >
628 void hadamardProduct( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
629  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
630  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
631 {
632  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
633  internal::checkSizes< ISIZE >( dstVector );
634  internal::checkSizes< ISIZE >( vectorA );
635  internal::checkSizes< ISIZE >( vectorB );
636 
637  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
638  {
639  dstVector[ i ] = vectorA[ i ] * vectorB[ i ];
640  }
641 }
642 
644 
649 
657 template< std::ptrdiff_t ISIZE, typename VECTOR >
659 auto l2NormSquared( VECTOR const & vector )
660 {
661  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
662  internal::checkSizes< ISIZE >( vector );
663 
664  auto norm = vector[ 0 ] * vector[ 0 ];
665  for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
666  {
667  norm = norm + vector[ i ] * vector[ i ];
668  }
669  return norm;
670 }
671 
678 template< std::ptrdiff_t ISIZE, typename VECTOR >
680 auto l2Norm( VECTOR const & vector )
681 {
682  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
683  internal::checkSizes< ISIZE >( vector );
684 
685  return math::sqrt( l2NormSquared< ISIZE >( vector ) );
686 }
687 
695 template< std::ptrdiff_t ISIZE, typename VECTOR >
697 auto normalize( VECTOR && vector )
698 {
699  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
700  internal::checkSizes< ISIZE >( vector );
701 
702  auto const normInv = math::invSqrt( l2NormSquared< ISIZE >( vector ) );
703  scale< ISIZE >( vector, normInv );
704 
705  return 1 / normInv;
706 }
707 
716 template< std::ptrdiff_t JSIZE, typename VECTOR_A, typename VECTOR_B >
718 auto AiBi( VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
719  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
720 {
721  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
722  internal::checkSizes< JSIZE >( vectorA );
723  internal::checkSizes< JSIZE >( vectorB );
724 
725  auto result = vectorA[ 0 ] * vectorB[ 0 ];
726  for( std::ptrdiff_t i = 1; i < JSIZE; ++i )
727  {
728  result = result + vectorA[ i ] * vectorB[ i ];
729  }
730 
731  return result;
732 }
733 
743 template< typename DST_VECTOR, typename VECTOR_A, typename VECTOR_B >
745 void crossProduct( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
746  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
747  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
748 {
749  internal::checkSizes< 3 >( dstVector );
750  internal::checkSizes< 3 >( vectorA );
751  internal::checkSizes< 3 >( vectorB );
752 
753  dstVector[ 0 ] = vectorA[ 1 ] * vectorB[ 2 ] - vectorA[ 2 ] * vectorB[ 1 ];
754  dstVector[ 1 ] = vectorA[ 2 ] * vectorB[ 0 ] - vectorA[ 0 ] * vectorB[ 2 ];
755  dstVector[ 2 ] = vectorA[ 0 ] * vectorB[ 1 ] - vectorA[ 1 ] * vectorB[ 0 ];
756 }
757 
759 
764 
778 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_MATRIX, typename VECTOR_A, typename VECTOR_B >
780 void Rij_eq_AiBj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
781  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
782  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
783 {
784  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
785  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
786  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
787  internal::checkSizes< ISIZE >( vectorA );
788  internal::checkSizes< JSIZE >( vectorB );
789 
790  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
791  {
792  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
793  {
794  dstMatrix[ i ][ j ] = vectorA[ i ] * vectorB[ j ];
795  }
796  }
797 }
798 
808 template< std::ptrdiff_t M, typename DST_MATRIX, typename VECTOR_A >
810 void Rij_eq_AiAj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
811  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA )
812 {
813  static_assert( M > 0, "M must be greater than zero." );
814  internal::checkSizes< M, M >( dstMatrix );
815  internal::checkSizes< M >( vectorA );
816 
817  for( std::ptrdiff_t i = 0; i < M; ++i )
818  {
819  for( std::ptrdiff_t j = 0; j < M; ++j )
820  {
821  dstMatrix[ i ][ j ] = vectorA[ i ] * vectorA[ j ];
822  }
823  }
824 }
825 
838 template< std::ptrdiff_t JSIZE, std::ptrdiff_t ISIZE, typename DST_MATRIX, typename VECTOR_A, typename VECTOR_B >
840 void Rij_add_AiBj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
841  VECTOR_A const & LVARRAY_RESTRICT_REF vectorA,
842  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
843 {
844  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
845  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
846  internal::checkSizes< JSIZE, ISIZE >( dstMatrix );
847  internal::checkSizes< JSIZE >( vectorA );
848  internal::checkSizes< ISIZE >( vectorB );
849 
850  for( std::ptrdiff_t i = 0; i < JSIZE; ++i )
851  {
852  for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
853  {
854  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + vectorA[ i ] * vectorB[ j ];
855  }
856  }
857 }
858 
871 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_VECTOR, typename MATRIX_A, typename VECTOR_B >
873 void Ri_eq_AijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
874  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
875  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
876 {
877  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
878  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
879  internal::checkSizes< ISIZE >( dstVector );
880  internal::checkSizes< ISIZE, JSIZE >( matrixA );
881  internal::checkSizes< JSIZE >( vectorB );
882 
883  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
884  {
885  dstVector[ i ] = matrixA[ i ][ 0 ] * vectorB[ 0 ];
886  for( std::ptrdiff_t j = 1; j < JSIZE; ++j )
887  {
888  dstVector[ i ] = dstVector[ i ] + matrixA[ i ][ j ] * vectorB[ j ];
889  }
890  }
891 }
892 
905 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_VECTOR, typename MATRIX_A, typename VECTOR_B >
907 void Ri_add_AijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
908  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
909  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
910 {
911  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
912  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
913  internal::checkSizes< ISIZE >( dstVector );
914  internal::checkSizes< ISIZE, JSIZE >( matrixA );
915  internal::checkSizes< JSIZE >( vectorB );
916 
917  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
918  {
919  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
920  {
921  dstVector[ i ] = dstVector[ i ] + matrixA[ i ][ j ] * vectorB[ j ];
922  }
923  }
924 }
925 
939 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_VECTOR, typename MATRIX_A, typename VECTOR_B >
941 void Ri_eq_AjiBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
942  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
943  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
944 {
945  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
946  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
947  internal::checkSizes< ISIZE >( dstVector );
948  internal::checkSizes< JSIZE, ISIZE >( matrixA );
949  internal::checkSizes< JSIZE >( vectorB );
950 
951  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
952  {
953  dstVector[ i ] = matrixA[ 0 ][ i ] * vectorB[ 0 ];
954  for( std::ptrdiff_t j = 1; j < JSIZE; ++j )
955  {
956  dstVector[ i ] = dstVector[ i ] + matrixA[ j ][ i ] * vectorB[ j ];
957  }
958  }
959 }
960 
974 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_VECTOR, typename MATRIX_A, typename VECTOR_B >
976 void Ri_add_AjiBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
977  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
978  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
979 {
980  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
981  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
982  internal::checkSizes< ISIZE >( dstVector );
983  internal::checkSizes< JSIZE, ISIZE >( matrixA );
984  internal::checkSizes< JSIZE >( vectorB );
985 
986  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
987  {
988  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
989  {
990  dstVector[ i ] = dstVector[ i ] + matrixA[ j ][ i ] * vectorB[ j ];
991  }
992  }
993 }
994 
996 
1001 
1012 template< std::ptrdiff_t ISIZE, std::ptrdiff_t JSIZE, typename DST_MATRIX, typename SRC_MATRIX >
1014 void transpose( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1015  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix )
1016 {
1017  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1018  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1019  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1020  internal::checkSizes< JSIZE, ISIZE >( srcMatrix );
1021 
1022  for( std::ptrdiff_t i = 0; i < JSIZE; ++i )
1023  {
1024  for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
1025  {
1026  dstMatrix[ j ][ i ] = srcMatrix[ i ][ j ];
1027  }
1028  }
1029 }
1030 
1045 template< std::ptrdiff_t ISIZE,
1046  std::ptrdiff_t JSIZE,
1047  std::ptrdiff_t KSIZE,
1048  typename DST_MATRIX,
1049  typename MATRIX_A,
1050  typename MATRIX_B >
1052 void Rij_eq_AikBkj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1053  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1054  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1055 {
1056  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1057  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1058  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1059  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1060  internal::checkSizes< ISIZE, KSIZE >( matrixA );
1061  internal::checkSizes< KSIZE, JSIZE >( matrixB );
1062 
1063 
1064  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1065  {
1066  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1067  {
1068  dstMatrix[ i ][ j ] = matrixA[ i ][ 0 ] * matrixB[ 0 ][ j ];
1069  for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1070  {
1071  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ k ][ j ];
1072  }
1073  }
1074  }
1075 }
1076 
1091 template< std::ptrdiff_t ISIZE,
1092  std::ptrdiff_t JSIZE,
1093  std::ptrdiff_t KSIZE,
1094  typename DST_MATRIX,
1095  typename MATRIX_A,
1096  typename MATRIX_B >
1098 void Rij_add_AikBkj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1099  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1100  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1101 {
1102  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1103  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1104  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1105  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1106  internal::checkSizes< ISIZE, KSIZE >( matrixA );
1107  internal::checkSizes< KSIZE, JSIZE >( matrixB );
1108 
1109 
1110  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1111  {
1112  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1113  {
1114  for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1115  {
1116  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ k ][ j ];
1117  }
1118  }
1119  }
1120 }
1121 
1136 template< std::ptrdiff_t ISIZE,
1137  std::ptrdiff_t JSIZE,
1138  std::ptrdiff_t KSIZE,
1139  typename DST_MATRIX,
1140  typename MATRIX_A,
1141  typename MATRIX_B >
1143 void Rij_eq_AikBjk( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1144  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1145  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1146 {
1147  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1148  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1149  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1150  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1151  internal::checkSizes< ISIZE, KSIZE >( matrixA );
1152  internal::checkSizes< JSIZE, KSIZE >( matrixB );
1153 
1154 
1155  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1156  {
1157  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1158  {
1159  dstMatrix[ i ][ j ] = matrixA[ i ][ 0 ] * matrixB[ j ][ 0 ];
1160  for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1161  {
1162  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ j ][ k ];
1163  }
1164  }
1165  }
1166 }
1167 
1182 template< std::ptrdiff_t ISIZE,
1183  std::ptrdiff_t JSIZE,
1184  std::ptrdiff_t KSIZE,
1185  typename DST_MATRIX,
1186  typename MATRIX_A,
1187  typename MATRIX_B >
1189 void Rij_add_AikBjk( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1190  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1191  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1192 {
1193  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1194  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1195  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1196  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1197  internal::checkSizes< ISIZE, KSIZE >( matrixA );
1198  internal::checkSizes< JSIZE, KSIZE >( matrixB );
1199 
1200  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1201  {
1202  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1203  {
1204  for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1205  {
1206  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixB[ j ][ k ];
1207  }
1208  }
1209  }
1210 }
1211 
1223 template< std::ptrdiff_t ISIZE,
1224  std::ptrdiff_t JSIZE,
1225  typename DST_MATRIX,
1226  typename MATRIX_A >
1228 void Rij_add_AikAjk( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1229  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA )
1230 {
1231  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1232  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1233  internal::checkSizes< ISIZE, ISIZE >( dstMatrix );
1234  internal::checkSizes< ISIZE, JSIZE >( matrixA );
1235 
1236  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1237  {
1238  for( std::ptrdiff_t j = 0; j < ISIZE; ++j )
1239  {
1240  for( std::ptrdiff_t k = 0; k < JSIZE; ++k )
1241  {
1242  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ i ][ k ] * matrixA[ j ][ k ];
1243  }
1244  }
1245  }
1246 }
1247 
1262 template< std::ptrdiff_t ISIZE,
1263  std::ptrdiff_t JSIZE,
1264  std::ptrdiff_t KSIZE,
1265  typename DST_MATRIX,
1266  typename MATRIX_A,
1267  typename MATRIX_B >
1269 void Rij_eq_AkiBkj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1270  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1271  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1272 {
1273  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1274  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1275  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1276  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1277  internal::checkSizes< KSIZE, ISIZE >( matrixA );
1278  internal::checkSizes< KSIZE, JSIZE >( matrixB );
1279 
1280  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1281  {
1282  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1283  {
1284  dstMatrix[ i ][ j ] = matrixA[ 0 ][ i ] * matrixB[ 0 ][ j ];
1285  for( std::ptrdiff_t k = 1; k < KSIZE; ++k )
1286  {
1287  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ k ][ i ] * matrixB[ k ][ j ];
1288  }
1289  }
1290  }
1291 }
1292 
1307 template< std::ptrdiff_t ISIZE,
1308  std::ptrdiff_t JSIZE,
1309  std::ptrdiff_t KSIZE,
1310  typename DST_MATRIX,
1311  typename MATRIX_A,
1312  typename MATRIX_B >
1314 void Rij_add_AkiBkj( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
1315  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
1316  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
1317 {
1318  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1319  static_assert( JSIZE > 0, "JSIZE must be greater than zero." );
1320  static_assert( KSIZE > 0, "KSIZE must be greater than zero." );
1321  internal::checkSizes< ISIZE, JSIZE >( dstMatrix );
1322  internal::checkSizes< KSIZE, ISIZE >( matrixA );
1323  internal::checkSizes< KSIZE, JSIZE >( matrixB );
1324 
1325  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1326  {
1327  for( std::ptrdiff_t j = 0; j < JSIZE; ++j )
1328  {
1329  for( std::ptrdiff_t k = 0; k < KSIZE; ++k )
1330  {
1331  dstMatrix[ i ][ j ] = dstMatrix[ i ][ j ] + matrixA[ k ][ i ] * matrixB[ k ][ j ];
1332  }
1333  }
1334  }
1335 }
1336 
1338 
1343 
1351 template< std::ptrdiff_t ISIZE, typename MATRIX >
1353 void transpose( MATRIX && LVARRAY_RESTRICT_REF matrix )
1354 {
1355  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1356  internal::checkSizes< ISIZE, ISIZE >( matrix );
1357 
1358  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1359  {
1360  for( std::ptrdiff_t j = i + 1; j < ISIZE; ++j )
1361  {
1362  auto const entryIJ = matrix[ i ][ j ];
1363  matrix[ i ][ j ] = matrix[ j ][ i ];
1364  matrix[ j ][ i ] = entryIJ;
1365  }
1366  }
1367 }
1368 
1377 template< std::ptrdiff_t ISIZE, typename MATRIX >
1379 void addIdentity( MATRIX && matrix, std::remove_reference_t< decltype( matrix[ 0 ][ 0 ] ) > const scale )
1380 {
1381  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1382  internal::checkSizes< ISIZE, ISIZE >( matrix );
1383 
1384  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1385  {
1386  matrix[ i ][ i ] += scale;
1387  }
1388 }
1389 
1396 template< std::ptrdiff_t ISIZE, typename MATRIX >
1398 auto trace( MATRIX const & matrix )
1399 {
1400  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1401  internal::checkSizes< ISIZE, ISIZE >( matrix );
1402 
1403  auto trace = matrix[ 0 ][ 0 ];
1404  for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
1405  {
1406  trace += matrix[ i ][ i ];
1407  }
1408 
1409  return trace;
1410 }
1411 
1413 
1418 
1428 template< std::ptrdiff_t ISIZE, typename SYM_MATRIX >
1430 void symAddIdentity( SYM_MATRIX && symMatrix, std::remove_reference_t< decltype( symMatrix[ 0 ] ) > const scale )
1431 {
1432  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1433  internal::checkSizes< SYM_SIZE< ISIZE > >( symMatrix );
1434 
1435  for( std::ptrdiff_t i = 0; i < ISIZE; ++i )
1436  {
1437  symMatrix[ i ] += scale;
1438  }
1439 }
1440 
1447 template< std::ptrdiff_t ISIZE, typename SYM_MATRIX >
1449 auto symTrace( SYM_MATRIX const & symMatrix )
1450 {
1451  static_assert( ISIZE > 0, "ISIZE must be greater than zero." );
1452  internal::checkSizes< SYM_SIZE< ISIZE > >( symMatrix );
1453 
1454  auto trace = symMatrix[ 0 ];
1455  for( std::ptrdiff_t i = 1; i < ISIZE; ++i )
1456  {
1457  trace += symMatrix[ i ];
1458  }
1459 
1460  return trace;
1461 }
1462 
1464 
1465 } // namespace tensorOps
1466 } // namespace LvArray
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:51
constexpr void fill(VECTOR &&vector, std::remove_reference_t< decltype(vector[0]) > const value)
Set the entries of vector to value.
constexpr std::ptrdiff_t SYM_SIZE
The size of a symmetric MxM matrix in Voigt notation.
constexpr void Rij_add_AikAjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA)
Multiply matrixA with the transpose of itself and put the result into dstMatrix.
constexpr void scale(VECTOR &&vector, std::remove_reference_t< decltype(vector[0]) > const scale)
Multiply the entries of vector by scale.
constexpr void Rij_add_AikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with the transpose of matrixB and put the result into dstMatrix. ...
constexpr void symAddIdentity(SYM_MATRIX &&symMatrix, std::remove_reference_t< decltype(symMatrix[0]) > const scale)
Add scale times the identity matrix to symMatrix.
constexpr void transpose(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SRC_MATRIX const &LVARRAY_RESTRICT_REF srcMatrix)
Store the transpose of the NxM matrix srcMatrix in dstMatrix.
#define HAS_STATIC_MEMBER(NAME)
Macro that expands to a static constexpr bool templated on a type that is only true when the type has...
float sqrt(float const x)
Definition: math.hpp:121
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
Definition: Macros.hpp:449
constexpr void copy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Copy srcVector into dstVector.
constexpr void Ri_add_AijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of matrixA and vectorB adding the result to dstVector...
constexpr auto l2NormSquared(VECTOR const &vector)
Contains the implementation of LvArray::ArraySlice.
constexpr void Rij_eq_AiAj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA)
Perform the outer product of vectorA with itself writing the result to dstMatrix. ...
constexpr void Rij_eq_AkiBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrixA with matrixB and put the result into dstMatrix. ...
Contains some portable math functions.
constexpr void subtract(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Subtract srcVector from dstVector.
constexpr void Rij_add_AkiBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrixA with matrixB and add the result into dstMatrix. ...
float invSqrt(float const x)
Definition: math.hpp:147
constexpr auto l2Norm(VECTOR const &vector)
float abs(float const x)
Definition: math.hpp:81
constexpr void Rij_eq_AikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with the transpose of matrixB and put the result into dstMatrix. ...
constexpr void Rij_eq_AiBj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the outer product of vectorA and vectorB writing the result to dstMatrix. ...
constexpr void Rij_eq_AikBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with matrixB and put the result into dstMatrix.
constexpr void addScalar(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, std::remove_reference_t< decltype(dstVector[0]) > const value)
Add value to dstVector.
The top level namespace.
Definition: Array.hpp:24
constexpr auto normalize(VECTOR &&vector)
Scale vector to a unit vector.
constexpr void Ri_eq_AjiBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of the transpose of matrixA and vectorB writing the result t...
constexpr auto AiBi(VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
constexpr void addIdentity(MATRIX &&matrix, std::remove_reference_t< decltype(matrix[0][0]) > const scale)
Add scale times the identity matrix to matrix.
constexpr auto trace(MATRIX const &matrix)
constexpr void Ri_eq_AijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of matrixA and vectorB writing the result to dstVector...
constexpr void crossProduct(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Compute the cross product of vectorA and vectorB and put it in dstVector.
constexpr void Rij_add_AikBkj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply matrixA with matrixB and add the result to dstMatrix.
constexpr auto symTrace(SYM_MATRIX const &symMatrix)
constexpr void Rij_add_AiBj(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the outer product of vectorA and vectorB adding the result to dstMatrix.
constexpr void add(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Add srcVector to dstVector.
constexpr void scaledCopy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector, std::remove_reference_t< decltype(srcVector[0]) > const scale)
Copy srcVector scaled by scale into dstVector.
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
Definition: math.hpp:46
constexpr void hadamardProduct(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, VECTOR_A const &LVARRAY_RESTRICT_REF vectorA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the elements of vectorA and vectorB putting the result into dstVector.
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:237
constexpr void Ri_add_AjiBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Perform the matrix vector multiplication of the transpose of matrixA and vectorB adding the result to...
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:389
constexpr auto maxAbsoluteEntry(VECTOR &&vector)
constexpr void scaledAdd(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector, std::remove_reference_t< decltype(srcVector[0]) > const scale)
Add srcVector scaled by scale to dstVector.