diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H index 1da27f106b6fd6a7964403ae49e5b4cb16c2861c..f96d583b1f2abf352a54ff64f2985a98aa33a482 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -122,6 +122,9 @@ public: //- Dictionary of controls dictionary controlDict_; + //- Default maximum number of iterations in the solver + static const label defaultMaxIter_ = 1000; + //- Maximum number of iterations in the solver label maxIter_; diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C index 651be6cee2828b0e31003bef43a034ad2bd24d09..dd908b91f0aa97dbc3cba2b02b57584772d3a9aa 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixSolver.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -131,7 +131,7 @@ Foam::LduMatrix<Type, DType, LUType>::solver::solver controlDict_(solverDict), - maxIter_(1000), + maxIter_(defaultMaxIter_), minIter_(0), tolerance_(1e-6*pTraits<Type>::one), relTol_(Zero) diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C index 11cdf31485f3b81a70828042859dcb9195519ccd..e9eb25143af250e109cc6fd6a087c641ee0090aa 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,6 +35,9 @@ namespace Foam } +const Foam::label Foam::lduMatrix::solver::defaultMaxIter_ = 1000; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Foam::lduMatrix::lduMatrix(const lduMesh& mesh) diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H index 575916f633e76c3a01f6950217a03ff42273d051..30ba325a5aa37b617e5630061bba58f7506964db 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -106,6 +106,9 @@ public: //- Dictionary of controls dictionary controlDict_; + //- Default maximum number of iterations in the solver + static const label defaultMaxIter_; + //- Maximum number of iterations in the solver label maxIter_; diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C index d554375cae33932f7042b0e211f0f2896dcfa951..bc1e134741bd2da36479e4c03e3ecee734bf6b68 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -157,10 +157,10 @@ Foam::lduMatrix::solver::solver void Foam::lduMatrix::solver::readControls() { - maxIter_ = controlDict_.lookupOrDefault<label>("maxIter", 1000); - minIter_ = controlDict_.lookupOrDefault<label>("minIter", 0); + maxIter_ = controlDict_.lookupOrDefault<label>("maxIter", defaultMaxIter_); + minIter_ = controlDict_.lookupOrDefault<label>("minIter", 0); tolerance_ = controlDict_.lookupOrDefault<scalar>("tolerance", 1e-6); - relTol_ = controlDict_.lookupOrDefault<scalar>("relTol", 0); + relTol_ = controlDict_.lookupOrDefault<scalar>("relTol", 0); } diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/PBiCG/PBiCG.C b/src/OpenFOAM/matrices/lduMatrix/solvers/PBiCG/PBiCG.C index 54088f550fc1953ab8cad63c562fe1e54172a840..b4e630571f6a71339666acef8d36ad61aa563f8e 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/PBiCG/PBiCG.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/PBiCG/PBiCG.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -208,6 +208,16 @@ Foam::solverPerformance Foam::PBiCG::solve ); } + // Recommend PBiCGStab if PBiCG fails to converge + if (solverPerf.nIterations() > max(defaultMaxIter_, maxIter_)) + { + FatalErrorInFunction + << "PBiCG has failed to converge within the maximum number" + " of iterations " << max(defaultMaxIter_, maxIter_) << nl + << " Please try the more robust PBiCGStab solver." + << exit(FatalError); + } + return solverPerf; }