ECOGEN 4.0
Evolutive, Compressible, Open, Genuine, Easy, N-phase
Loading...
Searching...
No Matches
Tensor.h
Go to the documentation of this file.
1//
2// ,---. ,--, .---. ,--, ,---. .-. .-.
3// | .-' .' .') / .-. ) .' .' | .-' | \| |
4// | `-. | |(_) | | |(_) | | __ | `-. | | |
5// | .-' \ \ | | | | \ \ ( _) | .-' | |\ |
6// | `--. \ `-. \ `-' / \ `-) ) | `--. | | |)|
7// /( __.' \____\ )---' )\____/ /( __.' /( (_)
8// (__) (_) (__) (__) (__)
9// Official webSite: https://code-mphi.github.io/ECOGEN/
10//
11// This file is part of ECOGEN.
12//
13// ECOGEN is the legal property of its developers, whose names
14// are listed in the copyright file included with this source
15// distribution.
16//
17// ECOGEN is free software: you can redistribute it and/or modify
18// it under the terms of the GNU General Public License as published
19// by the Free Software Foundation, either version 3 of the License,
20// or (at your option) any later version.
21//
22// ECOGEN is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with ECOGEN (file LICENSE).
29// If not, see <http://www.gnu.org/licenses/>.
30
31#ifndef TENSOR_H
32#define TENSOR_H
33
34#include "../Errors.h"
35#include <array>
36
37class Tensor;
38#include "Coord.h"
39
41enum TensorElement { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };
42
45class Tensor
46{
47 public:
48 Tensor();
49 Tensor(const Tensor& tensor);
50 Tensor(const double &xx, const double &xy, const double &xz, const double &yx, const double &yy, const double &yz, const double &zx, const double &zy, const double &zz);
51 Tensor(const Coord &x, const Coord &y, const Coord &z);
52 ~Tensor();
53
56 static const Tensor defaultTensor;
60
62 const double& getElement(const int& element) const { return m_array[element]; }
64 const double& getXX() const { return m_array[XX]; }
66 const double& getXY() const { return m_array[XY]; }
68 const double& getXZ() const { return m_array[XZ]; }
70 const double& getYX() const { return m_array[YX]; }
72 const double& getYY() const { return m_array[YY]; }
74 const double& getYZ() const { return m_array[YZ]; }
76 const double& getZX() const { return m_array[ZX]; }
78 const double& getZY() const { return m_array[ZY]; }
80 const double& getZZ() const { return m_array[ZZ]; }
83 void setXX(const double& xx);
86 void setXY(const double& xy);
89 void setXZ(const double& xz);
92 void setYX(const double& xx);
95 void setYY(const double& xy);
98 void setYZ(const double& xz);
101 void setZX(const double& xx);
104 void setZY(const double& xy);
107 void setZZ(const double& xz);
110 void setTensor(const Tensor& tensor);
113 void setTensor(const double& value);
115 void identity();
117 void correctZeros();
118
121 Coord scalar(const Coord& a) const;
126 void localProjection(const Coord& normal, const Coord& tangent, const Coord& binormal);
131 void reverseProjection(const Coord& normal, const Coord& tangent, const Coord& binormal);
132 void setTensorByLines(const Coord& x, const Coord& y, const Coord& z);
133 void setTensorByColumns(const Coord& x, const Coord& y, const Coord& z);
134
139 void tensorToCoords(Coord& x, Coord& y, Coord& z) const;
142 void tensorToArray(double* array) const;
145 void arrayToTensor(const double* array);
146
149 void transpose(Tensor& transposedTensor) const;
153 void matrixProduct(const Tensor& tensor2, Tensor& resultingTensor) const;
155 double trace() const;
157 double determinant() const;
160 void inverse(Tensor& inverseTensor) const;
161
163 bool isIdentity() const;
164
168 void eigen(Tensor& eigenvalues, Tensor& eigenvectors) const;
169
170 //Operator surcharges
171 Tensor& operator=(const double& scalar);
172 Tensor& operator=(const Tensor& a);
173 Tensor& operator*= (const double& scalar);
174 Tensor& operator/= (const double& scalar);
175 Tensor operator* (const double& scalar) const;
176 Tensor operator/ (const double& scalar) const;
177 Tensor& operator+= (const Tensor& a);
178 Tensor& operator-= (const Tensor& a);
179
180 protected:
181 std::array<double, 9> m_array;
182};
183
184extern Tensor tensorBuff;
186extern Tensor tensorCobase;
188extern Tensor tensorF;
189extern Tensor tensorG;
190extern Tensor tensorG2;
191extern Tensor tensorA;
193extern Tensor tensorP;
195extern Tensor tensorD;
196
197//Extern operator surcharges of the class because they take two arguments
198Tensor operator* (const double& scalar, const Tensor& a);
199Tensor operator+ (const Tensor& a, const Tensor& b);
200Tensor operator- (const Tensor& a, const Tensor& b);
201
202#endif // TENSOR_H
Tensor tensorEigenvalues
Definition Tensor.cpp:41
Tensor tensorG2
Definition Tensor.cpp:39
Tensor tensorNonConsCobase
Definition Tensor.cpp:36
TensorElement
Enumeration for the tensor elements.
Definition Tensor.h:41
@ ZZ
Definition Tensor.h:41
@ XY
Definition Tensor.h:41
@ XZ
Definition Tensor.h:41
@ YZ
Definition Tensor.h:41
@ YX
Definition Tensor.h:41
@ YY
Definition Tensor.h:41
@ XX
Definition Tensor.h:41
@ ZX
Definition Tensor.h:41
@ ZY
Definition Tensor.h:41
Tensor tensorCobase
Definition Tensor.cpp:35
Tensor tensorD
Definition Tensor.cpp:44
Tensor tensorP
Definition Tensor.cpp:42
Tensor operator*(const double &scalar, const Tensor &a)
Definition Tensor.cpp:576
Tensor tensorBuff
Definition Tensor.cpp:33
Tensor operator+(const Tensor &a, const Tensor &b)
Definition Tensor.cpp:585
Tensor tensorA
Definition Tensor.cpp:40
Tensor tensorG
Definition Tensor.cpp:38
Tensor operator-(const Tensor &a, const Tensor &b)
Definition Tensor.cpp:594
Tensor tensorF
Definition Tensor.cpp:37
Tensor tensorPinverse
Definition Tensor.cpp:43
Tensor tensorIdentity
Definition Tensor.cpp:34
Class for a coordinate system object such as coordinates of the vertex or a vector.
Definition Coord.h:43
Class for a matrix 3x3 system object.
Definition Tensor.h:46
void setYZ(const double &xz)
Set the value in the yz-element of the Tensor object.
Definition Tensor.cpp:130
void setTensorByColumns(const Coord &x, const Coord &y, const Coord &z)
Definition Tensor.cpp:284
void correctZeros()
Set to perfect zero each of the epsilon terms.
Definition Tensor.cpp:181
void matrixProduct(const Tensor &tensor2, Tensor &resultingTensor) const
Compute the matrix product of the two tensors.
Definition Tensor.cpp:345
const double & getZX() const
Return the value of the zx-element of the Tensor object.
Definition Tensor.h:76
const double & getXZ() const
Return the value of the xz-element of the Tensor object.
Definition Tensor.h:68
bool isIdentity() const
Return true if equal to identity.
Definition Tensor.cpp:408
void setZZ(const double &xz)
Set the value in the zz-element of the Tensor object.
Definition Tensor.cpp:142
void setZY(const double &xy)
Set the value in the zy-element of the Tensor object.
Definition Tensor.cpp:138
void transpose(Tensor &transposedTensor) const
Compute the transpose of the tensor.
Definition Tensor.cpp:328
void setXZ(const double &xz)
Set the value in the xz-element of the Tensor object.
Definition Tensor.cpp:118
double determinant() const
Return the determinant of the tensor.
Definition Tensor.cpp:378
std::array< double, 9 > m_array
Definition Tensor.h:181
Tensor()
Definition Tensor.cpp:46
Tensor & operator*=(const double &scalar)
Definition Tensor.cpp:517
void setYY(const double &xy)
Set the value in the yy-element of the Tensor object.
Definition Tensor.cpp:126
double trace() const
Return the trace of the tensor.
Definition Tensor.cpp:371
~Tensor()
Definition Tensor.cpp:98
void tensorToArray(double *array) const
Transform the Tensor into 1D array (pointer)
Definition Tensor.cpp:310
void setTensor(const Tensor &tensor)
Set the Tensor object.
Definition Tensor.cpp:146
Tensor & operator-=(const Tensor &a)
Definition Tensor.cpp:565
const double & getElement(const int &element) const
Return the value of the specific element of the Tensor object.
Definition Tensor.h:62
void localProjection(const Coord &normal, const Coord &tangent, const Coord &binormal)
Projection in the local coordinate system which is defined by the transmitted normal,...
Definition Tensor.cpp:200
void reverseProjection(const Coord &normal, const Coord &tangent, const Coord &binormal)
Reverse projection in the absolute Cartesian coordinate system.
Definition Tensor.cpp:234
void eigen(Tensor &eigenvalues, Tensor &eigenvectors) const
Compute the eigenvalues and eigenvectors of the tensor with Jacobi's algorithm.
Definition Tensor.cpp:428
const double & getZY() const
Return the value of the zy-element of the Tensor object.
Definition Tensor.h:78
Coord scalar(const Coord &a) const
Return the scalar product between the Tensor and the Coord.
Definition Tensor.cpp:190
const double & getYX() const
Return the value of the yx-element of the Tensor object.
Definition Tensor.h:70
void setZX(const double &xx)
Set the value in the zx-element of the Tensor object.
Definition Tensor.cpp:134
static const Tensor defaultTensor
Default Tensor object (const version)
Definition Tensor.h:56
void setXX(const double &xx)
Set the value in the xx-element of the Tensor object.
Definition Tensor.cpp:110
void setTensorByLines(const Coord &x, const Coord &y, const Coord &z)
Definition Tensor.cpp:267
Tensor & operator+=(const Tensor &a)
Definition Tensor.cpp:555
void tensorToCoords(Coord &x, Coord &y, Coord &z) const
Transform the Tensor into Coords (vectors)
Definition Tensor.cpp:301
static Tensor defaultTensorNonConst
Default Tensor object (non-const version)
Definition Tensor.h:59
Tensor & operator/=(const double &scalar)
Definition Tensor.cpp:527
const double & getYY() const
Return the value of the yy-element of the Tensor object.
Definition Tensor.h:72
Tensor operator/(const double &scalar) const
Definition Tensor.cpp:546
const double & getZZ() const
Return the value of the zz-element of the Tensor object.
Definition Tensor.h:80
void setXY(const double &xy)
Set the value in the xy-element of the Tensor object.
Definition Tensor.cpp:114
const double & getXX() const
Return the value of the xx-element of the Tensor object.
Definition Tensor.h:64
void inverse(Tensor &inverseTensor) const
Compute the inverse of the tensor.
Definition Tensor.cpp:387
void setYX(const double &xx)
Set the value in the yx-element of the Tensor object.
Definition Tensor.cpp:122
void identity()
Set the Tensor object to identity.
Definition Tensor.cpp:164
Tensor & operator=(const double &scalar)
Definition Tensor.cpp:497
void arrayToTensor(const double *array)
Transform the 1D array (pointer) into Tensor.
Definition Tensor.cpp:319
const double & getYZ() const
Return the value of the yz-element of the Tensor object.
Definition Tensor.h:74
const double & getXY() const
Return the value of the xy-element of the Tensor object.
Definition Tensor.h:66
Tensor operator*(const double &scalar) const
Definition Tensor.cpp:537