Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::MatrixBlock
29
30Description
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
40SourceFiles
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
54namespace Foam
55{
56
57/*---------------------------------------------------------------------------*\
58 Class ConstMatrixBlock Declaration
59\*---------------------------------------------------------------------------*/
60
61template<class MatrixType>
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
84public:
85
86 // Typedefs
87
88 //- The value type the Matrix contains
89 typedef typename MatrixType::cmptType cmptType;
90
91 //- The value type the Matrix contains
92 typedef typename MatrixType::value_type value_type;
93
94 //- The type to represent the size of a Matrix
95 typedef typename MatrixType::size_type size_type;
96
97
98 // Constructors
100 //- Construct block for matrix, size and location
101 inline ConstMatrixBlock
102 (
103 const MatrixType& matrix,
104 const label m,
105 const label n,
106 const label mStart,
107 const label nStart
108 );
109
110
111 // Member Functions
112
113 //- Return the number of rows in the block
114 label m() const noexcept { return mRows_; }
115
116 //- Return the number of columns in the block
117 label n() const noexcept { return nCols_; }
118
119 //- The number of elements in the block (m*n)
120 inline label size() const noexcept;
121
122 //- Return row/column sizes of the block
123 inline labelPair sizes() const noexcept;
124
125 //- (i, j) const element access operator
126 inline const cmptType& operator()
128 const label i,
129 const label j
130 ) const;
131
132 //- Convert a column of a matrix to a Field
133 operator Field<cmptType>() const;
134
135 //- Check if (i, j) is within range of row-column limits
136 void checkIndex(const label i, const label j) const;
137};
138
139
140/*---------------------------------------------------------------------------*\
141 Class MatrixBlock Declaration
142\*---------------------------------------------------------------------------*/
143
144template<class MatrixType>
145class MatrixBlock
146{
147 // Private Data
148
149 //- Reference to the parent matrix
150 MatrixType& matrix_;
151
152 //- Block size
153 const label mRows_;
154 const label nCols_;
155
156 //- Block location in parent matrix
157 const label rowStart_;
158 const label colStart_;
159
160
161 // Private Member Functions
162
163 //- Error message for failed sanity checks during matrix construction
164 label disallow(const char *what) const;
165
166
167public:
168
169 // Typedefs
171 //- The value type the Matrix contains
172 typedef typename MatrixType::cmptType cmptType;
173
174 //- The value type the Matrix contains
175 typedef typename MatrixType::value_type value_type;
176
177 //- The type to represent the size of a Matrix
178 typedef typename MatrixType::size_type size_type;
179
180
181 // Generated Methods
182
183 //- Copy construct
184 MatrixBlock(const MatrixBlock&) = default;
185
186
187 // Constructors
188
189 //- Construct block for matrix, size and location
190 inline MatrixBlock
191 (
192 MatrixType& matrix,
193 const label m,
194 const label n,
195 const label mStart,
196 const label nStart
197 );
198
199
200 // Member Functions
201
202 //- Return the number of rows in the block
203 label m() const noexcept { return mRows_; }
204
205 //- Return the number of columns in the block
206 label n() const noexcept { return nCols_; }
208 //- The number of elements in the block (m*n)
209 inline label size() const noexcept;
210
211 //- Return row/column sizes of the block
212 inline labelPair sizes() const noexcept;
213
214 //- (i, j) const element access operator
215 inline const cmptType& operator()
216 (
217 const label i,
218 const label j
219 ) const;
220
221 //- (i, j) element access operator
222 inline cmptType& operator()(const label i, const label j);
223
224 //- Convert a column of a matrix to a Field
225 operator Field<cmptType>() const;
226
227 //- Check if (i, j) is within range of row-column limits
228 void checkIndex(const label i, const label j) const;
229
230
231 // Member Operators
232
233 //- Assignment to a compatible matrix
234 template<class Form>
235 void operator=(const Matrix<Form, cmptType>&);
236
237 //- Assignment to a compatible const block
238 void operator=(const ConstMatrixBlock<MatrixType>&);
239
240 //- Assignment to a compatible block
241 void operator=(const MatrixBlock<MatrixType>&);
242
243 //- Assignment to a compatible const block
244 template<class MatrixType2>
245 void operator=(const ConstMatrixBlock<MatrixType2>&);
246
247 //- Assignment to a compatible block
248 template<class MatrixType2>
249 void operator=(const MatrixBlock<MatrixType2>&);
250
251 //- Assignment to a compatible MatrixSpace
252 template<class MSForm, direction Nrows, direction Ncols>
253 void operator=(const MatrixSpace<MSForm, cmptType, Nrows, Ncols>&);
254
255 //- Assignment to a compatible MatrixSpace block
256 template
257 <
258 template<class, direction, direction> class Block,
259 class SubTensor,
260 direction BRowStart,
261 direction BColStart
262 >
263 void operator=(const Block<SubTensor, BRowStart, BColStart>&);
264
265 //- Assignment to a compatible VectorSpace (column-vector)
266 template<class VSForm, direction Ncmpts>
267 void operator=(const VectorSpace<VSForm, cmptType, Ncmpts>&);
268
269 //- Assignment to a compatible VectorSpace (column-vector) block
270 template
271 <
272 template<class, direction> class Block,
273 class SubVector,
274 direction BStart
275 >
276 void operator=(const Block<SubVector, BStart>&);
277
278 //- Assignment to a Field (column-vector)
279 void operator=(const Field<cmptType>&);
280};
281
282
283// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284
285} // End namespace Foam
286
287// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288
289#include "MatrixBlockI.H"
290
291// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292
293#ifdef NoRepository
294 #include "MatrixBlock.C"
295#endif
296
297// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298
299#endif
300
301// ************************************************************************* //
void checkIndex(const label i, const label j) const
Check if (i, j) is within range of row-column limits.
Definition MatrixBlock.C:97
label m() const noexcept
Return the number of rows in the block.
MatrixType::size_type size_type
The type to represent the size of a Matrix.
labelPair sizes() const noexcept
Return row/column sizes of the block.
MatrixType::value_type value_type
The value type the Matrix contains.
Definition MatrixBlock.H:99
label size() const noexcept
The number of elements in the block (m*n).
label n() const noexcept
Return the number of columns in the block.
MatrixType::cmptType cmptType
The value type the Matrix contains.
Definition MatrixBlock.H:94
ConstMatrixBlock(const MatrixType &matrix, const label m, const label n, const label mStart, const label nStart)
Construct block for matrix, size and location.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A templated block of an (m x n) matrix of type <MatrixType>.
void checkIndex(const label i, const label j) const
Check if (i, j) is within range of row-column limits.
label m() const noexcept
Return the number of rows in the block.
MatrixType::size_type size_type
The type to represent the size of a Matrix.
labelPair sizes() const noexcept
Return row/column sizes of the block.
MatrixType::value_type value_type
The value type the Matrix contains.
label n() const noexcept
Return the number of columns in the block.
MatrixType::cmptType cmptType
The value type the Matrix contains.
MatrixBlock(const MatrixBlock &)=default
Copy construct.
Templated matrix space.
Definition MatrixSpace.H:57
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition Matrix.H:77
Templated vector space.
Definition VectorSpace.H:75
Namespace for OpenFOAM.
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265