Loading...
Searching...
No Matches
MatrixBlockI.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 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
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30
31template<class MatrixType>
33(
34 const MatrixType& matrix,
35 const label m,
36 const label n,
37 const label mStart,
38 const label nStart
39)
40:
41 matrix_(matrix),
42 mRows_(0 < m ? m : disallow("row dim")),
43 nCols_(0 < n ? n : disallow("col dim")),
44 rowStart_
45 (
46 0 <= mStart
47 || mStart + mRows_ <= matrix.m()
48 ? mStart : disallow("row start")
49 ),
50 colStart_
51 (
52 0 <= nStart
53 || nStart + nCols_ <= matrix.n()
54 ? nStart : disallow("col start")
55 )
56{}
57
58
59template<class MatrixType>
61(
62 MatrixType& matrix,
63 const label m,
64 const label n,
65 const label mStart,
66 const label nStart
67)
68:
69 matrix_(matrix),
70 mRows_(0 < m ? m : disallow("row dim")),
71 nCols_(0 < n ? n : disallow("col dim")),
72 rowStart_
73 (
74 0 <= mStart
75 || mStart + mRows_ <= matrix.m()
76 ? mStart : disallow("row start")
77 ),
78 colStart_
79 (
80 0 <= nStart
81 || nStart + nCols_ <= matrix.n()
82 ? nStart : disallow("col start")
83 )
84{}
85
86
87// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88
89template<class MatrixType>
91{
92 return (mRows_ * nCols_);
93}
94
95
96template<class MatrixType>
97inline Foam::label Foam::MatrixBlock<MatrixType>::size() const noexcept
99 return (mRows_ * nCols_);
100}
101
102
103template<class MatrixType>
104inline Foam::labelPair
107 return labelPair(mRows_, nCols_);
108}
109
110
111template<class MatrixType>
112inline Foam::labelPair
114{
115 return labelPair(mRows_, nCols_);
117
118
119// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
120
121template<class MatrixType>
122inline const typename MatrixType::cmptType&
124(
125 const label i,
126 const label j
127) const
128{
129 #ifdef FULLDEBUG
130 checkIndex(i, j);
131 #endif
133 return matrix_(i + rowStart_, j + colStart_);
134}
135
136
137template<class MatrixType>
138inline const typename MatrixType::cmptType&
140(
141 const label i,
142 const label j
143) const
144{
145 #ifdef FULLDEBUG
146 checkIndex(i, j);
147 #endif
149 return matrix_(i + rowStart_, j + colStart_);
150}
151
152
153template<class MatrixType>
154inline typename MatrixType::cmptType&
156(
157 const label i,
158 const label j
159)
160{
161 #ifdef FULLDEBUG
162 checkIndex(i, j);
163 #endif
164
165 return matrix_(i + rowStart_, j + colStart_);
166}
167
168
169// ************************************************************************* //
label n
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.
labelPair sizes() const noexcept
Return row/column sizes of the block.
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.
ConstMatrixBlock(const MatrixType &matrix, const label m, const label n, const label mStart, const label nStart)
Construct block for matrix, size and location.
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.
labelPair sizes() const noexcept
Return row/column sizes of the block.
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.
MatrixBlock(const MatrixBlock &)=default
Copy construct.
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
const direction noexcept
Definition scalarImpl.H:265