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-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::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 
61 public:
62 
63  //- Equivalent type of labels used for valid component indexing
64  typedef Vector2D<label> labelType;
65 
66 
67  // Member constants
68 
69  //- Rank of Vector2D is 1
70  static constexpr direction rank = 1;
71 
72 
73  //- Component labeling enumeration
74  enum components { X, Y };
75 
76 
77  // Constructors
78 
79  //- Construct null
80  inline Vector2D();
81 
82  //- Construct initialized to zero
83  inline Vector2D(const Foam::zero);
84 
85  //- Copy construct from VectorSpace of the same rank
86  inline Vector2D(const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs);
87 
88  //- Construct from two components
89  inline Vector2D(const Cmpt& vx, const Cmpt& vy);
90 
91  //- Construct from Istream
92  inline Vector2D(Istream& is);
93 
94 
95  // Member Functions
96 
97  //- Access to the vector x component
98  inline const Cmpt& x() const;
99 
100  //- Access to the vector y component
101  inline const Cmpt& y() const;
102 
103  //- Access to the vector x component
104  inline Cmpt& x();
105 
106  //- Access to the vector y component
107  inline Cmpt& y();
108 
109 
110  //- Normalise the vector by its magnitude
111  inline Vector2D<Cmpt>& normalise();
112 
113 
114  //- Perp dot product (dot product with perpendicular vector)
115  inline scalar perp(const Vector2D<Cmpt>& b) const;
116 
117 };
118 
119 
120 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
121 
122 //- Data are contiguous if component type is contiguous
123 template<class Cmpt>
124 struct is_contiguous<Vector2D<Cmpt>> : is_contiguous<Cmpt> {};
125 
126 //- Data are contiguous label if component type is label
127 template<class Cmpt>
128 struct is_contiguous_label<Vector2D<Cmpt>> : is_contiguous_label<Cmpt> {};
129 
130 //- Data are contiguous scalar if component type is scalar
131 template<class Cmpt>
132 struct is_contiguous_scalar<Vector2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace Foam
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 #include "Vector2DI.H"
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #endif
146 
147 // ************************************************************************* //
VectorSpace.H
Foam::Vector2D::Y
Definition: Vector2D.H:73
Foam::Vector2D::rank
static constexpr direction rank
Rank of Vector2D is 1.
Definition: Vector2D.H:69
Foam::Vector2D::Vector2D
Vector2D()
Construct null.
Definition: Vector2DI.H:32
Foam::Vector2D< scalar >::components
components
Component labeling enumeration.
Definition: Vector2D.H:73
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:73
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:63
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:99
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:78
Vector2DI.H
Foam::Vector2D::perp
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:132
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:71
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), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61