triad.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 Class
28  Foam::triad
29 
30 Description
31  Representation of a 3D Cartesian coordinate system as a Vector of
32  row vectors.
33 
34 See also
35  Foam::quaternion
36 
37 SourceFiles
38  triadI.H
39  triad.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_triad_H
44 #define Foam_triad_H
45 
46 #include "vector.H"
47 #include "tensor.H"
48 #include "contiguous.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 class triad;
57 class quaternion;
58 inline Istream& operator>>(Istream&, triad&);
59 inline Ostream& operator<<(Ostream&, const triad&);
60 
61 /*---------------------------------------------------------------------------*\
62  Class triad Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class triad
66 :
67  public Vector<vector>
68 {
69 public:
70 
71  // Constructors
72 
73  //- Default construct as 'unset'
74  inline triad();
75 
76  //- Construct from components
77  inline triad(const Vector<vector>& vv);
78 
79  //- Construct from coordinate axes (row vectors)
80  inline triad(const vector& x, const vector& y, const vector& z);
81 
82  //- Construct from a tensor
83  inline triad(const tensor& t);
84 
85  //- Construct from a primary axis with the other two unset
86  inline triad(const vector& pa);
87 
88  //- Construct from a quaternion
89  triad(const quaternion& q);
90 
91  //- Construct from Istream
92  inline triad(Istream&);
93 
94 
95  // Static Data Members
96 
97  static const triad I;
98  static const triad unset;
99 
100 
101  // Member Functions
102 
103  //- Is the vector in the direction d set
104  inline bool set(const direction d) const;
105 
106  //- Are all the vector set
107  inline bool set() const;
108 
109  //- Return the primary direction of the vector v
110  static inline direction primaryDirection(const vector& v);
111 
112  //- Return the vector orthogonal to the two provided
113  static inline vector orthogonal(const vector& v1, const vector& v2);
114 
115  //- Inplace orthogonalise so that it is ortho-normal
116  void orthogonalise();
117 
118  //- Normalise each set axis vector to have a unit magnitude
119  // Uses vector::normalise with handling of small magnitudes.
120  void normalise();
121 
122  //- Align this triad with the given vector v
123  // by rotating the most aligned axis to be coincident with v
124  void align(const vector& v);
125 
126  //- Sort the axes such that they are closest to the x, y and z axes
127  triad sortxyz() const;
128 
129  //- Convert to a quaternion
130  operator quaternion() const;
131 
132  //- Return transpose
133  inline triad T() const;
134 
135 
136  // Column-vector access.
137 
138  //- Extract vector for column 0
139  inline vector cx() const;
140 
141  //- Extract vector for column 1
142  inline vector cy() const;
143 
144  //- Extract vector for column 2
145  inline vector cz() const;
146 
147 
148  // Member Operators
149 
150  inline void operator=(const Vector<vector>& vv);
151 
152  inline void operator=(const tensor& t);
153 
154  //- Add the triad t2 to this triad
155  // without normalising or orthogonalising
156  void operator+=(const triad& t2);
157 
158 
159  // IOstream Operators
160 
161  friend Istream& operator>>(Istream&, triad&);
162  friend Ostream& operator<<(Ostream&, const triad&);
163 
164 
165  // Housekeeping
166 
167  //- Same as orthogonalise
168  void orthogonalize() { this->orthogonalise(); }
169 
170  //- Same as normalise
171  void normalize() { this->normalise(); }
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
176 
177 //- Contiguous data for triad
178 template<> struct is_contiguous<triad> : std::true_type {};
179 
180 //- Contiguous 'scalar' data for triad
181 template<> struct is_contiguous_scalar<triad> : std::true_type {};
182 
183 
184 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
185 
186 //- Return a quantity of the difference between two triads
187 scalar diff(const triad& A, const triad& B);
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #include "triadI.H"
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:373
uint8_t direction
Definition: direction.H:46
friend Istream & operator>>(Istream &, triad &)
void align(const vector &v)
Align this triad with the given vector v.
Definition: triad.C:235
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const vector & y() const noexcept
Access to the vector y component.
Definition: Vector.H:140
triad()
Default construct as &#39;unset&#39;.
Definition: triadI.H:24
void orthogonalize()
Same as orthogonalise.
Definition: triad.H:210
void operator=(const Vector< vector > &vv)
Definition: triadI.H:151
static const triad I
Definition: triad.H:106
void orthogonalise()
Inplace orthogonalise so that it is ortho-normal.
Definition: triad.C:95
void normalize()
Same as normalise.
Definition: triad.H:215
static const triad unset
Definition: triad.H:107
Istream & operator>>(Istream &, directionInfo &)
triad sortxyz() const
Sort the axes such that they are closest to the x, y and z axes.
Definition: triad.C:280
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:53
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...
const vector & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
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
const vector & z() const noexcept
Access to the vector z component.
Definition: Vector.H:145
void operator+=(const triad &t2)
Add the triad t2 to this triad.
Definition: triad.C:172
void normalise()
Normalise each set axis vector to have a unit magnitude.
Definition: triadI.H:117
friend Ostream & operator<<(Ostream &, const triad &)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Tensor of scalars, i.e. Tensor<scalar>.
vector cy() const
Extract vector for column 1.
Definition: triadI.H:131
vector cz() const
Extract vector for column 2.
Definition: triadI.H:137
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
Namespace for OpenFOAM.