From 8c0718cb430ae145fb380909efc31a79c3603d89 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 12 Aug 2016 14:56:03 +0100 Subject: [PATCH] LduMatrix/SolverPerformance: Changed nIterations from label to labelType corresponding to the type solved Now the number of iterations to solve each component in a segregated solution are stored and returned in the SolverPerformance class. Resolves bug-report http://bugs.openfoam.org/view.php?id=2189 --- .../LduMatrix/LduMatrix/SolverPerformance.C | 13 +++--- .../LduMatrix/LduMatrix/SolverPerformance.H | 41 ++++++++++--------- .../Solvers/DiagonalSolver/DiagonalSolver.C | 2 +- .../LduMatrix/Solvers/PBiCCCG/PBiCCCG.C | 11 +++-- .../LduMatrix/Solvers/PBiCICG/PBiCICG.C | 9 +++- .../matrices/LduMatrix/Solvers/PCICG/PCICG.C | 13 ++++-- .../Solvers/SmoothSolver/SmoothSolver.C | 11 +++-- 7 files changed, 62 insertions(+), 38 deletions(-) diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C index e898751fd..196b2cac7 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -66,7 +66,7 @@ bool Foam::SolverPerformance::checkConvergence if (debug >= 2) { Info<< solverName_ - << ": Iteration " << noIterations_ + << ": Iteration " << nIterations_ << " residual = " << finalResidual_ << endl; } @@ -119,7 +119,7 @@ void Foam::SolverPerformance::print { os << ", Initial residual = " << component(initialResidual_, cmpt) << ", Final residual = " << component(finalResidual_, cmpt) - << ", No Iterations " << noIterations_ + << ", No Iterations " << nIterations_ << endl; } } @@ -135,6 +135,7 @@ void Foam::SolverPerformance::replace { initialResidual_.replace(cmpt, sp.initialResidual()); finalResidual_.replace(cmpt, sp.finalResidual()); + nIterations_.replace(cmpt, sp.nIterations()); singular_[cmpt] = sp.singular(); } @@ -149,7 +150,7 @@ Foam::SolverPerformance::max() fieldName_, cmptMax(initialResidual_), cmptMax(finalResidual_), - noIterations_, + cmptMax(nIterations_), converged_, singular() ); @@ -207,7 +208,7 @@ Foam::Istream& Foam::operator>> >> sp.fieldName_ >> sp.initialResidual_ >> sp.finalResidual_ - >> sp.noIterations_ + >> sp.nIterations_ >> sp.converged_ >> sp.singular_; is.readEndList("SolverPerformance"); @@ -228,7 +229,7 @@ Foam::Ostream& Foam::operator<< << sp.fieldName_ << token::SPACE << sp.initialResidual_ << token::SPACE << sp.finalResidual_ << token::SPACE - << sp.noIterations_ << token::SPACE + << sp.nIterations_ << token::SPACE << sp.converged_ << token::SPACE << sp.singular_ << token::SPACE << token::END_LIST; diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H index 1c639c443..52fa3c9ca 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H @@ -78,14 +78,17 @@ Ostream& operator<< template class SolverPerformance { + // Label type corresponding to Type + typedef typename pTraits::labelType labelType; + // Private data - word solverName_; - word fieldName_; - Type initialResidual_; - Type finalResidual_; - label noIterations_; - bool converged_; + word solverName_; + word fieldName_; + Type initialResidual_; + Type finalResidual_; + labelType nIterations_; + bool converged_; FixedList::nComponents> singular_; @@ -112,7 +115,7 @@ public: : initialResidual_(Zero), finalResidual_(Zero), - noIterations_(0), + nIterations_(Zero), converged_(false), singular_(false) {} @@ -120,20 +123,20 @@ public: SolverPerformance ( - const word& solverName, - const word& fieldName, - const Type& iRes = pTraits::zero, - const Type& fRes = pTraits::zero, - const label nIter = 0, - const bool converged = false, - const bool singular = false + const word& solverName, + const word& fieldName, + const Type& iRes = pTraits::zero, + const Type& fRes = pTraits::zero, + const labelType& nIter = pTraits::zero, + const bool converged = false, + const bool singular = false ) : solverName_(solverName), fieldName_(fieldName), initialResidual_(iRes), finalResidual_(fRes), - noIterations_(nIter), + nIterations_(nIter), converged_(converged), singular_(singular) {} @@ -188,15 +191,15 @@ public: //- Return number of iterations - label nIterations() const + const labelType& nIterations() const { - return noIterations_; + return nIterations_; } //- Return number of iterations - label& nIterations() + labelType& nIterations() { - return noIterations_; + return nIterations_; } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C index 4c1cf19a2..70a1fd852 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C @@ -69,7 +69,7 @@ Foam::DiagonalSolver::solve this->fieldName_, Zero, Zero, - 0, + Zero, true, false ); diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C index 11f7d52aa..ad61ed9cc 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C @@ -62,6 +62,8 @@ Foam::PBiCCCG::solve this->fieldName_ ); + label nIter = 0; + label nCells = psi.size(); Type* __restrict__ psiPtr = psi.begin(); @@ -131,7 +133,7 @@ Foam::PBiCCCG::solve // --- Update search directions: wArT = gSumProd(wA, rT); - if (solverPerf.nIterations() == 0) + if (nIter == 0) { for (label cell=0; cell::solve } while ( ( - solverPerf.nIterations()++ < this->maxIter_ + nIter++ < this->maxIter_ && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) - || solverPerf.nIterations() < this->minIter_ + || nIter < this->minIter_ ); } + solverPerf.nIterations() = + pTraits::labelType>::one*nIter; + return solverPerf; } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C index 860765e4c..ff437a850 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C @@ -59,6 +59,8 @@ Foam::PBiCICG::solve(Field& psi) const this->fieldName_ ); + label nIter = 0; + label nCells = psi.size(); Type* __restrict__ psiPtr = psi.begin(); @@ -124,7 +126,7 @@ Foam::PBiCICG::solve(Field& psi) const // --- Update search directions: wArT = gSumCmptProd(wA, rT); - if (solverPerf.nIterations() == 0) + if (nIter == 0) { for (label cell=0; cell::solve(Field& psi) const } while ( - solverPerf.nIterations()++ < this->maxIter_ + nIter++ < this->maxIter_ && !(solverPerf.checkConvergence(this->tolerance_, this->relTol_)) ); } + solverPerf.nIterations() = + pTraits::labelType>::one*nIter; + return solverPerf; } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C index 8570c9953..5e97b21b7 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,6 +59,8 @@ Foam::PCICG::solve(Field& psi) const this->fieldName_ ); + label nIter = 0; + label nCells = psi.size(); Type* __restrict__ psiPtr = psi.begin(); @@ -118,7 +120,7 @@ Foam::PCICG::solve(Field& psi) const // --- Update search directions: wArA = gSumCmptProd(wA, rA); - if (solverPerf.nIterations() == 0) + if (nIter == 0) { for (label cell=0; cell::solve(Field& psi) const } while ( ( - solverPerf.nIterations()++ < this->maxIter_ + nIter++ < this->maxIter_ && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) - || solverPerf.nIterations() < this->minIter_ + || nIter < this->minIter_ ); } + solverPerf.nIterations() = + pTraits::labelType>::one*nIter; + return solverPerf; } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C index 76d3b4369..8de57089c 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C @@ -68,6 +68,8 @@ Foam::SmoothSolver::solve(Field& psi) const this->fieldName_ ); + label nIter = 0; + // If the nSweeps_ is negative do a fixed number of sweeps if (nSweeps_ < 0) { @@ -81,7 +83,7 @@ Foam::SmoothSolver::solve(Field& psi) const smootherPtr->smooth(psi, -nSweeps_); - solverPerf.nIterations() -= nSweeps_; + nIter -= nSweeps_; } else { @@ -145,14 +147,17 @@ Foam::SmoothSolver::solve(Field& psi) const } while ( ( - (solverPerf.nIterations() += nSweeps_) < this->maxIter_ + (nIter += nSweeps_) < this->maxIter_ && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) - || solverPerf.nIterations() < this->minIter_ + || nIter < this->minIter_ ); } } + solverPerf.nIterations() = + pTraits::labelType>::one*nIter; + return solverPerf; }