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
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 template <class Cmpt, int length>
35 const char* const DiagTensorN<Cmpt, length>::typeName =
36 ("diagTensor" + name(length)).c_str();
38 template <class Cmpt, int length>
39 const DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::zero(0);
41 template <class Cmpt, int length>
42 const DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::one(1);
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 template <class Cmpt, int length>
48 inline DiagTensorN<Cmpt, length>::DiagTensorN()
52 // Construct given VectorSpace
53 template <class Cmpt, int length>
54 inline DiagTensorN<Cmpt, length>::DiagTensorN
56 const VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>& vs
59 VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>(vs)
63 //- Construct from component
64 template <class Cmpt, int length>
65 inline DiagTensorN<Cmpt, length>::DiagTensorN(const Cmpt& tx)
67 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOpS(*this, tx, eqOp<Cmpt>());
71 // Construct from Istream
72 template <class Cmpt, int length>
73 inline DiagTensorN<Cmpt, length>::DiagTensorN(Istream& is)
75 VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>(is)
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 //- Return diagonal tensor diagonal
82 template <class Cmpt, int length>
83 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::diag() const
88 //- Return diagonal tensor transpose
89 template <class Cmpt, int length>
90 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::T() const
96 //- Assign to a SphericalTensorN
97 template <class Cmpt, int length>
98 inline void DiagTensorN<Cmpt, length>::operator=(const SphericalTensorN<Cmpt, length>& st)
100 const Cmpt& s = st.v_[0];
101 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOpS(*this, s, eqOp<Cmpt>());
104 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
106 //- Addition of DiagTensorN and DiagTensorN
107 template <class Cmpt, int length>
108 inline DiagTensorN<Cmpt,length>
109 operator+(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
111 DiagTensorN<Cmpt, length> res;
112 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::op(res, dt1, dt2, plusOp<Cmpt>());
117 //- Addition of DiagTensorN and SphericalTensorN
118 template <class Cmpt, int length>
119 inline DiagTensorN<Cmpt,length>
120 operator+(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
122 const Cmpt& s = st2.v_[0];
123 DiagTensorN<Cmpt, length> res;
124 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opVS(res, dt1, s, plusOp<Cmpt>());
129 //- Addition of SphericalTensorN and DiagTensorN
130 template <class Cmpt, int length>
131 inline DiagTensorN<Cmpt,length>
132 operator+(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
134 const Cmpt& s = st1.v_[0];
135 DiagTensorN<Cmpt, length> res;
136 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opSV(res, s, dt2, plusOp<Cmpt>());
141 //- Subtraction of DiagTensorN and DiagTensorN
142 template <class Cmpt, int length>
143 inline DiagTensorN<Cmpt,length>
144 operator-(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
146 DiagTensorN<Cmpt, length> res;
147 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::op(res, dt1, dt2, minusOp<Cmpt>());
152 //- Subtraction of DiagTensorN and SphericalTensorN
153 template <class Cmpt, int length>
154 inline DiagTensorN<Cmpt,length>
155 operator-(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
157 const Cmpt& s = st2.v_[0];
158 DiagTensorN<Cmpt, length> res;
159 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opVS(res, dt1, s, minusOp<Cmpt>());
164 //- Subtraction of SphericalTensorN and DiagTensorN
165 template <class Cmpt, int length>
166 inline DiagTensorN<Cmpt,length>
167 operator-(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
169 const Cmpt& s = st1.v_[0];
170 DiagTensorN<Cmpt, length> res;
171 VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opSV(res, s, dt2, minusOp<Cmpt>());
176 //- Inner-product between a diagonal tensor and a diagonal tensor
177 template <class Cmpt, int length>
179 innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
180 operator&(const DiagTensorN<Cmpt, length>& dt1, const DiagTensorN<Cmpt, length>& dt2)
182 DiagTensorN<Cmpt, length> res;
183 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::op(res, dt1, dt2, multiplyOp<Cmpt>());
188 //- Inner-product between spherical tensor and diagonal tensor
189 template <class Cmpt, int length>
191 innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
192 operator&(const SphericalTensorN<Cmpt, length>& st1, const DiagTensorN<Cmpt, length>& dt2)
194 const Cmpt& s = st1.v_[0];
195 DiagTensorN<Cmpt, length> res;
196 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt2, multiplyOp<Cmpt>());
201 //- Inner-product between diagonal tensor and spherical tensor
202 template <class Cmpt, int length>
204 innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
205 operator&(const DiagTensorN<Cmpt, length>& dt1, const SphericalTensorN<Cmpt, length>& st2)
207 const Cmpt& s = st2.v_[0];
208 DiagTensorN<Cmpt, length> res;
209 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVS(res, dt1, s, multiplyOp<Cmpt>());
214 //- Inner-product between a diagonal tensor and a vector
215 template <class Cmpt, int length>
217 innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >::type
218 operator&(const DiagTensorN<Cmpt, length>& dt, const VectorN<Cmpt, length>& v)
220 VectorN<Cmpt, length> res;
221 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV(res, dt, v, multiplyOp<Cmpt>());
227 //- Inner-product between a vector and a tensor
228 template <class Cmpt, int length>
230 innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
231 operator&(const VectorN<Cmpt, length>& v, const DiagTensorN<Cmpt, length>& dt)
233 VectorN<Cmpt, length> res;
234 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV(res, v, dt, multiplyOp<Cmpt>());
239 //- Division of a scalar by a diagonalTensor
240 template <class Cmpt, int length>
241 inline DiagTensorN<Cmpt, length>
242 operator/(const scalar s, const DiagTensorN<Cmpt, length>& dt)
244 DiagTensorN<Cmpt, length> res;
245 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt, divideOp3<Cmpt, scalar, Cmpt>());
250 //- Inner Product of a VectorN by an inverse diagonalTensor
251 template <class Cmpt, int length>
252 inline VectorN<Cmpt,length>
253 operator/(const VectorN<Cmpt,length>& v, const DiagTensorN<Cmpt,length>& dt)
255 VectorN<Cmpt, length> res(v);
256 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOp(res, dt, divideEqOp<Cmpt>());
261 //- Inner Product of a DiagTensorN and an inverse DiagTensorN
262 template <class Cmpt, int length>
263 inline DiagTensorN<Cmpt,length>
264 operator/(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
266 DiagTensorN<Cmpt, length> res;
267 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::op(res, dt1, dt2, divideOp<Cmpt>());
272 //- Inner Product of a SphericalTensorN and an inverse DiagTensorN
273 template <class Cmpt, int length>
274 inline DiagTensorN<Cmpt,length>
275 operator/(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
277 const Cmpt& s = st1.v_[0];
278 DiagTensorN<Cmpt, length> res;
279 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt2, divideOp<Cmpt>());
284 //- Inner Product of a DiagTensorN and an inverse SphericalTensorN
285 template <class Cmpt, int length>
286 inline DiagTensorN<Cmpt,length>
287 operator/(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
289 const Cmpt& s = st2.v_[0];
290 DiagTensorN<Cmpt, length> res;
291 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opVS(res, dt1, s, divideOp<Cmpt>());
296 //- Return the inverse of a diagonal tensor
297 template <class Cmpt, int length>
298 inline DiagTensorN<Cmpt, length> inv(const DiagTensorN<Cmpt, length>& dt)
300 DiagTensorN<Cmpt, length> res;
301 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, 1.0, dt, divideOp<Cmpt>());
306 //- Return tensor diagonal
307 template <class Cmpt, int length>
308 inline DiagTensorN<Cmpt, length> diag(const DiagTensorN<Cmpt, length>& dt)
314 //- Return the component sum
315 // template <class Cmpt, int length>
316 // inline Cmpt sum(const DiagTensorN<Cmpt, length>& dt)
318 // Cmpt result=Cmpt::zero;
319 // for(register label i=0; i<DiagTensorN<Cmpt, length>::nComponents; i++)
327 //- Transform the spherical tensor
328 //- The components are assumed to be individual scalars
329 //- i.e. transform has no effect
330 template<class Cmpt, int length>
331 inline DiagTensorN<Cmpt, length> transform
334 const DiagTensorN<Cmpt, length>& v
341 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
343 template<class Cmpt, int length>
344 class outerProduct<DiagTensorN<Cmpt, length>, Cmpt>
348 typedef DiagTensorN<Cmpt, length> type;
351 template<class Cmpt, int length>
352 class outerProduct<Cmpt, DiagTensorN<Cmpt, length> >
356 typedef DiagTensorN<Cmpt, length> type;
360 template<class Cmpt, int length>
361 class innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
365 typedef DiagTensorN<Cmpt, length> type;
369 template<class Cmpt, int length>
370 class innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
374 typedef DiagTensorN<Cmpt, length> type;
378 template<class Cmpt, int length>
379 class innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
383 typedef DiagTensorN<Cmpt, length> type;
387 template<class Cmpt, int length>
388 class innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
392 typedef VectorN<Cmpt, length> type;
396 template<class Cmpt, int length>
397 class innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >
401 typedef VectorN<Cmpt, length> type;
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 } // End namespace Foam
409 // ************************************************************************* //