-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp3a_mandel6x1.hpp
827 lines (754 loc) · 25.8 KB
/
p3a_mandel6x1.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
#pragma once
#include "p3a_scalar.hpp"
#include "p3a_macros.hpp"
#include "p3a_functions.hpp"
#include "p3a_diagonal3x3.hpp"
#include "p3a_constants.hpp"
#include "p3a_vector3.hpp"
#include "p3a_symmetric3x3.hpp"
#include "p3a_static_matrix.hpp"
#include "p3a_matrix3x3.hpp"
/********************************* NOTES ************************************
*
* Symmetric Tensor (Voigt-Mandel) Math Library
* ============================================
*
* Scope of the Library
* ----------------------------------
* This set of classes and functions allows for linear algebra to be performed
* in the context of material models. This package enables the usual linear
* algebra operations with symmetric 1x6, 6x1, 6x6, 6x3, and 3x6 tensors and
* is able to perform mixed operations with the `diagonal3x3`, `symmetric3x3`
* and `matrix3x3` classes also avaliable in P3A. operations are carried out
* component by component, elimininating the need for arrays and permitting
* functions to be _inline_ consistent with the performance requirements of
* P3A.
*
* This header provides the class:
*
* - `mandel6x1` (6x1) 2nd order Tensor
*
* Constructors:
*
* - `mandel6x1(mandel6x1)`
* - `mandel6x1(<list of values>)`
* - `mandel6x1(symmetric3x3)`
* - `mandel6x1(matrix3x3)` -- includes testing for symmetry
* - `mandel6x1(static_matrix3x3)` -- includes testing for symmetry
*
* Other `mandelNxN` headers provide the classes:
*
* - `mandel6x6` (6x6) 4th order Tensor
* - `mandel3x6` (3x6) 3rd order Tensor
* - `mandel6x3` (6x3) 3rd order Tensor
*
* Mandel Notation and Voigt Notation
* ----------------------------------
* The primary addition of this library is the ability to perform the usual
* linear algebra relations with normal Tensors and Vectors along with symmetric
* ones often found in mechanics. This package uses *Mandel* notation, not
* _Voigt_ notation. Mandel notation is simmilar to Voigt's notation in that
* symmetric 2<sup>nd</sup>-order tensors are represented by 6x1 vectors, and
* 4<sup>th</sup>-order tensors are represented by 6x6 tensors. Mandel notation
* is applied to all tensors/vectors unlike Voigt notation.
*
* Mandel notation allows for all standard linear algebra operations to be
* correctly normalized and eliminates the need for strain, or stress-like Voigt
* tensors (symmetric strain-like tensors will have of 2 in front of off-diagonal
* components, while stress like tensors will have a factor of 1). Converting
* to Mandel notation (which properly normalizes the tensor) will ease computations
* with operations produce vectors (3x1) or full (3x3) 2<sup>nd</sup>-order tensors.
*
* Mandel Transformation is applied internally upon construction of a Mandel-type
* object which includes all of the symmetric Mandel Tensor types (6x1, 6x6, 3x6,
* or 6x3). Avaliable constructors vary by mandel tensor type, so see notes in each
* specific header. By default, all constructors apply the Mandel Transform, but it can be
* overridden by specifying a Boolean `false` value to the end of the constructor
* argument list. Note that, if you use the `zero()` or `identity()` constructor,
* you will have a tensor that won't carry the transform to further operations, the
* transformation must be applied manually by applying the method `MandelXform()`
* method to the Mandel-type object. The transform will be contained in any result
* returning a Mandel-type object. This means that the Mandel transformation must be
* inverted when converting mandel6x1 (6-element symmetric tensors) to full
* 9-element (3x3) 2<sup>nd</sup>-order tensors.
*
* This library automatically inverts the Mandel transformation when returning a
* member of the `matrix3x3` or `symmetric3x3` classes. Operations that
* return Vectors will not need to be modified (this is why we are using Mandel
* transformations)!
*
*/
namespace p3a {
/******************************************************************/
/******************************************************************/
template <class T>
class mandel6x1
/**
* Represents a 2nd order tensor as a 6x1 Mandel array
*
******************************************************************/
{
T m_x1,m_x2,m_x3,m_x4,m_x5,m_x6;
bool applyTransform;
public:
static constexpr T r2 = square_root_of_two_value<T>();
static constexpr T r2i = T(1.0)/square_root_of_two_value<T>();
static constexpr T two= T(2.0);
/**** constructors, destructors, and assigns ****/
P3A_ALWAYS_INLINE constexpr
mandel6x1() = default;
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(
T const& X1, T const& X2, T const& X3,
T const& X4, T const& X5, T const& X6):
m_x1(X1),
m_x2(X2),
m_x3(X3),
m_x4(X4),
m_x5(X5),
m_x6(X6),
applyTransform(true)
{
this->MandelXform();
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(
T const& X1, T const& X2, T const& X3,
T const& X4, T const& X5, T const& X6, bool const& Xform)
:m_x1(X1)
,m_x2(X2)
,m_x3(X3)
,m_x4(X4)
,m_x5(X5)
,m_x6(X6)
,applyTransform(Xform)
{
if (applyTransform)
this->MandelXform();
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(symmetric3x3<T> const& a):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(a.yz()),
m_x5(a.xz()),
m_x6(a.xy()),
applyTransform(true)
{
this->MandelXform();
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(symmetric3x3<T> const& a, bool const& Xform):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(a.yz()),
m_x5(a.xz()),
m_x6(a.xy()),
applyTransform(Xform)
{
if (applyTransform)
this->MandelXform();
}
P3A_HOST_DEVICE P3A_NEVER_INLINE
mandel6x1(matrix3x3<T> const& a):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(a.yz()),
m_x5(a.xz()),
m_x6(a.xy()),
applyTransform(true)
{
this->MandelXform();
}
P3A_NEVER_INLINE
mandel6x1(matrix3x3<T> const& a, bool const& Xform):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(a.yz()),
m_x5(a.xz()),
m_x6(a.xy()),
applyTransform(Xform)
{
if (applyTransform)
this->MandelXform();
}
P3A_NEVER_INLINE
mandel6x1(static_matrix<T,3,3> const& a):
m_x1(a(0,0)),
m_x2(a(1,1)),
m_x3(a(2,2)),
m_x4(a(1,2)),
m_x5(a(0,2)),
m_x6(a(0,1)),
applyTransform(true)
{
this->MandelXform();
}
P3A_NEVER_INLINE
mandel6x1(static_matrix<T,3,3> const& a, bool const& Xform):
m_x1(a(0,0)),
m_x2(a(1,1)),
m_x3(a(2,2)),
m_x4(a(1,2)),
m_x5(a(0,2)),
m_x6(a(0,1)),
applyTransform(Xform)
{
if (applyTransform)
this->MandelXform();
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(diagonal3x3<T> const& a):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(T(0.0)),
m_x5(T(0.0)),
m_x6(T(0.0)),
applyTransform(true)
{
this->MandelXform();
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1(diagonal3x3<T> const& a, bool const& Xform):
m_x1(a.xx()),
m_x2(a.yy()),
m_x3(a.zz()),
m_x4(T(0.0)),
m_x5(T(0.0)),
m_x6(T(0.0)),
applyTransform(Xform)
{
if(applyTransform)
this->MandelXform();
}
//Return components by ij descriptor
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& xx() const { return m_x1; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& yy() const { return m_x2; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& zz() const { return m_x3; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& yz() const { return m_x4; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& xz() const { return m_x5; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& xy() const { return m_x6; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& xx() { return m_x1; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& yy() { return m_x2; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& zz() { return m_x3; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& yz() { return m_x4; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& xz() { return m_x5; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& xy() { return m_x6; }
//return by mandel index 1-6
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x1() const { return m_x1; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x2() const { return m_x2; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x3() const { return m_x3; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x4() const { return m_x4; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x5() const { return m_x5; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T const& x6() const { return m_x6; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x1() { return m_x1; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x2() { return m_x2; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x3() { return m_x3; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x4() { return m_x4; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x5() { return m_x5; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T& x6() { return m_x6; }
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE static constexpr
mandel6x1<T> zero()
{
return mandel6x1<T>(
T(0), T(0), T(0),
T(0), T(0), T(0),false);
}
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE static constexpr
mandel6x1<T> identity()
{
return mandel6x1<T>(
T(1), T(1), T(1),
T(0), T(0), T(0));
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void MandelXform()
{
m_x4 *= r2;
m_x5 *= r2;
m_x6 *= r2;
}
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void invMandelXform()
{
m_x4 /= r2;
m_x5 /= r2;
m_x6 /= r2;
}
//conversion of symmetric3x3 to mandel6x1 via assignment
template <class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1<U> operator=(
symmetric3x3<U> const& t)
{
return mandel6x1<U>(
t.xx(),
t.yy(),
t.zz(),
t.yz(),
t.xz(),
t.xy(),
true);
}
//conversion of static_matrix<3,3> to mandel6x1 via assignment
template <class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1<U> operator=(
static_matrix<U,3,3> const& t)
{
return mandel6x1<U>(t , true);
}
};
/*****************************************************************************
* Operators overloads for mandel6x1 tensors (2nd order tensor)
*****************************************************************************/
//mandel6x1 binary operators with scalars
//multiplication by constant
template <class A, class B>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<B>, mandel6x1<decltype(A() * B())>>::type
operator*(
mandel6x1<A> const& t,
B const& c)
{
return mandel6x1<decltype(t.x1()*c)>(
t.x1()*c,
t.x2()*c,
t.x3()*c,
t.x4()*c,
t.x5()*c,
t.x6()*c,
false);
}
//multiplication by constant
template <class A, class B>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<A>, mandel6x1<decltype(A() * B())>>::type
operator*(
A const& c,
mandel6x1<B> const& t)
{
return t * c;
}
//division by constant
template <class A, class B>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
typename std::enable_if<is_scalar<B>, mandel6x1<decltype(A() * B())>>::type
operator/(
mandel6x1<A> const& t,
B const& c)
{
return mandel6x1<decltype(A() * B())>(
t.x1() / c,
t.x2() / c,
t.x3() / c,
t.x4() / c,
t.x5() / c,
t.x6() / c,
false);
}
//multiplication *= by constant
template <class A>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void operator*=(
mandel6x1<A>& t,
A const& c)
{
t.x1() *= c;
t.x2() *= c;
t.x3() *= c;
t.x4() *= c;
t.x5() *= c;
t.x6() *= c;
}
//division /= by constant
template <class A>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void operator/=(
mandel6x1<A>& t,
A const& c)
{
t.x1() /= c;
t.x2() /= c;
t.x3() /= c;
t.x4() /= c;
t.x5() /= c;
t.x6() /= c;
}
//mandel6x1 -= subtraction
template <class T>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void operator-=(
mandel6x1<T>& a,
mandel6x1<T> const& b)
{
a.x1() -= b.x1();
a.x2() -= b.x2();
a.x3() -= b.x3();
a.x4() -= b.x4();
a.x5() -= b.x5();
a.x6() -= b.x6();
}
//mandel6x1 addition
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator+(
mandel6x1<T> const& a,
mandel6x1<U> const& b)
{
return mandel6x1<decltype(a.x1()*b.x1())>(
a.x1() + b.x1(),
a.x2() + b.x2(),
a.x3() + b.x3(),
a.x4() + b.x4(),
a.x5() + b.x5(),
a.x6() + b.x6(),
false);
}
//mandel6x1 += addition
template <class T>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
void operator+=(
mandel6x1<T>& a,
mandel6x1<T> const& b)
{
a.x1() += b.x1();
a.x2() += b.x2();
a.x3() += b.x3();
a.x4() += b.x4();
a.x5() += b.x5();
a.x6() += b.x6();
}
//mandel6x1 subtraction
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator-(
mandel6x1<T> const& a,
mandel6x1<U> const& b)
{
return mandel6x1<decltype(a.x1()+b.x1())>(
a.x1() - b.x1(),
a.x2() - b.x2(),
a.x3() - b.x3(),
a.x4() - b.x4(),
a.x5() - b.x5(),
a.x6() - b.x6(),
false);
}
//mandel6x1 negation
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1<T> operator-(
mandel6x1<T> const& a)
{
return mandel6x1<T>(
-a.x1(),
-a.x2(),
-a.x3(),
-a.x4(),
-a.x5(),
-a.x6(),
false);
}
/*****************************************************************************
* Linear Algebra for Mandel6x1 (2nd order tensor)
*****************************************************************************/
//trace
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T trace(
mandel6x1<T> const& a)
{
return a.x1() + a.x2() + a.x3();
}
//determinate
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
T determinant(
mandel6x1<T> const& t)
{
return t.x1() * (t.x2()*t.x3() - t.x4()*t.x4()/t.two) -
t.x6()/t.r2 * (t.x3()*t.x6()/t.r2 - t.x4()*t.x5()/t.two) +
t.x5()/t.r2 * (t.x6()*t.x4()/t.two - t.x2()*t.x5()/t.r2);
}
//inverse
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
mandel6x1<T> inverse(
mandel6x1<T> const& V)
{
//Direct calculation of inverse of (6x1) 2nd-order Mandel tensor
T det = determinant(V);
return mandel6x1<T>(
(V.x2()*V.x3() - V.x4()*V.x4()/V.two)/det,
(V.x1()*V.x3() - V.x5()*V.x5()/V.two)/det,
(V.x1()*V.x2() - V.x6()*V.x6()/V.two)/det,
(V.x6()*V.x5()/V.two - V.x1()*V.x4()/V.r2)/det,
(V.x6()*V.x4()/V.two - V.x2()*V.x5()/V.r2)/det,
(V.x4()*V.x5()/V.two - V.x6()*V.x3()/V.r2)/det,
true);
//not in mandel form anymore; return to mandel form for consistency with
//other functions
}
/** Tensor multiply MandelVector (6x1) by MandelVector (6x1) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(
mandel6x1<T> const &v,
mandel6x1<U> const &t)
{
mandel6x1<T> tt = t;
mandel6x1<U> vv = v;
tt.invMandelXform();
vv.invMandelXform();
using result_type = decltype(v.xx() * t.xx());
return mandel6x1<result_type>(
tt.x1()*vv.x1()+tt.x6()*vv.x6()+tt.x5()*vv.x5(),
tt.x6()*vv.x6()+tt.x2()*vv.x2()+tt.x4()*vv.x4(),
tt.x5()*vv.x5()+tt.x4()*vv.x4()+tt.x3()*vv.x3(),
tt.x6()*vv.x5()+tt.x2()*vv.x4()+tt.x4()*vv.x3(),
tt.x1()*vv.x5()+tt.x6()*vv.x4()+tt.x5()*vv.x3(),
tt.x1()*vv.x6()+tt.x6()*vv.x2()+tt.x5()*vv.x4(),
true);
}
/** Tensor multiply MandelVector (6x1) by symmetric3x3 (3x3) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(
mandel6x1<T> const &v,
symmetric3x3<U> const &tt)
{
mandel6x1<T> vv = v;
vv.invMandelXform();
using result_type = decltype(tt.xx() * v.xx());
return mandel6x1<result_type>(
tt.xx()*vv.x1()+tt.xy()*vv.x6()+tt.xz()*vv.x5(),
tt.xy()*vv.x6()+tt.yy()*vv.x2()+tt.yz()*vv.x4(),
tt.xz()*vv.x5()+tt.yz()*vv.x4()+tt.zz()*vv.x3(),
tt.xy()*vv.x5()+tt.yy()*vv.x4()+tt.yz()*vv.x3(),
tt.xx()*vv.x5()+tt.xy()*vv.x4()+tt.xz()*vv.x3(),
tt.xx()*vv.x6()+tt.xy()*vv.x2()+tt.xz()*vv.x4(),
true);
}
/** Tensor multiply symmetric3x3 by MandelVector (6x1) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(
symmetric3x3<T> const &tt,
mandel6x1<U> const &v)
{
mandel6x1<U> vv = v;
vv.invMandelXform();
using result_type = decltype(tt.xx() * v.xx());
return mandel6x1<result_type>(
tt.xx()*vv.x1()+tt.xy()*vv.x6()+tt.xz()*vv.x5(),
tt.xy()*vv.x6()+tt.yy()*vv.x2()+tt.yz()*vv.x4(),
tt.xz()*vv.x5()+tt.yz()*vv.x4()+tt.zz()*vv.x3(),
tt.xy()*vv.x5()+tt.yy()*vv.x4()+tt.yz()*vv.x3(),
tt.xx()*vv.x5()+tt.xy()*vv.x4()+tt.xz()*vv.x3(),
tt.xx()*vv.x6()+tt.xy()*vv.x2()+tt.xz()*vv.x4(),
true);
}
/** Tensor multiply MandelVector (6x1) by diagonal3x3 (3x3) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(mandel6x1<T> const &v, diagonal3x3<U> const &tt)
{
mandel6x1<T> vv = v;
vv.invMandelXform();
using result_type = decltype(tt.xx() * v.xx());
return mandel6x1<result_type>(
tt.xx()*vv.x1(),
tt.yy()*vv.x2(),
tt.zz()*vv.x3(),
tt.yy()*vv.x4(),
tt.xx()*vv.x5(),
tt.xx()*vv.x6(),
true);
}
/** Tensor multiply diagonal3x3 (3x3) by MandelVector (6x1) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(diagonal3x3<T> const &tt, mandel6x1<U> const &v)
{
mandel6x1<U> vv = v;
vv.invMandelXform();
using result_type = decltype(tt.xx() * v.xx());
return mandel6x1<result_type>(
tt.xx()*vv.x1(),
tt.yy()*vv.x2(),
tt.zz()*vv.x3(),
tt.yy()*vv.x4(),
tt.xx()*vv.x5(),
tt.xx()*vv.x6(),
true);
}
/** Tensor multiply MandelVector (6x1) by vector3 (3x1) **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(mandel6x1<T> const &m, vector3<U> const &v)
{
mandel6x1<T> t = m;
t.invMandelXform();
//The transformation is reversed as the operation is performed
// by first converting to a tensor.
using result_type = decltype(t.xx() * v.x());
return vector3<result_type>(
t.x1()*v.x() + t.x6()*v.y() + t.x5()*v.z(),
t.x6()*v.x() + t.x2()*v.y() + t.x4()*v.z(),
t.x5()*v.x() + t.x4()*v.y() + t.x3()*v.z());
}
//partial pivoting in <dynamic_matrix.hpp>
//////////////////////////////////////////////////////////////////////////////////
// Operations Yielding Scalars (double dot product of two tensors (2nd order)
//////////////////////////////////////////////////////////////////////////////////
//double dot product of mandel6x1 with mandel6x1
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(mandel6x1<T> const &t, mandel6x1<U> const &v)
{
using result_type = decltype(t.x1() * v.x());
return result_type(t.x1()*v.x1() + t.x2()*v.x2() + t.x3()*v.x3() + t.two*t.x4()*v.x4() + t.two*t.x5()*v.x5() + t.two*t.x6()*v.x6());
}
//double dot product of mandel6x1 with diagonal3x3
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(mandel6x1<T> const &t, diagonal3x3<U> const &d)
{
using result_type = decltype(t.x1() * d.x());
return result_type(t.x1()*d.xx() + t.x2()*d.yy() + t.x3()*d.zz());
}
//double dot product of diagonal3x3 and mandel6x1
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(diagonal3x3<T> const &d, mandel6x1<U> const &t)
{
using result_type = decltype(d.xx() * t.x1());
return result_type(t.x1()*d.xx() + t.x2()*d.yy() + t.x3()*d.zz());
}
//double dot product of mandel6x1 and symmetric3x3
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot( mandel6x1<T> const &v, symmetric3x3<U> const &t)
{
using result_type = decltype(v.x1() * t.xx());
return result_type(t.xx()*v.x1() + t.yy()*v.x2() + t.zz()*v.x3() + v.two*t.yz()*v.x4() + v.two*t.xz()*v.x5() + v.two*t.xy()*v.x6());
}
//double dot product of symmetric3x3 and mandel6x1
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(symmetric3x3<T> const& t, mandel6x1<U> const &v)
{
using result_type = decltype(v.x1() * t.xx());
return result_type(t.xx()*v.x1() + t.yy()*v.x2() + t.zz()*v.x3() + v.two*t.yz()*v.x4() + v.two*t.xz()*v.x5() + v.two*t.xy()*v.x6());
}
//double dot product of mandel6x1 and matrix3x3
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(mandel6x1<T> const& v, matrix3x3<U> const& t)
{
using result_type = decltype(t.xx() * v.x1());
return result_type(t.xx()*v.x1() + t.yy()*v.x2() + t.zz()*v.x3() + t.yz()*v.x4() + t.xz()*v.x5() + t.xy()*v.x6() + t.zy()*v.x4() + t.zx()*v.x5() + t.yx()*v.x6());
}
//double dot product of matrix3x3 and mandel6x1
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto ddot(matrix3x3<T> const& t, mandel6x1<U> const& v)
{
using result_type = decltype(v.x1() * t.xx());
return result_type(t.xx()*v.x1() + t.yy()*v.x2() + t.zz()*v.x3() + t.yz()*v.x4() + t.xz()*v.x5() + t.xy()*v.x6() + t.zy()*v.x4() + t.zx()*v.x5() + t.yx()*v.x6());
}
//////////////////////////////////////////////////////////////////////////////////
// Operations Yielding matrix3x3
//////////////////////////////////////////////////////////////////////////////////
/** Tensor mult: mandel6x1 by matrix3x3 **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(mandel6x1<T> const& v, matrix3x3<U> const& t)
{
using result_type = decltype(t.xx() * v.x1());
//The transformation is reversed as the operation is performed
// by first converting to a tensor.
return matrix3x3<result_type>(v.x1()*t.xx()+v.x6()/v.r2*t.yx()+v.x5()/v.r2*t.zx(),v.x1()*t.xy()+v.x6()/v.r2*t.yy()+v.x5()/v.r2*t.zy(),v.x1()*t.xz()+v.x6()/v.r2*t.yz()+v.x5()/v.r2*t.zz(),
v.x6()/v.r2*t.xx()+v.x2()*t.yx()+v.x4()/v.r2*t.zx(),v.x6()/v.r2*t.xy()+v.x2()*t.yy()+v.x4()/v.r2*t.zy(),v.x6()/v.r2*t.xz()+v.x2()*t.yz()+v.x4()/v.r2*t.zz(),
v.x5()/v.r2*t.xx()+v.x4()/v.r2*t.yx()+v.x3()*t.zx(),v.x5()/v.r2*t.xy()+v.x4()/v.r2*t.yy()+v.x3()*t.zy(),v.x5()/v.r2*t.xz()+v.x4()/v.r2*t.yz()+v.x3()*t.zz());
}
/** Tensor mult: matrix3x3 by mandel6x1 **/
template <class T, class U>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
auto operator*(matrix3x3<T> const& t, mandel6x1<U> const& v)
{
//The transformation is reversed as the operation is performed
// by first converting to a tensor.
using result_type = decltype(t.xx() * v.x1());
return matrix3x3<result_type>(t.xx()*v.x1()+t.xy()*v.x6()/v.r2+t.xz()*v.x5()/v.r2,t.xx()*v.x6()/v.r2+t.xy()*v.x2()+t.xz()*v.x4()/v.r2,t.xx()*v.x5()/v.r2+t.xy()*v.x4()/v.r2+t.xz()*v.x3(),
t.yx()*v.x1()+t.yy()*v.x6()/v.r2+t.yz()*v.x5()/v.r2,t.yx()*v.x6()/v.r2+t.yy()*v.x2()+t.yz()*v.x4()/v.r2,t.yx()*v.x5()/v.r2+t.yy()*v.x4()/v.r2+t.yz()*v.x3(),
t.zx()*v.x1()+t.zy()*v.x6()/v.r2+t.zz()*v.x5()/v.r2,t.zx()*v.x6()/v.r2+t.zy()*v.x2()+t.zz()*v.x4()/v.r2,t.zx()*v.x5()/v.r2+t.zy()*v.x4()/v.r2+t.zz()*v.x3());
}
//////////////////////////////////////////////////////////////////////////////////
// Operations Yielding symmetric3x3 from a mandel6x1
//////////////////////////////////////////////////////////////////////////////////
/** Convert MandelVector (6x1) to symmetric3x3 **/
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
symmetric3x3<T> mandel6x1_to_symmetric3x3(mandel6x1<T> const& v)
{
//invert Mandel Tranformation of MandelVector
return symmetric3x3<T>(v.x1(),v.x6()/v.r2,v.x5()/v.r2,
v.x2() ,v.x4()/v.r2,
v.x3());
}
/** Convert MandelVector (6x1) to symmetric3x3 **/
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE constexpr
matrix3x3<T> mandel6x1_to_matrix3x3(mandel6x1<T> const& v)
{
//invert Mandel Tranformation of MandelVector
return matrix3x3<T>(v.x1(), v.x6()/v.r2,v.x5()/v.r2,
v.x6()/v.r2,v.x2() ,v.x4()/v.r2,
v.x5()/v.r2,v.x4()/v.r2,v.x3());
}
//misc
inline int constexpr mandel6x1_component_count = 6;
//output print
template <class U>
P3A_ALWAYS_INLINE constexpr
std::ostream& operator<<(std::ostream& os, mandel6x1<U> const& a)
{
os << std::cout.precision(4);
os << std::scientific;
os << "\t | " << a.x1() << " " << a.x6()*a.r2i << " " << a.x5()*a.r2i << " |" <<std::endl;
os << "\t | " << a.x6()*a.r2i << " " << a.x2() << " " << a.x4()*a.r2i << " |" <<std::endl;
os << "\t | " << a.x5()*a.r2i << " " << a.x4()*a.r2i << " " << a.x3() << " |" <<std::endl;
return os;
}
}