Tensor.H 10.3 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2018-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30

Class
    Foam::Tensor

Description
31 32 33 34
    A templated (3 x 3) tensor of objects of \<T\> derived from MatrixSpace.

See also
    Test-Tensor.C
35 36 37 38

SourceFiles
    TensorI.H

39
See also
40 41 42
    Foam::MatrixSpace
    Foam::Vector

43 44 45 46 47
\*---------------------------------------------------------------------------*/

#ifndef Tensor_H
#define Tensor_H

48
#include "MatrixSpace.H"
49 50 51 52 53 54 55 56
#include "Vector.H"
#include "SphericalTensor.H"

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

namespace Foam
{

57 58 59
// Forward Declarations
template<class Cmpt> class SymmTensor;

60

61 62 63 64
/*---------------------------------------------------------------------------*\
                           Class Tensor Declaration
\*---------------------------------------------------------------------------*/

Henry's avatar
Henry committed
65
template<class Cmpt>
66 67
class Tensor
:
68
    public MatrixSpace<Tensor<Cmpt>, Cmpt, 3, 3>
69 70 71
{
public:

72 73 74 75
    // Typedefs

        //- Equivalent type of labels used for valid component indexing
        typedef Tensor<label> labelType;
76 77


78
    // Member Constants
79

80
        //- Rank of Tensor is 2
81
        static constexpr direction rank = 2;
82 83


84
    // Static Data Members
85

86
        static const Tensor I;
87 88 89 90 91 92


    //- Component labeling enumeration
    enum components { XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ };


93 94 95 96
    // Generated Methods

        //- Default construct
        Tensor() = default;
97

98 99 100 101 102 103 104 105
        //- Copy construct
        Tensor(const Tensor&) = default;

        //- Copy assignment
        Tensor& operator=(const Tensor&) = default;


    // Constructors
106

107
        //- Construct initialized to zero
108
        inline Tensor(const Foam::zero);
109 110 111

        //- Construct given MatrixSpace of the same rank
        template<class Cmpt2>
112
        inline Tensor(const MatrixSpace<Tensor<Cmpt2>, Cmpt2, 3, 3>& vs);
113

Henry's avatar
Henry committed
114 115
        //- Construct given VectorSpace of the same rank
        template<class Cmpt2>
116
        inline Tensor(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs);
117 118

        //- Construct given SphericalTensor
119
        inline Tensor(const SphericalTensor<Cmpt>& st);
120 121

        //- Construct given SymmTensor
122
        inline Tensor(const SymmTensor<Cmpt>& st);
123

124 125 126 127 128 129 130
        //- Construct given triad of row vectors,
        //- optionally treated as transposed (ie, column vectors)
        inline Tensor
        (
            const Vector<Vector<Cmpt>>& vecs,
            const bool transposed = false
        );
131

132 133
        //- Construct given the three row vectors,
        //- optionally treated as transposed (ie, column vectors)
134 135 136 137
        inline Tensor
        (
            const Vector<Cmpt>& x,
            const Vector<Cmpt>& y,
138 139
            const Vector<Cmpt>& z,
            const bool transposed = false
140 141
        );

142 143 144 145 146 147 148 149
        //- Construct given the nine components
        inline Tensor
        (
            const Cmpt txx, const Cmpt txy, const Cmpt txz,
            const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
            const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
        );

150 151 152 153 154 155 156 157 158 159 160 161
        //- Construct from a block of another matrix space
        template
        <
            template<class, direction, direction> class Block2,
            direction BRowStart,
            direction BColStart
        >
        Tensor
        (
            const Block2<Tensor<Cmpt>, BRowStart, BColStart>& block
        );

162
        //- Construct from Istream
163
        inline explicit Tensor(Istream& is);
164 165 166 167


    // Member Functions

168
        // Component access
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

            inline const Cmpt& xx() const;
            inline const Cmpt& xy() const;
            inline const Cmpt& xz() const;
            inline const Cmpt& yx() const;
            inline const Cmpt& yy() const;
            inline const Cmpt& yz() const;
            inline const Cmpt& zx() const;
            inline const Cmpt& zy() const;
            inline const Cmpt& zz() const;

            inline Cmpt& xx();
            inline Cmpt& xy();
            inline Cmpt& xz();
            inline Cmpt& yx();
            inline Cmpt& yy();
            inline Cmpt& yz();
            inline Cmpt& zx();
            inline Cmpt& zy();
            inline Cmpt& zz();

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219

        // Column-vector access.

            //- Extract vector for column 0
            inline Vector<Cmpt> cx() const;

            //- Extract vector for column 1
            inline Vector<Cmpt> cy() const;

            //- Extract vector for column 2
            inline Vector<Cmpt> cz() const;

            //- Extract vector for given column.
            //  Compile-time check of column index.
            template<direction Col>
            inline Vector<Cmpt> col() const;

            //- Extract vector for given column (0,1,2).
            //  Runtime check of column index.
            inline Vector<Cmpt> col(const direction c) const;

            //- Set values of given column
            //  Compile-time check of column index.
            template<direction Col>
            inline void col(const Vector<Cmpt>& v);

            //- Set values of given column (0,1,2)
            //  Runtime check of column index.
            inline void col(const direction c, const Vector<Cmpt>& v);

220 221 222 223 224 225 226 227
            //- Set column values
            inline void cols
            (
                const Vector<Cmpt>& x,
                const Vector<Cmpt>& y,
                const Vector<Cmpt>& z
            );

228

229
        // Row-vector access.
230

231
            //- Extract vector for row 0
232
            inline Vector<Cmpt> x() const;
233 234

            //- Extract vector for row 1
235
            inline Vector<Cmpt> y() const;
236 237

            //- Extract vector for row 2
238
            inline Vector<Cmpt> z() const;
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

            //- Extract vector for given row.
            //  Compile-time check of row index.
            template<direction Row>
            inline Vector<Cmpt> row() const;

            //- Extract vector for given row (0,1,2)
            //  Runtime check of row index.
            inline Vector<Cmpt> row(const direction r) const;

            //- Set values of given row
            //  Compile-time check of row index.
            template<direction Row>
            inline void row(const Vector<Cmpt>& v);

            //- Set values of given row (0,1,2)
            //  Runtime check of row index.
            inline void row(const direction r, const Vector<Cmpt>& v);

258 259 260 261 262 263 264 265
            //- Set row values
            inline void rows
            (
                const Vector<Cmpt>& x,
                const Vector<Cmpt>& y,
                const Vector<Cmpt>& z
            );

266

267
        // Diagonal access and manipulation
268 269 270 271 272 273

            //- Extract the diagonal as a vector
            inline Vector<Cmpt> diag() const;

            //- Set values of the diagonal
            inline void diag(const Vector<Cmpt>& v);
274 275 276


    // Tensor Operations
277

278
        //- Return non-Hermitian transpose
279 280
        inline Tensor<Cmpt> T() const;

281 282 283
        //- Return inverse
        inline Tensor<Cmpt> inv() const;

284 285 286 287 288 289
        //- Inner-product of this with another Tensor.
        inline Tensor<Cmpt> inner(const Tensor<Cmpt>& t2) const;

        //- Schur-product of this with another Tensor.
        inline Tensor<Cmpt> schur(const Tensor<Cmpt>& t2) const;

290 291 292

    // Member Operators

293 294
        //- Assign inner-product of this with another Tensor.
        inline void operator&=(const Tensor<Cmpt>& t);
Henry Weller's avatar
Henry Weller committed
295

296 297 298
        //- Inherit MatrixSpace assignment operators
        using Tensor::msType::operator=;

299 300 301 302
        //- Assign to an equivalent vector space
        template<class Cmpt2>
        inline void operator=(const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>&);

303 304 305 306 307
        //- Assign to a SphericalTensor
        inline void operator=(const SphericalTensor<Cmpt>&);

        //- Assign to a SymmTensor
        inline void operator=(const SymmTensor<Cmpt>&);
308

309
        //- Assign to a triad of row vectors
310
        inline void operator=(const Vector<Vector<Cmpt>>&);
311 312 313 314 315 316 317 318 319 320


    // Housekeeping

        //- Deprecated(2018-12) Return vector for given row (0,1)
        //  \deprecated(2018-12) use row() method
        Vector<Cmpt> vectorComponent(const direction cmpt) const
        {
            return row(cmpt);
        }
321 322 323
};


324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
// * * * * * * * * * * * * * * * * * Traits  * * * * * * * * * * * * * * * * //

//- Data are contiguous if component type is contiguous
template<class Cmpt>
struct is_contiguous<Tensor<Cmpt>> : is_contiguous<Cmpt> {};

//- Data are contiguous label if component type is label
template<class Cmpt>
struct is_contiguous_label<Tensor<Cmpt>> : is_contiguous_label<Cmpt> {};

//- Data are contiguous scalar if component type is scalar
template<class Cmpt>
struct is_contiguous_scalar<Tensor<Cmpt>> : is_contiguous_scalar<Cmpt> {};


339 340 341 342 343 344 345 346 347
template<class Cmpt>
class typeOfRank<Cmpt, 2>
{
public:

    typedef Tensor<Cmpt> type;
};


348 349 350 351 352 353 354 355 356
template<class Cmpt>
class typeOfTranspose<Cmpt, Tensor<Cmpt>>
{
public:

    typedef Tensor<Cmpt> type;
};


357 358 359 360 361 362 363 364 365
template<class Cmpt>
class typeOfSolve<Tensor<Cmpt>>
{
public:

    typedef Tensor<solveScalar> type;
};


366 367 368 369 370 371 372 373 374 375 376 377 378 379
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

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

// Include inline implementations
#include "TensorI.H"

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

#endif

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