Bugfix: fixed memory leak for cached gradient in limited grad schemes
[foam-extend-4.0.git] / src / foam / matrices / lduMatrix / lduMatrix / lduMatrixTests.C
blobca4641b57c4dea323acbb18a932a69b899698d97
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Convergence and singularity tests for solvers.
27 \*---------------------------------------------------------------------------*/
29 #include "lduMatrix.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 bool Foam::lduMatrix::solverPerformance::checkConvergence
35     const scalar Tolerance,
36     const scalar RelTolerance
39     if (debug >= 2)
40     {
41         Info<< solverName_
42             << ":  Iteration " << noIterations_
43             << " residual = " << finalResidual_
44             << endl;
45     }
47     if
48     (
49         finalResidual_ < Tolerance   // Abs. tolerance
50      || (
51             RelTolerance > SMALL
52          && finalResidual_ <= RelTolerance*initialResidual_ // Rel. tolerance
53         )
54   // || (solverName == "symSolve" && iter == 0)
55     )
56     {
57         converged_ = true;
58     }
59     else
60     {
61         converged_ = false;
62     }
64     return converged_;
68 bool Foam::lduMatrix::solverPerformance::checkSingularity
70     const scalar residual
73     if (residual > VSMALL)
74     {
75         singular_ = false;
76     }
77     else
78     {
79         singular_ = true;
80     }
82     return singular_;
86 void Foam::lduMatrix::solverPerformance::print() const
88     if (debug)
89     {
90         Info<< solverName_ << ":  Solving for " << fieldName_;
92         if (singular())
93         {
94             Info<< ":  solution singularity" << endl;
95         }
96         else
97         {
98             Info<< ", Initial residual = " << initialResidual_
99                 << ", Final residual = " << finalResidual_
100                 << ", No Iterations " << noIterations_
101                 << endl;
102         }
103     }
107 bool Foam::lduSolverPerformance::operator!=
109     const lduSolverPerformance& sp
110 ) const
112     return
113     (
114         solverName()      != sp.solverName()
115      || fieldName()       != sp.fieldName()
116      || initialResidual() != sp.initialResidual()
117      || finalResidual()   != sp.finalResidual()
118      || nIterations()     != sp.nIterations()
119      || converged()       != sp.converged()
120      || singular()        != sp.singular()
121     );
125 Foam::Istream& Foam::operator>>
127     Istream& is,
128     lduSolverPerformance& sp
131     is.readBeginList("SolverPerformance<Type>");
132     is  >> sp.solverName_
133         >> sp.fieldName_
134         >> sp.initialResidual_
135         >> sp.finalResidual_
136         >> sp.noIterations_
137         >> sp.converged_
138         >> sp.singular_;
139     is.readEndList("SolverPerformance<Type>");
141     return is;
145 Foam::Ostream& Foam::operator<<
147     Ostream& os,
148     const lduSolverPerformance& sp
151     os  << token::BEGIN_LIST
152         << sp.solverName_ << token::SPACE
153         << sp.fieldName_ << token::SPACE
154         << sp.initialResidual_ << token::SPACE
155         << sp.finalResidual_ << token::SPACE
156         << sp.noIterations_ << token::SPACE
157         << sp.converged_ << token::SPACE
158         << sp.singular_ << token::SPACE
159         << token::END_LIST;
161     return os;
165 // ************************************************************************* //