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/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 template <class Cmpt, int length>
34 const char* const DiagTensorN<Cmpt, length>::typeName =
35 ("diagTensor" + name(length)).c_str();
37 template <class Cmpt, int length>
38 const DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::zero(0);
40 template <class Cmpt, int length>
41 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
76 // Construct from Istream
77 template <class Cmpt, int length>
78 inline DiagTensorN<Cmpt, length>::DiagTensorN(Istream& is)
80 VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>(is)
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 //- Return diagonal tensor diagonal
87 template <class Cmpt, int length>
88 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::diag() const
93 //- Return diagonal tensor transpose
94 template <class Cmpt, int length>
95 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::T() const
101 //- Assign to a SphericalTensorN
102 template <class Cmpt, int length>
103 inline void DiagTensorN<Cmpt, length>::operator=
105 const SphericalTensorN<Cmpt, length>& st
108 const Cmpt& s = st.v_[0];
109 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOpS
117 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
119 //- Addition of DiagTensorN and DiagTensorN
120 template <class Cmpt, int length>
121 inline DiagTensorN<Cmpt, length>
124 const DiagTensorN<Cmpt, length>& dt1,
125 const DiagTensorN<Cmpt, length>& dt2
128 DiagTensorN<Cmpt, length> res;
129 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::op
141 //- Addition of DiagTensorN and SphericalTensorN
142 template <class Cmpt, int length>
143 inline DiagTensorN<Cmpt, length>
146 const DiagTensorN<Cmpt, length>& dt1,
147 const SphericalTensorN<Cmpt, length>& st2
150 const Cmpt& s = st2.v_[0];
151 DiagTensorN<Cmpt, length> res;
152 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opVS
164 //- Addition of SphericalTensorN and DiagTensorN
165 template <class Cmpt, int length>
166 inline DiagTensorN<Cmpt, length>
169 const SphericalTensorN<Cmpt, length>& st1,
170 const DiagTensorN<Cmpt, length>& dt2
173 const Cmpt& s = st1.v_[0];
174 DiagTensorN<Cmpt, length> res;
175 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV
187 //- Subtraction of DiagTensorN and DiagTensorN
188 template <class Cmpt, int length>
189 inline DiagTensorN<Cmpt, length>
192 const DiagTensorN<Cmpt, length>& dt1,
193 const DiagTensorN<Cmpt, length>& dt2
196 DiagTensorN<Cmpt, length> res;
197 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::op
209 //- Subtraction of DiagTensorN and SphericalTensorN
210 template <class Cmpt, int length>
211 inline DiagTensorN<Cmpt, length>
214 const DiagTensorN<Cmpt, length>& dt1,
215 const SphericalTensorN<Cmpt, length>& st2
218 const Cmpt& s = st2.v_[0];
219 DiagTensorN<Cmpt, length> res;
220 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opVS
232 //- Subtraction of SphericalTensorN and DiagTensorN
233 template <class Cmpt, int length>
234 inline DiagTensorN<Cmpt, length>
237 const SphericalTensorN<Cmpt, length>& st1,
238 const DiagTensorN<Cmpt, length>& dt2
241 const Cmpt& s = st1.v_[0];
242 DiagTensorN<Cmpt, length> res;
243 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV
255 //- Inner-product between a diagonal tensor and a diagonal tensor
256 template <class Cmpt, int length>
258 innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
261 const DiagTensorN<Cmpt, length>& dt1,
262 const DiagTensorN<Cmpt, length>& dt2
265 DiagTensorN<Cmpt, length> res;
266 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::op
278 //- Inner-product between spherical tensor and diagonal tensor
279 template <class Cmpt, int length>
281 innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
284 const SphericalTensorN<Cmpt, length>& st1,
285 const DiagTensorN<Cmpt, length>& dt2
288 const Cmpt& s = st1.v_[0];
289 DiagTensorN<Cmpt, length> res;
290 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opSV
302 //- Inner-product between diagonal tensor and spherical tensor
303 template <class Cmpt, int length>
305 innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
308 const DiagTensorN<Cmpt, length>& dt1,
309 const SphericalTensorN<Cmpt, length>& st2
312 const Cmpt& s = st2.v_[0];
313 DiagTensorN<Cmpt, length> res;
314 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVS
326 //- Inner-product between a diagonal tensor and a vector
327 template <class Cmpt, int length>
329 innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >::type
332 const DiagTensorN<Cmpt, length>& dt,
333 const VectorN<Cmpt, length>& v
336 VectorN<Cmpt, length> res;
337 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV
350 //- Inner-product between a vector and a tensor
351 template <class Cmpt, int length>
353 innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
356 const VectorN<Cmpt, length>& v,
357 const DiagTensorN<Cmpt, length>& dt
360 VectorN<Cmpt, length> res;
361 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV
373 //- Division of a scalar by a diagonalTensor
374 template <class Cmpt, int length>
375 inline DiagTensorN<Cmpt, length>
376 operator/(const scalar s, const DiagTensorN<Cmpt, length>& dt)
378 DiagTensorN<Cmpt, length> res;
379 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV
384 divideOp3<Cmpt, scalar, Cmpt>()
391 //- Inner Product of a VectorN by an inverse diagonalTensor
392 template <class Cmpt, int length>
393 inline VectorN<Cmpt, length>
394 operator/(const VectorN<Cmpt, length>& v, const DiagTensorN<Cmpt, length>& dt)
396 VectorN<Cmpt, length> res(v);
397 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOp
408 //- Inner Product of a DiagTensorN and an inverse DiagTensorN
409 template <class Cmpt, int length>
410 inline DiagTensorN<Cmpt, length>
413 const DiagTensorN<Cmpt, length>& dt1,
414 const DiagTensorN<Cmpt, length>& dt2
417 DiagTensorN<Cmpt, length> res;
418 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::op
430 //- Inner Product of a SphericalTensorN and an inverse DiagTensorN
431 template <class Cmpt, int length>
432 inline DiagTensorN<Cmpt, length>
435 const SphericalTensorN<Cmpt, length>& st1,
436 const DiagTensorN<Cmpt, length>& dt2
439 const Cmpt& s = st1.v_[0];
440 DiagTensorN<Cmpt, length> res;
441 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV
453 //- Inner Product of a DiagTensorN and an inverse SphericalTensorN
454 template <class Cmpt, int length>
455 inline DiagTensorN<Cmpt, length>
458 const DiagTensorN<Cmpt, length>& dt1,
459 const SphericalTensorN<Cmpt, length>& st2
462 const Cmpt& s = st2.v_[0];
463 DiagTensorN<Cmpt, length> res;
464 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opVS
476 //- Return the inverse of a diagonal tensor
477 template <class Cmpt, int length>
478 inline DiagTensorN<Cmpt, length> inv(const DiagTensorN<Cmpt, length>& dt)
480 DiagTensorN<Cmpt, length> res;
481 VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV
493 //- Return tensor diagonal
494 template <class Cmpt, int length>
495 inline DiagTensorN<Cmpt, length> diag(const DiagTensorN<Cmpt, length>& dt)
501 //- Return the component sum
502 // template <class Cmpt, int length>
503 // inline Cmpt sum(const DiagTensorN<Cmpt, length>& dt)
505 // Cmpt result=Cmpt::zero;
506 // for(register label i=0; i<DiagTensorN<Cmpt, length>::nComponents; i++)
514 //- Transform the spherical tensor
515 //- The components are assumed to be individual scalars
516 //- i.e. transform has no effect
517 template<class Cmpt, int length>
518 inline DiagTensorN<Cmpt, length> transform
521 const DiagTensorN<Cmpt, length>& v
528 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
530 template<class Cmpt, int length>
531 class outerProduct<DiagTensorN<Cmpt, length>, Cmpt>
535 typedef DiagTensorN<Cmpt, length> type;
538 template<class Cmpt, int length>
539 class outerProduct<Cmpt, DiagTensorN<Cmpt, length> >
543 typedef DiagTensorN<Cmpt, length> type;
547 template<class Cmpt, int length>
548 class innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
552 typedef DiagTensorN<Cmpt, length> type;
556 template<class Cmpt, int length>
557 class innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
561 typedef DiagTensorN<Cmpt, length> type;
565 template<class Cmpt, int length>
566 class innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
570 typedef DiagTensorN<Cmpt, length> type;
574 template<class Cmpt, int length>
575 class innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
579 typedef VectorN<Cmpt, length> type;
583 template<class Cmpt, int length>
584 class innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >
588 typedef VectorN<Cmpt, length> type;
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
594 } // End namespace Foam
596 // ************************************************************************* //