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 -------------------------------------------------------------------------------
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::SquareMatrix
29 
30 Description
31  A templated (N x N) square matrix of objects of <Type>,
32  containing N*N elements, derived from Matrix.
33 
34 See also
35  Test-SquareMatrix.C
36 
37 SourceFiles
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 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 template<class Type> class RectangularMatrix;
56 
57 /*---------------------------------------------------------------------------*\
58  Class SquareMatrix Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class SquareMatrix
63 :
64  public Matrix<SquareMatrix<Type>, Type>
65 {
66 public:
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;
78 
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);
92 
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>
126  inline SquareMatrix(const ConstMatrixBlock<MatrixType>& mat);
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);
138 
139  //- Clone
140  inline autoPtr<SquareMatrix<Type>> clone() const;
141 
142 
143  // Member Functions
144 
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
182 
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 
197 
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 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
autoPtr< SquareMatrix< Type > > clone() const
Clone.
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:62
bool symmetric() const
Return true if the square matrix is effectively symmetric/Hermitian.
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
label n() const noexcept
The number of columns.
Definition: Matrix.H:271
void resize_nocopy(const label n)
Resize the matrix without preserving existing content.
A templated (M x N) rectangular matrix of objects of <Type>, containing M*N elements, derived from Matrix.
labelList sortPermutation(CompOp &compare) const
Return a sort permutation using the given comparison operator on the diagonal entries.
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order: ...
SquareMatrix()=default
Default construct.
void setSize(const label m)
Resize the matrix preserving the elements.
label m() const noexcept
The number of rows.
Definition: Matrix.H:261
void resize(const label m)
Resize the matrix preserving the elements.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:43
SquareMatrix & operator=(const SquareMatrix &)=default
Copy assignment.
volScalarField & p
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix...
Definition: SquareMatrix.H:57
bool tridiagonal() const
Return true if the square matrix is reduced tridiagonal.
Namespace for OpenFOAM.
void applyPermutation(const labelUList &p)
Column-reorder this Matrix according to the given permutation.
Definition: SquareMatrix.C:47