1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
42 //- Return tensor transpose
44 inline tensor2 tensor2::T() const
48 transpose[0] = this->operator[](0);
49 transpose[1] = this->operator[](2);
50 transpose[2] = this->operator[](1);
51 transpose[3] = this->operator[](3);
57 //- Assign to a sphericalTensor2
59 inline void tensor2::operator=(const sphericalTensor2& st)
68 //- Assign to a diagTensor2
70 inline void tensor2::operator=(const diagTensor2& dt)
78 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
80 //- Inner-product between two tensors
82 operator&(const tensor2& t1, const tensor2& t2)
86 result[0] = t1[0]*t2[0] + t1[1]*t2[2];
87 result[1] = t1[0]*t2[1] + t1[1]*t2[3];
88 result[2] = t1[2]*t2[0] + t1[3]*t2[2];
89 result[3] = t1[2]*t2[1] + t1[3]*t2[3];
95 //- Inner-product between a diagonal tensors and a tensor
97 operator&(const diagTensor2& dt1, const tensor2& t2)
101 result[0] = dt1[0]*t2[0];
102 result[1] = dt1[0]*t2[1];
103 result[2] = dt1[1]*t2[2];
104 result[3] = dt1[1]*t2[3];
109 //- Inner-product between a tensor and diagonal tensor
111 operator&(const tensor2& t1, const diagTensor2& dt2)
115 result[0] = t1[0]*dt2[0];
116 result[1] = t1[1]*dt2[1];
117 result[2] = t1[2]*dt2[0];
118 result[3] = t1[3]*dt2[1];
124 //- Inner-product between a spherical tensor and a tensor
126 operator&(const sphericalTensor2& st1, const tensor2& t2)
130 result[0] = st1[0]*t2[0];
131 result[1] = st1[0]*t2[1];
132 result[2] = st1[0]*t2[2];
133 result[3] = st1[0]*t2[3];
138 //- Inner-product between a tensor and spherical tensor
140 operator&(const tensor2& t1, const sphericalTensor2& st2)
144 result[0] = t1[0]*st2[0];
145 result[1] = t1[1]*st2[0];
146 result[2] = t1[2]*st2[0];
147 result[3] = t1[3]*st2[0];
153 //- Inner-product between a tensor and a vector
155 operator&(const tensor2& t, const vector2& v)
159 result[0] = t[0]*v[0] + t[1]*v[1];
160 result[1] = t[2]*v[0] + t[3]*v[1];
166 //- Inner-product between a vector and a tensor
168 operator&(const vector2& v, const tensor2& t)
172 result[0] = v[0]*t[0] + v[1]*t[2];
173 result[1] = v[0]*t[1] + v[1]*t[3];
179 //- Outer-product between two vectors
181 operator*(const vector2& v1, const vector2& v2)
185 result[0] = v1[0]*v2[0];
186 result[1] = v1[0]*v2[1];
187 result[2] = v1[1]*v2[0];
188 result[3] = v1[1]*v2[1];
194 //- Return the determinant of a tensor
195 inline scalar det(const tensor2& t)
203 //- Return the inverse of a tensor given the determinant
204 inline tensor2 inv(const tensor2& t)
213 return cofactor/det(t);
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace Foam
221 // ************************************************************************* //