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-2021 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 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Cmpt>
33 :
35 {}
36 
37 
38 template<class Cmpt>
40 (
41  const VectorSpace<Vector2D<Cmpt>, Cmpt, 2>& vs
42 )
43 :
45 {}
46 
47 
48 template<class Cmpt>
49 inline Foam::Vector2D<Cmpt>::Vector2D(const Cmpt& vx, const Cmpt& vy)
50 {
51  this->v_[X] = vx;
52  this->v_[Y] = vy;
53 }
54 
55 
56 template<class Cmpt>
58 :
59  Vector2D::vsType(is)
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
65 template<class Cmpt>
66 inline const Cmpt& Foam::Vector2D<Cmpt>::x() const
67 {
68  return this->v_[X];
69 }
70 
71 
72 template<class Cmpt>
73 inline const Cmpt& Foam::Vector2D<Cmpt>::y() const
74 {
75  return this->v_[Y];
76 }
77 
78 
79 template<class Cmpt>
81 {
82  return this->v_[X];
83 }
84 
85 
86 template<class Cmpt>
88 {
89  return this->v_[Y];
90 }
91 
92 
93 template<class Cmpt>
95 {
96  const scalar s(Foam::mag(*this));
97 
98  if (s < ROOTVSMALL)
99  {
100  *this = Zero;
101  }
102  else
103  {
104  *this /= s;
105  }
106 
107  return *this;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 namespace Foam
114 {
115 
116 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
117 
118 template<class Cmpt>
121 {
122  return Cmpt(v1.x()*v2.x() + v1.y()*v2.y());
123 }
124 
125 
126 template<class Cmpt>
127 inline scalar Vector2D<Cmpt>::perp(const Vector2D<Cmpt>& b) const
128 {
129  return x()*b.y() - y()*b.x();
130 }
131 
132 
133 template<class Cmpt>
134 inline bool Vector2D<Cmpt>::isClose
135 (
136  const Vector2D<Cmpt>& b,
137  const scalar tol
138 ) const
139 {
140  return (mag(x() - b.x()) < tol && mag(y() - b.y()) < tol);
141 }
142 
143 
144 template<class Cmpt>
145 inline Vector2D<Cmpt> operator*(const Cmpt& s, const Vector2D<Cmpt>& v)
146 {
147  return Vector2D<Cmpt>(s*v.x(), s*v.y());
148 }
149 
150 
151 template<class Cmpt>
152 inline Vector2D<Cmpt> operator*(const Vector2D<Cmpt>& v, const Cmpt& s)
153 {
154  return s*v;
155 }
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // ************************************************************************* //
Foam::Vector2D::isClose
bool isClose(const Vector2D< Cmpt > &b, const scalar tol=1e-10) const
Return true if vector is within tol.
Definition: Vector2DI.H:135
s
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))
Definition: gmvOutputSpray.H:25
Foam::operator&
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::innerProduct
Definition: products.H:141
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:55
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
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::Vector2D
Vector2D()=default
Default construct.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::Vector2D::normalise
Vector2D< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: Vector2DI.H:94
Foam::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:590
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Vector2D::y
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
Foam::Vector2D::perp
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:127
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62