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 template<class Cmpt, int length>
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 template <class Cmpt, int length>
38 const char* const VectorN<Cmpt, length>::typeName =
39 ("vector" + name(length)).c_str();
41 template <class Cmpt, int length>
42 const VectorN<Cmpt, length> VectorN<Cmpt, length>::zero(0);
44 template <class Cmpt, int length>
45 const VectorN<Cmpt, length> VectorN<Cmpt, length>::one(1);
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 template <class Cmpt, int length>
52 inline VectorN<Cmpt, length>::VectorN()
56 // Construct given VectorSpace
57 template <class Cmpt, int length>
58 inline VectorN<Cmpt, length>::VectorN
60 const VectorSpace<VectorN<Cmpt, length>, Cmpt, length>& vs
63 VectorSpace<VectorN<Cmpt, length>, Cmpt, length>(vs)
67 // Construct given Cmpts
68 template <class Cmpt, int length>
69 inline VectorN<Cmpt, length>::VectorN(const Cmpt& vx)
71 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::eqOpS(*this, vx, eqOp<Cmpt>());
75 // Construct from Istream
76 template <class Cmpt, int length>
77 inline VectorN<Cmpt, length>::VectorN(Istream& is)
79 VectorSpace<VectorN<Cmpt, length>, Cmpt, length>(is)
83 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
85 template <class Cmpt, int length>
86 inline const Cmpt& VectorN<Cmpt, length>::operator()(const direction i) const
88 return this->operator[](i);
92 template <class Cmpt, int length>
93 inline Cmpt& VectorN<Cmpt, length>::operator()(const direction i)
95 return this->operator[](i);
99 //- Multiply components of VectorN by VectorN
100 template<class Cmpt, int length>
101 inline VectorN<Cmpt, length> VectorN<Cmpt, length>::cmptMultiply(const VectorN<Cmpt, length>& v)
103 VectorN<Cmpt, length> res;
104 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::op(res, *this, v, multiplyOp<Cmpt>());
109 //- Transform the spherical tensor
110 //- The components are assumed to be individual scalars
111 //- i.e. transform has no effect
112 template<class Cmpt, int length>
113 inline VectorN<Cmpt, length> transform
116 const VectorN<Cmpt, length>& v
123 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
125 template<class Cmpt, int length>
126 class outerProduct<Cmpt, VectorN<Cmpt, length> >
130 typedef VectorN<Cmpt, length> type;
134 template<class Cmpt, int length>
135 class outerProduct<VectorN<Cmpt, length>, Cmpt>
139 typedef VectorN<Cmpt, length> type;
143 template<class Cmpt, int length>
144 class outerProduct<VectorN<Cmpt, length>, VectorN<Cmpt, length> >
148 typedef TensorN<Cmpt, length> type;
152 //- Inner-product between a vector and a vector
153 template <class Cmpt, int length>
154 inline Cmpt operator&
156 const VectorN<Cmpt, length>& v1,
157 const VectorN<Cmpt, length>& v2
160 Cmpt res = pTraits<Cmpt>::zero;
161 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::SopEqOpVV
162 (res, v1, v2, plusEqOp<Cmpt>(), multiplyOp<Cmpt>());
167 //- Componentwise division of scalar by VectorN
168 template<class Cmpt, int length>
169 inline VectorN<Cmpt, length>
170 operator/(const scalar s, const VectorN<Cmpt, length>& v)
172 VectorN<Cmpt, length> res;
173 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::opSV(res, s, v, divideOp3<Cmpt, scalar, Cmpt>());
178 //- Multiply components of VectorN by VectorN
179 template<class Cmpt, int length>
180 inline VectorN<Cmpt, length> cmptMultiply(const VectorN<Cmpt, length>& v1, const VectorN<Cmpt, length>& v2)
182 VectorN<Cmpt, length> res;
183 VectorSpaceOps<VectorN<Cmpt, length>::nComponents,0>::op(res, v1, v2, multiplyOp<Cmpt>());
187 //- Return the component sum
188 // template <class Cmpt, int length>
189 // inline Cmpt sum(const VectorN<Cmpt, length>& v)
191 // Cmpt result = pTraits<Cmpt>::zero;
192 // for(register label i=0; i<VectorN<Cmpt, length>::nComponents; i++)
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 } // End namespace Foam
204 // ************************************************************************* //