triad.H 5.3 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2018-2019 OpenCFD Ltd.
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7 8
     \\/     M anipulation  |
-------------------------------------------------------------------------------
                            | Copyright (C) 2012-2016 OpenFOAM Foundation
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::triad

Description
30 31
    Representation of a 3D Cartesian coordinate system as a Vector of
    row vectors.
32

33
See also
34 35 36 37 38 39 40 41 42 43 44 45
    Foam::quaternion

SourceFiles
    triadI.H
    triad.C

\*---------------------------------------------------------------------------*/

#ifndef triad_H
#define triad_H

#include "vector.H"
46
#include "tensor.H"
47 48 49 50 51 52 53
#include "contiguous.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

54 55
// Forward declarations
class triad;
56
class quaternion;
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
class Istream;
class Ostream;
Istream& operator>>(Istream&, triad&);
Ostream& operator<<(Ostream&, const triad&);

/*---------------------------------------------------------------------------*\
                           Class triad Declaration
\*---------------------------------------------------------------------------*/

class triad
:
    public Vector<vector>
{

public:

    // Constructors

        //- Construct null
        inline triad();

        //- Construct from components
        inline triad(const Vector<vector>& vv);

81
        //- Construct from coordinate axes (row vectors)
82 83
        inline triad(const vector& x, const vector& y, const vector& z);

84 85 86
        //- Construct from a tensor
        inline triad(const tensor& t);

87 88 89 90 91 92 93 94 95 96 97 98
        //- Construct from a primary axis with the other two unset
        inline triad(const vector& pa);

        //- Construct from a quaternion
        triad(const quaternion& q);

        //- Construct from Istream
        inline triad(Istream&);


    // Static data members

99
        static const triad I;
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        static const triad unset;


    // Member Functions

        //- Is the vector in the direction d set
        inline bool set(const direction d) const;

        //- Are all the vector set
        inline bool set() const;

        //- Return the primary direction of the vector v
        static inline direction primaryDirection(const vector& v);

        //- Return the vector orthogonal to the two provided
        static inline vector orthogonal(const vector& v1, const vector& v2);

        //- Orthogonalize this triad so that it is ortho-normal
        void orthogonalize();

        //- Normalize each set axis vector to have a unit magnitude
        void normalize();

        //- Align this triad with the given vector v
        //  by rotating the most aligned axis to be coincident with v
        void align(const vector& v);

        //- Sort the axes such that they are closest to the x, y and z axes
        triad sortxyz() const;

130
        //- Convert to a quaternion
131 132
        operator quaternion() const;

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        //- Return transpose
        inline triad T() const;


    // Column-vector access.

        //- Extract vector for column 0
        inline vector cx() const;

        //- Extract vector for column 1
        inline vector cy() const;

        //- Extract vector for column 2
        inline vector cz() const;

148 149 150

    // Member Operators

151
        inline void operator=(const Vector<vector>& vv);
152

153
        inline void operator=(const tensor& t);
154

155 156 157 158 159 160 161 162 163 164 165 166
        //- Add the triad t2 to this triad
        //  without normalizing or orthogonalizing
        void operator+=(const triad& t2);


    // IOstream Operators

        inline friend Istream& operator>>(Istream&, triad&);
        inline friend Ostream& operator<<(Ostream&, const triad&);
};


167 168 169 170 171 172 173 174 175
// * * * * * * * * * * * * * * * * * Traits  * * * * * * * * * * * * * * * * //

//- Contiguous data for triad
template<> struct is_contiguous<triad> : std::true_type {};

//- Contiguous 'scalar' data for triad
template<> struct is_contiguous_scalar<triad> : std::true_type {};


176 177
// * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //

178 179 180
//- Return a quantity of the difference between two triads
scalar diff(const triad& A, const triad& B);

181 182 183 184 185 186 187 188 189 190 191 192 193 194

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "triadI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //