MatrixBlock.C
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 #include "MatrixBlock.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class MatrixType>
32 {
33  if (nCols_ != 1)
34  {
36  << "Number of columns " << nCols_ << " != 1"
37  << abort(FatalError);
38  }
39 
40  Field<cmptType> f(mRows_);
41 
42  forAll(f, i)
43  {
44  f[i] = operator()(i, 0);
45  }
46 
47  return f;
48 }
49 
50 
51 template<class MatrixType>
53 {
54  if (nCols_ != 1)
55  {
57  << "Number of columns " << nCols_ << " != 1"
58  << abort(FatalError);
59  }
60 
61  Field<cmptType> f(mRows_);
62 
63  forAll(f, i)
64  {
65  f[i] = operator()(i, 0);
66  }
67 
68  return f;
69 }
70 
71 
72 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
73 
74 template<class MatrixType>
75 template<class Form>
77 (
78  const Matrix<Form, cmptType>& Mb
79 )
80 {
81  if (mRows_ != Mb.m() || nCols_ != Mb.n())
82  {
84  << "Attempt to assign blocks of different sizes: "
85  << mRows_ << "x" << nCols_ << " != "
86  << Mb.m() << "x" << Mb.n()
87  << abort(FatalError);
88  }
89 
90  for (label i=0; i<mRows_; i++)
91  {
92  for (label j=0; j<nCols_; j++)
93  {
94  (*this)(i, j) = Mb(i, j);
95  }
96  }
97 }
98 
99 
100 template<class MatrixType>
102 (
104 )
105 {
106  if (this != &Mb)
107  {
108  if (mRows_ != Mb.m() || nCols_ != Mb.n())
109  {
111  << "Attempt to assign blocks of different sizes: "
112  << mRows_ << "x" << nCols_ << " != "
113  << Mb.m() << "x" << Mb.n()
114  << abort(FatalError);
115  }
116 
117  for (label i=0; i<mRows_; i++)
118  {
119  for (label j=0; j<nCols_; j++)
120  {
121  (*this)(i, j) = Mb(i, j);
122  }
123  }
124  }
125 }
126 
127 
128 template<class MatrixType>
130 (
131  const MatrixBlock<MatrixType>& Mb
132 )
133 {
134  if (this != &Mb)
135  {
136  if (mRows_ != Mb.m() || nCols_ != Mb.n())
137  {
139  << "Attempt to assign blocks of different sizes: "
140  << mRows_ << "x" << nCols_ << " != "
141  << Mb.m() << "x" << Mb.n()
142  << abort(FatalError);
143  }
144 
145  for (label i=0; i<mRows_; i++)
146  {
147  for (label j=0; j<nCols_; j++)
148  {
149  (*this)(i, j) = Mb(i, j);
150  }
151  }
152  }
153 }
154 
155 
156 template<class MatrixType>
157 template<class MatrixType2>
159 (
161 )
162 {
163  if (this != &Mb)
164  {
165  if (mRows_ != Mb.m() || nCols_ != Mb.n())
166  {
168  << "Attempt to assign blocks of different sizes: "
169  << mRows_ << "x" << nCols_ << " != "
170  << Mb.m() << "x" << Mb.n()
171  << abort(FatalError);
172  }
173 
174  for (label i=0; i<mRows_; i++)
175  {
176  for (label j=0; j<nCols_; j++)
177  {
178  (*this)(i, j) = Mb(i, j);
179  }
180  }
181  }
182 }
183 
184 
185 template<class MatrixType>
186 template<class MatrixType2>
188 (
189  const MatrixBlock<MatrixType2>& Mb
190 )
191 {
192  if (this != &Mb)
193  {
194  if (mRows_ != Mb.m() || nCols_ != Mb.n())
195  {
197  << "Attempt to assign blocks of different sizes: "
198  << mRows_ << "x" << nCols_ << " != "
199  << Mb.m() << "x" << Mb.n()
200  << abort(FatalError);
201  }
202 
203  for (label i=0; i<mRows_; i++)
204  {
205  for (label j=0; j<nCols_; j++)
206  {
207  (*this)(i, j) = Mb(i, j);
208  }
209  }
210  }
211 }
212 
213 
214 template<class MatrixType>
215 template
216 <
217  template<class, Foam::direction, Foam::direction> class MSBlock,
218  class SubTensor,
219  Foam::direction BRowStart,
220  Foam::direction BColStart
221 >
223 (
224  const MSBlock<SubTensor, BRowStart, BColStart>& Mb
225 )
226 {
227  if (mRows_ != Mb.mRows || nCols_ != Mb.nCols)
228  {
230  << "Attempt to assign blocks of different sizes: "
231  << mRows_ << "x" << nCols_ << " != "
232  << Mb.mRows << "x" << Mb.nCols
233  << abort(FatalError);
234  }
235 
236  for (direction i=0; i<mRows_; ++i)
237  {
238  for (direction j=0; j<nCols_; ++j)
239  {
240  operator()(i, j) = Mb(i, j);
241  }
242  }
243 }
244 
245 
246 template<class MatrixType>
247 template
248 <
249  template<class, Foam::direction> class VSBlock,
250  class SubVector,
251  Foam::direction BStart
252 >
254 (
255  const VSBlock<SubVector, BStart>& Mb
256 )
257 {
258  if (mRows_ != Mb.nComponents || nCols_ != 1)
259  {
261  << "Attempt to assign blocks of different sizes: "
262  << mRows_ << "x" << nCols_ << " != "
263  << Mb.nComponents << "x" << 1
264  << abort(FatalError);
265  }
266 
267  for (direction i=0; i<mRows_; ++i)
268  {
269  operator()(i, 0) = Mb[i];
270  }
271 }
272 
273 
274 template<class MatrixType>
275 template<class MSForm, Foam::direction Nrows, Foam::direction Ncols>
277 (
279 )
280 {
281  if (mRows_ != Nrows || nCols_ != Ncols)
282  {
284  << "Attempt to assign blocks of different sizes: "
285  << mRows_ << "x" << nCols_ << " != "
286  << Nrows << "x" << Ncols
287  << abort(FatalError);
288  }
289 
290  for (label i=0; i<mRows_; i++)
291  {
292  for (label j=0; j<nCols_; j++)
293  {
294  (*this)(i, j) = ms(i, j);
295  }
296  }
297 }
298 
299 
300 template<class MatrixType>
301 template<class VSForm, Foam::direction Ncmpts>
303 (
305 )
306 {
307  if (mRows_ != Ncmpts || nCols_ != 1)
308  {
310  << "Attempt to assign blocks of different sizes: "
311  << mRows_ << "x" << nCols_ << " != "
312  << Ncmpts << "x" << 1
313  << abort(FatalError);
314  }
315 
316  for (direction i=0; i<Ncmpts; ++i)
317  {
318  operator()(i, 0) = ms[i];
319  }
320 }
321 
322 
323 template<class MatrixType>
325 {
326  if (mRows_ != f.size() || nCols_ != 1)
327  {
329  << "Error: cannot assign blocks of different size (left is "
330  << mRows_ << "x" << nCols_ << " != "
331  << f.size() << "x" << 1
332  << abort(FatalError);
333  }
334 
335  forAll(f, i)
336  {
337  operator()(i, 0) = f[i];
338  }
339 }
340 
341 
342 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
void operator=(const Matrix< Form, cmptType > &)
Assignment to a compatible matrix.
Definition: MatrixBlock.C:77
Templated vector space.
Definition: VectorSpace.H:53
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:71
Templated matrix space.
Definition: MatrixSpace.H:55
Pre-declare SubField and related Field type.
Definition: Field.H:57
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A templated (m x n) matrix of objects of <T>.
labelList f(nPoints)