triadI.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2022 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 inline Foam::triad::triad()
32 :
34 {}
35 
36 
37 inline Foam::triad::triad(const Vector<vector>& vv)
38 :
39  Vector<vector>(vv)
40 {}
41 
42 
43 inline Foam::triad::triad(const vector& x, const vector& y, const vector& z)
44 :
45  Vector<vector>(x, y, z)
46 {}
47 
48 
49 inline Foam::triad::triad(const tensor& t)
50 :
51  Vector<vector>(t.x(), t.y(), t.z())
52 {}
53 
54 
55 inline Foam::triad::triad(const vector& pa)
56 {
57  operator=(triad::unset);
58  operator[](primaryDirection(pa)) = pa;
59 }
60 
61 
62 inline Foam::triad::triad(Istream& is)
63 :
64  Vector<vector>(is)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
70 inline bool Foam::triad::set(const direction d) const
71 {
72  return operator[](d)[0] < GREAT;
73 }
74 
75 
76 inline bool Foam::triad::set() const
77 {
78  return set(0) && set(1) && set(2);
79 }
80 
81 
83 {
84  if
85  (
86  Foam::mag(v.x()) > Foam::mag(v.y())
87  && Foam::mag(v.x()) > Foam::mag(v.z())
88  )
89  {
90  return triad::X;
91  }
92  else if (Foam::mag(v.y()) > Foam::mag(v.z()))
93  {
94  return triad::Y;
95  }
96  else
97  {
98  return triad::Z;
99  }
100 }
101 
102 
104 (
105  const vector& v1,
106  const vector& v2
107 )
108 {
109  vector v3 = v1 ^ v2;
110 
111  scalar magV3 = Foam::mag(v3);
112 
113  if (magV3 > 0.5)
114  {
115  return v3/magV3;
116  }
117  else
118  {
119  return triad::unset[0];
120  }
121 }
122 
123 
124 inline void Foam::triad::normalise()
125 {
126  if (set(0)) (*this)[0].normalise();
127  if (set(1)) (*this)[1].normalise();
128  if (set(2)) (*this)[2].normalise();
129 }
130 
132 inline Foam::vector Foam::triad::cx() const
133 {
134  return vector(x().x(), y().x(), z().x());
135 }
136 
138 inline Foam::vector Foam::triad::cy() const
139 {
140  return vector(x().y(), y().y(), z().y());
141 }
142 
144 inline Foam::vector Foam::triad::cz() const
145 {
146  return vector(x().z(), y().z(), z().z());
147 }
148 
149 
150 inline Foam::triad Foam::triad::T() const
151 {
152  return triad(cx(), cy(), cz());
153 }
154 
155 
156 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
158 inline void Foam::triad::operator=(const Vector<vector>& vv)
159 {
161 }
162 
163 
164 inline void Foam::triad::operator=(const tensor& t)
165 {
166  x() = t.x();
167  y() = t.y();
168  z() = t.z();
169 }
170 
171 
172 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
173 
175 {
176  is >> static_cast<Vector<vector>&>(t);
177  return is;
178 }
179 
180 
181 inline Foam::Ostream& Foam::operator<<(Ostream& os, const triad& t)
182 {
183  os << static_cast<const Vector<vector>&>(t);
184  return os;
185 }
186 
187 
188 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
triad()
Default construct as &#39;unset&#39;.
Definition: triadI.H:24
void operator=(const Vector< vector > &vv)
Definition: triadI.H:151
void unset(List< bool > &bools, const labelUList &locations)
Unset the listed locations (assign &#39;false&#39;).
Definition: BitOps.C:99
scalar y
static const triad unset
Definition: triad.H:107
Istream & operator>>(Istream &, directionInfo &)
Vector< scalar > vector
Definition: vector.H:57
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
Definition: Vector.H:58
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
static direction primaryDirection(const vector &v)
Return the primary direction of the vector v.
Definition: triadI.H:75
static vector orthogonal(const vector &v1, const vector &v2)
Return the vector orthogonal to the two provided.
Definition: triadI.H:97
Representation of a 3D Cartesian coordinate system as a Vector of row vectors.
Definition: triad.H:60
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
vector cx() const
Extract vector for column 0.
Definition: triadI.H:125
triad T() const
Return transpose.
Definition: triadI.H:143
void normalise()
Normalise each set axis vector to have a unit magnitude.
Definition: triadI.H:117
Vector & operator=(const Vector &)=default
Copy assignment.
Tensor of scalars, i.e. Tensor<scalar>.
vector cy() const
Extract vector for column 1.
Definition: triadI.H:131
bool set() const
Are all the vector set.
Definition: triadI.H:69
vector cz() const
Extract vector for column 2.
Definition: triadI.H:137