VectorI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Cmpt>
33 :
35 {}
36 
37 
38 template<class Cmpt>
39 template<class Cmpt2>
41 (
42  const VectorSpace<Vector<Cmpt2>, Cmpt2, 3>& vs
43 )
44 :
45  Vector::vsType(vs)
46 {}
47 
48 
49 template<class Cmpt>
51 (
52  const Cmpt& vx,
53  const Cmpt& vy,
54  const Cmpt& vz
55 )
56 {
57  this->v_[X] = vx;
58  this->v_[Y] = vy;
59  this->v_[Z] = vz;
60 }
61 
62 
63 template<class Cmpt>
65 :
66  Vector::vsType(is)
67 {}
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
72 template<class Cmpt>
73 inline const Cmpt& Foam::Vector<Cmpt>::x() const
74 {
75  return this->v_[X];
76 }
77 
78 template<class Cmpt>
79 inline const Cmpt& Foam::Vector<Cmpt>::y() const
80 {
81  return this->v_[Y];
82 }
83 
84 template<class Cmpt>
85 inline const Cmpt& Foam::Vector<Cmpt>::z() const
86 {
87  return this->v_[Z];
88 }
89 
90 
91 template<class Cmpt>
92 inline Cmpt& Foam::Vector<Cmpt>::x()
93 {
94  return this->v_[X];
95 }
96 
97 template<class Cmpt>
98 inline Cmpt& Foam::Vector<Cmpt>::y()
99 {
100  return this->v_[Y];
101 }
102 
103 template<class Cmpt>
104 inline Cmpt& Foam::Vector<Cmpt>::z()
105 {
106  return this->v_[Z];
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
112 template<class Cmpt>
114 (
115  const Foam::List<Vector<Cmpt>>&
116 ) const
117 {
118  return *this;
119 }
120 
121 
122 template<class Cmpt>
124 {
125  const scalar s(Foam::mag(*this));
126 
127  if (s < ROOTVSMALL)
128  {
129  *this = Zero;
130  }
131  else
132  {
133  *this /= s;
134  }
135 
136  return *this;
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
141 
142 namespace Foam
143 {
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 //- Dummy innerProduct for scalar to allow the construction of vtables for
148 // virtual member functions involving the inner-products of fields
149 // for which a "NotImplemented" specialization for scalar is provided.
150 template<class Cmpt>
151 class innerProduct<Vector<Cmpt>, scalar>
152 {
153 public:
154 
155  typedef scalar type;
156 };
157 
158 
159 template<class Cmpt>
161 operator&(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
162 {
163  return Cmpt(v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z());
164 }
165 
166 
167 template<class Cmpt>
168 inline Vector<Cmpt> operator^(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
169 {
170  return Vector<Cmpt>
171  (
172  (v1.y()*v2.z() - v1.z()*v2.y()),
173  (v1.z()*v2.x() - v1.x()*v2.z()),
174  (v1.x()*v2.y() - v1.y()*v2.x())
175  );
176 }
177 
178 
179 template<class Cmpt>
180 inline Vector<Cmpt> operator*(const Cmpt& s, const Vector<Cmpt>& v)
181 {
182  return Vector<Cmpt>(s*v.x(), s*v.y(), s*v.z());
183 }
184 
185 
186 template<class Cmpt>
187 inline Vector<Cmpt> operator*(const Vector<Cmpt>& v, const Cmpt& s)
188 {
189  return s*v;
190 }
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace Foam
196 
197 // ************************************************************************* //
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::operator&
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::innerProduct
Definition: products.H:141
Foam::Vector::normalise
Vector< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: VectorI.H:123
Foam::Vector::Vector
Vector()=default
Default construct.
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Vector::centre
const Vector< Cmpt > & centre(const Foam::List< Vector< Cmpt >> &) const
Return *this (used for point which is a typedef to Vector<scalar>.
Definition: VectorI.H:114
Foam::innerProduct< Vector< Cmpt >, scalar >::type
scalar type
Definition: VectorI.H:155
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::operator^
bitSet operator^(const bitSet &a, const bitSet &b)
Bitwise-XOR of two bitsets to form a unique bit-set.
Definition: bitSetI.H:768
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62