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 class Istream;
59 class Ostream;
60 Istream& operator>>(Istream&, triad&);
61 Ostream& operator<<(Ostream&, const triad&);
62 
63 /*---------------------------------------------------------------------------*\
64  Class triad Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class triad
68 :
69  public Vector<vector>
70 {
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct null
77  inline triad();
78 
79  //- Construct from components
80  inline triad(const Vector<vector>& vv);
81 
82  //- Construct from coordinate axes (row vectors)
83  inline triad(const vector& x, const vector& y, const vector& z);
84 
85  //- Construct from a tensor
86  inline triad(const tensor& t);
87 
88  //- Construct from a primary axis with the other two unset
89  inline triad(const vector& pa);
90 
91  //- Construct from a quaternion
92  triad(const quaternion& q);
93 
94  //- Construct from Istream
95  inline triad(Istream&);
96 
97 
98  // Static data members
99 
100  static const triad I;
101  static const triad unset;
102 
103 
104  // Member Functions
105 
106  //- Is the vector in the direction d set
107  inline bool set(const direction d) const;
108 
109  //- Are all the vector set
110  inline bool set() const;
111 
112  //- Return the primary direction of the vector v
113  static inline direction primaryDirection(const vector& v);
114 
115  //- Return the vector orthogonal to the two provided
116  static inline vector orthogonal(const vector& v1, const vector& v2);
117 
118  //- Orthogonalize this triad so that it is ortho-normal
119  void orthogonalize();
120 
121  //- Normalize each set axis vector to have a unit magnitude
122  void normalize();
123 
124  //- Align this triad with the given vector v
125  // by rotating the most aligned axis to be coincident with v
126  void align(const vector& v);
127 
128  //- Sort the axes such that they are closest to the x, y and z axes
129  triad sortxyz() const;
130 
131  //- Convert to a quaternion
132  operator quaternion() const;
133 
134  //- Return transpose
135  inline triad T() const;
136 
137 
138  // Column-vector access.
139 
140  //- Extract vector for column 0
141  inline vector cx() const;
142 
143  //- Extract vector for column 1
144  inline vector cy() const;
145 
146  //- Extract vector for column 2
147  inline vector cz() const;
148 
149 
150  // Member Operators
151 
152  inline void operator=(const Vector<vector>& vv);
153 
154  inline void operator=(const tensor& t);
155 
156  //- Add the triad t2 to this triad
157  // without normalizing or orthogonalizing
158  void operator+=(const triad& t2);
159 
160 
161  // IOstream Operators
162 
163  inline friend Istream& operator>>(Istream&, triad&);
164  inline friend Ostream& operator<<(Ostream&, const triad&);
165 };
166 
167 
168 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
169 
170 //- Contiguous data for triad
171 template<> struct is_contiguous<triad> : std::true_type {};
172 
173 //- Contiguous 'scalar' data for triad
174 template<> struct is_contiguous_scalar<triad> : std::true_type {};
175 
176 
177 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
178 
179 //- Return a quantity of the difference between two triads
180 scalar diff(const triad& A, const triad& B);
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #include "triadI.H"
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 #endif
194 
195 // ************************************************************************* //
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:99
Foam::triad::operator<<
friend Ostream & operator<<(Ostream &, const triad &)
triadI.H
Foam::triad::unset
static const triad unset
Definition: triad.H:100
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:66
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