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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::Vector
29
30Description
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
39SourceFiles
40 VectorI.H
41
42\*---------------------------------------------------------------------------*/
43
44#ifndef Foam_Vector_H
45#define Foam_Vector_H
46
47#include "contiguous.H"
48#include "VectorSpace.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54
55// Forward Declarations
56template<class T> class List;
57
58/*---------------------------------------------------------------------------*\
59 Class Vector Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class Cmpt>
63class Vector
64:
65 public VectorSpace<Vector<Cmpt>, Cmpt, 3>
66{
67public:
68
69 // Typedefs
70
71 //- Equivalent type of labels used for valid component indexing
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 //- Inplace normalise the vector by its magnitude
134 // For small magnitudes (less than ROOTVSMALL) set to zero.
135 // Will not be particularly useful for a vector of labels
136 inline Vector<Cmpt>& normalise(const scalar tol = ROOTVSMALL);
137
138 //- Inplace removal of components that are collinear to the given
139 //- unit vector.
140 inline Vector<Cmpt>& removeCollinear(const Vector<Cmpt>& unitVec);
141
142
143 //- Return *this (used for point which is a typedef to Vector<scalar>.
144 inline const Vector<Cmpt>& centre
145 (
146 const Foam::UList<Vector<Cmpt>>& /* (unused) */
147 ) const;
148};
149
150
151// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
152
153//- Data are contiguous if component type is contiguous
154template<class Cmpt>
155struct is_contiguous<Vector<Cmpt>> : is_contiguous<Cmpt> {};
156
157//- Data are contiguous label if component type is label
158template<class Cmpt>
159struct is_contiguous_label<Vector<Cmpt>> : is_contiguous_label<Cmpt> {};
160
161//- Data are contiguous scalar if component type is scalar
162template<class Cmpt>
163struct is_contiguous_scalar<Vector<Cmpt>> : is_contiguous_scalar<Cmpt> {};
164
165
166template<class Cmpt>
167class typeOfRank<Cmpt, 1>
168{
169public:
171 typedef Vector<Cmpt> type;
172};
173
174
175template<class Cmpt>
176class symmTypeOfRank<Cmpt, 1>
177{
178public:
180 typedef Vector<Cmpt> type;
181};
182
183
184template<class Cmpt>
185class typeOfSolve<Vector<Cmpt>>
186{
187public:
190};
191
192
193// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194
195} // End namespace Foam
196
197// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198
199#include "VectorI.H"
200
201// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202
203#endif
204
205// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Templated vector space.
Definition: VectorSpace.H:79
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
Cmpt & y()
Access to the vector y component.
Definition: VectorI.H:98
Vector< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Vector.H:71
Vector & operator=(const Vector &)=default
Copy assignment.
components
Component labeling enumeration.
Definition: Vector.H:81
Cmpt & x()
Access to the vector x component.
Definition: VectorI.H:92
static constexpr direction rank
Rank of Vector is 1.
Definition: Vector.H:77
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition: VectorI.H:123
const Vector< Cmpt > & centre(const Foam::UList< Vector< Cmpt > > &) const
Return *this (used for point which is a typedef to Vector<scalar>.
Definition: VectorI.H:114
Vector(const Vector &)=default
Copy construct.
Cmpt & z()
Access to the vector z component.
Definition: VectorI.H:104
Vector()=default
Default construct.
Vector< Cmpt > & removeCollinear(const Vector< Cmpt > &unitVec)
Definition: VectorI.H:142
Vector< Cmpt > type
Definition: Vector.H:170
Vector< solveScalar > type
Definition: Vector.H:188
The extended precision type (solveScalar for float)
Definition: products.H:79
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
uint8_t direction
Definition: direction.H:56
A template class to specify if a data type is composed solely of Foam::label elements.
Definition: contiguous.H:86
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:94
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:78