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 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 2D square matrix of objects of <T>, where the n x n matrix
32  dimension is known and used for subscript bounds checking, etc.
33 
34 SourceFiles
35  SquareMatrixI.H
36  SquareMatrix.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef SquareMatrix_H
41 #define SquareMatrix_H
42 
43 #include "Matrix.H"
44 #include "Identity.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward Declarations
52 template<class Type> class RectangularMatrix;
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class SquareMatrix Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type>
60 class SquareMatrix
61 :
62  public Matrix<SquareMatrix<Type>, Type>
63 {
64 
65 public:
66 
67  // Constructors
68 
69  //- Construct null
70  inline SquareMatrix();
71 
72  //- Construct for given size (rows == cols)
73  inline explicit SquareMatrix(const label n);
74 
75  //- Construct for given size (rows == cols)
76  //- initializing all elements to zero
77  inline SquareMatrix(const label n, const zero);
78 
79  //- Construct for given size (rows == cols)
80  //- initializing all elements to the given value
81  inline SquareMatrix(const label n, const Type& val);
82 
83  //- Construct for given size (rows == cols)
84  //- initializing to the identity matrix
85  template<class AnyType>
86  inline SquareMatrix(const label n, const Identity<AnyType>);
87 
88  template<class AnyType>
89  inline SquareMatrix(const labelPair& dims, const Identity<AnyType>);
90 
91  //- Construct given number of rows/columns (checked to be equal)
92  // For constructor consistency in rectangular matrices
93  inline explicit SquareMatrix(const labelPair& dims);
94 
95  //- Construct given number of rows/columns (checked to be equal)
96  //- initializing all elements to zero
97  // For constructor consistency with rectangular matrices
98  inline SquareMatrix(const labelPair& dims, const zero);
99 
100  //- Construct given number of rows/columns (checked to be equal)
101  //- initializing all elements to the given value
102  // For constructor consistency with rectangular matrices
103  inline SquareMatrix(const labelPair& dims, const Type& val);
104 
105  //- Construct given number of rows/columns (checked to be equal)
106  //- initializing all elements to zero
107  inline SquareMatrix(const label m, const label n, const zero);
108 
109  //- Construct from sub-matrix block
110  template<class MatrixType>
111  inline SquareMatrix(const ConstMatrixBlock<MatrixType>& mat);
112 
113  //- Construct from sub-matrix block
114  template<class MatrixType>
115  inline SquareMatrix(const MatrixBlock<MatrixType>& mat);
116 
117  //- Construct as copy of a RectangularMatrix
118  //- which is checked to be square
119  inline explicit SquareMatrix(const RectangularMatrix<Type>& mat);
120 
121  //- Construct from Istream
122  inline explicit SquareMatrix(Istream& is);
123 
124  //- Clone
125  inline autoPtr<SquareMatrix<Type>> clone() const;
126 
127 
128  // Member Functions
129 
130  // Edit
131 
132  //- Resize the matrix preserving the elements
133  inline void resize(const label m);
134 
135  //- Resize the matrix preserving the elements (compatibility)
136  inline void resize(const label m, const label n);
137 
138  //- Resize the matrix preserving the elements
139  inline void setSize(const label m);
140 
141  //- Resize the matrix without reallocating storage (unsafe)
142  inline void shallowResize(const label m);
143 
144  // Check
145 
146  //- Return true if the square matrix is effectively symmetric/Hermitian
147  inline bool symmetric() const;
148 
149  //- Return true if the square matrix is reduced tridiagonal
150  inline bool tridiagonal() const;
151 
152 
153  // Member Operators
154 
155  //- Assign all elements to zero
156  inline void operator=(const zero);
157 
158  //- Assign all elements to value
159  inline void operator=(const Type& val);
160 
161  //- Set to identity matrix
162  template<class AnyType>
163  void operator=(const Identity<AnyType>);
164 };
165 
166 
167 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
168 
169 //- Return the LU decomposed SquareMatrix det
170 template<class Type>
171 scalar detDecomposed(const SquareMatrix<Type>&, const label sign);
172 
173 //- Return the SquareMatrix det
174 template<class Type>
175 scalar det(const SquareMatrix<Type>&);
176 
177 //- Return the SquareMatrix det and the LU decomposition in the original matrix
178 template<class Type>
179 scalar det(SquareMatrix<Type>&);
180 
181 template<class Type>
182 class typeOfInnerProduct<Type, SquareMatrix<Type>, SquareMatrix<Type>>
183 {
184 public:
185 
186  typedef SquareMatrix<Type> type;
187 };
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #include "SquareMatrixI.H"
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 #ifdef NoRepository
200  #include "SquareMatrix.C"
201 #endif
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #endif
206 
207 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::SquareMatrix::SquareMatrix
SquareMatrix()
Construct null.
Definition: SquareMatrixI.H:41
Foam::SquareMatrix::clone
autoPtr< SquareMatrix< Type > > clone() const
Clone.
Definition: SquareMatrixI.H:213
Matrix.H
Foam::SquareMatrix::operator=
void operator=(const zero)
Assign all elements to zero.
Definition: SquareMatrixI.H:301
Foam::SquareMatrix::resize
void resize(const label m)
Resize the matrix preserving the elements.
Definition: SquareMatrixI.H:222
Foam::detDecomposed
scalar detDecomposed(const SquareMatrix< Type > &, const label sign)
Return the LU decomposed SquareMatrix det.
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:48
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Identity
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:49
Foam::MatrixBlock
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:66
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::SquareMatrix::symmetric
bool symmetric() const
Return true if the square matrix is effectively symmetric/Hermitian.
Definition: SquareMatrixI.H:256
Foam::RectangularMatrix
A templated 2D rectangular m x n matrix of objects of <Type>.
Definition: RectangularMatrix.H:56
SquareMatrixI.H
Foam::Matrix< SquareMatrix< Type >, Type >::n
label n() const noexcept
The number of columns.
Foam::SquareMatrix::tridiagonal
bool tridiagonal() const
Return true if the square matrix is reduced tridiagonal.
Definition: SquareMatrixI.H:273
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Identity.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::SquareMatrix
A templated 2D square matrix of objects of <T>, where the n x n matrix dimension is known and used fo...
Definition: SquareMatrix.H:59
Foam::Matrix< SquareMatrix< Type >, Type >::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:95
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::typeOfInnerProduct
Definition: products.H:51
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::SquareMatrix::setSize
void setSize(const label m)
Resize the matrix preserving the elements.
Definition: SquareMatrixI.H:242
Foam::ConstMatrixBlock
Definition: Matrix.H:65
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62
Foam::SquareMatrix::shallowResize
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
Definition: SquareMatrixI.H:249
SquareMatrix.C
Foam::zero
A class representing the concept of 0 (zero), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61
Foam::typeOfInnerProduct< Type, SquareMatrix< Type >, SquareMatrix< Type > >::type
SquareMatrix< Type > type
Definition: SquareMatrix.H:185