MatrixBlock.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 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::MatrixBlock
29 
30 Description
31  A templated block of an (m x n) matrix of type <MatrixType>.
32 
33  Foam::ConstMatrixBlock: block of a const matrix
34  Foam::MatrixBlock: block of a non-const matrix
35 
36  The block may be assigned to a block of another matrix or to a VectorSpace
37  or MatrixSpace e.g. \c tensor. Conversion of a column block to a \c
38  Field<T> is also provide.
39 
40 SourceFiles
41  MatrixBlock.C
42  MatrixBlockI.H
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef MatrixBlock_H
47 #define MatrixBlock_H
48 
49 #include "Matrix.H"
50 #include "MatrixSpace.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class ConstMatrixBlock Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class MatrixType>
62 class ConstMatrixBlock
63 {
64  // Private Data
65 
66  //- Const reference to the parent matrix
67  const MatrixType& matrix_;
68 
69  //- Block size
70  const label mRows_;
71  const label nCols_;
72 
73  //- Block location in parent matrix
74  const label rowStart_;
75  const label colStart_;
76 
77 
78  // Private Member Functions
79 
80  //- Error message for failed sanity checks during matrix construction
81  label disallow(const char *what) const;
82 
83 
84 public:
85 
86  typedef typename MatrixType::cmptType cmptType;
87 
88  // Constructors
89 
90  //- Construct block for matrix, size and location
91  inline ConstMatrixBlock
92  (
93  const MatrixType& matrix,
94  const label m,
95  const label n,
96  const label mStart,
97  const label nStart
98  );
99 
100 
101  // Member Functions
102 
103  //- Return the number of rows in the block
104  inline label m() const;
105 
106  //- Return the number of columns in the block
107  inline label n() const;
108 
109  //- Return row/column sizes
110  inline labelPair sizes() const;
111 
112  //- (i, j) const element access operator
113  inline const cmptType& operator()
114  (
115  const label i,
116  const label j
117  ) const;
118 
119  //- Convert a column of a matrix to a Field
120  operator Field<cmptType>() const;
121 
122  //- Check if (i, j) is within range of row-column limits
123  void checkIndex(const label i, const label j) const;
124 };
125 
126 
127 /*---------------------------------------------------------------------------*\
128  Class MatrixBlock Declaration
129 \*---------------------------------------------------------------------------*/
130 
131 template<class MatrixType>
132 class MatrixBlock
133 {
134  // Private Data
135 
136  //- Reference to the parent matrix
137  MatrixType& matrix_;
138 
139  //- Block size
140  const label mRows_;
141  const label nCols_;
142 
143  //- Block location in parent matrix
144  const label rowStart_;
145  const label colStart_;
146 
147 
148  // Private Member Functions
149 
150  //- Error message for failed sanity checks during matrix construction
151  label disallow(const char *what) const;
152 
153 
154 public:
155 
156  typedef typename MatrixType::cmptType cmptType;
157 
158 
159  // Generated Methods
160 
161  //- Copy construct
162  MatrixBlock(const MatrixBlock&) = default;
163 
164 
165  // Constructors
166 
167  //- Construct block for matrix, size and location
168  inline MatrixBlock
169  (
170  MatrixType& matrix,
171  const label m,
172  const label n,
173  const label mStart,
174  const label nStart
175  );
176 
177 
178  // Member Functions
179 
180  //- Return the number of rows in the block
181  inline label m() const;
182 
183  //- Return the number of columns in the block
184  inline label n() const;
185 
186  //- Return row/column sizes
187  inline labelPair sizes() const;
188 
189  //- (i, j) const element access operator
190  inline const cmptType& operator()
191  (
192  const label i,
193  const label j
194  ) const;
195 
196  //- (i, j) element access operator
197  inline cmptType& operator()(const label i, const label j);
198 
199  //- Convert a column of a matrix to a Field
200  operator Field<cmptType>() const;
201 
202  //- Check if (i, j) is within range of row-column limits
203  void checkIndex(const label i, const label j) const;
204 
205 
206  // Member Operators
207 
208  //- Assignment to a compatible matrix
209  template<class Form>
210  void operator=(const Matrix<Form, cmptType>&);
211 
212  //- Assignment to a compatible const block
214 
215  //- Assignment to a compatible block
216  void operator=(const MatrixBlock<MatrixType>&);
217 
218  //- Assignment to a compatible const block
219  template<class MatrixType2>
221 
222  //- Assignment to a compatible block
223  template<class MatrixType2>
224  void operator=(const MatrixBlock<MatrixType2>&);
225 
226  //- Assignment to a compatible MatrixSpace
227  template<class MSForm, direction Nrows, direction Ncols>
229 
230  //- Assignment to a compatible MatrixSpace block
231  template
232  <
233  template<class, direction, direction> class Block,
234  class SubTensor,
235  direction BRowStart,
236  direction BColStart
237  >
238  void operator=(const Block<SubTensor, BRowStart, BColStart>&);
239 
240  //- Assignment to a compatible VectorSpace (column-vector)
241  template<class VSForm, direction Ncmpts>
243 
244  //- Assignment to a compatible VectorSpace (column-vector) block
245  template
246  <
247  template<class, direction> class Block,
248  class SubVector,
249  direction BStart
250  >
251  void operator=(const Block<SubVector, BStart>&);
252 
253  //- Assignment to a Field (column-vector)
254  void operator=(const Field<cmptType>&);
255 };
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #include "MatrixBlockI.H"
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #ifdef NoRepository
269  #include "MatrixBlock.C"
270 #endif
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #endif
275 
276 // ************************************************************************* //
Foam::MatrixBlock::n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:111
Matrix.H
MatrixSpace.H
Foam::MatrixBlock::sizes
labelPair sizes() const
Return row/column sizes.
Definition: MatrixBlockI.H:125
Foam::MatrixBlock::MatrixBlock
MatrixBlock(const MatrixBlock &)=default
Copy construct.
Foam::MatrixBlock::operator()
const cmptType & operator()(const label i, const label j) const
(i, j) const element access operator
Definition: MatrixBlockI.H:152
MatrixBlock.C
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:53
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::MatrixSpace
Templated matrix space.
Definition: MatrixSpace.H:58
Foam::ConstMatrixBlock::ConstMatrixBlock
ConstMatrixBlock(const MatrixType &matrix, const label m, const label n, const label mStart, const label nStart)
Construct block for matrix, size and location.
Definition: MatrixBlockI.H:33
Foam::MatrixBlock::cmptType
MatrixType::cmptType cmptType
Definition: MatrixBlock.H:155
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::MatrixBlock
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:66
MatrixBlockI.H
Foam::MatrixBlock::checkIndex
void checkIndex(const label i, const label j) const
Check if (i, j) is within range of row-column limits.
Definition: MatrixBlock.C:125
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ConstMatrixBlock::n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:97
Foam::MatrixBlock::m
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:104
Foam::ConstMatrixBlock::cmptType
MatrixType::cmptType cmptType
Definition: MatrixBlock.H:85
Foam::Pair< label >
Foam::MatrixBlock::operator=
void operator=(const Matrix< Form, cmptType > &)
Assignment to a compatible matrix.
Definition: MatrixBlock.C:150
Foam::ConstMatrixBlock::m
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:90
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::ConstMatrixBlock
Definition: Matrix.H:65
Foam::ConstMatrixBlock::sizes
labelPair sizes() const
Return row/column sizes.
Definition: MatrixBlockI.H:118
Foam::ConstMatrixBlock::checkIndex
void checkIndex(const label i, const label j) const
Check if (i, j) is within range of row-column limits.
Definition: MatrixBlock.C:104