Remove trailing whitespace systematically
[foam-extend-3.2.git] / src / foam / primitives / VectorN / DiagTensorNI.H
blob404c163f4ffb44cc5fecfac5f7f390c58398f8b5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
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);
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 // Construct null
46 template <class Cmpt, int length>
47 inline DiagTensorN<Cmpt, length>::DiagTensorN()
51 // Construct given VectorSpace
52 template <class Cmpt, int length>
53 inline DiagTensorN<Cmpt, length>::DiagTensorN
55     const VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>& vs
58     VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>(vs)
62 //- Construct from component
63 template <class Cmpt, int length>
64 inline DiagTensorN<Cmpt, length>::DiagTensorN(const Cmpt& tx)
66     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOpS(*this, tx, eqOp<Cmpt>());
70 // Construct from Istream
71 template <class Cmpt, int length>
72 inline DiagTensorN<Cmpt, length>::DiagTensorN(Istream& is)
74     VectorSpace<DiagTensorN<Cmpt, length>, Cmpt, length>(is)
78 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
80 //- Return diagonal tensor diagonal
81 template <class Cmpt, int length>
82 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::diag() const
84     return *this;
87 //- Return diagonal tensor transpose
88 template <class Cmpt, int length>
89 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::T() const
91     return *this;
95 //- Assign to a SphericalTensorN
96 template <class Cmpt, int length>
97 inline void DiagTensorN<Cmpt, length>::operator=(const SphericalTensorN<Cmpt, length>& st)
99     const Cmpt& s = st.v_[0];
100     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOpS(*this, s, eqOp<Cmpt>());
103 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
105 //- Addition of DiagTensorN and DiagTensorN
106 template <class Cmpt, int length>
107 inline DiagTensorN<Cmpt,length>
108 operator+(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
110     DiagTensorN<Cmpt, length> res;
111     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::op(res, dt1, dt2, plusOp<Cmpt>());
112     return res;
116 //- Addition of DiagTensorN and SphericalTensorN
117 template <class Cmpt, int length>
118 inline DiagTensorN<Cmpt,length>
119 operator+(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
121     const Cmpt& s = st2.v_[0];
122     DiagTensorN<Cmpt, length> res;
123     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opVS(res, dt1, s, plusOp<Cmpt>());
124     return res;
128 //- Addition of SphericalTensorN and DiagTensorN
129 template <class Cmpt, int length>
130 inline DiagTensorN<Cmpt,length>
131 operator+(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
133     const Cmpt& s = st1.v_[0];
134     DiagTensorN<Cmpt, length> res;
135     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opSV(res, s, dt2, plusOp<Cmpt>());
136     return res;
140 //- Subtraction of DiagTensorN and DiagTensorN
141 template <class Cmpt, int length>
142 inline DiagTensorN<Cmpt,length>
143 operator-(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
145     DiagTensorN<Cmpt, length> res;
146     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::op(res, dt1, dt2, minusOp<Cmpt>());
147     return res;
151 //- Subtraction of DiagTensorN and SphericalTensorN
152 template <class Cmpt, int length>
153 inline DiagTensorN<Cmpt,length>
154 operator-(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
156     const Cmpt& s = st2.v_[0];
157     DiagTensorN<Cmpt, length> res;
158     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opVS(res, dt1, s, minusOp<Cmpt>());
159     return res;
163 //- Subtraction of SphericalTensorN and DiagTensorN
164 template <class Cmpt, int length>
165 inline DiagTensorN<Cmpt,length>
166 operator-(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
168     const Cmpt& s = st1.v_[0];
169     DiagTensorN<Cmpt, length> res;
170     VectorSpaceOps<DiagTensorN<Cmpt,length>::nComponents,0>::opSV(res, s, dt2, minusOp<Cmpt>());
171     return res;
175 //- Inner-product between a diagonal tensor and a diagonal tensor
176 template <class Cmpt, int length>
177 inline typename
178 innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
179 operator&(const DiagTensorN<Cmpt, length>& dt1, const DiagTensorN<Cmpt, length>& dt2)
181     DiagTensorN<Cmpt, length> res;
182     VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::op(res, dt1, dt2, multiplyOp<Cmpt>());
183     return res;
187 //- Inner-product between spherical tensor and diagonal tensor
188 template <class Cmpt, int length>
189 inline typename
190 innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
191 operator&(const SphericalTensorN<Cmpt, length>& st1, const DiagTensorN<Cmpt, length>& dt2)
193     const Cmpt& s = st1.v_[0];
194     DiagTensorN<Cmpt, length> res;
195     VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt2, multiplyOp<Cmpt>());
196     return res;
200 //- Inner-product between diagonal tensor and spherical tensor
201 template <class Cmpt, int length>
202 inline typename
203 innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
204 operator&(const DiagTensorN<Cmpt, length>& dt1, const SphericalTensorN<Cmpt, length>& st2)
206     const Cmpt& s = st2.v_[0];
207     DiagTensorN<Cmpt, length> res;
208     VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVS(res, dt1, s, multiplyOp<Cmpt>());
209     return res;
213 //- Inner-product between a diagonal tensor and a vector
214 template <class Cmpt, int length>
215 inline typename
216 innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >::type
217 operator&(const DiagTensorN<Cmpt, length>& dt, const VectorN<Cmpt, length>& v)
219     VectorN<Cmpt, length> res;
220     VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV(res, dt, v, multiplyOp<Cmpt>());
221     return res;
226 //- Inner-product between a vector and a tensor
227 template <class Cmpt, int length>
228 inline typename
229 innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >::type
230 operator&(const VectorN<Cmpt, length>& v, const DiagTensorN<Cmpt, length>& dt)
232     VectorN<Cmpt, length> res;
233     VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVV(res, v, dt, multiplyOp<Cmpt>());
234     return res;
238 //- Division of a scalar by a diagonalTensor
239 template <class Cmpt, int length>
240 inline DiagTensorN<Cmpt, length>
241 operator/(const scalar s, const DiagTensorN<Cmpt, length>& dt)
243     DiagTensorN<Cmpt, length> res;
244     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt, divideOp3<Cmpt, scalar, Cmpt>());
245     return res;
249 //- Inner Product of a VectorN by an inverse diagonalTensor
250 template <class Cmpt, int length>
251 inline VectorN<Cmpt,length>
252 operator/(const VectorN<Cmpt,length>& v, const DiagTensorN<Cmpt,length>& dt)
254     VectorN<Cmpt, length> res(v);
255     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::eqOp(res, dt, divideEqOp<Cmpt>());
256     return res;
260 //- Inner Product of a DiagTensorN and an inverse DiagTensorN
261 template <class Cmpt, int length>
262 inline DiagTensorN<Cmpt,length>
263 operator/(const DiagTensorN<Cmpt,length>& dt1, const DiagTensorN<Cmpt,length>& dt2)
265     DiagTensorN<Cmpt, length> res;
266     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::op(res, dt1, dt2, divideOp<Cmpt>());
267     return res;
271 //- Inner Product of a SphericalTensorN and an inverse DiagTensorN
272 template <class Cmpt, int length>
273 inline DiagTensorN<Cmpt,length>
274 operator/(const SphericalTensorN<Cmpt,length>& st1, const DiagTensorN<Cmpt,length>& dt2)
276     const Cmpt& s = st1.v_[0];
277     DiagTensorN<Cmpt, length> res;
278     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, s, dt2, divideOp<Cmpt>());
279     return res;
283 //- Inner Product of a DiagTensorN and an inverse SphericalTensorN
284 template <class Cmpt, int length>
285 inline DiagTensorN<Cmpt,length>
286 operator/(const DiagTensorN<Cmpt,length>& dt1, const SphericalTensorN<Cmpt,length>& st2)
288     const Cmpt& s = st2.v_[0];
289     DiagTensorN<Cmpt, length> res;
290     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opVS(res, dt1, s, divideOp<Cmpt>());
291     return res;
295 //- Return the inverse of a diagonal tensor
296 template <class Cmpt, int length>
297 inline DiagTensorN<Cmpt, length> inv(const DiagTensorN<Cmpt, length>& dt)
299     DiagTensorN<Cmpt, length> res;
300     VectorSpaceOps<DiagTensorN<Cmpt, length>::nComponents,0>::opSV(res, 1.0, dt, divideOp<Cmpt>());
301     return res;
305 //- Return tensor diagonal
306 template <class Cmpt, int length>
307 inline DiagTensorN<Cmpt, length> diag(const DiagTensorN<Cmpt, length>& dt)
309     return dt;
313 //- Return the component sum
314 // template <class Cmpt, int length>
315 // inline Cmpt sum(const DiagTensorN<Cmpt, length>& dt)
316 // {
317 //     Cmpt result=Cmpt::zero;
318 //     for(register label i=0; i<DiagTensorN<Cmpt, length>::nComponents; i++)
319 //     {
320 //         result += dt[i];
321 //     }
322 //     return result;
323 // }
326 //- Transform the spherical tensor
327 //- The components are assumed to be individual scalars
328 //- i.e. transform has no effect
329 template<class Cmpt, int length>
330 inline DiagTensorN<Cmpt, length> transform
332     const tensor& tt,
333     const DiagTensorN<Cmpt, length>& v
336     return v;
340 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
342 template<class Cmpt, int length>
343 class outerProduct<DiagTensorN<Cmpt, length>, Cmpt>
345 public:
347     typedef DiagTensorN<Cmpt, length> type;
350 template<class Cmpt, int length>
351 class outerProduct<Cmpt, DiagTensorN<Cmpt, length> >
353 public:
355     typedef DiagTensorN<Cmpt, length> type;
359 template<class Cmpt, int length>
360 class innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
362 public:
364     typedef DiagTensorN<Cmpt, length> type;
368 template<class Cmpt, int length>
369 class innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
371 public:
373     typedef DiagTensorN<Cmpt, length> type;
377 template<class Cmpt, int length>
378 class innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
380 public:
382     typedef DiagTensorN<Cmpt, length> type;
386 template<class Cmpt, int length>
387 class innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
389 public:
391     typedef VectorN<Cmpt, length> type;
395 template<class Cmpt, int length>
396 class innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >
398 public:
400     typedef VectorN<Cmpt, length> type;
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 } // End namespace Foam
408 // ************************************************************************* //