SquareMatrix.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-2022 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::SquareMatrix
29
30Description
31 A templated (N x N) square matrix of objects of <Type>,
32 containing N*N elements, derived from Matrix.
33
34See also
35 Test-SquareMatrix.C
36
37SourceFiles
38 SquareMatrixI.H
39 SquareMatrix.C
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef SquareMatrix_H
44#define SquareMatrix_H
45
46#include "Matrix.H"
47#include "Identity.H"
48#include <numeric>
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54
55// Forward Declarations
56template<class Type> class RectangularMatrix;
57
58
59/*---------------------------------------------------------------------------*\
60 Class SquareMatrix Declaration
61\*---------------------------------------------------------------------------*/
62
63template<class Type>
64class SquareMatrix
65:
66 public Matrix<SquareMatrix<Type>, Type>
67{
68
69public:
70
71 // Generated Methods
72
73 //- Default construct
74 SquareMatrix() = default;
75
76 //- Copy construct
77 SquareMatrix(const SquareMatrix&) = default;
78
79 //- Copy assignment
80 SquareMatrix& operator=(const SquareMatrix&) = default;
81
82
83 // Constructors
84
85 //- Construct for given size (rows == cols)
86 inline explicit SquareMatrix(const label n);
87
88 //- Construct for given size (rows == cols)
89 //- initializing all elements to zero
90 inline SquareMatrix(const label n, const Foam::zero);
91
92 //- Construct for given size (rows == cols)
93 //- initializing all elements to the given value
94 inline SquareMatrix(const label n, const Type& val);
95
96 //- Construct for given size (rows == cols)
97 //- initializing to the identity matrix
98 template<class AnyType>
99 inline SquareMatrix(const label n, const Identity<AnyType>);
100
101 //- Construct for given size (rows == cols) by using a labelPair
102 //- initializing to the identity matrix
103 template<class AnyType>
104 inline SquareMatrix(const labelPair& dims, const Identity<AnyType>);
105
106 //- Construct given number of rows/columns
107 //- by using a labelPair (checked to be equal)
108 // For constructor consistency in rectangular matrices
109 inline explicit SquareMatrix(const labelPair& dims);
110
111 //- Construct given number of rows/columns
112 //- by using a labelPair (checked to be equal)
113 //- and initializing all elements to zero
114 // For constructor consistency with rectangular matrices
115 inline SquareMatrix(const labelPair& dims, const Foam::zero);
116
117 //- Construct given number of rows/columns
118 //- by using a labelPair (checked to be equal)
119 //- and initializing all elements to the given value
120 // For constructor consistency with rectangular matrices
121 inline SquareMatrix(const labelPair& dims, const Type& val);
122
123 //- Construct given number of rows/columns (checked to be equal)
124 //- initializing all elements to zero
125 inline SquareMatrix(const label m, const label n, const Foam::zero);
126
127 //- Construct from const sub-matrix block
128 template<class MatrixType>
130
131 //- Construct from sub-matrix block
132 template<class MatrixType>
133 inline SquareMatrix(const MatrixBlock<MatrixType>& mat);
134
135 //- Construct as copy of a RectangularMatrix
136 //- which is checked to be square
137 inline explicit SquareMatrix(const RectangularMatrix<Type>& mat);
138
139 //- Construct from Istream
140 inline explicit SquareMatrix(Istream& is);
141
142 //- Clone
143 inline autoPtr<SquareMatrix<Type>> clone() const;
144
145
146 // Member Functions
147
148 // Edit
149
150 //- Resize the matrix preserving the elements
151 inline void resize(const label m);
152
153 //- Resize the matrix preserving the elements (compatibility)
154 inline void resize(const label m, const label n);
155
156 //- Resize the matrix preserving the elements
157 inline void setSize(const label m);
158
159 //- Resize the matrix without reallocating storage (unsafe)
160 inline void shallowResize(const label m);
161
162 // Check
163
164 //- Return true if the square matrix is effectively symmetric/Hermitian
165 inline bool symmetric() const;
166
167 //- Return true if the square matrix is reduced tridiagonal
168 inline bool tridiagonal() const;
169
170 // Sort
171
172 //- Return a sort permutation labelList according to
173 //- a given comparison on the diagonal entries
174 template<class CompOp>
175 List<label> sortPermutation(CompOp& compare) const;
176
177 //- Column-reorder this Matrix according to
178 //- a given permutation labelList
179 void applyPermutation(const List<label>& p);
180
181
182 // Member Operators
183
184 //- Move assignment
185 inline void operator=(SquareMatrix<Type>&& mat);
186
187 //- Assign all elements to zero
188 inline void operator=(const Foam::zero);
189
190 //- Assign all elements to value
191 inline void operator=(const Type& val);
192
193 //- Set to identity matrix
194 template<class AnyType>
195 void operator=(const Identity<AnyType>);
196};
197
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201} // End namespace Foam
202
203// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204
205#include "SquareMatrixI.H"
206
207// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208
209#ifdef NoRepository
210 #include "SquareMatrix.C"
211#endif
212
213// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214
215#endif
216
217// ************************************************************************* //
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: MatrixBlock.H:132
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: Matrix.H:81
label n() const noexcept
The number of columns.
Definition: MatrixI.H:103
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
A templated (M x N) rectangular matrix of objects of <Type>, containing M*N elements,...
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
Definition: SquareMatrix.H:66
bool symmetric() const
Return true if the square matrix is effectively symmetric/Hermitian.
SquareMatrix(const SquareMatrix &)=default
Copy construct.
List< label > sortPermutation(CompOp &compare) const
SquareMatrix()=default
Default construct.
autoPtr< SquareMatrix< Type > > clone() const
Clone.
void applyPermutation(const List< label > &p)
Definition: SquareMatrix.C:56
bool tridiagonal() const
Return true if the square matrix is reduced tridiagonal.
void setSize(const label m)
Resize the matrix preserving the elements.
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
SquareMatrix & operator=(const SquareMatrix &)=default
Copy assignment.
void resize(const label m)
Resize the matrix preserving the elements.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
volScalarField & p
Namespace for OpenFOAM.