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 | Copyright (C) 2011-2016 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  // initializing 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  // initializing all elements to zero
88  inline SquareMatrix(const label m, const label n, const zero);
89 
90  //- Construct given number of rows/columns
91  // Initializing to the identity matrix
92  inline SquareMatrix(const label n, const Identity<Type>);
93 
94  //- Construct with given number of rows and rows
95  // initializing 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  // Edit
112 
113  //- Resize the matrix preserving the elements
114  inline void setSize(const label m);
115 
116  //- Resize the matrix without reallocating storage (unsafe)
117  inline void shallowResize(const label m);
118 
119 
120  // Member operators
121 
122  //- Assignment of all elements to zero
123  void operator=(const zero);
124 
125  //- Assignment elements to the
126  void operator=(const Identity<Type>);
127 };
128 
129 
130 // Global functions and operators
131 
132 //- Return the LU decomposed SquareMatrix det
133 template<class Type>
134 scalar detDecomposed(const SquareMatrix<Type>&, const label sign);
135 
136 //- Return the SquareMatrix det
137 template<class Type>
138 scalar det(const SquareMatrix<Type>&);
139 
140 //- Return the SquareMatrix det and the LU decomposition in the original matrix
141 template<class Type>
142 scalar det(SquareMatrix<Type>&);
143 
144 template<class Type>
145 class typeOfInnerProduct<Type, SquareMatrix<Type>, SquareMatrix<Type>>
146 {
147 public:
149  typedef SquareMatrix<Type> type;
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #include "SquareMatrixI.H"
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #ifdef NoRepository
164  #include "SquareMatrix.C"
165 #endif
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #endif
170 
171 // ************************************************************************* //
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
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
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: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 templated 2D rectangular m x n matrix of objects of <Type>.
A templated (m x n) matrix of objects of <T>.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
void setSize(const label m)
Resize the matrix preserving the elements.
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.