SymmTensor2D.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::SymmTensor2D
29 
30 Description
31  A templated (2 x 2) symmetric tensor of objects of <T>, effectively
32  containing 3 elements, derived from VectorSpace.
33 
34 See also
35  Test-SymmTensor2D.C
36 
37 SourceFiles
38  SymmTensor2DI.H
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_SymmTensor2D_H
43 #define Foam_SymmTensor2D_H
44 
45 #include "contiguous.H"
46 #include "Vector2D.H"
47 #include "SphericalTensor2D.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class SymmTensor2D Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class Cmpt>
59 class SymmTensor2D
60 :
61  public VectorSpace<SymmTensor2D<Cmpt>, Cmpt, 3>
62 {
63 public:
64 
65  // Typedefs
66 
67  //- Equivalent type of labels used for valid component indexing
69 
70 
71  // Member Constants
72 
73  //- Rank of SymmTensor2D is 2
74  static constexpr direction rank = 2;
75 
76 
77  // Static Data Members
78 
79  static const SymmTensor2D I;
80 
81 
82  //- Component labeling enumeration
83  enum components { XX, XY, YY };
84 
85 
86  // Generated Methods
87 
88  //- Default construct
89  SymmTensor2D() = default;
90 
91  //- Copy construct
92  SymmTensor2D(const SymmTensor2D&) = default;
93 
94  //- Copy assignment
95  SymmTensor2D& operator=(const SymmTensor2D&) = default;
96 
97 
98  // Constructors
99 
100  //- Construct initialized to zero
101  inline SymmTensor2D(const Foam::zero);
102 
103  //- Construct given VectorSpace
104  inline SymmTensor2D(const VectorSpace<SymmTensor2D<Cmpt>, Cmpt, 3>&);
105 
106  //- Construct given SphericalTensor
107  inline SymmTensor2D(const SphericalTensor2D<Cmpt>&);
108 
109  //- Construct given the three components
110  inline SymmTensor2D
111  (
112  const Cmpt txx, const Cmpt txy,
113  const Cmpt tyy
114  );
115 
116  //- Construct from Istream
117  inline explicit SymmTensor2D(Istream& is);
118 
119 
120  // Member Functions
121 
122  // Component Access
123 
124  const Cmpt& xx() const noexcept { return this->v_[XX]; }
125  const Cmpt& xy() const noexcept { return this->v_[XY]; }
126  const Cmpt& yx() const noexcept { return this->v_[XY]; }
127  const Cmpt& yy() const noexcept { return this->v_[YY]; }
128 
129  Cmpt& xx() noexcept { return this->v_[XX]; }
130  Cmpt& xy() noexcept { return this->v_[XY]; }
131  Cmpt& yx() noexcept { return this->v_[XY]; }
132  Cmpt& yy() noexcept { return this->v_[YY]; }
133 
134 
135  // Diagonal access and manipulation
136 
137  //- Extract the diagonal as a vector
138  inline Vector2D<Cmpt> diag() const;
139 
140  //- Set values of the diagonal
141  inline void diag(const Vector2D<Cmpt>& v);
143  //- The L2-norm squared of the diagonal
144  inline scalar diagSqr() const;
145 
147  // Tensor Operations
149  //- Return non-Hermitian transpose
150  const SymmTensor2D<Cmpt>& T() const noexcept { return *this; }
151 
152  //- The determinate
153  inline Cmpt det() const;
154 
155  //- Return adjunct matrix (transpose of cofactor matrix)
156  inline SymmTensor2D<Cmpt> adjunct() const;
157 
158  //- Return cofactor matrix (transpose of adjunct matrix)
159  inline SymmTensor2D<Cmpt> cof() const;
160 
161  //- Return inverse
162  inline SymmTensor2D<Cmpt> inv() const;
163 
164 
165  // Member Operators
166 
167  //- Inherit VectorSpace assignment operators
169 
170  //- Construct given SphericalTensor2D
171  inline void operator=(const SphericalTensor2D<Cmpt>&);
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
176 
177 //- Data are contiguous if component type is contiguous
178 template<class Cmpt>
179 struct is_contiguous<SymmTensor2D<Cmpt>> : is_contiguous<Cmpt> {};
180 
181 //- Data are contiguous label if component type is label
182 template<class Cmpt>
183 struct is_contiguous_label<SymmTensor2D<Cmpt>> : is_contiguous_label<Cmpt> {};
184 
185 //- Data are contiguous scalar if component type is scalar
186 template<class Cmpt>
187 struct is_contiguous_scalar<SymmTensor2D<Cmpt>> : is_contiguous_scalar<Cmpt> {};
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #include "SymmTensor2DI.H"
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #endif
201 
202 // ************************************************************************* //
SymmTensor2D< label > labelType
Equivalent type of labels used for valid component indexing.
Definition: SymmTensor2D.H:65
SymmTensor2D()=default
Default construct.
SymmTensor2D< Cmpt > inv() const
Return inverse.
uint8_t direction
Definition: direction.H:46
static const SymmTensor2D I
Definition: SymmTensor2D.H:78
const Cmpt & xx() const noexcept
Definition: SymmTensor2D.H:141
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensor2DI.H:73
components
Component labeling enumeration.
Definition: SymmTensor2D.H:84
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const Cmpt & xy() const noexcept
Definition: SymmTensor2D.H:142
Templated vector space.
Definition: VectorSpace.H:52
const Cmpt & yx() const noexcept
Definition: SymmTensor2D.H:143
SymmTensor2D< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
Cmpt det() const
The determinate.
Definition: SymmTensor2DI.H:98
const Cmpt & yy() const noexcept
Definition: SymmTensor2D.H:144
SymmTensor2D & operator=(const SymmTensor2D &)=default
Copy assignment.
const SymmTensor2D< Cmpt > & T() const noexcept
Return non-Hermitian transpose.
Definition: SymmTensor2D.H:175
static constexpr direction rank
Rank of SymmTensor2D is 2.
Definition: SymmTensor2D.H:73
const direction noexcept
Definition: Scalar.H:258
friend Ostream & operator(Ostream &, const VectorSpace< Form, Cmpt, Ncmpts > &)
SymmTensor2D< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
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 templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements, derived from VectorSpace.
Definition: SymmTensor2D.H:54
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).
Definition: Vector2D.H:51
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: SymmTensor2DI.H:87
Cmpt v_[Ncmpts]
The components of this vector space.
Definition: VectorSpace.H:81
Namespace for OpenFOAM.