1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Global functions for expansion and contraction of tensor coefficient
29 Hrvoje Jasak, Wikki Ltd. All rights reserved
31 \*---------------------------------------------------------------------------*/
33 #ifndef expandTensor_H
34 #define expandTensor_H
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 //- Return the diagonal of a tensor as a scalar
45 inline void contractScalar(Cmpt& result, const Tensor<Cmpt>& t)
47 result = 1.0/3.0*(t.xx() + t.yy() + t.zz());
51 //- Return the diagonal of a tensor as a scalar
53 inline Cmpt contractScalar(const Tensor<Cmpt>& t)
56 contractScalar(result, t);
61 //- Return the diagonal of a tensor as a vector
63 inline void contractLinear(Vector<Cmpt>& result, const Tensor<Cmpt>& t)
65 result = Vector<Cmpt>(t.xx(), t.yy(), t.zz());
69 //- Return the diagonal of a tensor as a vector
71 inline Vector<Cmpt> contractLinear(const Tensor<Cmpt>& t)
74 contractLinear(result, t);
79 //- Return the vector given a scalar
81 inline void expandScalar(Vector<Cmpt>& result, const Cmpt& v)
83 result = Vector<Cmpt>(v, v, v);
87 //- Return the tensor given a scalar
89 inline void expandScalar(Tensor<Cmpt>& result, const Cmpt& v)
93 v, pTraits<Cmpt>::zero, pTraits<Cmpt>::zero,
94 pTraits<Cmpt>::zero, v, pTraits<Cmpt>::zero,
95 pTraits<Cmpt>::zero, pTraits<Cmpt>::zero, v
100 //- Return the tensor given a diagonal vector
101 template <class Cmpt>
102 inline void expandLinear(Tensor<Cmpt>& result, const Vector<Cmpt>& v)
104 result = Tensor<Cmpt>
106 v.x(), pTraits<Cmpt>::zero, pTraits<Cmpt>::zero,
107 pTraits<Cmpt>::zero, v.y(), pTraits<Cmpt>::zero,
108 pTraits<Cmpt>::zero, pTraits<Cmpt>::zero, v.z()
113 } // End namespace Foam
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 // ************************************************************************* //