Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / primitives / VectorN / DiagTensorNI.H
blob53d2864d7598b77340893d53543b7d591093ac45
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
28 namespace Foam
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  * * * * * * * * * * * * * * //
46 // Construct null
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
68     (
69         *this,
70         tx,
71         eqOp<Cmpt>()
72     );
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
90     return *this;
93 //- Return diagonal tensor transpose
94 template <class Cmpt, int length>
95 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::T() const
97     return *this;
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
110     (
111         *this,
112         s,
113         eqOp<Cmpt>()
114     );
117 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
119 //- Addition of DiagTensorN and DiagTensorN
120 template <class Cmpt, int length>
121 inline DiagTensorN<Cmpt, length>
122 operator+
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
130     (
131         res,
132         dt1,
133         dt2,
134         plusOp<Cmpt>()
135     );
137     return res;
141 //- Addition of DiagTensorN and SphericalTensorN
142 template <class Cmpt, int length>
143 inline DiagTensorN<Cmpt, length>
144 operator+
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
153     (
154         res,
155         dt1,
156         s,
157         plusOp<Cmpt>()
158     );
160     return res;
164 //- Addition of SphericalTensorN and DiagTensorN
165 template <class Cmpt, int length>
166 inline DiagTensorN<Cmpt, length>
167 operator+
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
176     (
177         res,
178         s,
179         dt2,
180         plusOp<Cmpt>()
181     );
183     return res;
187 //- Subtraction of DiagTensorN and DiagTensorN
188 template <class Cmpt, int length>
189 inline DiagTensorN<Cmpt, length>
190 operator-
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
198     (
199         res,
200         dt1,
201         dt2,
202         minusOp<Cmpt>()
203     );
205     return res;
209 //- Subtraction of DiagTensorN and SphericalTensorN
210 template <class Cmpt, int length>
211 inline DiagTensorN<Cmpt, length>
212 operator-
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
221     (
222         res,
223         dt1,
224         s,
225         minusOp<Cmpt>()
226     );
228     return res;
232 //- Subtraction of SphericalTensorN and DiagTensorN
233 template <class Cmpt, int length>
234 inline DiagTensorN<Cmpt, length>
235 operator-
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
244     (
245         res,
246         s,
247         dt2,
248         minusOp<Cmpt>()
249     );
251     return res;
255 //- Inner-product between a diagonal tensor and a diagonal tensor
256 template <class Cmpt, int length>
257 inline typename
258 innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
259 operator&
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
267     (
268         res,
269         dt1,
270         dt2,
271         multiplyOp<Cmpt>()
272     );
274     return res;
278 //- Inner-product between spherical tensor and diagonal tensor
279 template <class Cmpt, int length>
280 inline typename
281 innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
282 operator&
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
291     (
292         res,
293         s,
294         dt2,
295         multiplyOp<Cmpt>()
296     );
298     return res;
302 //- Inner-product between diagonal tensor and spherical tensor
303 template <class Cmpt, int length>
304 inline typename
305 innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
306 operator&
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
315     (
316         res,
317         dt1,
318         s,
319         multiplyOp<Cmpt>()
320     );
322     return res;
326 //- Inner-product between a diagonal tensor and a vector
327 template <class Cmpt, int length>
328 inline typename
329 innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >::type
330 operator&
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
338     (
339         res,
340         dt,
341         v,
342         multiplyOp<Cmpt>()
343     );
345     return res;
350 //- Inner-product between a vector and a tensor
351 template <class Cmpt, int length>
352 inline typename
353 innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
354 operator&
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
362     (
363         res,
364         v,
365         dt,
366         multiplyOp<Cmpt>()
367     );
369     return res;
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
380     (
381         res,
382         s,
383         dt,
384         divideOp3<Cmpt, scalar, Cmpt>()
385     );
387     return res;
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
398     (
399         res,
400         dt,
401         divideEqOp<Cmpt>()
402     );
404     return res;
408 //- Inner Product of a DiagTensorN and an inverse DiagTensorN
409 template <class Cmpt, int length>
410 inline DiagTensorN<Cmpt, length>
411 operator/
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
419     (
420         res,
421         dt1,
422         dt2,
423         divideOp<Cmpt>()
424     );
426     return res;
430 //- Inner Product of a SphericalTensorN and an inverse DiagTensorN
431 template <class Cmpt, int length>
432 inline DiagTensorN<Cmpt, length>
433 operator/
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
442     (
443         res,
444         s,
445         dt2,
446         divideOp<Cmpt>()
447     );
449     return res;
453 //- Inner Product of a DiagTensorN and an inverse SphericalTensorN
454 template <class Cmpt, int length>
455 inline DiagTensorN<Cmpt, length>
456 operator/
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
465     (
466         res,
467         dt1,
468         s,
469         divideOp<Cmpt>()
470     );
472     return res;
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
482     (
483         res,
484         1.0,
485         dt,
486         divideOp<Cmpt>()
487     );
489     return res;
493 //- Return tensor diagonal
494 template <class Cmpt, int length>
495 inline DiagTensorN<Cmpt, length> diag(const DiagTensorN<Cmpt, length>& dt)
497     return dt;
501 //- Return the component sum
502 // template <class Cmpt, int length>
503 // inline Cmpt sum(const DiagTensorN<Cmpt, length>& dt)
504 // {
505 //     Cmpt result=Cmpt::zero;
506 //     for(register label i=0; i<DiagTensorN<Cmpt, length>::nComponents; i++)
507 //     {
508 //         result += dt[i];
509 //     }
510 //     return result;
511 // }
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
520     const tensor& tt,
521     const DiagTensorN<Cmpt, length>& v
524     return v;
528 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
530 template<class Cmpt, int length>
531 class outerProduct<DiagTensorN<Cmpt, length>, Cmpt>
533 public:
535     typedef DiagTensorN<Cmpt, length> type;
538 template<class Cmpt, int length>
539 class outerProduct<Cmpt, DiagTensorN<Cmpt, length> >
541 public:
543     typedef DiagTensorN<Cmpt, length> type;
547 template<class Cmpt, int length>
548 class innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
550 public:
552     typedef DiagTensorN<Cmpt, length> type;
556 template<class Cmpt, int length>
557 class innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
559 public:
561     typedef DiagTensorN<Cmpt, length> type;
565 template<class Cmpt, int length>
566 class innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
568 public:
570     typedef DiagTensorN<Cmpt, length> type;
574 template<class Cmpt, int length>
575 class innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
577 public:
579     typedef VectorN<Cmpt, length> type;
583 template<class Cmpt, int length>
584 class innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >
586 public:
588     typedef VectorN<Cmpt, length> type;
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
594 } // End namespace Foam
596 // ************************************************************************* //