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>
90 inline Foam::label Foam::ConstMatrixBlock<MatrixType>::m() const
91 {
92  return mRows_;
93 }
94 
95 
96 template<class MatrixType>
97 inline Foam::label Foam::ConstMatrixBlock<MatrixType>::n() const
98 {
99  return nCols_;
100 }
101 
102 
103 template<class MatrixType>
104 inline Foam::label Foam::MatrixBlock<MatrixType>::m() const
105 {
106  return mRows_;
107 }
108 
109 
110 template<class MatrixType>
111 inline Foam::label Foam::MatrixBlock<MatrixType>::n() const
112 {
113  return nCols_;
114 }
115 
116 
117 template<class MatrixType>
119 {
120  return labelPair(mRows_, nCols_);
121 }
122 
123 
124 template<class MatrixType>
126 {
127  return labelPair(mRows_, nCols_);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
132 
133 template<class MatrixType>
134 inline const typename MatrixType::cmptType&
136 (
137  const label i,
138  const label j
139 ) const
140 {
141  #ifdef FULLDEBUG
142  checkIndex(i, j);
143  #endif
144 
145  return matrix_(i + rowStart_, j + colStart_);
146 }
147 
148 
149 template<class MatrixType>
150 inline const typename MatrixType::cmptType&
152 (
153  const label i,
154  const label j
155 ) const
156 {
157  #ifdef FULLDEBUG
158  checkIndex(i, j);
159  #endif
160 
161  return matrix_(i + rowStart_, j + colStart_);
162 }
163 
164 
165 template<class MatrixType>
166 inline typename MatrixType::cmptType&
168 (
169  const label i,
170  const label j
171 )
172 {
173  #ifdef FULLDEBUG
174  checkIndex(i, j);
175  #endif
176 
177  return matrix_(i + rowStart_, j + colStart_);
178 }
179 
180 
181 // ************************************************************************* //
Foam::MatrixBlock::n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:111
Foam::MatrixBlock::sizes
labelPair sizes() const
Return row/column sizes.
Definition: MatrixBlockI.H:125
Foam::MatrixBlock::MatrixBlock
MatrixBlock(const MatrixBlock &)=default
Copy construct.
Foam::labelPair
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:54
n
label n
Definition: TABSMDCalcMethod2.H:31
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
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:66
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::Pair< label >
Foam::ConstMatrixBlock::m
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:90
Foam::ConstMatrixBlock
Definition: Matrix.H:65
Foam::ConstMatrixBlock::sizes
labelPair sizes() const
Return row/column sizes.
Definition: MatrixBlockI.H:118