Loading...
Searching...
No Matches
Vector2DI.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-2025 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
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30
31template<class Cmpt>
33:
35{}
36
37
38template<class Cmpt>
40(
41 const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs
43:
44 Vector2D::vsType(vs)
45{}
46
47
48template<class Cmpt>
49inline Foam::Vector2D<Cmpt>::Vector2D(const Cmpt& vx, const Cmpt& vy)
51 this->x() = vx;
52 this->y() = vy;
53}
54
55
56template<class Cmpt>
58:
60{}
61
62
63// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64
65template<class Cmpt>
66inline Foam::scalar Foam::Vector2D<Cmpt>::magSqr() const
67{
68 return
69 (
70 Foam::magSqr(this->x())
71 + Foam::magSqr(this->y())
72 );
73}
74
75
76template<class Cmpt>
77inline Foam::scalar Foam::Vector2D<Cmpt>::mag() const
79 return ::sqrt(this->magSqr());
80}
81
82
83template<class Cmpt>
84inline Foam::scalar
86{
87 return
88 (
89 Foam::magSqr(v2.x() - this->x())
90 + Foam::magSqr(v2.y() - this->y())
91 );
92}
93
94
95template<class Cmpt>
96inline Foam::scalar Foam::Vector2D<Cmpt>::dist(const Vector2D<Cmpt>& v2) const
97{
98 return ::sqrt(this->distSqr(v2));
99}
100
101
102template<class Cmpt>
104{
105 const scalar s = this->mag();
106
107 if (s < tol)
108 {
109 *this = Zero;
110 }
111 else
112 {
113 *this /= s;
114 }
116 return *this;
117}
118
119
120template<class Cmpt>
123{
124 *this -= (*this & unitVec) * unitVec;
125 return *this;
127
128
129// * * * * * * * * * * * * * Comparison Operations * * * * * * * * * * * * * //
130
131template<class Cmpt>
132inline bool
134{
135 return
136 (
137 (a.x() < b.x())
138 || (!(b.x() < a.x()) && (a.y() < b.y()))
139 );
140}
141
142
143template<class Cmpt>
144inline bool
146{
147 return
148 (
149 (a.y() < b.y())
150 || (!(b.y() < a.y()) && (a.x() < b.x()))
151 );
152}
153
154
155// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
157namespace Foam
158{
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162template<class Cmpt>
163inline Cmpt operator&(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
164{
165 return Cmpt(v1.x()*v2.x() + v1.y()*v2.y());
166}
167
168
169template<class Cmpt>
170inline scalar Vector2D<Cmpt>::perp(const Vector2D<Cmpt>& b) const
171{
172 return x()*b.y() - y()*b.x();
173}
174
175
176template<class Cmpt>
177inline bool Vector2D<Cmpt>::isClose
178(
179 const Vector2D<Cmpt>& b,
180 const scalar tol
181) const
182{
183 return (Foam::mag(x() - b.x()) < tol && Foam::mag(y() - b.y()) < tol);
184}
185
186
187template<class Cmpt>
188inline Vector2D<Cmpt> operator*(const Cmpt& s, const Vector2D<Cmpt>& v)
189{
190 return Vector2D<Cmpt>(s*v.x(), s*v.y());
191}
192
193
194template<class Cmpt>
195inline Vector2D<Cmpt> operator*(const Vector2D<Cmpt>& v, const Cmpt& s)
196{
197 return s*v;
198}
199
200
201// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202
203} // End namespace Foam
204
205// ************************************************************************* //
scalar y
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition Vector2D.H:54
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector2D.H:127
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector).
Definition Vector2DI.H:163
scalar dist(const Vector2D< Cmpt > &v2) const
The L2-norm distance from another vector. The mag() of the difference.
Definition Vector2DI.H:89
scalar distSqr(const Vector2D< Cmpt > &v2) const
The L2-norm distance squared from another vector. The magSqr() of the difference.
Definition Vector2DI.H:78
static bool less_yx(const Vector2D< Cmpt > &a, const Vector2D< Cmpt > &b)
Lexicographically compare a and b with order (y:x).
Definition Vector2DI.H:138
bool isClose(const Vector2D< Cmpt > &b, const scalar tol=1e-10) const
Return true if vector is within tol.
Definition Vector2DI.H:171
scalar mag() const
The length (L2-norm) of the vector.
Definition Vector2DI.H:70
Vector2D()=default
Default construct.
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector2D.H:132
scalar magSqr() const
The length (L2-norm) squared of the vector.
Definition Vector2DI.H:59
Vector2D< Cmpt > & removeCollinear(const Vector2D< Cmpt > &unitVec)
Inplace removal of components that are collinear to the given unit vector.
Definition Vector2DI.H:115
static bool less_xy(const Vector2D< Cmpt > &a, const Vector2D< Cmpt > &b)
Lexicographically compare a and b with order (x:y).
Definition Vector2DI.H:126
Vector2D< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Normalise the vector by its magnitude.
Definition Vector2DI.H:96
Templated vector space.
Definition VectorSpace.H:75
VectorSpace< Vector2D< Cmpt >, Cmpt, Ncmpts > vsType
Definition VectorSpace.H:86
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
tmp< GeometricField< Type, faPatchField, areaMesh > > operator&(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
volScalarField & b