Vector2D.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::Vector2D
29
30Description
31 Templated 2D Vector derived from VectorSpace adding construction from
32 2 components, element access using x() and y() member functions and
33 the inner-product (dot-product).
34
35SourceFiles
36 Vector2DI.H
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_Vector2D_H
41#define Foam_Vector2D_H
42
43#include "contiguous.H"
44#include "VectorSpace.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51/*---------------------------------------------------------------------------*\
52 Class Vector2D Declaration
53\*---------------------------------------------------------------------------*/
54
55template<class Cmpt>
56class Vector2D
57:
58 public VectorSpace<Vector2D<Cmpt>, Cmpt, 2>
59{
60public:
61
62 // Typedefs
63
64 //- Equivalent type of labels used for valid component indexing
66
67
68 // Member Constants
69
70 //- Rank of Vector2D is 1
71 static constexpr direction rank = 1;
72
73
74 //- Component labeling enumeration
75 enum components { X, Y };
76
77
78 // Generated Methods
79
80 //- Default construct
81 Vector2D() = default;
82
83 //- Copy construct
84 Vector2D(const Vector2D&) = default;
85
86 //- Copy assignment
87 Vector2D& operator=(const Vector2D&) = default;
88
89
90 // Constructors
91
92 //- Construct initialized to zero
93 inline Vector2D(const Foam::zero);
94
95 //- Copy construct from VectorSpace of the same rank
96 inline Vector2D(const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs);
97
98 //- Construct from two components
99 inline Vector2D(const Cmpt& vx, const Cmpt& vy);
100
101 //- Construct from Istream
102 inline explicit Vector2D(Istream& is);
103
104
105 // Member Functions
106
107 //- Access to the vector x component
108 inline const Cmpt& x() const;
109
110 //- Access to the vector y component
111 inline const Cmpt& y() const;
112
113 //- Access to the vector x component
114 inline Cmpt& x();
115
116 //- Access to the vector y component
117 inline Cmpt& y();
118
119
120 //- Normalise the vector by its magnitude
121 // For small magnitudes (less than ROOTVSMALL) set to zero.
122 // Will not be particularly useful for a vector of labels
123 inline Vector2D<Cmpt>& normalise(const scalar tol = ROOTVSMALL);
124
125 //- Inplace removal of components that are collinear to the given
126 //- unit vector.
127 inline Vector2D<Cmpt>& removeCollinear(const Vector2D<Cmpt>& unitVec);
128
129
130 //- Perp dot product (dot product with perpendicular vector)
131 inline scalar perp(const Vector2D<Cmpt>& b) const;
132
133 //- Return true if vector is within tol
134 inline bool isClose
135 (
136 const Vector2D<Cmpt>& b,
137 const scalar tol = 1e-10
138 ) const;
139};
140
141
142// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
143
144//- Data are contiguous if component type is contiguous
145template<class Cmpt>
146struct is_contiguous<Vector2D<Cmpt>> : is_contiguous<Cmpt> {};
147
148//- Data are contiguous label if component type is label
149template<class Cmpt>
150struct is_contiguous_label<Vector2D<Cmpt>> : is_contiguous_label<Cmpt> {};
151
152//- Data are contiguous scalar if component type is scalar
153template<class Cmpt>
154struct is_contiguous_scalar<Vector2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
155
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158
159} // End namespace Foam
160
161// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162
163#include "Vector2DI.H"
164
165// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166
167#endif
168
169// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:58
Cmpt & y()
Access to the vector y component.
Definition: Vector2DI.H:87
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:136
components
Component labeling enumeration.
Definition: Vector2D.H:74
Cmpt & x()
Access to the vector x component.
Definition: Vector2DI.H:80
static constexpr direction rank
Rank of Vector2D is 1.
Definition: Vector2D.H:70
Vector2D & operator=(const Vector2D &)=default
Copy assignment.
bool isClose(const Vector2D< Cmpt > &b, const scalar tol=1e-10) const
Return true if vector is within tol.
Definition: Vector2DI.H:144
Vector2D()=default
Default construct.
Vector2D(const Vector2D &)=default
Copy construct.
Vector2D< Cmpt > & removeCollinear(const Vector2D< Cmpt > &unitVec)
Definition: Vector2DI.H:113
Vector2D< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Vector2D.H:64
Vector2D< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Normalise the vector by its magnitude.
Definition: Vector2DI.H:94
Templated vector space.
Definition: VectorSpace.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.
uint8_t direction
Definition: direction.H:56
volScalarField & b
Definition: createFields.H:27
volScalarField & e
Definition: createFields.H:11
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