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
32 \*---------------------------------------------------------------------------*/
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 //- Return the Average of a vector of as a scalar
42 template <class Cmpt, int length>
43 inline void contractScalar(Cmpt& result, const VectorN<Cmpt, length>& t)
45 result = pTraits<Cmpt>::zero;
47 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
52 //- Modified 2009/11/3 by I. Clifford
53 result *= 1.0/VectorN<Cmpt, length>::nComponents;
57 //- Return the Average of a vector of as a scalar
58 template <class Cmpt, int length>
59 inline Cmpt contractScalar(const VectorN<Cmpt, length>& t)
62 contractScalar(result, t);
67 //- Return the diagonal of a TensorN as a scalar
68 template <class Cmpt, int length>
69 inline void contractScalar(Cmpt& result, const TensorN<Cmpt, length>& t)
71 result = pTraits<Cmpt>::zero;
74 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
77 j += TensorN<Cmpt, length>::rowLength+1;
80 //- Modified 2009/11/3 by I. Clifford
81 result *= 1.0/TensorN<Cmpt, length>::rowLength;
85 //- Return the diagonal of a TensorN as a scalar
86 template <class Cmpt, int length>
87 inline Cmpt contractScalar(const TensorN<Cmpt, length>& t)
90 contractScalar(result, t);
95 //- Return the diagonal of a DiagTensorN as a scalar
96 template <class Cmpt, int length>
97 inline void contractScalar(Cmpt& result, const DiagTensorN<Cmpt, length>& t)
99 result = pTraits<Cmpt>::zero;
101 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
106 result *= 1.0/TensorN<Cmpt, length>::rowLength;
110 //- Return the diagonal of a DiagTensorN as a scalar
111 template <class Cmpt, int length>
112 inline Cmpt contractScalar(const DiagTensorN<Cmpt, length>& t)
115 contractScalar(result, t);
120 //- Return the diagonal of a SphericalTensorN as a scalar
121 template <class Cmpt, int length>
122 inline void contractScalar(Cmpt& result, const SphericalTensorN<Cmpt, length>& t)
128 //- Return the diagonal of a SphericalTensorN as a scalar
129 template <class Cmpt, int length>
130 inline Cmpt contractScalar(const SphericalTensorN<Cmpt, length>& t)
133 contractScalar(result, t);
138 //- Return the diagonal of a TensorN as a vector
139 template <class Cmpt, int length>
140 inline void contractLinear
142 VectorN<Cmpt, length>& result,
143 const TensorN<Cmpt, length>& t
147 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
150 j += TensorN<Cmpt, length>::rowLength+1;
155 //- Return the diagonal of a TensorN as a vector
156 template <class Cmpt, int length>
157 inline VectorN<Cmpt, length> contractLinear(const TensorN<Cmpt, length>& t)
159 VectorN<Cmpt, length> result;
160 contractLinear(result, t);
165 //- Return the diagonal of a DiagTensorN as a vector
166 template <class Cmpt, int length>
167 inline void contractLinear
169 VectorN<Cmpt, length>& result,
170 const DiagTensorN<Cmpt, length>& t
173 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
180 //- Return the diagonal of a DiagTensorN as a vector
181 template <class Cmpt, int length>
182 inline VectorN<Cmpt, length> contractLinear(const DiagTensorN<Cmpt, length>& t)
184 VectorN<Cmpt, length> result;
185 contractLinear(result, t);
190 //- Return the diagonal of a SphericalTensorN as a vector
191 template <class Cmpt, int length>
192 inline void contractLinear
194 VectorN<Cmpt, length>& result,
195 const SphericalTensorN<Cmpt, length>& t
198 for (int i = 0; i < SphericalTensorN<Cmpt, length>::rowLength; i++)
205 //- Return the diagonal of a SphericalTensorN as a vector
206 template <class Cmpt, int length>
207 inline VectorN<Cmpt, length> contractLinear
209 const SphericalTensorN<Cmpt, length>& t
212 VectorN<Cmpt, length> result;
213 contractLinear(result, t);
218 //- Return the VectorN given a scalar
219 template <class Cmpt, int length>
220 inline void expandScalar(VectorN<Cmpt, length>& result, const Cmpt& v)
222 for (int i = 0; i < VectorN<Cmpt, length>::nComponents; i++)
229 //- Return the TensorN given a scalar
230 template <class Cmpt, int length>
231 inline void expandScalar(TensorN<Cmpt, length>& result, const Cmpt& v)
233 result = TensorN<Cmpt, length>::zero;
236 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
239 j += TensorN<Cmpt, length>::rowLength+1;
244 //- Return the DiagTensorN given a scalar
245 template <class Cmpt, int length>
246 inline void expandScalar(DiagTensorN<Cmpt, length>& result, const Cmpt& v)
248 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
255 //- Return the SphericalTensorN given a scalar
256 template <class Cmpt, int length>
257 inline void expandScalar(SphericalTensorN<Cmpt, length>& result, const Cmpt& v)
263 //- Return the TensorN given a diagonal vectorN
264 template <class Cmpt, int length>
265 inline void expandLinear
267 TensorN<Cmpt, length>& result,
268 const VectorN<Cmpt, length>& v
271 result = TensorN<Cmpt, length>::zero;
274 for (int i = 0; i < TensorN<Cmpt, length>::rowLength; i++)
277 j += TensorN<Cmpt, length>::rowLength+1;
281 //- Return the DiagTensorN given a diagonal vectorN
282 template <class Cmpt, int length>
283 inline void expandLinear
285 DiagTensorN<Cmpt, length>& result,
286 const VectorN<Cmpt, length>& v
289 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
296 //- Return the SphericalTensorN given a diagonal vectorN
297 template <class Cmpt, int length>
298 inline void expandLinear
300 SphericalTensorN<Cmpt, length>& result,
301 const VectorN<Cmpt, length>& v
304 result[0] = pTraits<Cmpt>::zero;
306 for (int i = 0; i < DiagTensorN<Cmpt, length>::rowLength; i++)
311 result[0] *= 1.0/DiagTensorN<Cmpt, length>::rowLength;
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 } // End namespace Foam
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 // ************************************************************************* //