Vector.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-2019 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 Class
28  Foam::Vector
29 
30 Description
31  Templated 3D Vector derived from VectorSpace adding construction from
32  3 components, element access using x(), y() and z() member functions and
33  the inner-product (dot-product) and cross product operators.
34 
35  A centre() member function which returns the Vector for which it is called
36  is defined so that point which is a typedef to Vector<scalar> behaves as
37  other shapes in the shape hierarchy.
38 
39 SourceFiles
40  VectorI.H
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Vector_H
45 #define Vector_H
46 
47 #include "contiguous.H"
48 #include "VectorSpace.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 template<class T> class List;
57 
58 /*---------------------------------------------------------------------------*\
59  Class Vector Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class Cmpt>
63 class Vector
64 :
65  public VectorSpace<Vector<Cmpt>, Cmpt, 3>
66 {
67 public:
68 
69  // Typedefs
70 
71  //- Equivalent type of labels used for valid component indexing
72  typedef Vector<label> labelType;
73 
74 
75  // Member Constants
76 
77  //- Rank of Vector is 1
78  static constexpr direction rank = 1;
79 
80 
81  //- Component labeling enumeration
82  enum components { X, Y, Z };
83 
84 
85  // Generated Methods
86 
87  //- Default construct
88  Vector() = default;
89 
90  //- Copy construct
91  Vector(const Vector&) = default;
92 
93  //- Copy assignment
94  Vector& operator=(const Vector&) = default;
95 
96 
97  // Constructors
98 
99  //- Construct initialized to zero
100  inline Vector(const Foam::zero);
101 
102  //- Copy construct from VectorSpace of the same rank
103  template<class Cmpt2>
104  inline Vector(const VectorSpace<Vector<Cmpt2>, Cmpt2, 3>& vs);
105 
106  //- Construct from three components
107  inline Vector(const Cmpt& vx, const Cmpt& vy, const Cmpt& vz);
108 
109  //- Construct from Istream
110  inline explicit Vector(Istream& is);
111 
112 
113  // Member Functions
114 
115  //- Access to the vector x component
116  inline const Cmpt& x() const;
117 
118  //- Access to the vector y component
119  inline const Cmpt& y() const;
120 
121  //- Access to the vector z component
122  inline const Cmpt& z() const;
123 
124  //- Access to the vector x component
125  inline Cmpt& x();
126 
127  //- Access to the vector y component
128  inline Cmpt& y();
129 
130  //- Access to the vector z component
131  inline Cmpt& z();
132 
133 
134  //- Normalise the vector by its magnitude
135  inline Vector<Cmpt>& normalise();
136 
137 
138  //- Return *this (used for point which is a typedef to Vector<scalar>.
139  inline const Vector<Cmpt>& centre
140  (
141  const Foam::List<Vector<Cmpt>>&
142  ) const;
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
147 
148 //- Data are contiguous if component type is contiguous
149 template<class Cmpt>
150 struct is_contiguous<Vector<Cmpt>> : is_contiguous<Cmpt> {};
151 
152 //- Data are contiguous label if component type is label
153 template<class Cmpt>
154 struct is_contiguous_label<Vector<Cmpt>> : is_contiguous_label<Cmpt> {};
155 
156 //- Data are contiguous scalar if component type is scalar
157 template<class Cmpt>
158 struct is_contiguous_scalar<Vector<Cmpt>> : is_contiguous_scalar<Cmpt> {};
159 
160 
161 template<class Cmpt>
162 class typeOfRank<Cmpt, 1>
163 {
164 public:
165 
166  typedef Vector<Cmpt> type;
167 };
168 
169 
170 template<class Cmpt>
171 class symmTypeOfRank<Cmpt, 1>
172 {
173 public:
174 
175  typedef Vector<Cmpt> type;
176 };
177 
178 
179 template<class Cmpt>
180 class typeOfSolve<Vector<Cmpt>>
181 {
182 public:
183 
184  typedef Vector<solveScalar> type;
185 };
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace Foam
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #include "VectorI.H"
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
Foam::Vector::operator=
Vector & operator=(const Vector &)=default
Copy assignment.
VectorSpace.H
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::Vector::Z
Definition: Vector.H:81
Foam::Vector::Y
Definition: Vector.H:81
Foam::typeOfSolve
The extended precision type (solveScalar for float)
Definition: products.H:78
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::rank
static constexpr direction rank
Rank of Vector is 1.
Definition: Vector.H:77
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::Vector< Foam::List< scalar > >::components
components
Component labeling enumeration.
Definition: Vector.H:81
Foam::is_contiguous_label
A template class to specify if a data type is composed solely of Foam::label elements.
Definition: contiguous.H:83
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::typeOfSolve< Vector< Cmpt > >::type
Vector< solveScalar > type
Definition: Vector.H:183
Foam::symmTypeOfRank< Cmpt, 1 >::type
Vector< Cmpt > type
Definition: Vector.H:174
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Vector::X
Definition: Vector.H:81
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
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::is_contiguous_scalar
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:91
Foam::symmTypeOfRank
Definition: products.H:72
Foam::typeOfRank
Definition: products.H:67
Foam::typeOfRank< Cmpt, 1 >::type
Vector< Cmpt > type
Definition: Vector.H:165
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
contiguous.H
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::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::direction
uint8_t direction
Definition: direction.H:52
Foam::typeOfSolve::type
Type type
Definition: products.H:82
VectorI.H
Foam::is_contiguous
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:75
Foam::Vector::labelType
Vector< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Vector.H:71
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62