Vector2D.H 4.58 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6
7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2018-2020 OpenCFD Ltd.
10
11
12
13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14
15
16
17
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
18
19
20
21
22
23
24

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

Class
    Foam::Vector2D

Description
    Templated 2D Vector derived from VectorSpace adding construction from
    2 components, element access using x() and y() member functions and
    the inner-product (dot-product).

SourceFiles
    Vector2DI.H

\*---------------------------------------------------------------------------*/

#ifndef Vector2D_H
#define Vector2D_H

43
#include "contiguous.H"
44
45
46
47
48
49
50
51
52
53
54
#include "VectorSpace.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
                           Class Vector2D Declaration
\*---------------------------------------------------------------------------*/

Henry's avatar
Henry committed
55
template<class Cmpt>
56
57
58
59
60
61
class Vector2D
:
    public VectorSpace<Vector2D<Cmpt>, Cmpt, 2>
{
public:

62
63
64
65
    // Typedefs

        //- Equivalent type of labels used for valid component indexing
        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
75
76
77


    //- Component labeling enumeration
    enum components { X, Y };


78
79
80
81
82
83
84
    // Generated Methods

        //- Default construct
        Vector2D() = default;

        //- Copy construct
        Vector2D(const Vector2D&) = default;
85

86
87
88
89
90
        //- Copy assignment
        Vector2D& operator=(const Vector2D&) = default;


    // Constructors
91

92
        //- Construct initialized to zero
93
        inline Vector2D(const Foam::zero);
94

95
96
        //- Copy construct from VectorSpace of the same rank
        inline Vector2D(const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs);
97

98
        //- Construct from two components
99
100
101
        inline Vector2D(const Cmpt& vx, const Cmpt& vy);

        //- Construct from Istream
102
        inline explicit Vector2D(Istream& is);
103
104
105
106


    // Member Functions

107
108
        //- Access to the vector x component
        inline const Cmpt& x() const;
109

110
111
        //- Access to the vector y component
        inline const Cmpt& y() const;
112

113
114
        //- Access to the vector x component
        inline Cmpt& x();
115

116
117
        //- Access to the vector y component
        inline Cmpt& y();
118

119
120
121
122
123
        //- Normalise the vector by its magnitude
        inline Vector2D<Cmpt>& normalise();

        //- Perp dot product (dot product with perpendicular vector)
        inline scalar perp(const Vector2D<Cmpt>& b) const;
124
125
126
127
128
129
130

        //- Return true if vector is within tol
        inline bool isClose
        (
            const Vector2D<Cmpt>& b,
            const scalar tol = 1e-10
        ) const;
131
132
133
};


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// * * * * * * * * * * * * * * * * * Traits  * * * * * * * * * * * * * * * * //

//- Data are contiguous if component type is contiguous
template<class Cmpt>
struct is_contiguous<Vector2D<Cmpt>> : is_contiguous<Cmpt> {};

//- Data are contiguous label if component type is label
template<class Cmpt>
struct is_contiguous_label<Vector2D<Cmpt>> : is_contiguous_label<Cmpt> {};

//- Data are contiguous scalar if component type is scalar
template<class Cmpt>
struct is_contiguous_scalar<Vector2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};


149
150
151
152
153
154
155
156
157
158
159
160
161
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "Vector2DI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //