SquareMatrix.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::SquareMatrix
26 
27 Description
28  A templated 2D square matrix of objects of <T>, where the n x n matrix
29  dimension is known and used for subscript bounds checking, etc.
30 
31 SourceFiles
32  SquareMatrixI.H
33  SquareMatrix.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef SquareMatrix_H
38 #define SquareMatrix_H
39 
40 #include "Matrix.H"
41 #include "Identity.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of friend functions and operators
49 
50 template<class Type>
51 class RectangularMatrix;
52 
53 
54 /*---------------------------------------------------------------------------*\
55  Class Matrix Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class Type>
59 class SquareMatrix
60 :
61  public Matrix<SquareMatrix<Type>, Type>
62 {
63 
64 public:
65 
66  // Constructors
67 
68  //- Null constructor.
69  inline SquareMatrix();
70 
71  //- Construct given number of rows/columns.
72  inline SquareMatrix(const label n);
73 
74  //- Construct from a block of another matrix
75  template<class MatrixType>
77 
78  //- Construct from a block of another matrix
79  template<class MatrixType>
81 
82  //- Construct given number of rows/columns
83  // initialising all elements to zero
84  inline SquareMatrix(const label n, const zero);
85 
86  //- Construct given number of rows and columns (checked to be equal)
87  // initialising all elements to zero
88  inline SquareMatrix(const label m, const label n, const zero);
89 
90  //- Construct given number of rows/columns
91  // Initialising to the identity matrix
92  inline SquareMatrix(const label n, const Identity<Type>);
93 
94  //- Construct with given number of rows and rows
95  // initialising all elements to the given value
96  inline SquareMatrix(const label n, const Type&);
97 
98  //- Construct as copy of a RectangularMatrix
99  // which is checked to be square
100  inline explicit SquareMatrix(const RectangularMatrix<Type>&);
101 
102  //- Construct from Istream.
103  inline SquareMatrix(Istream&);
104 
105  //- Clone
106  inline autoPtr<SquareMatrix<Type>> clone() const;
107 
108 
109  // Member Functions
110 
111  //- Return the instantiated type name
112  static word typeName()
113  {
114  return word("SquareMatrix<") + pTraits<Type>::typeName + '>';
115  }
116 
117  // Edit
118 
119  //- Resize the matrix preserving the elements
120  inline void setSize(const label m);
121 
122  //- Resize the matrix without reallocating storage (unsafe)
123  inline void shallowResize(const label m);
124 
125 
126  // Member Operators
127 
128  //- Assignment of all elements to zero
129  void operator=(const zero);
130 
131  //- Assignment elements to the
132  void operator=(const Identity<Type>);
133 };
134 
135 
136 // Global functions and operators
137 
138 //- Return the LU decomposed SquareMatrix det
139 template<class Type>
140 scalar detDecomposed(const SquareMatrix<Type>&, const label sign);
141 
142 //- Return the SquareMatrix det
143 template<class Type>
144 scalar det(const SquareMatrix<Type>&);
145 
146 //- Return the SquareMatrix det and the LU decomposition in the original matrix
147 template<class Type>
148 scalar det(SquareMatrix<Type>&);
149 
150 template<class Type>
151 class typeOfInnerProduct<Type, SquareMatrix<Type>, SquareMatrix<Type>>
152 {
153 public:
155  typedef SquareMatrix<Type> type;
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #include "SquareMatrixI.H"
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #ifdef NoRepository
170  #include "SquareMatrix.C"
171 #endif
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
scalar detDecomposed(const SquareMatrix< Type > &, const label sign)
Return the LU decomposed SquareMatrix det.
label n() const
Return the number of columns.
Definition: MatrixI.H:64
Abstract template class to provide the form resulting from.
Definition: products.H:47
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.
Traits class for primitives.
Definition: pTraits.H:50
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:71
void operator=(const zero)
Assignment of all elements to zero.
dimensionedScalar det(const dimensionedSphericalTensor &dt)
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
A class for handling words, derived from string.
Definition: word.H:59
A templated 2D rectangular m x n matrix of objects of <Type>.
A templated (m x n) matrix of objects of <T>.
static word typeName()
Return the instantiated type name.
Definition: SquareMatrix.H:111
void setSize(const label m)
Resize the matrix preserving the elements.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
label m() const
Return the number of rows.
Definition: MatrixI.H:57
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:47
A templated 2D square matrix of objects of <T>, where the n x n matrix dimension is known and used fo...
Definition: SquareMatrix.H:58
SquareMatrix()
Null constructor.
Definition: SquareMatrixI.H:29
Namespace for OpenFOAM.