From 79614840b3bcb74ed30aa688218c85890f50ee82 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 11 Dec 2013 17:27:27 +0000 Subject: [PATCH] All ldu solvers: new optional parameter "minIter" to specify the minimum number of iterations the solver should perform. --- .../matrices/LduMatrix/LduMatrix/LduMatrix.H | 3 +++ .../matrices/LduMatrix/LduMatrix/LduMatrixSolver.C | 2 ++ .../matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C | 13 ++++++++++--- .../matrices/LduMatrix/Solvers/PCICG/PCICG.C | 13 ++++++++++--- .../LduMatrix/Solvers/SmoothSolver/SmoothSolver.C | 13 ++++++++++--- .../matrices/lduMatrix/lduMatrix/lduMatrix.C | 2 +- .../matrices/lduMatrix/lduMatrix/lduMatrix.H | 3 +++ .../matrices/lduMatrix/lduMatrix/lduMatrixSolver.C | 1 + .../lduMatrix/solvers/GAMG/GAMGSolverSolve.C | 13 ++++++++++--- .../matrices/lduMatrix/solvers/PBiCG/PBiCG.C | 13 ++++++++++--- src/OpenFOAM/matrices/lduMatrix/solvers/PCG/PCG.C | 13 ++++++++++--- .../lduMatrix/solvers/smoothSolver/smoothSolver.C | 13 ++++++++++--- 12 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H index c2414b0f8b..71aae68507 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H @@ -125,6 +125,9 @@ public: //- Maximum number of iterations in the solver label maxIter_; + //- Minimum number of iterations in the solver + label minIter_; + //- Final convergence tolerance Type tolerance_; diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C index 50831a0ec9..ef3afff4ab 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C @@ -135,6 +135,7 @@ Foam::LduMatrix::solver::solver controlDict_(solverDict), maxIter_(1000), + minIter_(0), tolerance_(1e-6*pTraits::one), relTol_(pTraits::zero) { @@ -148,6 +149,7 @@ template void Foam::LduMatrix::solver::readControls() { readControl(controlDict_, maxIter_, "maxIter"); + readControl(controlDict_, minIter_, "minIter"); readControl(controlDict_, tolerance_, "tolerance"); readControl(controlDict_, relTol_, "relTol"); } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C index 7ee6da05dc..302785c1c4 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C @@ -104,7 +104,11 @@ Foam::PBiCCCG::solve solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged - if (!solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + if + ( + this->minIter_ > 0 + || !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) { // --- Select and construct the preconditioner autoPtr::preconditioner> @@ -182,8 +186,11 @@ Foam::PBiCCCG::solve } while ( - solverPerf.nIterations()++ < this->maxIter_ - && !(solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + ( + solverPerf.nIterations()++ < this->maxIter_ + && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) + || solverPerf.nIterations() < this->minIter_ ); } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C index cc8f1d1c72..87d087d199 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C @@ -92,7 +92,11 @@ Foam::PCICG::solve(Field& psi) const solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged - if (!solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + if + ( + this->minIter_ > 0 + || !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) { // --- Select and construct the preconditioner autoPtr::preconditioner> @@ -174,8 +178,11 @@ Foam::PCICG::solve(Field& psi) const } while ( - solverPerf.nIterations()++ < this->maxIter_ - && !(solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + ( + solverPerf.nIterations()++ < this->maxIter_ + && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) + || solverPerf.nIterations() < this->minIter_ ); } diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C index 9cf5c81223..b6725506ed 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C @@ -113,7 +113,11 @@ Foam::SmoothSolver::solve(Field& psi) const // Check convergence, solve if not converged - if (!solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + if + ( + this->minIter_ > 0 + || !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) { autoPtr::smoother> smootherPtr = LduMatrix::smoother::New @@ -140,8 +144,11 @@ Foam::SmoothSolver::solve(Field& psi) const ); } while ( - (solverPerf.nIterations() += nSweeps_) < this->maxIter_ - && !(solverPerf.checkConvergence(this->tolerance_, this->relTol_)) + ( + (solverPerf.nIterations() += nSweeps_) < this->maxIter_ + && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) + ) + || solverPerf.nIterations() < this->minIter_ ); } } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C index fd9c43da08..b8bc5c930c 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C @@ -31,7 +31,7 @@ License namespace Foam { -defineTypeNameAndDebug(lduMatrix, 1); + defineTypeNameAndDebug(lduMatrix, 1); } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H index a75668dfdd..fdaf834a74 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H @@ -107,6 +107,9 @@ public: //- Maximum number of iterations in the solver label maxIter_; + //- Minimum number of iterations in the solver + label minIter_; + //- Final convergence tolerance scalar tolerance_; diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C index cee5c1dc2f..aed21fe9f7 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C @@ -164,6 +164,7 @@ Foam::lduMatrix::solver::solver void Foam::lduMatrix::solver::readControls() { maxIter_ = controlDict_.lookupOrDefault