ECOGEN 6.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
53
56class Tensor
57{
58 public:
59 Tensor();
60 Tensor(const Tensor& tensor);
61 Tensor(const double& xx,
62 const double& xy,
63 const double& xz,
64 const double& yx,
65 const double& yy,
66 const double& yz,
67 const double& zx,
68 const double& zy,
69 const double& zz);
70 Tensor(const Coord& x, const Coord& y, const Coord& z);
71 ~Tensor();
72
75 static const Tensor defaultTensor;
79
81 const double& getElement(const int& element) const { return m_array[element]; }
83 const double& getXX() const { return m_array[XX]; }
85 const double& getXY() const { return m_array[XY]; }
87 const double& getXZ() const { return m_array[XZ]; }
89 const double& getYX() const { return m_array[YX]; }
91 const double& getYY() const { return m_array[YY]; }
93 const double& getYZ() const { return m_array[YZ]; }
95 const double& getZX() const { return m_array[ZX]; }
97 const double& getZY() const { return m_array[ZY]; }
99 const double& getZZ() const { return m_array[ZZ]; }
102 void setXX(const double& xx);
105 void setXY(const double& xy);
108 void setXZ(const double& xz);
111 void setYX(const double& xx);
114 void setYY(const double& xy);
117 void setYZ(const double& xz);
120 void setZX(const double& xx);
123 void setZY(const double& xy);
126 void setZZ(const double& xz);
129 void setTensor(const Tensor& tensor);
132 void setTensor(const double& value);
134 void identity();
136 void correctZeros();
137
140 Coord scalar(const Coord& a) const;
145 void localProjection(const Coord& normal, const Coord& tangent, const Coord& binormal);
150 void reverseProjection(const Coord& normal, const Coord& tangent, const Coord& binormal);
151 void setTensorByLines(const Coord& x, const Coord& y, const Coord& z);
152 void setTensorByColumns(const Coord& x, const Coord& y, const Coord& z);
153
158 void tensorToCoords(Coord& x, Coord& y, Coord& z) const;
161 void tensorToArray(double* array) const;
164 void arrayToTensor(const double* array);
165
168 void transpose(Tensor& transposedTensor) const;
172 void matrixProduct(const Tensor& tensor2, Tensor& resultingTensor) const;
174 double trace() const;
176 double determinant() const;
179 void inverse(Tensor& inverseTensor) const;
181 double infinityNorm() const;
183 double frobeniusNorm() const;
186 void exponentialPade(Tensor& tensorExpPade);
187
189 bool isIdentity() const;
190
194 void eigen(Tensor& eigenvalues, Tensor& eigenvectors) const;
195
196 //Operator surcharges
197 Tensor& operator=(const double& scalar);
198 Tensor& operator=(const Tensor& a);
199 Tensor& operator*=(const double& scalar);
200 Tensor& operator/=(const double& scalar);
201 Tensor operator*(const double& scalar) const;
202 Tensor operator/(const double& scalar) const;
203 Tensor& operator+=(const Tensor& a);
204 Tensor& operator-=(const Tensor& a);
205
206 protected:
207 std::array<double, 9> m_array;
208};
209
210//KS//Clean up unused variables
211extern Tensor tensorBuff;
212extern Tensor tensorBuff2;
214extern Tensor tensorCobase;
216extern Tensor tensorF;
217extern Tensor tensorG;
218extern Tensor tensorG2;
219extern Tensor tensorA;
221extern Tensor tensorP;
223extern Tensor tensorD;
225extern Tensor tensorPade;
226extern Tensor tensorX2;
227extern Tensor tensorX4;
228extern Tensor tensorX6;
229extern Tensor tensorU;
230extern Tensor tensorV;
231extern Tensor tensorQ;
232extern Tensor tensorStrainRate; //<! S: Strain rate tensor (gradU)
233extern Tensor tensorStrainRateTranspose; //<! S^T: Transposed strain rate tensor (gradU)
234
235//Extern operator surcharges of the class because they take two arguments
236Tensor operator*(const double& scalar, const Tensor& a);
237Tensor operator+(const Tensor& a, const Tensor& b);
238Tensor operator-(const Tensor& a, const Tensor& b);
239
240#endif // TENSOR_H
Tensor tensorStrainRateTranspose
Definition Tensor.cpp:55
Tensor tensorEigenvalues
Definition Tensor.cpp:42
Tensor tensorG2
Definition Tensor.cpp:40
Tensor tensorPade
Definition Tensor.cpp:47
Tensor tensorNonConsCobase
Definition Tensor.cpp:37
Tensor tensorCobase
Definition Tensor.cpp:36
Tensor tensorD
Definition Tensor.cpp:45
Tensor tensorU
Definition Tensor.cpp:51
Tensor tensorP
Definition Tensor.cpp:43
Tensor tensorX4
Definition Tensor.cpp:49
Tensor tensorBuff
Definition Tensor.cpp:33
Tensor tensorX2
Definition Tensor.cpp:48
Tensor tensorV
Definition Tensor.cpp:52
Tensor tensorStrainRate
Definition Tensor.cpp:54
Tensor tensorA
Definition Tensor.cpp:41
Tensor tensorG
Definition Tensor.cpp:39
Tensor tensorBuff2
Definition Tensor.cpp:34
Tensor tensorQ
Definition Tensor.cpp:53
Tensor tensorX6
Definition Tensor.cpp:50
Tensor tensorF
Definition Tensor.cpp:38
Tensor tensorPinverse
Definition Tensor.cpp:44
Tensor tensorDLogCobaseDt
Definition Tensor.cpp:46
Tensor tensorIdentity
Definition Tensor.cpp:35
TensorElement
Enumeration for the tensor elements.
Definition Tensor.h:42
@ ZZ
Definition Tensor.h:51
@ XY
Definition Tensor.h:44
@ XZ
Definition Tensor.h:45
@ YZ
Definition Tensor.h:48
@ YX
Definition Tensor.h:46
@ YY
Definition Tensor.h:47
@ XX
Definition Tensor.h:43
@ ZX
Definition Tensor.h:49
@ ZY
Definition Tensor.h:50
Tensor operator*(const double &scalar, const Tensor &a)
Definition Tensor.cpp:656
Tensor operator+(const Tensor &a, const Tensor &b)
Definition Tensor.cpp:665
Tensor operator-(const Tensor &a, const Tensor &b)
Definition Tensor.cpp:674
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:57
void setYZ(const double &xz)
Set the value in the yz-element of the Tensor object.
Definition Tensor.cpp:149
void setTensorByColumns(const Coord &x, const Coord &y, const Coord &z)
Definition Tensor.cpp:305
void correctZeros()
Set to perfect zero each of the epsilon terms.
Definition Tensor.cpp:200
void matrixProduct(const Tensor &tensor2, Tensor &resultingTensor) const
Compute the matrix product of the two tensors.
Definition Tensor.cpp:366
const double & getZX() const
Return the value of the zx-element of the Tensor object.
Definition Tensor.h:95
const double & getXZ() const
Return the value of the xz-element of the Tensor object.
Definition Tensor.h:87
bool isIdentity() const
Return true if equal to identity.
Definition Tensor.cpp:427
void setZZ(const double &xz)
Set the value in the zz-element of the Tensor object.
Definition Tensor.cpp:161
void setZY(const double &xy)
Set the value in the zy-element of the Tensor object.
Definition Tensor.cpp:157
void transpose(Tensor &transposedTensor) const
Compute the transpose of the tensor.
Definition Tensor.cpp:349
void setXZ(const double &xz)
Set the value in the xz-element of the Tensor object.
Definition Tensor.cpp:137
double determinant() const
Return the determinant of the tensor.
Definition Tensor.cpp:396
std::array< double, 9 > m_array
Definition Tensor.h:207
Tensor()
Definition Tensor.cpp:57
Tensor & operator*=(const double &scalar)
Definition Tensor.cpp:597
void setYY(const double &xy)
Set the value in the yy-element of the Tensor object.
Definition Tensor.cpp:145
double trace() const
Return the trace of the tensor.
Definition Tensor.cpp:392
~Tensor()
Definition Tensor.cpp:117
void tensorToArray(double *array) const
Transform the Tensor into 1D array (pointer).
Definition Tensor.cpp:331
void setTensor(const Tensor &tensor)
Set the Tensor object.
Definition Tensor.cpp:165
Tensor & operator-=(const Tensor &a)
Definition Tensor.cpp:645
const double & getElement(const int &element) const
Return the value of the specific element of the Tensor object.
Definition Tensor.h:81
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:219
void reverseProjection(const Coord &normal, const Coord &tangent, const Coord &binormal)
Reverse projection in the absolute Cartesian coordinate system.
Definition Tensor.cpp:255
void eigen(Tensor &eigenvalues, Tensor &eigenvectors) const
Compute the eigenvalues and eigenvectors of the tensor with Jacobi's algorithm.
Definition Tensor.cpp:499
const double & getZY() const
Return the value of the zy-element of the Tensor object.
Definition Tensor.h:97
double infinityNorm() const
Compute the infinity norm of the tensor.
Definition Tensor.cpp:448
Coord scalar(const Coord &a) const
Return the scalar product between the Tensor and the Coord.
Definition Tensor.cpp:209
const double & getYX() const
Return the value of the yx-element of the Tensor object.
Definition Tensor.h:89
void setZX(const double &xx)
Set the value in the zx-element of the Tensor object.
Definition Tensor.cpp:153
static const Tensor defaultTensor
Default Tensor object (const version).
Definition Tensor.h:75
void setXX(const double &xx)
Set the value in the xx-element of the Tensor object.
Definition Tensor.cpp:129
void setTensorByLines(const Coord &x, const Coord &y, const Coord &z)
Definition Tensor.cpp:288
Tensor & operator+=(const Tensor &a)
Definition Tensor.cpp:635
void exponentialPade(Tensor &tensorExpPade)
Compute the exponential of the tensor using a Padé 6*6 algorithm.
Definition Tensor.cpp:473
void tensorToCoords(Coord &x, Coord &y, Coord &z) const
Transform the Tensor into Coords (vectors).
Definition Tensor.cpp:322
static Tensor defaultTensorNonConst
Default Tensor object (non-const version).
Definition Tensor.h:78
Tensor & operator/=(const double &scalar)
Definition Tensor.cpp:607
const double & getYY() const
Return the value of the yy-element of the Tensor object.
Definition Tensor.h:91
Tensor operator/(const double &scalar) const
Definition Tensor.cpp:626
const double & getZZ() const
Return the value of the zz-element of the Tensor object.
Definition Tensor.h:99
void setXY(const double &xy)
Set the value in the xy-element of the Tensor object.
Definition Tensor.cpp:133
const double & getXX() const
Return the value of the xx-element of the Tensor object.
Definition Tensor.h:83
void inverse(Tensor &inverseTensor) const
Compute the inverse of the tensor.
Definition Tensor.cpp:405
void setYX(const double &xx)
Set the value in the yx-element of the Tensor object.
Definition Tensor.cpp:141
double frobeniusNorm() const
Compute the Frobenius (L2) norm of the tensor.
Definition Tensor.cpp:462
void identity()
Set the Tensor object to identity.
Definition Tensor.cpp:183
Tensor & operator=(const double &scalar)
Definition Tensor.cpp:577
void arrayToTensor(const double *array)
Transform the 1D array (pointer) into Tensor.
Definition Tensor.cpp:340
const double & getYZ() const
Return the value of the yz-element of the Tensor object.
Definition Tensor.h:93
const double & getXY() const
Return the value of the xy-element of the Tensor object.
Definition Tensor.h:85
Tensor operator*(const double &scalar) const
Definition Tensor.cpp:617