All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixI.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) 2011-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 #include "MatrixBlock.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Form, class Type>
32 :
33  mRows_(0),
34  nCols_(0),
35  v_(nullptr)
36 {}
37 
38 
39 template<class Form, class Type>
41 clone() const
42 {
44 }
45 
46 
47 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48 
49 template<class Form, class Type>
51 {
52  return NullObjectRef<Matrix<Form, Type>>();
53 }
54 
55 
56 template<class Form, class Type>
58 {
59  return mRows_;
60 }
61 
62 
63 template<class Form, class Type>
65 {
66  return nCols_;
67 }
68 
69 
70 template<class Form, class Type>
72 {
73  return mRows_*nCols_;
74 }
75 
76 
77 template<class Form, class Type>
78 inline void Foam::Matrix<Form, Type>::checki(const label i) const
79 {
80  #ifdef FULLDEBUG
81  if (!mRows_ || !nCols_)
82  {
84  << "Attempt to access element from empty matrix"
85  << abort(FatalError);
86  }
87  else if (i<0 || i>=mRows_)
88  {
90  << "Index " << i << " out of range 0 ... " << mRows_-1
91  << abort(FatalError);
92  }
93  #endif
94 }
95 
96 
97 template<class Form, class Type>
98 inline void Foam::Matrix<Form, Type>::checkj(const label j) const
99 {
100  #ifdef FULLDEBUG
101  if (!mRows_ || !nCols_)
102  {
104  << "Attempt to access element from empty matrix"
105  << abort(FatalError);
106  }
107  else if (j<0 || j>=nCols_)
108  {
110  << "index " << j << " out of range 0 ... " << nCols_-1
111  << abort(FatalError);
112  }
113  #endif
114 }
115 
116 
117 template<class Form, class Type>
118 inline const Type* Foam::Matrix<Form, Type>::v() const
119 {
120  return v_;
121 }
122 
123 
124 template<class Form, class Type>
126 {
127  return v_;
128 }
129 
130 
131 template<class Form, class Type>
134 (
135  const label m,
136  const label n,
137  const label mStart,
138  const label nStart
139 ) const
140 {
142  (
143  *this,
144  m,
145  n,
146  mStart,
147  nStart
148  );
149 }
150 
151 
152 template<class Form, class Type>
153 template<class VectorSpace>
156 (
157  const label mStart,
158  const label nStart
159 ) const
160 {
162  (
163  *this,
164  VectorSpace::mRows,
165  VectorSpace::nCols,
166  mStart,
167  nStart
168  );
169 }
170 
171 
172 template<class Form, class Type>
175 (
176  const label m,
177  const label mStart
178 ) const
179 {
181  (
182  *this,
183  m,
184  1,
185  mStart,
186  0
187  );
188 }
189 
190 
191 template<class Form, class Type>
194 (
195  const label m,
196  const label mStart,
197  const label nStart
198 ) const
199 {
201  (
202  *this,
203  m,
204  1,
205  mStart,
206  nStart
207  );
208 }
209 
210 
211 template<class Form, class Type>
214 (
215  const label m,
216  const label n,
217  const label mStart,
218  const label nStart
219 )
220 {
221  return MatrixBlock<mType>
222  (
223  *this,
224  m,
225  n,
226  mStart,
227  nStart
228  );
229 }
230 
231 
232 template<class Form, class Type>
233 template<class VectorSpace>
235 Foam::Matrix<Form, Type>::block(const label mStart, const label nStart)
236 {
237  return MatrixBlock<mType>
238  (
239  *this,
240  VectorSpace::mRows,
241  VectorSpace::nCols,
242  mStart,
243  nStart
244  );
245 }
246 
247 
248 template<class Form, class Type>
251 {
252  return MatrixBlock<mType>
253  (
254  *this,
255  m,
256  1,
257  mStart,
258  0
259  );
260 }
261 
262 
263 template<class Form, class Type>
266 (
267  const label m,
268  const label mStart,
269  const label nStart
270 )
271 {
272  return MatrixBlock<mType>
273  (
274  *this,
275  m,
276  1,
277  mStart,
278  nStart
279  );
280 }
281 
282 
283 template<class Form, class Type>
285 {
286  mRows_ = m;
287  nCols_ = n;
288 }
289 
290 
291 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
292 
293 template<class Form, class Type>
294 inline const Type& Foam::Matrix<Form, Type>::operator()
295 (
296  const label i,
297  const label j
298 ) const
299 {
300  checki(i);
301  checkj(j);
302  return v_[i*nCols_ + j];
303 }
304 
305 
306 template<class Form, class Type>
308 (
309  const label i,
310  const label j
311 )
312 {
313  checki(i);
314  checkj(j);
315  return v_[i*nCols_ + j];
316 }
317 
318 
319 template<class Form, class Type>
320 inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
321 {
322  checki(i);
323  return v_ + i*nCols_;
324 }
325 
326 
327 template<class Form, class Type>
329 {
330  checki(i);
331  return v_ + i*nCols_;
332 }
333 
334 
335 // ************************************************************************* //
label n() const
Return the number of columns.
Definition: MatrixI.H:64
void shallowResize(const label m, const label n)
Resize the matrix without reallocating storage (unsafe)
Definition: MatrixI.H:284
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
void checki(const label i) const
Check index i is within valid range (0 ... m-1).
Definition: MatrixI.H:78
autoPtr< mType > clone() const
Clone.
Definition: MatrixI.H:41
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:71
Matrix()
Null constructor.
Definition: MatrixI.H:31
void checkj(const label j) const
Check index j is within valid range (0 ... n-1).
Definition: MatrixI.H:98
static const mType & null()
Return a null Matrix.
Definition: MatrixI.H:50
label size() const
Return the number of elements in matrix (m*n)
Definition: MatrixI.H:71
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A templated (m x n) matrix of objects of <T>.
Type * operator[](const label)
Return subscript-checked row of Matrix.
Definition: MatrixI.H:328
friend Ostream & operator(Ostream &, const mType &)
Write Matrix to Ostream.
ConstMatrixBlock< mType > block(const label m, const label n, const label mStart, const label nStart) const
Definition: MatrixI.H:134
label m() const
Return the number of rows.
Definition: MatrixI.H:57
label n
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const Type * v() const
Return element vector of the constant Matrix.
Definition: MatrixI.H:118
ConstMatrixBlock< mType > col(const label m, const label rowStart) const
Definition: MatrixI.H:175