Vector2DI.H 3.65 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

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

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

31
32
33
34
35
36
37
template<class Cmpt>
inline Foam::Vector2D<Cmpt>::Vector2D(const Foam::zero)
:
    Vector2D::vsType(Zero)
{}


Henry's avatar
Henry committed
38
template<class Cmpt>
39
40
41
42
inline Foam::Vector2D<Cmpt>::Vector2D
(
    const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs
)
43
:
44
    Vector2D::vsType(vs)
45
46
47
{}


Henry's avatar
Henry committed
48
template<class Cmpt>
49
inline Foam::Vector2D<Cmpt>::Vector2D(const Cmpt& vx, const Cmpt& vy)
50
51
52
53
54
55
{
    this->v_[X] = vx;
    this->v_[Y] = vy;
}


Henry's avatar
Henry committed
56
template<class Cmpt>
57
inline Foam::Vector2D<Cmpt>::Vector2D(Istream& is)
58
:
59
    Vector2D::vsType(is)
60
61
62
63
64
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

Henry's avatar
Henry committed
65
template<class Cmpt>
66
inline const Cmpt& Foam::Vector2D<Cmpt>::x() const
67
68
69
70
{
    return this->v_[X];
}

71

Henry's avatar
Henry committed
72
template<class Cmpt>
73
inline const Cmpt& Foam::Vector2D<Cmpt>::y() const
74
75
76
77
78
{
    return this->v_[Y];
}


Henry's avatar
Henry committed
79
template<class Cmpt>
80
inline Cmpt& Foam::Vector2D<Cmpt>::x()
81
82
83
84
{
    return this->v_[X];
}

85

Henry's avatar
Henry committed
86
template<class Cmpt>
87
inline Cmpt& Foam::Vector2D<Cmpt>::y()
88
89
90
91
92
{
    return this->v_[Y];
}


93
94
95
96
97
98
99
100
101
102
103
104
105
template<class Cmpt>
inline Foam::Vector2D<Cmpt>& Foam::Vector2D<Cmpt>::normalise()
{
    const scalar s(Foam::mag(*this));

    if (s < ROOTVSMALL)
    {
        *this = Zero;
    }
    else
    {
        *this /= s;
    }
106
107

    return *this;
108
109
110
}


111
112
113
114
115
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

116
117
// * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //

Henry's avatar
Henry committed
118
template<class Cmpt>
119
inline typename innerProduct<Vector2D<Cmpt>, Vector2D<Cmpt>>::type
120
121
122
123
124
125
operator&(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
{
    return Cmpt(v1.x()*v2.x() + v1.y()*v2.y());
}


Henry's avatar
Henry committed
126
template<class Cmpt>
127
128
inline scalar Vector2D<Cmpt>::perp(const Vector2D<Cmpt>& b) const
{
129
130
131
132
133
134
135
136
137
138
139
140
    return x()*b.y() - y()*b.x();
}


template<class Cmpt>
inline bool Vector2D<Cmpt>::isClose
(
    const Vector2D<Cmpt>& b,
    const scalar tol
) const
{
    return (mag(x() - b.x()) < tol && mag(y() - b.y()) < tol);
141
142
143
}


144
145
146
147
148
149
150
151
152
153
154
155
156
157
template<class Cmpt>
inline Vector2D<Cmpt> operator*(const Cmpt& s, const Vector2D<Cmpt>& v)
{
    return Vector2D<Cmpt>(s*v.x(), s*v.y());
}


template<class Cmpt>
inline Vector2D<Cmpt> operator*(const Vector2D<Cmpt>& v, const Cmpt& s)
{
    return s*v;
}


158
159
160
161
162
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

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