All ldu solvers: new optional parameter "minIter"
to specify the minimum number of iterations the solver should perform.
This commit is contained in:
parent
a8c917fd4b
commit
79614840b3
@ -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_;
|
||||
|
||||
|
@ -135,6 +135,7 @@ Foam::LduMatrix<Type, DType, LUType>::solver::solver
|
||||
controlDict_(solverDict),
|
||||
|
||||
maxIter_(1000),
|
||||
minIter_(0),
|
||||
tolerance_(1e-6*pTraits<Type>::one),
|
||||
relTol_(pTraits<Type>::zero)
|
||||
{
|
||||
@ -148,6 +149,7 @@ template<class Type, class DType, class LUType>
|
||||
void Foam::LduMatrix<Type, DType, LUType>::solver::readControls()
|
||||
{
|
||||
readControl(controlDict_, maxIter_, "maxIter");
|
||||
readControl(controlDict_, minIter_, "minIter");
|
||||
readControl(controlDict_, tolerance_, "tolerance");
|
||||
readControl(controlDict_, relTol_, "relTol");
|
||||
}
|
||||
|
@ -104,7 +104,11 @@ Foam::PBiCCCG<Type, DType, LUType>::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<typename LduMatrix<Type, DType, LUType>::preconditioner>
|
||||
@ -182,8 +186,11 @@ Foam::PBiCCCG<Type, DType, LUType>::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_
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,11 @@ Foam::PCICG<Type, DType, LUType>::solve(Field<Type>& 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<typename LduMatrix<Type, DType, LUType>::preconditioner>
|
||||
@ -174,8 +178,11 @@ Foam::PCICG<Type, DType, LUType>::solve(Field<Type>& 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_
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,11 @@ Foam::SmoothSolver<Type, DType, LUType>::solve(Field<Type>& 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<typename LduMatrix<Type, DType, LUType>::smoother>
|
||||
smootherPtr = LduMatrix<Type, DType, LUType>::smoother::New
|
||||
@ -140,8 +144,11 @@ Foam::SmoothSolver<Type, DType, LUType>::solve(Field<Type>& 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_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(lduMatrix, 1);
|
||||
defineTypeNameAndDebug(lduMatrix, 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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_;
|
||||
|
||||
|
@ -164,6 +164,7 @@ Foam::lduMatrix::solver::solver
|
||||
void Foam::lduMatrix::solver::readControls()
|
||||
{
|
||||
maxIter_ = controlDict_.lookupOrDefault<label>("maxIter", 1000);
|
||||
minIter_ = controlDict_.lookupOrDefault<label>("minIter", 0);
|
||||
tolerance_ = controlDict_.lookupOrDefault<scalar>("tolerance", 1e-6);
|
||||
relTol_ = controlDict_.lookupOrDefault<scalar>("relTol", 0);
|
||||
}
|
||||
|
@ -69,7 +69,11 @@ Foam::solverPerformance Foam::GAMGSolver::solve
|
||||
|
||||
|
||||
// Check convergence, solve if not converged
|
||||
if (!solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
if
|
||||
(
|
||||
minIter_ > 0
|
||||
|| !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
{
|
||||
// Create coarse grid correction fields
|
||||
PtrList<scalarField> coarseCorrFields;
|
||||
@ -131,8 +135,11 @@ Foam::solverPerformance Foam::GAMGSolver::solve
|
||||
}
|
||||
} while
|
||||
(
|
||||
++solverPerf.nIterations() < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
(
|
||||
++solverPerf.nIterations() < maxIter_
|
||||
&& !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < minIter_
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,11 @@ Foam::solverPerformance Foam::PBiCG::solve
|
||||
solverPerf.finalResidual() = solverPerf.initialResidual();
|
||||
|
||||
// --- Check convergence, solve if not converged
|
||||
if (!solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
if
|
||||
(
|
||||
minIter_ > 0
|
||||
|| !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
{
|
||||
// --- Select and construct the preconditioner
|
||||
autoPtr<lduMatrix::preconditioner> preconPtr =
|
||||
@ -192,8 +196,11 @@ Foam::solverPerformance Foam::PBiCG::solve
|
||||
/normFactor;
|
||||
} while
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < minIter_
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,11 @@ Foam::solverPerformance Foam::PCG::solve
|
||||
solverPerf.finalResidual() = solverPerf.initialResidual();
|
||||
|
||||
// --- Check convergence, solve if not converged
|
||||
if (!solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
if
|
||||
(
|
||||
minIter_ > 0
|
||||
|| !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
{
|
||||
// --- Select and construct the preconditioner
|
||||
autoPtr<lduMatrix::preconditioner> preconPtr =
|
||||
@ -177,8 +181,11 @@ Foam::solverPerformance Foam::PCG::solve
|
||||
|
||||
} while
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < minIter_
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,11 @@ Foam::solverPerformance Foam::smoothSolver::solve
|
||||
|
||||
|
||||
// Check convergence, solve if not converged
|
||||
if (!solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
if
|
||||
(
|
||||
minIter_ > 0
|
||||
|| !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
{
|
||||
autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
|
||||
(
|
||||
@ -176,8 +180,11 @@ Foam::solverPerformance Foam::smoothSolver::solve
|
||||
)/normFactor;
|
||||
} while
|
||||
(
|
||||
(solverPerf.nIterations() += nSweeps_) < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
(
|
||||
(solverPerf.nIterations() += nSweeps_) < maxIter_
|
||||
&& !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < minIter_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user