10#ifndef _REALTENSOR2_H_
11#define _REALTENSOR2_H_
19#include "gsl/gsl_eigen.h"
20#include "gsl/gsl_matrix.h"
21#include "gsl/gsl_vector.h"
48 t[0] =
t[1] =
t[2] =
t[3] =
t[4] =
t[5] =
t[6] =
t[7] =
t[8] = 0.0;
67 t[0] = xx;
t[1] = xy;
t[2] = xz;
68 t[3] = yx;
t[4] = yy;
t[5] = yz;
69 t[6] = zx;
t[7] = zy;
t[8] = zz;
80 for (
int i=0; i<3; i++)
81 for (
int j=0; j<3; j++)
82 t[3*i+j] = a[i] * b[j];
97 assert(i >= 0 && i < 3 && j >= 0 && j < 3);
108 assert(i >= 0 && i < 3 && j >= 0 && j < 3);
118 assert(i >= 0 && i < 9);
128 assert(i >= 0 && i < 9);
144 -
t[6], -
t[7], -
t[8] );
159 for (
int i=0; i<9; i++)
t[i] += a;
169 for (
int i=0; i<9; i++)
t[i] -= a;
179 for (
int i=0; i<9; i++)
t[i] *= a;
189 for (
int i=0; i<9; i++)
t[i] /= a;
204 for (
int i=0; i<9; i++)
t[i] += a[i];
214 for (
int i=0; i<9; i++)
t[i] -= a[i];
224 for (
int i=0; i<9; i++)
t[i] *= a[i];
234 for (
int i=0; i<9; i++)
t[i] /= a[i];
249 for (
int i=0; i<9; i++)
t[i] = a;
261 for (
int i=0; i<9; i++) rt.
t[i] += a;
272 for (
int i=0; i<9; i++) rt.
t[i] -= a;
283 for (
int i=0; i<9; i++) rt.
t[i] *= a;
294 for (
int i=0; i<9; i++) rt.
t[i] /= a;
310 for (
int i=0; i<3; i++)
311 for (
int j=0; j<3; j++) r[i] += (*
this)(i,j) * v[j];
327 for (
int i=0; i<9; i++) rt.
t[i] += a[i];
338 for (
int i=0; i<9; i++) rt.
t[i] -= a[i];
349 for (
int i=0; i<9; i++) rt.
t[i] *= a[i];
360 for (
int i=0; i<9; i++) rt.
t[i] /= a[i];
375 for (
int j=0; j<3; j++)
376 for (
int i=0; i<3; i++) rv(j) += v(i) * (*this)(i,j);
397 for (
int i=0; i<3; i++)
398 for (
int j=0; j<3; j++)
399 c += a[i] * b[j] * (*
this)(i,j);
410 for (
int i=0; i<3; i++)
411 for (
int j=0; j<3; j++) c += (*
this)(i,j) * a(i,j);
432 for (
int i=0; i<3; i++) {
433 for (
int j=0; j<3; j++) {
434 divT += -v[i] * v[j] * (*this)(j,i) / vmag;
436 divT += (*this)(i,i);
451 for (
int i=0; i<3; i++) tr += (*
this)(i,i);
461 for (
int i=0; i<3; i++)
462 for (
int j=0; j<3; j++) rt(i,j) = (*this)(j,i);
470 for (
int i=1; i<3; i++)
471 for (
int j=0; j<i; j++)
472 std::swap( (*
this)(i,j), (*
this)(j,i) );
481 for (
int i=0; i<9; i++) m2 +=
t[i]*
t[i];
482 return std::sqrt(m2);
490 return (*
this)(0,0) * ( (*
this)(1,1) * (*
this)(2,2) -
491 (*
this)(1,2) * (*
this)(2,1) ) +
492 (*this)(0,1) * ( (*
this)(1,2) * (*
this)(2,0) -
493 (*
this)(1,0) * (*
this)(2,2) ) +
494 (*this)(0,2) * ( (*
this)(1,0) * (*
this)(2,1) -
495 (*
this)(1,1) * (*
this)(2,0) );
508 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
509 gsl_matrix *
T = gsl_matrix_alloc(3,3);
510 gsl_matrix *Q = gsl_matrix_alloc(3,3);
511 gsl_vector *D = gsl_vector_alloc(3);
514 for (
int i=0; i<3; i++)
515 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
518 gsl_eigen_symmv(
T, D, Q, w);
522 for (
int i=0; i<3; i++) {
523 eV[i] = gsl_vector_get(D, i);
530 gsl_eigen_symmv_free(w);
546 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
547 gsl_matrix *
T = gsl_matrix_alloc(3,3);
548 gsl_matrix *Q = gsl_matrix_alloc(3,3);
549 gsl_vector *D = gsl_vector_alloc(3);
552 for (
int i=0; i<3; i++)
553 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
556 gsl_eigen_symmv(
T, D, Q, w);
560 for (
int i=0; i<3; i++)
561 for (
int j=0; j<3; j++) ev(i,j) = gsl_matrix_get(Q, i, j);
567 gsl_eigen_symmv_free(w);
586 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
587 gsl_matrix *
T = gsl_matrix_alloc(3,3);
588 gsl_matrix *Q = gsl_matrix_alloc(3,3);
589 gsl_vector *D = gsl_vector_alloc(3);
592 for (
int i=0; i<3; i++)
593 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
596 gsl_eigen_symmv(
T, D, Q, w);
599 for (
int i=0; i<3; i++) {
600 eVal[i] = gsl_vector_get(D, i);
601 for (
int j=0; j<3; j++)
eVec(i,j) = gsl_matrix_get(Q, i, j);
608 gsl_eigen_symmv_free(w);
628 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
629 gsl_matrix *
T = gsl_matrix_alloc(3,3);
630 gsl_matrix *Q = gsl_matrix_alloc(3,3);
631 gsl_vector *D = gsl_vector_alloc(3);
634 for (
int i=0; i<3; i++)
635 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
638 gsl_eigen_symmv(
T, D, Q, w);
641 for (
int i=0; i<3; i++)
642 gsl_vector_set(D, i, 1/(gsl_vector_get(D, i)));
654 for (
int i=0; i<3; i++) {
655 for (
int j=0; j<=i; j++) {
656 for (
int n=0; n<3; n++) {
657 Tinv(i,j) += gsl_vector_get(D, n) *
658 gsl_matrix_get(Q, i, n) *
659 gsl_matrix_get(Q, j, n);
663 for (
int i=0; i<3; i++) {
664 for (
int j=i+1; j<3; j++) {
665 Tinv(i,j) = Tinv(j,i);
673 gsl_eigen_symmv_free(w);
698 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
699 gsl_matrix *
T = gsl_matrix_alloc(3,3);
700 gsl_matrix *Q = gsl_matrix_alloc(3,3);
701 gsl_vector *D = gsl_vector_alloc(3);
704 for (
int i=0; i<3; i++)
705 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
708 gsl_eigen_symmv(
T, D, Q, w);
711 for (
int i=0; i<3; i++)
712 gsl_vector_set(D, i, std::sqrt(gsl_vector_get(D, i)));
724 for (
int i=0; i<3; i++) {
725 for (
int j=0; j<3; j++) {
726 for (
int n=0; n<3; n++) {
727 Tsqrt(i,j) += gsl_vector_get(D, n) *
728 gsl_matrix_get(Q, i, n) *
729 gsl_matrix_get(Q, j, n);
733 for (
int i=0; i<3; i++) {
734 for (
int j=i+1; j<3; j++) {
735 Tsqrt(i,j) = Tsqrt(j,i);
743 gsl_eigen_symmv_free(w);
766 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(3);
767 gsl_matrix *
T = gsl_matrix_alloc(3,3);
768 gsl_matrix *Q = gsl_matrix_alloc(3,3);
769 gsl_vector *D = gsl_vector_alloc(3);
772 for (
int i=0; i<3; i++)
773 for (
int j=0; j<3; j++) gsl_matrix_set(
T, i, j, (*
this)(i,j));
776 gsl_eigen_symmv(
T, D, Q, w);
779 for (
int i=0; i<3; i++)
780 gsl_vector_set(D, i, 1/std::sqrt(gsl_vector_get(D, i)));
792 for (
int i=0; i<3; i++) {
793 for (
int j=0; j<=i; j++) {
794 for (
int n=0; n<3; n++) {
795 TInvSqrt(i,j) += gsl_vector_get(D, n) *
796 gsl_matrix_get(Q, i, n) *
797 gsl_matrix_get(Q, j, n);
801 for (
int i=0; i<3; i++) {
802 for (
int j=i+1; j<3; j++) {
803 TInvSqrt(i,j) = TInvSqrt(j,i);
811 gsl_eigen_symmv_free(w);
837 a + t[3], a + t[4], a + t[5],
838 a + t[6], a + t[7], a + t[8] );
850 a - t[3], a - t[4], a - t[5],
851 a - t[6], a - t[7], a - t[8] );
863 a * t[3], a * t[4], a * t[5],
864 a * t[6], a * t[7], a * t[8] );
876 a / t[3], a / t[4], a / t[5],
877 a / t[6], a / t[7], a / t[8] );
927 for (
int j=0; j<3; j++) {
928 for (
int k=0; k<3; k++) vDotGradv[j] += v[k] * vGrad[3*k + j];
931 for (
int i=0; i<3; i++) {
933 for (
int j=0; j<3; j++)
934 b.
eN[i] += b.
eT[j] * (vmag*vmag * vGrad[3*i+j] - v[i] * vDotGradv[j]);
935 norm += b.
eN[i] * b.
eN[i];
948 Real xynorm = std::sqrt( b.
eT[0]*b.
eT[0] + b.
eT[1]*b.
eT[1] );
951 b.
eN[1] = b.
eN[2] = 0.0;
953 b.
eN[0] = b.
eT[1] / xynorm;
954 b.
eN[1] = -b.
eT[0] / xynorm;
Basic integer and real types.
Class that represents a mathematical vector in 3-space.
Class that represents a rank 2 tensor.
Definition RealTensor2.H:34
RealTensor2 operator/(const RealTensor2 &a) const
Divide two RealTensor2s elementwise.
Definition RealTensor2.H:358
RealTensor2 sqrt() const
Compute the square root of a symmetric tensor.
Definition RealTensor2.H:686
Real det() const
Compute the determinant.
Definition RealTensor2.H:489
RealTensor2 & operator+=(const RealTensor2 &a)
Add another RealTensor2 to the RealTensor2 elementwise.
Definition RealTensor2.H:203
RealTensor2 operator*(const RealTensor2 &a) const
Multiply two RealTensor2s elementwise.
Definition RealTensor2.H:347
RealVec operator*(const RealVec &v) const
Matrix-vector multiplication.
Definition RealTensor2.H:308
RealTensor2(const RealVec &a, const RealVec &b)
Construct a RealTensor2 as the outer product of two RealVecs.
Definition RealTensor2.H:79
RealTensor2 invSqrt() const
Compute the inverse of the square root of a symmetric tensor.
Definition RealTensor2.H:756
Real contract(const RealVec &a, const RealVec &b) const
Compute the tensor contraction a_i b_j T_ij.
Definition RealTensor2.H:395
RealVec contract2(const RealVec &v) const
Compute the tensor contraction v_j T_ij.
Definition RealTensor2.H:385
RealTensor2 & operator/=(const Real a)
Divide the RealTensor2 by a scalar elementwise.
Definition RealTensor2.H:188
Real mag()
Total magnitude.
Definition RealTensor2.H:479
Real t[9]
Definition RealTensor2.H:42
Real & operator()(int i, int j)
Return an element of the tensor.
Definition RealTensor2.H:96
RealTensor2(const Real &xx, const Real &xy, const Real &xz, const Real &yx, const Real &yy, const Real &yz, const Real &zx, const Real &zy, const Real &zz)
Construct a RealTensor2 from nine scalars.
Definition RealTensor2.H:63
Real trace() const
Return the trace of this tensor.
Definition RealTensor2.H:449
RealTensor2 operator-(const Real a) const
Subtract a scalar from a RealTensor2 elementwise.
Definition RealTensor2.H:270
RealVec eVal() const
Compute the eigenvalues of a symmetric tensor.
Definition RealTensor2.H:505
RealTensor2 inv() const
Compute the inverse of a symmetric tensor.
Definition RealTensor2.H:618
RealTensor2()
Construct a RealTensor2 of all zeros.
Definition RealTensor2.H:47
RealVec contract1(const RealVec &v) const
Compute the tensor contraction v_i T_ij.
Definition RealTensor2.H:373
RealTensor2 T() const
Return the transpose of this tensor.
Definition RealTensor2.H:459
void eigenDecompose(RealVec &eVal, RealTensor2 &eVec) const
Compute the eigendecomposition of a symmetric tensor.
Definition RealTensor2.H:583
RealTensor2 & operator/=(const RealTensor2 &a)
Divide this RealTensor2 by another RealTensor2 elementwise.
Definition RealTensor2.H:233
RealTensor2 operator/(const Real a) const
Divide a RealTensor2 by a scalar elementwise.
Definition RealTensor2.H:292
Real & operator[](int i)
Return an element of the tensor.
Definition RealTensor2.H:117
RealTensor2 & operator*=(const RealTensor2 &a)
Multiply another RealTensor2 by the RealTensor2 elementwise.
Definition RealTensor2.H:223
RealTensor2 operator*(const Real a) const
Multiply a scalar by a RealTensor2 elementwise.
Definition RealTensor2.H:281
RealTensor2 & operator=(const Real a)
Assign a scalar value to every element of a RealTensor2.
Definition RealTensor2.H:248
RealTensor2 & operator-=(const RealTensor2 &a)
Subtract another RealTensor2 from the RealTensor2 elementwise.
Definition RealTensor2.H:213
RealTensor2 & operator-=(const Real a)
Subtract a scalar from the RealTensor2 elementwise.
Definition RealTensor2.H:168
RealTensor2 eVec() const
Compute the eigenvectors of a symmetric tensor.
Definition RealTensor2.H:543
Real divTangent(const RealVec &v) const
Compute the divergence of the tangent vector.
Definition RealTensor2.H:425
RealTensor2 operator+(const RealTensor2 &a) const
Add two RealTensor2s elementwise.
Definition RealTensor2.H:325
RealTensor2 operator-(const RealTensor2 &a) const
Subtract two RealTensor2s elementwise.
Definition RealTensor2.H:336
RealTensor2 operator+(const Real a) const
Add a scalar and a RealTensor2 elementwise.
Definition RealTensor2.H:259
Real contract(const RealTensor2 &a) const
Compute the contraction of this tensor with another tensor.
Definition RealTensor2.H:408
RealTensor2 & operator+=(const Real a)
Add a scalar to the RealTensor2 elementwise.
Definition RealTensor2.H:158
RealTensor2 operator-() const
Return the negative of a RealTensor2.
Definition RealTensor2.H:141
RealTensor2 & operator*=(const Real a)
Multiply a scalar by the RealTensor2 elementwise.
Definition RealTensor2.H:178
void transpose()
Transpose this tensor in place.
Definition RealTensor2.H:469
Real mag() const
Computes the magnitude of the vector.
Definition Vec3.H:470
auto cross(const Vec3< U > &a) const -> Vec3< decltype(this->v[0]+a[0])>
Returns the cross product of this vector with another vector.
Definition Vec3.H:585
void normalize()
Normalizes this vector to have unit length.
Definition Vec3.H:491
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
criptic::RealTensor2 operator-(const criptic::Real a, const criptic::RealTensor2 &t)
Subtract a scalar from a RealTensor2 elementwise.
Definition RealTensor2.H:847
static const criptic::RealTensor2 identityTensor(1, 0, 0, 0, 1, 0, 0, 0, 1)
TNBBasis TNBVectors(const RealVec &v, const RealTensor2 &vGrad)
Compute tangent, normal, and binormal vectors.
Definition RealTensor2.H:913
criptic::RealTensor2 outer(const criptic::RealVec &v1, const criptic::RealVec &v2)
Compute the outer product of two RealVec objects.
Definition RealTensor2.H:887
criptic::RealTensor2 operator+(const criptic::Real a, const criptic::RealTensor2 &t)
Add a scalar and a RealTensor2 elementwise.
Definition RealTensor2.H:834
criptic::RealTensor2 operator/(const criptic::Real a, const criptic::RealTensor2 &t)
Divide a RealTensor2 by a scalar elementwise.
Definition RealTensor2.H:873
double Real
Definition Types.H:38
static const criptic::RealTensor2 zeroTensor(0, 0, 0, 0, 0, 0, 0, 0, 0)
criptic::FieldQty operator*(const criptic::Real a, const criptic::FieldQty &fq)
Multiply a scalar by a FieldQty elementwise.
Definition FieldQty.H:250
Structure to hold TNB basis data.
Definition RealTensor2.H:898
RealVec eB
Definition RealTensor2.H:901
RealVec eN
Definition RealTensor2.H:900
RealVec eT
Definition RealTensor2.H:899