1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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/>.
31 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 //- Return the Average of a vector of as a scalar
41 template <class Cmpt, int length>
42 inline void contractScalar(Cmpt& result, const VectorN<Cmpt, length>& t)
44 result = pTraits<Cmpt>::zero;
46 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
51 //- Modified 2009/11/3 by I. Clifford
52 result *= 1.0/VectorN<Cmpt, length>::nComponents;
56 //- Return the Average of a vector of as a scalar
57 template <class Cmpt, int length>
58 inline Cmpt contractScalar(const VectorN<Cmpt, length>& t)
61 contractScalar(result, t);
66 //- Return the diagonal of a TensorN as a scalar
67 template <class Cmpt, int length>
68 inline void contractScalar(Cmpt& result, const TensorN<Cmpt, length>& t)
70 result = pTraits<Cmpt>::zero;
73 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
76 j += TensorN<Cmpt, length>::rowLength+1;
79 //- Modified 2009/11/3 by I. Clifford
80 result *= 1.0/TensorN<Cmpt, length>::rowLength;
84 //- Return the diagonal of a TensorN as a scalar
85 template <class Cmpt, int length>
86 inline Cmpt contractScalar(const TensorN<Cmpt, length>& t)
89 contractScalar(result, t);
94 //- Return the diagonal of a DiagTensorN as a scalar
95 template <class Cmpt, int length>
96 inline void contractScalar(Cmpt& result, const DiagTensorN<Cmpt, length>& t)
98 result = pTraits<Cmpt>::zero;
100 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
105 result *= 1.0/TensorN<Cmpt, length>::rowLength;
109 //- Return the diagonal of a DiagTensorN as a scalar
110 template <class Cmpt, int length>
111 inline Cmpt contractScalar(const DiagTensorN<Cmpt, length>& t)
114 contractScalar(result, t);
119 //- Return the diagonal of a SphericalTensorN as a scalar
120 template <class Cmpt, int length>
121 inline void contractScalar(Cmpt& result, const SphericalTensorN<Cmpt, length>& t)
127 //- Return the diagonal of a SphericalTensorN as a scalar
128 template <class Cmpt, int length>
129 inline Cmpt contractScalar(const SphericalTensorN<Cmpt, length>& t)
132 contractScalar(result, t);
137 //- Return the diagonal of a TensorN as a vector
138 template <class Cmpt, int length>
139 inline void contractLinear
141 VectorN<Cmpt, length>& result,
142 const TensorN<Cmpt, length>& t
146 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
149 j += TensorN<Cmpt, length>::rowLength+1;
154 //- Return the diagonal of a TensorN as a vector
155 template <class Cmpt, int length>
156 inline VectorN<Cmpt, length> contractLinear(const TensorN<Cmpt, length>& t)
158 VectorN<Cmpt, length> result;
159 contractLinear(result, t);
164 //- Return the diagonal of a DiagTensorN as a vector
165 template <class Cmpt, int length>
166 inline void contractLinear
168 VectorN<Cmpt, length>& result,
169 const DiagTensorN<Cmpt, length>& t
172 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
179 //- Return the diagonal of a DiagTensorN as a vector
180 template <class Cmpt, int length>
181 inline VectorN<Cmpt, length> contractLinear(const DiagTensorN<Cmpt, length>& t)
183 VectorN<Cmpt, length> result;
184 contractLinear(result, t);
189 //- Return the diagonal of a SphericalTensorN as a vector
190 template <class Cmpt, int length>
191 inline void contractLinear
193 VectorN<Cmpt, length>& result,
194 const SphericalTensorN<Cmpt, length>& t
197 for (int i = 0; i < SphericalTensorN<Cmpt, length>::rowLength; i++)
204 //- Return the diagonal of a SphericalTensorN as a vector
205 template <class Cmpt, int length>
206 inline VectorN<Cmpt, length> contractLinear
208 const SphericalTensorN<Cmpt, length>& t
211 VectorN<Cmpt, length> result;
212 contractLinear(result, t);
217 //- Return the VectorN given a scalar
218 template <class Cmpt, int length>
219 inline void expandScalar(VectorN<Cmpt, length>& result, const Cmpt& v)
221 for (int i = 0; i < VectorN<Cmpt, length>::nComponents; i++)
228 //- Return the TensorN given a scalar
229 template <class Cmpt, int length>
230 inline void expandScalar(TensorN<Cmpt, length>& result, const Cmpt& v)
232 result = TensorN<Cmpt, length>::zero;
235 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
238 j += TensorN<Cmpt, length>::rowLength+1;
243 //- Return the DiagTensorN given a scalar
244 template <class Cmpt, int length>
245 inline void expandScalar(DiagTensorN<Cmpt, length>& result, const Cmpt& v)
247 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
254 //- Return the SphericalTensorN given a scalar
255 template <class Cmpt, int length>
256 inline void expandScalar(SphericalTensorN<Cmpt, length>& result, const Cmpt& v)
262 //- Return the TensorN given a diagonal vectorN
263 template <class Cmpt, int length>
264 inline void expandLinear
266 TensorN<Cmpt, length>& result,
267 const VectorN<Cmpt, length>& v
270 result = TensorN<Cmpt, length>::zero;
273 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
276 j += TensorN<Cmpt, length>::rowLength+1;
280 //- Return the DiagTensorN given a diagonal vectorN
281 template <class Cmpt, int length>
282 inline void expandLinear
284 DiagTensorN<Cmpt, length>& result,
285 const VectorN<Cmpt, length>& v
288 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
295 //- Return the SphericalTensorN given a diagonal vectorN
296 template <class Cmpt, int length>
297 inline void expandLinear
299 SphericalTensorN<Cmpt, length>& result,
300 const VectorN<Cmpt, length>& v
303 result[0] = pTraits<Cmpt>::zero;
305 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
310 result[0] *= 1.0/DiagTensorN<Cmpt, length>::rowLength;
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 // ************************************************************************* //