initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / lduMatrix / lduMatrix.C
blob858db6e01224142bf031d8887699f042703b0a56
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "lduMatrix.H"
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(lduMatrix, 1);
37 const Foam::scalar Foam::lduMatrix::great_ = 1.0e+20;
38 const Foam::scalar Foam::lduMatrix::small_ = 1.0e-20;
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 Foam::lduMatrix::lduMatrix(const lduMesh& mesh)
45     lduMesh_(mesh),
46     lowerPtr_(NULL),
47     diagPtr_(NULL),
48     upperPtr_(NULL)
52 Foam::lduMatrix::lduMatrix(const lduMatrix& A)
54     lduMesh_(A.lduMesh_),
55     lowerPtr_(NULL),
56     diagPtr_(NULL),
57     upperPtr_(NULL)
59     if (A.lowerPtr_)
60     {
61         lowerPtr_ = new scalarField(*(A.lowerPtr_));
62     }
64     if (A.diagPtr_)
65     {
66         diagPtr_ = new scalarField(*(A.diagPtr_));
67     }
69     if (A.upperPtr_)
70     {
71         upperPtr_ = new scalarField(*(A.upperPtr_));
72     }
76 Foam::lduMatrix::lduMatrix(lduMatrix& A, bool reUse)
78     lduMesh_(A.lduMesh_),
79     lowerPtr_(NULL),
80     diagPtr_(NULL),
81     upperPtr_(NULL)
83     if (reUse)
84     {
85         if (A.lowerPtr_)
86         {
87             lowerPtr_ = A.lowerPtr_;
88             A.lowerPtr_ = NULL;
89         }
91         if (A.diagPtr_)
92         {
93             diagPtr_ = A.diagPtr_;
94             A.diagPtr_ = NULL;
95         }
97         if (A.upperPtr_)
98         {
99             upperPtr_ = A.upperPtr_;
100             A.upperPtr_ = NULL;
101         }
102     }
103     else
104     {
105         if (A.lowerPtr_)
106         {
107             lowerPtr_ = new scalarField(*(A.lowerPtr_));
108         }
110         if (A.diagPtr_)
111         {
112             diagPtr_ = new scalarField(*(A.diagPtr_));
113         }
115         if (A.upperPtr_)
116         {
117             upperPtr_ = new scalarField(*(A.upperPtr_));
118         }
119     }
123 Foam::lduMatrix::lduMatrix
125     const lduMesh& mesh,
126     Istream& is
129     lduMesh_(mesh),
130     lowerPtr_(new scalarField(is)),
131     diagPtr_(new scalarField(is)),
132     upperPtr_(new scalarField(is))
136 Foam::lduMatrix::~lduMatrix()
138     if (lowerPtr_)
139     {
140         delete lowerPtr_;
141     }
143     if (diagPtr_)
144     {
145         delete diagPtr_;
146     }
148     if (upperPtr_)
149     {
150         delete upperPtr_;
151     }
155 Foam::scalarField& Foam::lduMatrix::lower()
157     if (!lowerPtr_)
158     {
159         if (upperPtr_)
160         {
161             lowerPtr_ = new scalarField(*upperPtr_);
162         }
163         else
164         {
165             lowerPtr_ = new scalarField(lduAddr().lowerAddr().size(), 0.0);
166         }
167     }
169     return *lowerPtr_;
173 Foam::scalarField& Foam::lduMatrix::diag()
175     if (!diagPtr_)
176     {
177         diagPtr_ = new scalarField(lduAddr().size(), 0.0);
178     }
180     return *diagPtr_;
184 Foam::scalarField& Foam::lduMatrix::upper()
186     if (!upperPtr_)
187     {
188         if (lowerPtr_)
189         {
190             upperPtr_ = new scalarField(*lowerPtr_);
191         }
192         else
193         {
194             upperPtr_ = new scalarField(lduAddr().lowerAddr().size(), 0.0);
195         }
196     }
198     return *upperPtr_;
202 const Foam::scalarField& Foam::lduMatrix::lower() const
204     if (!lowerPtr_ && !upperPtr_)
205     {
206         FatalErrorIn("lduMatrix::lower() const")
207             << "lowerPtr_ or upperPtr_ unallocated"
208             << abort(FatalError);
209     }
211     if (lowerPtr_)
212     {
213         return *lowerPtr_;
214     }
215     else
216     {
217         return *upperPtr_;
218     }
222 const Foam::scalarField& Foam::lduMatrix::diag() const
224     if (!diagPtr_)
225     {
226         FatalErrorIn("const scalarField& lduMatrix::diag() const")
227             << "diagPtr_ unallocated"
228             << abort(FatalError);
229     }
231     return *diagPtr_;
235 const Foam::scalarField& Foam::lduMatrix::upper() const
237     if (!lowerPtr_ && !upperPtr_)
238     {
239         FatalErrorIn("lduMatrix::upper() const")
240             << "lowerPtr_ or upperPtr_ unallocated"
241             << abort(FatalError);
242     }
244     if (upperPtr_)
245     {
246         return *upperPtr_;
247     }
248     else
249     {
250         return *lowerPtr_;
251     }
255 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
257 Foam::Ostream& Foam::operator<<(Ostream& os, const lduMatrix& ldum)
259     if (ldum.lowerPtr_)
260     {
261         os  << "Lower triangle = "
262             << *ldum.lowerPtr_
263             << endl << endl;
264     }
266     if (ldum.diagPtr_)
267     {
268         os  << "diagonal = "
269             << *ldum.diagPtr_
270             << endl << endl;
271     }
273     if (ldum.upperPtr_)
274     {
275         os  << "Upper triangle = "
276             << *ldum.upperPtr_
277             << endl << endl;
278     }
280     os.check("Ostream& operator<<(Ostream&, const lduMatrix&");
282     return os;
286 // ************************************************************************* //