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-2022 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:
34 Vector2D::vsType(Zero)
35{}
36
37
38template<class Cmpt>
40(
41 const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs
42)
43:
44 Vector2D::vsType(vs)
45{}
46
47
48template<class Cmpt>
49inline Foam::Vector2D<Cmpt>::Vector2D(const Cmpt& vx, const Cmpt& vy)
50{
51 this->v_[X] = vx;
52 this->v_[Y] = vy;
53}
54
55
56template<class Cmpt>
58:
59 Vector2D::vsType(is)
60{}
61
62
63// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64
65template<class Cmpt>
66inline const Cmpt& Foam::Vector2D<Cmpt>::x() const
67{
68 return this->v_[X];
69}
70
71
72template<class Cmpt>
73inline const Cmpt& Foam::Vector2D<Cmpt>::y() const
74{
75 return this->v_[Y];
76}
77
78
79template<class Cmpt>
81{
82 return this->v_[X];
83}
84
85
86template<class Cmpt>
88{
89 return this->v_[Y];
90}
91
93template<class Cmpt>
96 const scalar s(Foam::mag(*this));
97
98 if (s < tol)
99 {
100 *this = Zero;
102 else
103 {
104 *this /= s;
105 }
106
107 return *this;
108}
109
111template<class Cmpt>
114{
115 *this -= (*this & unitVec) * unitVec;
116 return *this;
117}
118
119
120// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121
122namespace Foam
123{
124
125// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
127template<class Cmpt>
131 return Cmpt(v1.x()*v2.x() + v1.y()*v2.y());
132}
134
135template<class Cmpt>
136inline scalar Vector2D<Cmpt>::perp(const Vector2D<Cmpt>& b) const
137{
138 return x()*b.y() - y()*b.x();
139}
140
141
142template<class Cmpt>
144(
145 const Vector2D<Cmpt>& b,
146 const scalar tol
147) const
148{
149 return (mag(x() - b.x()) < tol && mag(y() - b.y()) < tol);
150}
151
152
153template<class Cmpt>
154inline Vector2D<Cmpt> operator*(const Cmpt& s, const Vector2D<Cmpt>& v)
155{
156 return Vector2D<Cmpt>(s*v.x(), s*v.y());
157}
158
159
160template<class Cmpt>
161inline Vector2D<Cmpt> operator*(const Vector2D<Cmpt>& v, const Cmpt& s)
162{
163 return s*v;
164}
165
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169} // End namespace Foam
170
171// ************************************************************************* //
scalar y
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:58
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:136
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
bool isClose(const Vector2D< Cmpt > &b, const scalar tol=1e-10) const
Return true if vector is within tol.
Definition: Vector2DI.H:144
Vector2D()=default
Default construct.
Vector2D< Cmpt > & removeCollinear(const Vector2D< Cmpt > &unitVec)
Definition: Vector2DI.H:113
Templated vector space.
Definition: VectorSpace.H:79
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
PtrList< volScalarField > & Y
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 > &)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
volScalarField & b
Definition: createFields.H:27