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 SphericalTensorN<Cmpt, length>::typeName =
36 ("sphericalTensor" + name(length)).c_str();
38 template <class Cmpt, int length>
39 const SphericalTensorN<Cmpt, length> SphericalTensorN<Cmpt, length>::zero(0);
41 template <class Cmpt, int length>
42 const SphericalTensorN<Cmpt, length> SphericalTensorN<Cmpt, length>::one(1);
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 template <class Cmpt, int length>
48 inline SphericalTensorN<Cmpt, length>::SphericalTensorN()
52 // Construct given VectorSpace
53 template <class Cmpt, int length>
54 inline SphericalTensorN<Cmpt, length>::SphericalTensorN
56 const VectorSpace<SphericalTensorN<Cmpt, length>, Cmpt, 1>& vs
59 VectorSpace<SphericalTensorN<Cmpt, length>, Cmpt, 1>(vs)
63 //- Construct from component
64 template <class Cmpt, int length>
65 inline SphericalTensorN<Cmpt, length>::SphericalTensorN(const Cmpt& tx)
71 // Construct from Istream
72 template <class Cmpt, int length>
73 inline SphericalTensorN<Cmpt, length>::SphericalTensorN(Istream& is)
75 VectorSpace<SphericalTensorN<Cmpt, length>, Cmpt, 1>(is)
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 //- Return diagonal tensor diagonal
82 template <class Cmpt, int length>
83 inline SphericalTensorN<Cmpt, length> SphericalTensorN<Cmpt, length>::diag() const
88 //- Return spherical tensor transpose
89 template <class Cmpt, int length>
90 inline SphericalTensorN<Cmpt, length> SphericalTensorN<Cmpt, length>::T() const
96 //- Transform the spherical tensor
97 //- The components are assumed to be individual scalars
98 //- i.e. transform has no effect
99 template<class Cmpt, int length>
100 inline SphericalTensorN<Cmpt, length> transform
103 const SphericalTensorN<Cmpt, length>& v
110 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
113 //- Addition of SphericalTensorN and SphericalTensorN
114 template <class Cmpt, int length>
115 inline SphericalTensorN<Cmpt,length>
116 operator+(const SphericalTensorN<Cmpt,length>& st1, const SphericalTensorN<Cmpt,length>& st2)
118 return SphericalTensorN<Cmpt, length>(st1.v_[0] + st2.v_[0]);
122 //- Subtraction of SphericalTensorN and SphericalTensorN
123 template <class Cmpt, int length>
124 inline SphericalTensorN<Cmpt,length>
125 operator-(const SphericalTensorN<Cmpt,length>& st1, const SphericalTensorN<Cmpt,length>& st2)
127 return SphericalTensorN<Cmpt, length>(st1.v_[0] - st2.v_[0]);
131 //- Inner-product between spherical tensor and spherical tensor
132 template <class Cmpt, int length>
134 innerProduct<SphericalTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
135 operator&(const SphericalTensorN<Cmpt, length>& st1, const SphericalTensorN<Cmpt, length>& st2)
137 return SphericalTensorN<Cmpt, length>(st1.v_[0]*st2.v_[0]);
141 //- Inner-product between a spherical tensor and a vector
142 template <class Cmpt, int length>
144 innerProduct<SphericalTensorN<Cmpt, length>, VectorN<Cmpt, length> >::type
145 operator&(const SphericalTensorN<Cmpt, length>& st, const VectorN<Cmpt, length>& v)
147 const Cmpt& s = st.v_[0];
148 VectorN<Cmpt, length> res;
149 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opSV(res, s, v, multiplyOp<Cmpt>());
154 //- Inner-product between a vector and a spherical tensor
155 template <class Cmpt, int length>
157 innerProduct<VectorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >::type
158 operator&(const VectorN<Cmpt, length>& v, const SphericalTensorN<Cmpt, length>& st)
160 const Cmpt& s = st.v_[0];
161 VectorN<Cmpt, length> res;
162 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opVS(res, v, s, multiplyOp<Cmpt>());
167 //- Product of a scalar and a spherical tensor
168 template <class Cmpt, int length>
169 inline SphericalTensorN<Cmpt, length>
170 operator*(const scalar s, const SphericalTensorN<Cmpt, length>& st)
172 return SphericalTensorN<Cmpt, length>(s*st.v_[0]);
176 //- Division of a scalar by a spherical tensor
177 template <class Cmpt, int length>
178 inline SphericalTensorN<Cmpt, length>
179 operator/(const scalar s, const SphericalTensorN<Cmpt, length>& st)
181 return SphericalTensorN<Cmpt, length>(s/st.v_[0]);
185 //- Inner Product of a VectorN by an inverse SphericalTensorN
186 template <class Cmpt, int length>
187 inline VectorN<Cmpt,length>
188 operator/(const VectorN<Cmpt,length>& v, const SphericalTensorN<Cmpt,length>& st)
194 //- Inner Product of a SphericalTensorN and an inverse SphericalTensorN
195 template <class Cmpt, int length>
196 inline SphericalTensorN<Cmpt,length>
197 operator/(const SphericalTensorN<Cmpt,length>& st1, const SphericalTensorN<Cmpt,length>& st2)
199 return SphericalTensorN<Cmpt, length>(st1.v_[0]/st2.v_[0]);
203 //- Return the inverse of a spherical tensor
204 template <class Cmpt, int length>
205 inline SphericalTensorN<Cmpt, length> inv(const SphericalTensorN<Cmpt, length>& st)
207 return SphericalTensorN<Cmpt, length>(pTraits<Cmpt>::one/st.v_[0]);
211 //- Return tensor diagonal
212 template <class Cmpt, int length>
213 inline SphericalTensorN<Cmpt, length> diag(const SphericalTensorN<Cmpt, length>& st)
218 //- Return the component sum
219 template <class Cmpt, int length>
220 inline Cmpt sum(const SphericalTensorN<Cmpt, length>& st)
222 return SphericalTensorN<Cmpt, length>::rowLength*st.v_[0];
226 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
228 template<class Cmpt, int length>
229 class outerProduct<Cmpt, SphericalTensorN<Cmpt, length> >
233 typedef SphericalTensorN<Cmpt, length> type;
236 template<class Cmpt, int length>
237 class outerProduct<SphericalTensorN<Cmpt, length>, Cmpt>
241 typedef SphericalTensorN<Cmpt, length> type;
245 template<class Cmpt, int length>
246 class innerProduct<SphericalTensorN<Cmpt, length>, VectorN<Cmpt, length> >
250 typedef VectorN<Cmpt, length> type;
253 template<class Cmpt, int length>
254 class innerProduct<VectorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
258 typedef VectorN<Cmpt, length> type;
261 template<class Cmpt, int length>
262 class innerProduct<SphericalTensorN<Cmpt, length>, SphericalTensorN<Cmpt, length> >
266 typedef SphericalTensorN<Cmpt, length> type;
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 } // End namespace Foam
274 // ************************************************************************* //