Loading...
Searching...
No Matches
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-2023 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 Foam_SquareMatrix_H
44#define Foam_SquareMatrix_H
45
46#include "Matrix.H"
47#include "Identity.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55template<class Type> class RectangularMatrix;
56
57/*---------------------------------------------------------------------------*\
58 Class SquareMatrix Declaration
59\*---------------------------------------------------------------------------*/
60
61template<class Type>
62class SquareMatrix
63:
64 public Matrix<SquareMatrix<Type>, Type>
65{
66public:
67
68 // Generated Methods
69
70 //- Default construct
71 SquareMatrix() = default;
72
73 //- Copy construct
74 SquareMatrix(const SquareMatrix&) = default;
75
76 //- Copy assignment
77 SquareMatrix& operator=(const SquareMatrix&) = default;
79
80 // Constructors
81
82 //- Construct for given size (rows == cols), uninitialised content
83 inline explicit SquareMatrix(const label n);
84
85 //- Construct for given size (rows == cols)
86 //- initializing all elements to zero
87 inline SquareMatrix(const label n, Foam::zero);
88
89 //- Construct for given size (rows == cols)
90 //- initializing all elements to the given value
91 inline SquareMatrix(const label n, const Type& val);
93 //- Construct for given size (rows == cols)
94 //- initializing to the identity matrix
95 template<class AnyType>
96 inline SquareMatrix(const label n, const Identity<AnyType>);
97
98 //- Construct for given size (rows == cols) by using a labelPair
99 //- initializing to the identity matrix
100 template<class AnyType>
101 inline SquareMatrix(const labelPair& dims, const Identity<AnyType>);
102
103 //- Construct given number of rows/columns
104 //- by using a labelPair (checked to be equal)
105 // For constructor consistency in rectangular matrices
106 inline explicit SquareMatrix(const labelPair& dims);
107
108 //- Construct given number of rows/columns
109 //- by using a labelPair (checked to be equal)
110 //- and initializing all elements to zero
111 // For constructor consistency with rectangular matrices
112 inline SquareMatrix(const labelPair& dims, Foam::zero);
113
114 //- Construct given number of rows/columns
115 //- by using a labelPair (checked to be equal)
116 //- and initializing all elements to the given value
117 // For constructor consistency with rectangular matrices
118 inline SquareMatrix(const labelPair& dims, const Type& val);
119
120 //- Construct given number of rows/columns (checked to be equal)
121 //- initializing all elements to zero
122 inline SquareMatrix(const label m, const label n, Foam::zero);
123
124 //- Construct from const sub-matrix block
125 template<class MatrixType>
127
128 //- Construct from sub-matrix block
129 template<class MatrixType>
130 inline SquareMatrix(const MatrixBlock<MatrixType>& mat);
131
132 //- Construct as copy of a RectangularMatrix
133 //- which is checked to be square
134 inline explicit SquareMatrix(const RectangularMatrix<Type>& mat);
135
136 //- Construct from Istream
137 inline explicit SquareMatrix(Istream& is);
139 //- Clone
140 inline autoPtr<SquareMatrix<Type>> clone() const;
141
142
143 // Member Functions
145 // Edit
146
147 //- Resize the matrix preserving the elements
148 inline void resize(const label m);
149
150 //- Resize the matrix \em without preserving existing content
151 inline void resize_nocopy(const label n);
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 using the given comparison operator
173 //- on the diagonal entries
174 template<class CompOp>
175 labelList sortPermutation(CompOp& compare) const;
176
177 //- Column-reorder this Matrix according to the given permutation
178 void applyPermutation(const labelUList& p);
179
180
181 // Member Operators
183 //- Move assignment
184 inline void operator=(SquareMatrix<Type>&& mat);
185
186 //- Assign all elements to zero
187 inline void operator=(Foam::zero);
188
189 //- Assign all elements to value
190 inline void operator=(const Type& val);
191
192 //- Set to identity matrix
193 template<class AnyType>
194 void operator=(const Identity<AnyType>);
195};
196
198// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199
200} // End namespace Foam
201
202// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203
204#include "SquareMatrixI.H"
205
206// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207
208#ifdef NoRepository
209 #include "SquareMatrix.C"
210#endif
211
212// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213
214#endif
215
216// ************************************************************************* //
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition Identity.H:46
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A templated block of an (m x n) matrix of type <MatrixType>.
label m() const noexcept
The number of rows.
Definition Matrix.H:261
label n() const noexcept
The number of columns.
Definition Matrix.H:271
A templated (M x N) rectangular matrix of objects of <Type>, containing M*N elements,...
bool symmetric() const
Return true if the square matrix is effectively symmetric/Hermitian.
void operator=(Foam::zero)
Assign all elements to zero.
SquareMatrix(const label m, const label n, Foam::zero)
Construct given number of rows/columns (checked to be equal) initializing all elements to zero.
SquareMatrix(const RectangularMatrix< Type > &mat)
Construct as copy of a RectangularMatrix which is checked to be square.
void resize_nocopy(const label n)
Resize the matrix without preserving existing content.
SquareMatrix(const SquareMatrix &)=default
Copy construct.
SquareMatrix(const labelPair &dims)
Construct given number of rows/columns by using a labelPair (checked to be equal).
SquareMatrix(const label n, const Identity< AnyType >)
Construct for given size (rows == cols) initializing to the identity matrix.
SquareMatrix(const labelPair &dims, const Identity< AnyType >)
Construct for given size (rows == cols) by using a labelPair initializing to the identity matrix.
SquareMatrix(const labelPair &dims, Foam::zero)
Construct given number of rows/columns by using a labelPair (checked to be equal) and initializing al...
SquareMatrix(const labelPair &dims, const Type &val)
Construct given number of rows/columns by using a labelPair (checked to be equal) and initializing al...
void operator=(SquareMatrix< Type > &&mat)
Move assignment.
SquareMatrix()=default
Default construct.
autoPtr< SquareMatrix< Type > > clone() const
Clone.
labelList sortPermutation(CompOp &compare) const
Return a sort permutation using the given comparison operator on the diagonal entries.
SquareMatrix(const label n, Foam::zero)
Construct for given size (rows == cols) initializing all elements to zero.
SquareMatrix(const ConstMatrixBlock< MatrixType > &mat)
Construct from const sub-matrix block.
SquareMatrix(Istream &is)
Construct from Istream.
SquareMatrix(const label n, const Type &val)
Construct for given size (rows == cols) initializing all elements to the given value.
bool tridiagonal() const
Return true if the square matrix is reduced tridiagonal.
void applyPermutation(const labelUList &p)
Column-reorder this Matrix according to the given permutation.
SquareMatrix(const label n)
Construct for given size (rows == cols), uninitialised content.
void operator=(const Type &val)
Assign all elements to value.
void operator=(const Identity< AnyType >)
Set to identity matrix.
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.
SquareMatrix(const MatrixBlock< MatrixType > &mat)
Construct from sub-matrix block.
void resize(const label m)
Resize the matrix preserving the elements.
void resize(const label m, const label n)
Resize the matrix preserving the elements (compatibility).
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
volScalarField & p
Namespace for OpenFOAM.
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
List< label > labelList
A List of labels.
Definition List.H:62
UList< label > labelUList
A UList of labels.
Definition UList.H:75