BELFEM 0.9.4
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Tensor.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_TENSOR_HPP
13#define BELFEM_CL_TENSOR_HPP
14
15#include <cstring> // for std::memcpy
16#include <algorithm> // for std::sort std::fill_n
17#include <functional> // for std::plus std::minus
18
19#include "typedefs.hpp"
20#include "assert.hpp"
21#include "cl_Matrix.hpp"
22#include "fn_TR_mat_to_ten.hpp"
23#include "fn_TR_ten_to_mat.hpp"
24#include "fn_TR_contract42.hpp"
25#include "fn_TR_contract44.hpp"
26#include "fn_TR_equal_equal.hpp"
27
28#include "fn_TR_fill.hpp"
30
31#include "fn_inv.hpp"
32namespace belfem
33{
41 template< typename T >
42 class Tensor
43 {
44//----------------------------------------------------------------------------
45
46 // indices
47 const index_t mSizeI;
48 const index_t mSizeJ;
49 const index_t mSizeK;
50 const index_t mSizeL;
51
52 // memory jumps
53 const index_t mOffsetJ;
54 const index_t mOffsetK;
55 const index_t mOffsetL;
56
57 const index_t mOrder;
58 const index_t mCapacity;
59
60 T * mData = nullptr;
61
62//----------------------------------------------------------------------------
63 public:
64//----------------------------------------------------------------------------
65
66 // create an empty tensor
67 Tensor( const index_t aSizeI,
68 const index_t aSizeJ,
69 const index_t aSizeK,
70 const index_t aSizeL ) :
71 mSizeI( aSizeI ),
72 mSizeJ( aSizeJ ),
73 mSizeK( aSizeK ),
74 mSizeL( aSizeL ),
75 mOffsetJ( aSizeI ),
76 mOffsetK( aSizeI * aSizeJ ),
77 mOffsetL( aSizeI * aSizeJ * aSizeK ),
78 mOrder( 4 ),
79 mCapacity( aSizeI * aSizeJ * aSizeK * aSizeL )
80 {
81 BELFEM_ASSERT( mCapacity > 0, "Tensor sizes must not be zero" );
82
83 mData = ( T * ) malloc( ( mCapacity ) * sizeof( T ) );
84 }
85
86 // create an empty tensor
87 Tensor( const index_t aSizeI,
88 const index_t aSizeJ,
89 const index_t aSizeK ) :
90 mSizeI( aSizeI ),
91 mSizeJ( aSizeJ ),
92 mSizeK( aSizeK ),
93 mSizeL( 1 ),
94 mOffsetJ( aSizeI ),
95 mOffsetK( aSizeI * aSizeJ ),
96 mOffsetL( aSizeI * aSizeJ * aSizeK ),
97 mOrder( 3 ),
98 mCapacity( aSizeI * aSizeJ * aSizeK )
99 {
100 BELFEM_ASSERT( mCapacity > 0, "Tensor sizes must not be zero" );
101
102 mData = ( T * ) malloc( ( mCapacity ) * sizeof( T ) );
103 }
104
105 // create an empty tensor and initialize it with values
106 Tensor( const index_t aSizeI,
107 const index_t aSizeJ,
108 const index_t aSizeK,
109 const index_t aSizeL,
110 const real aValue ) :
111 Tensor( aSizeI, aSizeJ, aSizeK, aSizeL )
112 {
113 this->fill( aValue );
114 }
115
116 // create a tensor form an elasticity matrix
117 Tensor( const Matrix< real > & aElasticityMatrix ) :
118 Tensor( 3, 3, 3, 3 )
119 {
120 BELFEM_ASSERT( aElasticityMatrix.n_rows() == 6
121 && aElasticityMatrix.n_cols() == 6,
122 "Matrix must be allocated as 6x6" );
123
124 tensor::mat_to_ten( aElasticityMatrix, mData );
125 }
126
127//----------------------------------------------------------------------------
128
129 // copy constructor
130 Tensor( const Tensor< T > & aOther ) :
131 mSizeI( aOther.size_i() ),
132 mSizeJ( aOther.size_j() ),
133 mSizeK( aOther.size_k() ),
134 mSizeL( aOther.size_l() ),
135 mOffsetJ( aOther.mOffsetJ ),
136 mOffsetK( aOther.mOffsetK ),
137 mOffsetL( aOther.mOffsetL ),
138 mOrder( aOther.mOrder ),
139 mCapacity( aOther.mCapacity )
140 {
141 mData = ( T * ) malloc( mCapacity * sizeof( T ) );
142 std::memcpy( mData, aOther.mData, mCapacity * sizeof( T ) );
143 }
144
145//----------------------------------------------------------------------------
146
147 // move constructor
148 Tensor( Tensor< T > && aOther ) :
149 mSizeI( aOther.size_i() ),
150 mSizeJ( aOther.size_j() ),
151 mSizeK( aOther.size_k() ),
152 mSizeL( aOther.size_l() ),
153 mOffsetJ( aOther.mOffsetJ ),
154 mOffsetK( aOther.mOffsetK ),
155 mOffsetL( aOther.mOffsetL ),
156 mOrder( aOther.mOrder ),
157 mCapacity( aOther.mCapacity )
158 {
159 mData = aOther.mData ;
160 aOther.mData = nullptr ;
161 }
162
163//----------------------------------------------------------------------------
164
166 {
167 free( mData );
168 }
169
170//------------------------------------------------------------------------------
171// SIZES
172//------------------------------------------------------------------------------
173
174 index_t
175 size_i() const
176 {
177 return mSizeI ;
178 }
179
180 index_t
181 size_j() const
182 {
183 return mSizeJ ;
184 }
185
186 index_t
187 size_k() const
188 {
189 return mSizeK ;
190 }
191
192 index_t
193 size_l() const
194 {
195 return mSizeL ;
196 }
197 index_t
198 order() const
199 {
200 return mOrder ;
201 }
202
203//------------------------------------------------------------------------------
204// MEMORY
205//------------------------------------------------------------------------------
206
210 T *
212 {
213 return mData ;
214 }
215
216// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
217
221 const T *
222 data() const
223 {
224 return mData ;
225 }
226
227//------------------------------------------------------------------------------
228// UTILITIES
229//------------------------------------------------------------------------------
230
234 void
235 fill( const T aValue )
236 {
237 // populate pointer array
238 std::fill_n( mData, mCapacity, aValue );
239 }
240
241//------------------------------------------------------------------------------
242
246 void
247 fill( const T aA, const T aB )
248 {
249 BELFEM_ASSERT( this->is_3333(), "Tensor must be 3x3x3x3" );
250 tensor::fill( mData, aA, aB );
251 }
252
253//------------------------------------------------------------------------------
254
258 void
259 fill_isotropic_elasticity( const T E, const T nu )
260 {
261 BELFEM_ASSERT( this->is_3333(), "Tensor must be 3x3x3x3" );
262
263 // bulk modulus
264 T K = E / ( 3. * ( 1.0 - 2.0 * nu ) );
265
266 // shear modulus
267 T G = E / ( 2.0 * ( 1.0 + nu ) );
268
269 tensor::fill( mData, K, G );
270 }
271
272//------------------------------------------------------------------------------
273
274 // Poisson ratios in the cyclic convention of compliance_matrix()
275 void
277 const T aYoung1,
278 const T aYoung2,
279 const T aYoung3,
280 const T aPoisson23,
281 const T aPoisson31,
282 const T aPoisson12,
283 const T aShear23,
284 const T aShear31,
285 const T aShear12
286 )
287 {
288 BELFEM_ASSERT( this->is_3333(), "Tensor must be 3x3x3x3" );
289
290 // compliance matrix
291 Matrix< T > tS( 6, 6 );
292 compliance_matrix( aYoung1, aYoung2, aYoung3,
293 aPoisson23, aPoisson31, aPoisson12,
294 aShear23, aShear31, aShear12, tS );
295
296 // elasticity matrix
297 Matrix< T > tC = inv( tS );
298
299 // polulate data
300 tensor::mat_to_ten( tC, mData );
301 }
302
303//------------------------------------------------------------------------------
304
308 index_t
309 capacity() const
310 {
311 return mCapacity ;
312 }
313
314//------------------------------------------------------------------------------
315
319 bool
320 is_3333() const
321 {
322 return mSizeI == 3 && mSizeJ == 3 && mSizeK == 3 && mSizeL == 3 ;
323 }
324
325//------------------------------------------------------------------------------
326
327 void
328 print( const string aLabel="Tensor")
329 {
330 index_t tCount = 0 ;
331 fprintf( stdout, " %s:\n", aLabel.c_str() );
332
333 for( index_t l=0; l<mSizeL; ++l )
334 {
335 for( index_t k=0; k<mSizeK; ++k )
336 {
337 for( index_t j=0; j<mSizeJ; ++j )
338 {
339 for( index_t i=0; i<mSizeI; ++i )
340 {
341 fprintf( stdout, " %u : ( %u, %u, %u, %u ) = %12.3f\n",
342 ( unsigned int ) tCount,
343 ( unsigned int ) i,
344 ( unsigned int ) j,
345 ( unsigned int ) k,
346 ( unsigned int ) l,
347 ( double ) mData[ tCount ] );
348 ++tCount ;
349 }
350 }
351 }
352 }
353 }
354
355//------------------------------------------------------------------------------
356// ACCESS OPERATORS
357//------------------------------------------------------------------------------
358
362 T &
364 const index_t I,
365 const index_t J,
366 const index_t K )
367 {
368 BELFEM_ASSERT( mOrder == 3, "Tensor order must be of order 3" );
369
370 BELFEM_ASSERT( I < mSizeI, "Index i out of bounds ( %u vs %u )",
371 ( unsigned int ) I,
372 ( unsigned int ) mSizeI );
373
374 BELFEM_ASSERT( J < mSizeJ, "Index j out of bounds ( %u vs %u )",
375 ( unsigned int ) J,
376 ( unsigned int ) mSizeJ );
377
378 BELFEM_ASSERT( K < mSizeK, "Index k out of bounds ( %u vs %u )",
379 ( unsigned int ) K,
380 ( unsigned int ) mSizeK );
381
382 return mData[ K * mOffsetK + J * mOffsetJ + I ] ;
383 }
384
385// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
386
390 const T &
392 const index_t I,
393 const index_t J,
394 const index_t K ) const
395 {
396 BELFEM_ASSERT( mOrder == 3, "Tensor order must be of order 3" );
397
398 BELFEM_ASSERT( I < mSizeI, "Index i out of bounds ( %u vs %u )",
399 ( unsigned int ) I,
400 ( unsigned int ) mSizeI );
401
402 BELFEM_ASSERT( J < mSizeJ, "Index j out of bounds ( %u vs %u )",
403 ( unsigned int ) J,
404 ( unsigned int ) mSizeJ );
405
406 BELFEM_ASSERT( K < mSizeK, "Index k out of bounds ( %u vs %u )",
407 ( unsigned int ) K,
408 ( unsigned int ) mSizeK );
409
410 return mData[ K * mOffsetK + J * mOffsetJ + I ] ;
411 }
412
413// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
414
418 T &
420 const index_t I,
421 const index_t J,
422 const index_t K,
423 const index_t L )
424 {
425 BELFEM_ASSERT( mOrder == 4, "Tensor order must be of order 4" );
426
427 BELFEM_ASSERT( I < mSizeI, "Index i out of bounds ( %u vs %u )",
428 ( unsigned int ) I,
429 ( unsigned int ) mSizeI );
430
431 BELFEM_ASSERT( J < mSizeJ, "Index j out of bounds ( %u vs %u )",
432 ( unsigned int ) J,
433 ( unsigned int ) mSizeJ );
434
435 BELFEM_ASSERT( K < mSizeK, "Index k out of bounds ( %u vs %u )",
436 ( unsigned int ) K,
437 ( unsigned int ) mSizeK );
438
439 BELFEM_ASSERT( L < mSizeL, "Index l out of bounds ( %u vs %u )",
440 ( unsigned int ) L,
441 ( unsigned int ) mSizeL );
442
443 return mData[ L * mOffsetL + K * mOffsetK + J * mOffsetJ + I ] ;
444 }
445
446// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
447
451 const T &
453 const index_t I,
454 const index_t J,
455 const index_t K,
456 const index_t L ) const
457 {
458 BELFEM_ASSERT( mOrder == 4, "Tensor order must be of order 4" );
459
460 BELFEM_ASSERT( I < mSizeI, "Index i out of bounds ( %u vs %u )",
461 ( unsigned int ) I,
462 ( unsigned int ) mSizeI );
463
464 BELFEM_ASSERT( J < mSizeJ, "Index j out of bounds ( %u vs %u )",
465 ( unsigned int ) J,
466 ( unsigned int ) mSizeJ );
467
468 BELFEM_ASSERT( K < mSizeK, "Index k out of bounds ( %u vs %u )",
469 ( unsigned int ) K,
470 ( unsigned int ) mSizeK );
471
472 BELFEM_ASSERT( L < mSizeL, "Index l out of bounds ( %u vs %u )",
473 ( unsigned int ) L,
474 ( unsigned int ) mSizeL );
475
476 return mData[ L * mOffsetL + K * mOffsetK + J * mOffsetJ + I ] ;
477 }
478
479//------------------------------------------------------------------------------
480// Equal Operators
481//------------------------------------------------------------------------------
482
487 operator=( const Tensor< T > & aTensor )
488 {
489 if( this == &aTensor ) return *this;
490
491 BELFEM_ASSERT( mOrder == aTensor.order(),
492 "Tensor orders must match for copy assignment" );
493
494 BELFEM_ASSERT( mSizeI == aTensor.size_i(),
495 "Tensor dimensions must match for copy assignment" );
496
497 BELFEM_ASSERT( mSizeJ == aTensor.size_j(),
498 "Tensor dimensions must match for copy assignment" );
499
500 BELFEM_ASSERT( mSizeK == aTensor.size_k(),
501 "Tensor dimensions must match for copy assignment" );
502
503 BELFEM_ASSERT( mSizeL == aTensor.size_l(),
504 "Tensor dimensions must match for copy assignment" );
505
506 std::memcpy( mData, aTensor.data(), mCapacity * sizeof( T ) );
507 return *this;
508 }
509
510// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
511
516 operator=( Tensor< T > && aTensor )
517 {
518 if( this == &aTensor ) return *this;
519
520 BELFEM_ASSERT( mOrder == aTensor.order(),
521 "Tensor orders must match for move assignment" );
522
523 BELFEM_ASSERT( mSizeI == aTensor.size_i(),
524 "Tensor dimensions must match for move assignment" );
525
526 BELFEM_ASSERT( mSizeJ == aTensor.size_j(),
527 "Tensor dimensions must match for move assignment" );
528
529 BELFEM_ASSERT( mSizeK == aTensor.size_k(),
530 "Tensor dimensions must match for move assignment" );
531
532 BELFEM_ASSERT( mSizeL == aTensor.size_l(),
533 "Tensor dimensions must match for move assignment" );
534
535 free( mData );
536 mData = aTensor.mData ;
537 aTensor.mData = nullptr ;
538 return *this;
539 }
540
541// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
542
544 operator=( const T & aScalar )
545 {
546 this->fill( aScalar );
547 return *this;
548 }
549
550// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
551
553 operator=( const Matrix< T > & aElasticityMatrix )
554 {
555 BELFEM_ASSERT( this->is_3333(), "The tensor must be a 3x3x3x3 tensor" );
556
557 tensor::mat_to_ten( aElasticityMatrix, mData );
558
559 return *this;
560 }
561
562//------------------------------------------------------------------------------
563// Addition operators
564//------------------------------------------------------------------------------
565
567 operator+=( const T & aScalar )
568 {
569 std::for_each( mData, mData + mCapacity,
570 [ aScalar ]( T & tVal )
571 { tVal += aScalar; } );
572 return *this;
573 }
574
575// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
576
578 operator+=( const Tensor< T > & aTensor )
579 {
580 BELFEM_ASSERT( mOrder == aTensor.order(),
581 "Tensor orders must match for addition operator" );
582
583 BELFEM_ASSERT( mSizeI == aTensor.size_i(),
584 "Tensor dimensions must match for addition operator" );
585
586 BELFEM_ASSERT( mSizeJ == aTensor.size_j(),
587 "Tensor dimensions must match for addition operator" );
588
589 BELFEM_ASSERT( mSizeK == aTensor.size_k(),
590 "Tensor dimensions must match for addition operator" );
591
592 BELFEM_ASSERT( mSizeL == aTensor.size_l(),
593 "Tensor dimensions must match for addition operator" );
594
595 std::transform( mData, mData + mCapacity, aTensor.data(),
596 mData, std::plus< T >() );
597 return *this;
598 }
599
600//------------------------------------------------------------------------------
601// Subtraction operators
602//------------------------------------------------------------------------------
603
605 operator-=( const T & aScalar )
606 {
607 std::for_each( mData, mData + mCapacity,
608 [ aScalar ]( T & tVal )
609 { tVal -= aScalar; } );
610 return *this;
611 }
612
613// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
614
616 operator-=( const Tensor< T > & aTensor )
617 {
618 BELFEM_ASSERT( mOrder == aTensor.order(),
619 "Tensor orders must match for subtraction operator" );
620
621 BELFEM_ASSERT( mSizeI == aTensor.size_i(),
622 "Tensor dimensions must match for subtraction operator" );
623
624 BELFEM_ASSERT( mSizeJ == aTensor.size_j(),
625 "Tensor dimensions must match for subtraction operator" );
626
627 BELFEM_ASSERT( mSizeK == aTensor.size_k(),
628 "Tensor dimensions must match for subtraction operator" );
629
630 BELFEM_ASSERT( mSizeL == aTensor.size_l(),
631 "Tensor dimensions must match for subtraction operator" );
632
633 std::transform( mData, mData + mCapacity, aTensor.data(),
634 mData, std::minus< T >() );
635 return *this;
636 }
637
638//------------------------------------------------------------------------------
639// Multiplication
640//------------------------------------------------------------------------------
641
643 operator*=( const T & aScalar )
644 {
645 std::for_each( mData, mData + mCapacity,
646 [ aScalar ]( T & tVal )
647 { tVal *= aScalar; } );
648 return *this;
649 }
650
651//------------------------------------------------------------------------------
652// Division
653//------------------------------------------------------------------------------
654
656 operator/=( const T & aScalar )
657 {
658 std::for_each( mData, mData + mCapacity,
659 [ aScalar ]( T & tVal )
660 { tVal /= aScalar; } );
661 return *this;
662 }
663
664//------------------------------------------------------------------------------
665// Contraction
666//------------------------------------------------------------------------------
667
673 inline
674 void
675 ddot( const Tensor< T > & aB, Tensor< T > & aC )
676 {
677 BELFEM_ASSERT( this->is_3333(), "operating tensor must be 3x3x3x3" );
678 BELFEM_ASSERT( aB.is_3333(), "argument tensor must be 3x3x3x3" );
679 BELFEM_ASSERT( aC.is_3333(), "target tensor must be 3x3x3x3" );
680
681 tensor::contract44( mData, aB.data(), aC.data() );
682 }
683
684//------------------------------------------------------------------------------
685
691 inline
692 void
693 ddot( const Matrix< T > & aB, Matrix< T > & aC )
694 {
695 BELFEM_ASSERT( this->is_3333(),
696 "operating tensor must be 3x3x3x3" );
697
698 BELFEM_ASSERT( aB.n_rows() == 3
699 && aB.n_cols() == 3,
700 "argument matrix must be allocated as 3x3" );
701
702 BELFEM_ASSERT( aC.n_rows() == 3
703 && aC.n_cols() == 3,
704 "target matrix must be allocated as 3x3" );
705
706 tensor::contract42( mData, aB, aC );
707 }
708
709//------------------------------------------------------------------------------
710// Conversion
711//------------------------------------------------------------------------------
712
717 void
719 {
720 BELFEM_ASSERT( aMatrix.n_rows() == 6
721 && aMatrix.n_cols() == 6,
722 "Matrix must be allocated as 6x6" );
723
724 BELFEM_ASSERT( this->is_3333(), "The tensor must be a 3x3x3x3 tensor" );
725
726 tensor::ten_to_mat( mData, aMatrix );
727 }
728 };
729//------------------------------------------------------------------------------
730
731 template< typename T >
732 Tensor< T >
734 const Tensor< T > & aC )
735 {
736 BELFEM_ASSERT( aB.order() == aC.order(),
737 "Tensor orders must match for addition operator" );
738
739 BELFEM_ASSERT( aB.size_i() == aC.size_i(),
740 "Tensor dimensions must match for addition operator" );
741
742 BELFEM_ASSERT( aB.size_j() == aC.size_j(),
743 "Tensor dimensions must match for addition operator" );
744
745 BELFEM_ASSERT( aB.size_k() == aC.size_k(),
746 "Tensor dimensions must match for addition operator" );
747
748 BELFEM_ASSERT( aB.size_l() == aC.size_l(),
749 "Tensor dimensions must match for addition operator" );
750
751 Tensor< T > aA( aB );
752 aA += aC;
753
754 return aA ;
755 }
756
757//------------------------------------------------------------------------------
758
759 template< typename T >
760 Tensor< T >
762 const Tensor< T > & aC )
763 {
764 BELFEM_ASSERT( aB.order() == aC.order(),
765 "Tensor orders must match for subtraction operator" );
766
767 BELFEM_ASSERT( aB.size_i() == aC.size_i(),
768 "Tensor dimensions must match for subtraction operator" );
769
770 BELFEM_ASSERT( aB.size_j() == aC.size_j(),
771 "Tensor dimensions must match for subtraction operator" );
772
773 BELFEM_ASSERT( aB.size_k() == aC.size_k(),
774 "Tensor dimensions must match for subtraction operator" );
775
776 BELFEM_ASSERT( aB.size_l() == aC.size_l(),
777 "Tensor dimensions must match for subtraction operator" );
778
779 Tensor< T > aA( aB );
780 aA -= aC;
781 return aA ;
782 }
783
784//------------------------------------------------------------------------------
785// contraction
786//------------------------------------------------------------------------------
787
788 template< typename T >
789 Tensor< T >
791 const Tensor< T > & aB )
792 {
793 BELFEM_ASSERT( aA.is_3333() && aB.is_3333(),
794 "Both tensors must be of size 3x3x3x3" );
795
796 Tensor< T > aC( 3, 3, 3, 3 );
797 tensor::contract44( aA.data(), aB.data(), aC.data() );
798 return aC ;
799 }
800
801//------------------------------------------------------------------------------
802
803 template< typename T >
804 Matrix< T >
806 const Matrix< T > & aB )
807 {
809 "Tensor A must be of size 3x3x3x3" );
810
811 BELFEM_ASSERT( aB.n_rows() == 3 && aB.n_cols() == 3,
812 "when contracting a 3x3x3x3 tensor with a matrix, latter one must be 3x3" );
813
814 Matrix< T > aC ( 3, 3 );
815 tensor::contract42( aA.data(), aB, aC );
816 return aC ;
817 }
818
819//------------------------------------------------------------------------------
820
821 template< typename T >
822 bool
824 const Tensor< T > & aB )
825 {
826 if( aA.order() != aB.order()
827 || aA.size_i() != aB.size_i()
828 || aA.size_j() != aB.size_j()
829 || aA.size_k() != aB.size_k()
830 || aA.size_l() != aB.size_l() ) return false;
831
832 return tensor::equal_equal( aA.data(), aB.data(), aA.capacity() );
833 }
834
835//------------------------------------------------------------------------------
836} /* namespace belfem */
837#endif //BELFEM_CL_TENSOR_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
size_t n_rows() const
Definition cl_AR_Matrix.hpp:187
size_t n_cols() const
Definition cl_AR_Matrix.hpp:195
Third- or fourth-order tensor container; the constitutive helpers (contraction, rotation,...
Definition cl_Tensor.hpp:43
Tensor(Tensor< T > &&aOther)
Definition cl_Tensor.hpp:148
Tensor< T > & operator=(const T &aScalar)
Definition cl_Tensor.hpp:544
Tensor(const Tensor< T > &aOther)
Definition cl_Tensor.hpp:130
Tensor< T > & operator+=(const Tensor< T > &aTensor)
Definition cl_Tensor.hpp:578
void fill(const T aA, const T aB)
fill tensor in an isotropic way
Definition cl_Tensor.hpp:247
Tensor< T > & operator+=(const T &aScalar)
Definition cl_Tensor.hpp:567
index_t order() const
Definition cl_Tensor.hpp:198
void to_matrix(Matrix< real > &aMatrix)
converts a tensor to the elastitity matrix in Voigt notation
Definition cl_Tensor.hpp:718
void ddot(const Matrix< T > &aB, Matrix< T > &aC)
contract with 3x3 matrox
Definition cl_Tensor.hpp:693
Tensor< T > & operator*=(const T &aScalar)
Definition cl_Tensor.hpp:643
Tensor< T > & operator=(Tensor< T > &&aTensor)
move assignment
Definition cl_Tensor.hpp:516
T * data()
expose the underlying raw pointer
Definition cl_Tensor.hpp:211
Tensor< T > & operator=(const Matrix< T > &aElasticityMatrix)
Definition cl_Tensor.hpp:553
void fill_orthotropic_elasticity(const T aYoung1, const T aYoung2, const T aYoung3, const T aPoisson23, const T aPoisson31, const T aPoisson12, const T aShear23, const T aShear31, const T aShear12)
Definition cl_Tensor.hpp:276
index_t size_j() const
Definition cl_Tensor.hpp:181
Tensor(const index_t aSizeI, const index_t aSizeJ, const index_t aSizeK, const index_t aSizeL, const real aValue)
Definition cl_Tensor.hpp:106
~Tensor()
Definition cl_Tensor.hpp:165
void ddot(const Tensor< T > &aB, Tensor< T > &aC)
contract with other tensor
Definition cl_Tensor.hpp:675
bool is_3333() const
returns true if this is a 3x3x3x3 tensor
Definition cl_Tensor.hpp:320
T & operator()(const index_t I, const index_t J, const index_t K)
access operator ( writable version )
Definition cl_Tensor.hpp:363
void print(const string aLabel="Tensor")
Definition cl_Tensor.hpp:328
index_t size_l() const
Definition cl_Tensor.hpp:193
index_t capacity() const
memory size
Definition cl_Tensor.hpp:309
Tensor< T > & operator=(const Tensor< T > &aTensor)
copy assignment
Definition cl_Tensor.hpp:487
const T & operator()(const index_t I, const index_t J, const index_t K, const index_t L) const
access operator ( const version )
Definition cl_Tensor.hpp:452
Tensor< T > & operator-=(const T &aScalar)
Definition cl_Tensor.hpp:605
Tensor< T > & operator-=(const Tensor< T > &aTensor)
Definition cl_Tensor.hpp:616
Tensor(const index_t aSizeI, const index_t aSizeJ, const index_t aSizeK, const index_t aSizeL)
Definition cl_Tensor.hpp:67
Tensor(const Matrix< real > &aElasticityMatrix)
Definition cl_Tensor.hpp:117
const T & operator()(const index_t I, const index_t J, const index_t K) const
access operator ( const version )
Definition cl_Tensor.hpp:391
T & operator()(const index_t I, const index_t J, const index_t K, const index_t L)
access operator ( writable version )
Definition cl_Tensor.hpp:419
void fill(const T aValue)
fill all values
Definition cl_Tensor.hpp:235
Tensor(const index_t aSizeI, const index_t aSizeJ, const index_t aSizeK)
Definition cl_Tensor.hpp:87
Tensor< T > & operator/=(const T &aScalar)
Definition cl_Tensor.hpp:656
void fill_isotropic_elasticity(const T E, const T nu)
special funcition to create an isotropic elasticity tensor
Definition cl_Tensor.hpp:259
index_t size_k() const
Definition cl_Tensor.hpp:187
const T * data() const
expose the underlying raw pointer ( const version )
Definition cl_Tensor.hpp:222
index_t size_i() const
Definition cl_Tensor.hpp:175
Inverse of a square matrix.
void fill(T *A, const T a, const T b)
Definition fn_TR_fill.hpp:29
void contract42(const T *A, const T *B, T *C)
tensor contraction A_ijkl * B_kl = C_ij
Definition fn_TR_contract42_arma.hpp:28
void mat_to_ten(const T *C, T *A)
elasticity matrix conversion elasticity matrix C => tensor A
Definition fn_TR_mat_to_ten.hpp:27
void contract44(const T *A, const T *B, T *C)
tensor contraction A_ijmn * B_mnkl = C_ijkl
Definition fn_TR_contract44.hpp:26
bool equal_equal(const T *A, const T *B, const index_t aCapacity)
Definition fn_TR_equal_equal.hpp:23
void ten_to_mat(const T *A, T *C)
elasticity matrix conversion Elasticity tensor A => elasticity matrix C
Definition fn_TR_ten_to_mat.hpp:28
USER GUIDES:
Definition cl_Capacitor.cpp:16
auto operator+(const Matrix< T > &aA, const Matrix< T > &aB) -> decltype(aA.matrix_data()+aB.matrix_data())
Definition op_MatrixPlus.hpp:23
void compliance_matrix(const T &aE1, const T &aE2, const T &aE3, const T &aNu23, const T &aNu31, const T &aNu12, const T &aG23, const T &aG31, const T &aG12, Matrix< T > &aS)
orthotropic compliance matrix in Voigt order 11, 22, 33, 23, 31, 12.
Definition fn_compliance_matrix.hpp:33
@ nu
Definition cl_Material.hpp:156
@ E
Definition cl_Material.hpp:155
auto operator-(const Matrix< T > &aA, const Matrix< T > &aB) -> decltype(aA.matrix_data() - aB.matrix_data())
Definition op_MatrixMinus.hpp:23
uint32_t index_t
Definition typedefs.hpp:52
auto inv(const T &aExpression) -> decltype(arma::inv(aExpression))
Definition fn_AR_inv.hpp:22
auto operator%(const Vector< T > &aA, const Vector< T > &aB) -> decltype(aA.vector_data() % aB.vector_data())
Definition op_AR_VectorElementwiseMultiplication.hpp:22
double real
Definition typedefs.hpp:36
bool operator==(const Matrix< T > &aA, const Matrix< T > &aB)
Definition op_AR_MatrixEqualEqual.hpp:23