mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
All ldu solvers: new optional parameter "minIter"
to specify the minimum number of iterations the solver should perform.
This commit is contained in:
@ -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>
|
||||
@ -181,9 +185,12 @@ Foam::PBiCCCG<Type, DType, LUType>::solve
|
||||
cmptDivide(gSumCmptMag(rA), normFactor);
|
||||
|
||||
} while
|
||||
(
|
||||
(
|
||||
solverPerf.nIterations()++ < this->maxIter_
|
||||
&& !(solverPerf.checkConvergence(this->tolerance_, this->relTol_))
|
||||
&& !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>
|
||||
@ -173,9 +177,12 @@ Foam::PCICG<Type, DType, LUType>::solve(Field<Type>& psi) const
|
||||
cmptDivide(gSumCmptMag(rA), normFactor);
|
||||
|
||||
} while
|
||||
(
|
||||
(
|
||||
solverPerf.nIterations()++ < this->maxIter_
|
||||
&& !(solverPerf.checkConvergence(this->tolerance_, this->relTol_))
|
||||
&& !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
|
||||
@ -139,9 +143,12 @@ Foam::SmoothSolver<Type, DType, LUType>::solve(Field<Type>& psi) const
|
||||
normFactor
|
||||
);
|
||||
} while
|
||||
(
|
||||
(
|
||||
(solverPerf.nIterations() += nSweeps_) < this->maxIter_
|
||||
&& !(solverPerf.checkConvergence(this->tolerance_, this->relTol_))
|
||||
&& !solverPerf.checkConvergence(this->tolerance_, this->relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < this->minIter_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -130,9 +134,12 @@ Foam::solverPerformance Foam::GAMGSolver::solve
|
||||
solverPerf.print(Info(matrix().mesh().comm()));
|
||||
}
|
||||
} while
|
||||
(
|
||||
(
|
||||
++solverPerf.nIterations() < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
&& !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 =
|
||||
@ -191,9 +195,12 @@ Foam::solverPerformance Foam::PBiCG::solve
|
||||
gSumMag(rA, matrix().mesh().comm())
|
||||
/normFactor;
|
||||
} while
|
||||
(
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
&& !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 =
|
||||
@ -176,9 +180,12 @@ Foam::solverPerformance Foam::PCG::solve
|
||||
/normFactor;
|
||||
|
||||
} while
|
||||
(
|
||||
(
|
||||
solverPerf.nIterations()++ < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
&& !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
|
||||
(
|
||||
@ -175,9 +179,12 @@ Foam::solverPerformance Foam::smoothSolver::solve
|
||||
matrix().mesh().comm()
|
||||
)/normFactor;
|
||||
} while
|
||||
(
|
||||
(
|
||||
(solverPerf.nIterations() += nSweeps_) < maxIter_
|
||||
&& !(solverPerf.checkConvergence(tolerance_, relTol_))
|
||||
&& !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
|| solverPerf.nIterations() < minIter_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user