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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<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 
59 template<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 
89 template<class MatrixType>
91 {
92  return (mRows_ * nCols_);
93 }
94 
95 
96 template<class MatrixType>
97 inline Foam::label Foam::MatrixBlock<MatrixType>::size() const noexcept
98 {
99  return (mRows_ * nCols_);
100 }
101 
102 
103 template<class MatrixType>
104 inline Foam::labelPair
106 {
107  return labelPair(mRows_, nCols_);
108 }
109 
110 
111 template<class MatrixType>
112 inline Foam::labelPair
114 {
115  return labelPair(mRows_, nCols_);
116 }
118 
119 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
120 
121 template<class MatrixType>
122 inline 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
132 
133  return matrix_(i + rowStart_, j + colStart_);
134 }
135 
136 
137 template<class MatrixType>
138 inline 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
148 
149  return matrix_(i + rowStart_, j + colStart_);
150 }
151 
152 
153 template<class MatrixType>
154 inline 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 // ************************************************************************* //
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:62
labelPair sizes() const noexcept
Return row/column sizes of the block.
Definition: MatrixBlockI.H:106
labelPair sizes() const noexcept
Return row/column sizes of the block.
Definition: MatrixBlockI.H:98
label size() const noexcept
The number of elements in the block (m*n)
Definition: MatrixBlockI.H:83
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:26
const direction noexcept
Definition: scalarImpl.H:255
label size() const noexcept
The number of elements in the block (m*n)
Definition: MatrixBlockI.H:90
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
MatrixBlock(const MatrixBlock &)=default
Copy construct.
label n