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-2025 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/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/columns
95  // initialising all elements to the given value
96  inline SquareMatrix(const label n, const Type&);
97 
98  //- Construct with given number of rows/columns
99  // and start and end iterators
100  template<class InputIterator>
101  inline SquareMatrix
102  (
103  const label n,
104  InputIterator first,
105  InputIterator last
106  );
107 
108  //- Construct with given number of rows/columns and initialiser list
109  inline SquareMatrix(const label n, std::initializer_list<Type>);
110 
111  //- Construct from an initialiser list
112  inline SquareMatrix(std::initializer_list<Type>);
113 
114  //- Construct from initialiser list list
115  inline SquareMatrix(std::initializer_list<std::initializer_list<Type>>);
116 
117  //- Construct as copy of a RectangularMatrix
118  // which is checked to be square
119  inline explicit SquareMatrix(const RectangularMatrix<Type>&);
120 
121  //- Construct from Istream.
122  inline SquareMatrix(Istream&);
123 
124  //- Clone
125  inline autoPtr<SquareMatrix<Type>> clone() const;
126 
127 
128  // Member Functions
129 
130  //- Return the instantiated type name
131  static word typeName()
132  {
133  return word("SquareMatrix<") + pTraits<Type>::typeName + '>';
134  }
135 
136  // Edit
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 
145  // Member Operators
146 
147  //- Assignment of all elements to zero
148  void operator=(const zero);
149 
150  //- Assignment elements to the
151  void operator=(const Identity<Type>);
152 };
153 
154 
155 // Global functions and operators
156 
157 //- Return the LU decomposed SquareMatrix det
158 template<class Type>
159 scalar detDecomposed(const SquareMatrix<Type>&, const label sign);
160 
161 //- Return the SquareMatrix det
162 template<class Type>
163 scalar det(const SquareMatrix<Type>&);
164 
165 //- Return the SquareMatrix det and the LU decomposition in the original matrix
166 template<class Type>
167 scalar det(SquareMatrix<Type>&);
168 
169 template<class Type>
170 class typeOfInnerProduct<Type, SquareMatrix<Type>, SquareMatrix<Type>>
171 {
172 public:
173 
174  typedef SquareMatrix<Type> type;
175 };
176 
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 } // End namespace Foam
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #include "SquareMatrixI.H"
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #ifdef NoRepository
189  #include "SquareMatrix.C"
190 #endif
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
195 
196 // ************************************************************************* //
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:50
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>.
Definition: MatrixBlock.H:116
A templated (m x n) matrix of objects of <T>.
Definition: Matrix.H:83
label n() const
Return the number of columns.
Definition: MatrixI.H:64
label m() const
Return the number of rows.
Definition: MatrixI.H:57
A templated 2D rectangular m x n matrix of objects of <Type>.
A templated 2D square matrix of objects of <T>, where the n x n matrix dimension is known and used fo...
Definition: SquareMatrix.H:61
SquareMatrix()
Null constructor.
Definition: SquareMatrixI.H:29
static word typeName()
Return the instantiated type name.
Definition: SquareMatrix.H:130
autoPtr< SquareMatrix< Type > > clone() const
Clone.
void setSize(const label m)
Resize the matrix preserving the elements.
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
void operator=(const zero)
Assignment of all elements to zero.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Traits class for primitives.
Definition: pTraits.H:53
Abstract template class to provide the form resulting from.
Definition: products.H:48
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Namespace for OpenFOAM.
dimensionedScalar sign(const dimensionedScalar &ds)
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:59
void det(LagrangianPatchField< scalar > &f, const LagrangianPatchField< tensor > &f1)
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:39
scalar detDecomposed(const SquareMatrix< Type > &, const label sign)
Return the LU decomposed SquareMatrix det.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488