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-2019 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 triad_H
44 #define 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  //- Construct null
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  //- Orthogonalize this triad so that it is ortho-normal
116  void orthogonalize();
117 
118  //- Normalize each set axis vector to have a unit magnitude
119  void normalize();
120 
121  //- Align this triad with the given vector v
122  // by rotating the most aligned axis to be coincident with v
123  void align(const vector& v);
124 
125  //- Sort the axes such that they are closest to the x, y and z axes
126  triad sortxyz() const;
127 
128  //- Convert to a quaternion
129  operator quaternion() const;
130 
131  //- Return transpose
132  inline triad T() const;
133 
134 
135  // Column-vector access.
136 
137  //- Extract vector for column 0
138  inline vector cx() const;
139 
140  //- Extract vector for column 1
141  inline vector cy() const;
142 
143  //- Extract vector for column 2
144  inline vector cz() const;
145 
146 
147  // Member Operators
148 
149  inline void operator=(const Vector<vector>& vv);
150 
151  inline void operator=(const tensor& t);
152 
153  //- Add the triad t2 to this triad
154  // without normalizing or orthogonalizing
155  void operator+=(const triad& t2);
156 
157 
158  // IOstream Operators
159 
160  friend Istream& operator>>(Istream&, triad&);
161  friend Ostream& operator<<(Ostream&, const triad&);
162 };
163 
164 
165 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
166 
167 //- Contiguous data for triad
168 template<> struct is_contiguous<triad> : std::true_type {};
169 
170 //- Contiguous 'scalar' data for triad
171 template<> struct is_contiguous_scalar<triad> : std::true_type {};
172 
173 
174 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
175 
176 //- Return a quantity of the difference between two triads
177 scalar diff(const triad& A, const triad& B);
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #include "triadI.H"
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::Vector< vector >::x
const vector & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::triad::T
triad T() const
Return transpose.
Definition: triadI.H:146
Foam::triad::operator+=
void operator+=(const triad &t2)
Add the triad t2 to this triad.
Definition: triad.C:177
B
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Foam::triad::normalize
void normalize()
Normalize each set axis vector to have a unit magnitude.
Definition: triadI.H:120
Foam::triad::orthogonal
static vector orthogonal(const vector &v1, const vector &v2)
Return the vector orthogonal to the two provided.
Definition: triadI.H:100
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::triad::cx
vector cx() const
Extract vector for column 0.
Definition: triadI.H:128
Foam::triad::cz
vector cz() const
Extract vector for column 2.
Definition: triadI.H:140
Foam::triad::primaryDirection
static direction primaryDirection(const vector &v)
Return the primary direction of the vector v.
Definition: triadI.H:82
Foam::Vector< vector >::z
const vector & z() const
Access to the vector z component.
Definition: VectorI.H:85
tensor.H
Foam::triad::sortxyz
triad sortxyz() const
Sort the axes such that they are closest to the x, y and z axes.
Definition: triad.C:285
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
Foam::diff
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:378
Foam::triad::operator=
void operator=(const Vector< vector > &vv)
Definition: triadI.H:154
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::triad::I
static const triad I
Definition: triad.H:96
Foam::triad::operator<<
friend Ostream & operator<<(Ostream &, const triad &)
triadI.H
Foam::triad::unset
static const triad unset
Definition: triad.H:97
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::triad::orthogonalize
void orthogonalize()
Orthogonalize this triad so that it is ortho-normal.
Definition: triad.C:102
Foam::triad::align
void align(const vector &v)
Align this triad with the given vector v.
Definition: triad.C:240
Foam::triad::cy
vector cy() const
Extract vector for column 1.
Definition: triadI.H:134
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::is_contiguous_scalar
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:91
Foam::triad
Representation of a 3D Cartesian coordinate system as a Vector of row vectors.
Definition: triad.H:64
Foam::Vector< vector >::y
const vector & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
contiguous.H
Foam::triad::operator>>
friend Istream & operator>>(Istream &, triad &)
Foam::triad::set
bool set() const
Are all the vector set.
Definition: triadI.H:76
Foam::direction
uint8_t direction
Definition: direction.H:52
vector.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::triad::triad
triad()
Construct null.
Definition: triadI.H:31
Foam::is_contiguous
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:75