MatrixBlockI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class MatrixType>
30 (
31  const MatrixType& matrix,
32  const label m,
33  const label n,
34  const label mStart,
35  const label nStart
36 )
37 :
38  matrix_(matrix),
39  mRows_(m),
40  nCols_(n),
41  rowStart_(mStart),
42  colStart_(nStart)
43 {
44  #ifdef FULLDEBUG
45  if
46  (
47  rowStart_ + mRows_ > matrix.m()
48  || colStart_ + nCols_ > matrix.n()
49  )
50  {
52  << "Block addresses outside matrix"
53  << abort(FatalError);
54  }
55  #endif
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_(m),
71  nCols_(n),
72  rowStart_(mStart),
73  colStart_(nStart)
74 {
75  #ifdef FULLDEBUG
76  if
77  (
78  rowStart_ + mRows_ > matrix.m()
79  || colStart_ + nCols_ > matrix.n()
80  )
81  {
83  << "Block addresses outside matrix"
84  << abort(FatalError);
85  }
86  #endif
87 }
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class MatrixType>
94 {
95  return mRows_;
96 }
97 
98 
99 template<class MatrixType>
101 {
102  return nCols_;
103 }
104 
105 
106 template<class MatrixType>
108 {
109  return mRows_;
110 }
111 
112 
113 template<class MatrixType>
115 {
116  return nCols_;
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
121 
122 template<class MatrixType>
123 inline const typename MatrixType::cmptType&
125 (
126  const label i,
127  const label j
128 ) const
129 {
130  #ifdef FULLDEBUG
131  if (i<0 || i>=mRows_)
132  {
134  << "Index " << i << " out of range 0 ... " << mRows_-1
135  << abort(FatalError);
136  }
137  if (j<0 || j>=nCols_)
138  {
140  << "Index " << j << " out of range 0 ... " << nCols_-1
141  << abort(FatalError);
142  }
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  if (i<0 || i>=mRows_)
159  {
161  << "Index " << i << " out of range 0 ... " << mRows_-1
162  << abort(FatalError);
163  }
164  if (j<0 || j>=nCols_)
165  {
167  << "Index " << j << " out of range 0 ... " << nCols_-1
168  << abort(FatalError);
169  }
170  #endif
171 
172  return matrix_(i + rowStart_, j + colStart_);
173 }
174 
175 
176 template<class MatrixType>
177 inline typename MatrixType::cmptType&
179 (
180  const label i,
181  const label j
182 )
183 {
184  #ifdef FULLDEBUG
185  if (i<0 || i>=mRows_)
186  {
188  << "Index " << i << " out of range 0 ... " << mRows_-1
189  << abort(FatalError);
190  }
191  if (j<0 || j>=nCols_)
192  {
194  << "Index " << j << " out of range 0 ... " << nCols_-1
195  << abort(FatalError);
196  }
197  #endif
198 
199  return matrix_(i + rowStart_, j + colStart_);
200 }
201 
202 
203 // ************************************************************************* //
label n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:100
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:93
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:30
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: MatrixBlock.H:116
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:114
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:107
MatrixBlock(MatrixType &matrix, const label m, const label n, const label mStart, const label nStart)
Construct block for matrix, size and location.
Definition: MatrixBlockI.H:61
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError