1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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);
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
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
87 //- Return diagonal tensor transpose
88 template <class Cmpt, int length>
89 inline DiagTensorN<Cmpt, length> DiagTensorN<Cmpt, length>::T() const
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>());
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>());
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>());
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>());
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>());
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>());
175 //- Inner-product between a diagonal tensor and a diagonal tensor
176 template <class Cmpt, int length>
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>());
187 //- Inner-product between spherical tensor and diagonal tensor
188 template <class Cmpt, int length>
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>());
200 //- Inner-product between diagonal tensor and spherical tensor
201 template <class Cmpt, int length>
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>());
213 //- Inner-product between a diagonal tensor and a vector
214 template <class Cmpt, int length>
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>());
226 //- Inner-product between a vector and a tensor
227 template <class Cmpt, int length>
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>());
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>());
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>());
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>());
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>());
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>());
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>());
305 //- Return tensor diagonal
306 template <class Cmpt, int length>
307 inline DiagTensorN<Cmpt, length> diag(const DiagTensorN<Cmpt, length>& dt)
313 //- Return the component sum
314 // template <class Cmpt, int length>
315 // inline Cmpt sum(const DiagTensorN<Cmpt, length>& dt)
317 // Cmpt result=Cmpt::zero;
318 // for(register label i=0; i<DiagTensorN<Cmpt, length>::nComponents; i++)
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
333 const DiagTensorN<Cmpt, length>& v
340 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
342 template<class Cmpt, int length>
343 class outerProduct<DiagTensorN<Cmpt, length>, Cmpt>
347 typedef DiagTensorN<Cmpt, length> type;
350 template<class Cmpt, int length>
351 class outerProduct<Cmpt, DiagTensorN<Cmpt, length> >
355 typedef DiagTensorN<Cmpt, length> type;
359 template<class Cmpt, int length>
360 class innerProduct<DiagTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
364 typedef DiagTensorN<Cmpt, length> type;
368 template<class Cmpt, int length>
369 class innerProduct<SphericalTensorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
373 typedef DiagTensorN<Cmpt, length> type;
377 template<class Cmpt, int length>
378 class innerProduct<DiagTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
382 typedef DiagTensorN<Cmpt, length> type;
386 template<class Cmpt, int length>
387 class innerProduct<VectorN<Cmpt, length>, DiagTensorN<Cmpt, length> >
391 typedef VectorN<Cmpt, length> type;
395 template<class Cmpt, int length>
396 class innerProduct<DiagTensorN<Cmpt, length>, VectorN<Cmpt, length> >
400 typedef VectorN<Cmpt, length> type;
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 } // End namespace Foam
408 // ************************************************************************* //