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-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 Class
28  Foam::Vector2D
29 
30 Description
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 
35 SourceFiles
36  Vector2DI.H
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Vector2D_H
41 #define Vector2D_H
42 
43 #include "contiguous.H"
44 #include "VectorSpace.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class Vector2D Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class Cmpt>
56 class Vector2D
57 :
58  public VectorSpace<Vector2D<Cmpt>, Cmpt, 2>
59 {
60 public:
61 
62  // Typedefs
63 
64  //- Equivalent type of labels used for valid component indexing
65  typedef Vector2D<label> labelType;
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  inline Vector2D<Cmpt>& normalise();
122 
123 
124  //- Perp dot product (dot product with perpendicular vector)
125  inline scalar perp(const Vector2D<Cmpt>& b) const;
126 };
127 
128 
129 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
130 
131 //- Data are contiguous if component type is contiguous
132 template<class Cmpt>
133 struct is_contiguous<Vector2D<Cmpt>> : is_contiguous<Cmpt> {};
134 
135 //- Data are contiguous label if component type is label
136 template<class Cmpt>
137 struct is_contiguous_label<Vector2D<Cmpt>> : is_contiguous_label<Cmpt> {};
138 
139 //- Data are contiguous scalar if component type is scalar
140 template<class Cmpt>
141 struct is_contiguous_scalar<Vector2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #include "Vector2DI.H"
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #endif
155 
156 // ************************************************************************* //
VectorSpace.H
Foam::Vector2D::Y
Definition: Vector2D.H:74
Foam::Vector2D::rank
static constexpr direction rank
Rank of Vector2D is 1.
Definition: Vector2D.H:70
Foam::Vector2D< scalar >::components
components
Component labeling enumeration.
Definition: Vector2D.H:74
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:55
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::Vector2D::X
Definition: Vector2D.H:74
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Vector2D::labelType
Vector2D< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: Vector2D.H:64
Foam::Vector2D::Vector2D
Vector2D()=default
Default construct.
Foam::Vector2D::operator=
Vector2D & operator=(const Vector2D &)=default
Copy assignment.
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
contiguous.H
Foam::Vector2D::normalise
Vector2D< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: Vector2DI.H:94
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::Vector2D::y
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
Vector2DI.H
Foam::Vector2D::perp
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:127
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
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::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62