DiagTensor.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 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::DiagTensor
29 
30 Description
31  A templated (3 x 3) diagonal tensor of objects of <T>, effectively
32  containing 3 elements, derived from VectorSpace.
33 
34 See also
35  Test-DiagTensor.C
36 
37 SourceFiles
38  DiagTensorI.H
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_DiagTensor_H
43 #define Foam_DiagTensor_H
44 
45 #include "Tensor.H"
46 #include "SphericalTensor.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class DiagTensor Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Cmpt>
58 class DiagTensor
59 :
60  public VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>
61 {
62 public:
63 
64  // Typedefs
65 
66  //- Equivalent type of labels used for valid component indexing
68 
69 
70  // Member Constants
71 
72  //- Rank of DiagTensor is 2
73  static constexpr direction rank = 2;
74 
75 
76  //- Component labeling enumeration
77  enum components { XX, YY, ZZ };
78 
79 
80  // Generated Methods
81 
82  //- Default construct
83  DiagTensor() = default;
84 
85  //- Copy construct
86  DiagTensor(const DiagTensor&) = default;
87 
88  //- Copy assignment
89  DiagTensor& operator=(const DiagTensor&) = default;
90 
91 
92  // Constructors
93 
94  //- Construct initialized to zero
95  inline DiagTensor(const Foam::zero);
96 
97  //- Construct given VectorSpace
98  template<class Cmpt2>
99  inline DiagTensor(const VectorSpace<DiagTensor<Cmpt2>, Cmpt2, 3>&);
100 
101  //- Construct given SphericalTensor
102  inline DiagTensor(const SphericalTensor<Cmpt>&);
103 
104  //- Construct given three components
105  inline DiagTensor(const Cmpt& txx, const Cmpt& tyy, const Cmpt& tzz);
106 
107  //- Construct from Istream
108  inline explicit DiagTensor(Istream& is);
109 
110 
111  // Member Functions
112 
113  // Component Access
114 
115  const Cmpt& xx() const noexcept { return this->v_[XX]; }
116  const Cmpt& yy() const noexcept { return this->v_[YY]; }
117  const Cmpt& zz() const noexcept { return this->v_[ZZ]; }
118 
119  Cmpt& xx() noexcept { return this->v_[XX]; }
120  Cmpt& yy() noexcept { return this->v_[YY]; }
121  Cmpt& zz() noexcept { return this->v_[ZZ]; }
122 
123 
124  // Diagonal access and manipulation
125 
126  //- The L2-norm squared of the diagonal
127  inline scalar diagSqr() const;
128 };
129 
130 
131 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
133 //- Data are contiguous if component type is contiguous
134 template<class Cmpt>
135 struct is_contiguous<DiagTensor<Cmpt>> : is_contiguous<Cmpt> {};
137 //- Data are contiguous label if component type is label
138 template<class Cmpt>
139 struct is_contiguous_label<DiagTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
140 
141 //- Data are contiguous scalar if component type is scalar
142 template<class Cmpt>
143 struct is_contiguous_scalar<DiagTensor<Cmpt>> : is_contiguous_scalar<Cmpt> {};
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #include "DiagTensorI.H"
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #endif
157 
158 // ************************************************************************* //
const Cmpt & zz() const noexcept
Definition: DiagTensor.H:134
static constexpr direction rank
Rank of DiagTensor is 2.
Definition: DiagTensor.H:72
uint8_t direction
Definition: direction.H:46
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Templated vector space.
Definition: VectorSpace.H:52
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
components
Component labeling enumeration.
Definition: DiagTensor.H:78
DiagTensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: DiagTensor.H:64
DiagTensor()=default
Default construct.
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 3 elements, derived from VectorSpace.
Definition: DiagTensor.H:53
const direction noexcept
Definition: Scalar.H:258
const Cmpt & yy() const noexcept
Definition: DiagTensor.H:133
DiagTensor & operator=(const DiagTensor &)=default
Copy assignment.
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:80
A template class to specify that a data type can be considered as being contiguous in memory...
Definition: contiguous.H:70
A template class to specify if a data type is composed solely of Foam::label elements.
Definition: contiguous.H:75
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const Cmpt & xx() const noexcept
Definition: DiagTensor.H:132
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: DiagTensorI.H:78
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
Namespace for OpenFOAM.