LduMatrix.C
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) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "lduMatrix.H"
29 #include "IOstreams.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type, class DType, class LUType>
35 :
36  lduMesh_(mesh),
37  diagPtr_(nullptr),
38  upperPtr_(nullptr),
39  lowerPtr_(nullptr),
40  sourcePtr_(nullptr),
41  interfaces_(0),
42  interfacesUpper_(0),
43  interfacesLower_(0)
44 {}
45 
46 
47 template<class Type, class DType, class LUType>
49 :
50  lduMesh_(A.lduMesh_),
51  diagPtr_(nullptr),
52  upperPtr_(nullptr),
53  lowerPtr_(nullptr),
54  sourcePtr_(nullptr),
55  interfaces_(0),
56  interfacesUpper_(0),
57  interfacesLower_(0)
58 {
59  if (A.diagPtr_)
60  {
61  diagPtr_ = new Field<DType>(*(A.diagPtr_));
62  }
63 
64  if (A.upperPtr_)
65  {
66  upperPtr_ = new Field<LUType>(*(A.upperPtr_));
67  }
68 
69  if (A.lowerPtr_)
70  {
71  lowerPtr_ = new Field<LUType>(*(A.lowerPtr_));
72  }
73 
74  if (A.sourcePtr_)
75  {
76  sourcePtr_ = new Field<Type>(*(A.sourcePtr_));
77  }
78 }
79 
80 
81 template<class Type, class DType, class LUType>
83 :
84  lduMesh_(A.lduMesh_),
85  diagPtr_(nullptr),
86  upperPtr_(nullptr),
87  lowerPtr_(nullptr),
88  sourcePtr_(nullptr),
89  interfaces_(0),
90  interfacesUpper_(0),
91  interfacesLower_(0)
92 {
93  if (reuse)
94  {
95  if (A.diagPtr_)
96  {
97  diagPtr_ = A.diagPtr_;
98  A.diagPtr_ = nullptr;
99  }
100 
101  if (A.upperPtr_)
102  {
103  upperPtr_ = A.upperPtr_;
104  A.upperPtr_ = nullptr;
105  }
106 
107  if (A.lowerPtr_)
108  {
109  lowerPtr_ = A.lowerPtr_;
110  A.lowerPtr_ = nullptr;
111  }
112 
113  if (A.sourcePtr_)
114  {
115  sourcePtr_ = A.sourcePtr_;
116  A.sourcePtr_ = nullptr;
117  }
118  }
119  else
120  {
121  if (A.diagPtr_)
122  {
123  diagPtr_ = new Field<DType>(*(A.diagPtr_));
124  }
125 
126  if (A.upperPtr_)
127  {
128  upperPtr_ = new Field<LUType>(*(A.upperPtr_));
129  }
130 
131  if (A.lowerPtr_)
132  {
133  lowerPtr_ = new Field<LUType>(*(A.lowerPtr_));
134  }
135 
136  if (A.sourcePtr_)
137  {
138  sourcePtr_ = new Field<Type>(*(A.sourcePtr_));
139  }
140  }
141 }
142 
143 
144 template<class Type, class DType, class LUType>
146 (
147  const lduMesh& mesh,
148  Istream& is
149 )
150 :
151  lduMesh_(mesh),
152  diagPtr_(new Field<DType>(is)),
153  upperPtr_(new Field<LUType>(is)),
154  lowerPtr_(new Field<LUType>(is)),
155  sourcePtr_(new Field<Type>(is)),
156  interfaces_(0),
157  interfacesUpper_(0),
158  interfacesLower_(0)
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
163 
164 template<class Type, class DType, class LUType>
166 {
167  if (diagPtr_)
168  {
169  delete diagPtr_;
170  }
171 
172  if (upperPtr_)
173  {
174  delete upperPtr_;
175  }
176 
177  if (lowerPtr_)
178  {
179  delete lowerPtr_;
180  }
181 
182  if (sourcePtr_)
183  {
184  delete sourcePtr_;
185  }
186 }
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
191 template<class Type, class DType, class LUType>
193 {
194  if (!diagPtr_)
195  {
196  diagPtr_ = new Field<DType>(lduAddr().size(), Zero);
197  }
198 
199  return *diagPtr_;
200 }
201 
202 
203 template<class Type, class DType, class LUType>
205 {
206  if (!upperPtr_)
207  {
208  if (lowerPtr_)
209  {
210  upperPtr_ = new Field<LUType>(*lowerPtr_);
211  }
212  else
213  {
214  upperPtr_ = new Field<LUType>
215  (
216  lduAddr().lowerAddr().size(),
217  Zero
218  );
219  }
220  }
221 
222  return *upperPtr_;
223 }
224 
225 
226 template<class Type, class DType, class LUType>
228 {
229  if (!lowerPtr_)
230  {
231  if (upperPtr_)
232  {
233  lowerPtr_ = new Field<LUType>(*upperPtr_);
234  }
235  else
236  {
237  lowerPtr_ = new Field<LUType>
238  (
239  lduAddr().lowerAddr().size(),
240  Zero
241  );
242  }
243  }
244 
245  return *lowerPtr_;
246 }
247 
248 
249 template<class Type, class DType, class LUType>
251 {
252  if (!sourcePtr_)
253  {
254  sourcePtr_ = new Field<Type>(lduAddr().size(), Zero);
255  }
256 
257  return *sourcePtr_;
258 }
259 
260 
261 template<class Type, class DType, class LUType>
263 {
264  if (!diagPtr_)
265  {
267  << "diagPtr_ unallocated"
268  << abort(FatalError);
269  }
270 
271  return *diagPtr_;
272 }
273 
274 
275 template<class Type, class DType, class LUType>
277 {
278  if (!lowerPtr_ && !upperPtr_)
279  {
281  << "lowerPtr_ or upperPtr_ unallocated"
282  << abort(FatalError);
283  }
284 
285  if (upperPtr_)
286  {
287  return *upperPtr_;
288  }
289  else
290  {
291  return *lowerPtr_;
292  }
293 }
294 
295 
296 template<class Type, class DType, class LUType>
298 {
299  if (!lowerPtr_ && !upperPtr_)
300  {
302  << "lowerPtr_ or upperPtr_ unallocated"
303  << abort(FatalError);
304  }
305 
306  if (lowerPtr_)
307  {
308  return *lowerPtr_;
309  }
310  else
311  {
312  return *upperPtr_;
313  }
314 }
315 
316 
317 template<class Type, class DType, class LUType>
319 {
320  if (!sourcePtr_)
321  {
323  << "sourcePtr_ unallocated"
324  << abort(FatalError);
325  }
326 
327  return *sourcePtr_;
328 }
329 
330 
331 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
332 
333 template<class Type, class DType, class LUType>
334 Foam::Ostream& Foam::operator<<
335 (
336  Ostream& os,
338 )
339 {
340  if (ldum.diagPtr_)
341  {
342  os << "Diagonal = "
343  << *ldum.diagPtr_
344  << endl << endl;
345  }
346 
347  if (ldum.upperPtr_)
348  {
349  os << "Upper triangle = "
350  << *ldum.upperPtr_
351  << endl << endl;
352  }
353 
354  if (ldum.lowerPtr_)
355  {
356  os << "Lower triangle = "
357  << *ldum.lowerPtr_
358  << endl << endl;
359  }
360 
361  if (ldum.sourcePtr_)
362  {
363  os << "Source = "
364  << *ldum.sourcePtr_
365  << endl << endl;
366  }
367 
369 
370  return os;
371 }
372 
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #include "LduMatrixOperations.C"
377 #include "LduMatrixATmul.C"
379 #include "LduMatrixPreconditioner.C"
380 #include "LduMatrixSmoother.C"
381 #include "LduMatrixSolver.C"
382 
383 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
LduMatrixUpdateMatrixInterfaces.C
LduMatrixSolver.C
Foam::LduMatrix
LduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: LduMatrix.H:72
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
lduMatrix.H
Foam::LduMatrix::source
Field< Type > & source()
Definition: LduMatrix.C:250
Foam::LduMatrix::upper
Field< LUType > & upper()
Definition: LduMatrix.C:204
LduMatrixSmoother.C
LduMatrixATmul.C
LduMatrixOperations.C
Foam::Field< DType >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::LduMatrix::LduMatrix
LduMatrix(const lduMesh &)
Construct given an LDU addressed mesh.
Definition: LduMatrix.C:34
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::FatalError
error FatalError
Foam::LduMatrix::diag
Field< DType > & diag()
Definition: LduMatrix.C:192
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::LduMatrix::~LduMatrix
~LduMatrix()
Definition: LduMatrix.C:165
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
LduMatrixPreconditioner.C
Foam::lduMesh
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:62
Foam::LduMatrix::lower
Field< LUType > & lower()
Definition: LduMatrix.C:227