Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::DiagTensor
29
30Description
31 A templated (3 x 3) diagonal tensor of objects of <T>, effectively
32 containing 3 elements, derived from VectorSpace.
33
34See also
35 Test-DiagTensor.C
36
37SourceFiles
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
50namespace Foam
51{
52
53/*---------------------------------------------------------------------------*\
54 Class DiagTensor Declaration
55\*---------------------------------------------------------------------------*/
56
57template<class Cmpt>
58class DiagTensor
59:
60 public VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>
61{
62public:
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 };
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
92 // Constructors
93
94 //- Construct initialized to zero
95 inline DiagTensor(Foam::zero);
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
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
126 //- Extract the diagonal as a vector
127 inline Vector<Cmpt> diag() const;
128
129 //- The L2-norm squared of the diagonal
130 inline scalar diagSqr() const;
131};
134// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
135
136//- Data are contiguous if component type is contiguous
137template<class Cmpt>
138struct is_contiguous<DiagTensor<Cmpt>> : is_contiguous<Cmpt> {};
139
140//- Data are contiguous label if component type is label
141template<class Cmpt>
142struct is_contiguous_label<DiagTensor<Cmpt>> : is_contiguous_label<Cmpt> {};
143
144//- Data are contiguous scalar if component type is scalar
145template<class Cmpt>
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151} // End namespace Foam
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155#include "DiagTensorI.H"
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158
159#endif
160
161// ************************************************************************* //
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 3 elements,...
Definition DiagTensor.H:56
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition DiagTensorI.H:85
DiagTensor & operator=(const DiagTensor &)=default
Copy assignment.
DiagTensor< label > labelType
Equivalent type of labels used for valid component indexing.
Definition DiagTensor.H:64
const Cmpt & yy() const noexcept
Definition DiagTensor.H:133
DiagTensor(const Cmpt &txx, const Cmpt &tyy, const Cmpt &tzz)
Construct given three components.
Definition DiagTensorI.H:56
components
Component labeling enumeration.
Definition DiagTensor.H:78
DiagTensor()=default
Default construct.
static constexpr direction rank
Definition DiagTensor.H:72
Cmpt & xx() noexcept
Definition DiagTensor.H:136
Cmpt & zz() noexcept
Definition DiagTensor.H:138
DiagTensor(const VectorSpace< DiagTensor< Cmpt2 >, Cmpt2, 3 > &)
Construct given VectorSpace.
Definition DiagTensorI.H:37
DiagTensor(Istream &is)
Construct from Istream.
Definition DiagTensorI.H:69
DiagTensor(const SphericalTensor< Cmpt > &)
Construct given SphericalTensor.
Definition DiagTensorI.H:46
DiagTensor(const DiagTensor &)=default
Copy construct.
const Cmpt & xx() const noexcept
Definition DiagTensor.H:132
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition DiagTensorI.H:78
const Cmpt & zz() const noexcept
Definition DiagTensor.H:134
Cmpt & yy() noexcept
Definition DiagTensor.H:137
DiagTensor(Foam::zero)
Construct initialized to zero.
Definition DiagTensorI.H:28
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element,...
Cmpt v_[Ncmpts]
The components of this vector space.
Definition VectorSpace.H:81
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition Vector.H:61
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Namespace for OpenFOAM.
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265
A template class to specify if a data type is composed solely of Foam::label elements.
Definition contiguous.H:82
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition contiguous.H:87
A template class to specify that a data type can be considered as being contiguous in memory.
Definition contiguous.H:70