ENH: avoid the build-up of the background solver dictionary

The solverPerformanceDict gets larger due to the addition of a SolverPerformance
data per field at every outer iteration within the same main iteration/time
step.

However, the subsequent functionalities seem to use only the first and last
element of this dictionary per field; therefore, storing the interim values
was revealed to be redundant.

The change removes the interim values by transforming the `List` container
into the `Pair` container, and modifying the relevant algorithms.
This commit is contained in:
Kutalmis Bercin
2025-05-01 14:56:31 +01:00
parent 5bb030480d
commit ebbeef27b4
5 changed files with 17 additions and 8 deletions

View File

@ -39,12 +39,14 @@ void Foam::meshState::setSolverPerformance
{ {
dictionary& dict = const_cast<dictionary&>(solverPerformanceDict()); dictionary& dict = const_cast<dictionary&>(solverPerformanceDict());
List<SolverPerformance<Type>> perfs; Pair<SolverPerformance<Type>> perfs;
if (prevTimeIndex_ != this->time().timeIndex()) const label timeIndex = this->time().timeIndex();
if (prevTimeIndex_ != timeIndex)
{ {
// Reset solver performance between iterations // Reset solver performance between iterations
prevTimeIndex_ = this->time().timeIndex(); prevTimeIndex_ = timeIndex;
dict.clear(); dict.clear();
} }
else else
@ -52,7 +54,14 @@ void Foam::meshState::setSolverPerformance
dict.readIfPresent(name, perfs); dict.readIfPresent(name, perfs);
} }
perfs.push_back(sp); if (dict.found(name))
{
perfs.second() = sp;
}
else
{
perfs = Pair<SolverPerformance<Type>>(sp, sp);
}
dict.set(name, perfs); dict.set(name, perfs);
} }

View File

@ -227,7 +227,7 @@ bool Foam::solutionControl::maxTypeResidual
if (fvmesh.foundObject<fieldType>(fieldName)) if (fvmesh.foundObject<fieldType>(fieldName))
{ {
const List<SolverPerformance<Type>> sp(solverPerfDictEntry.stream()); const Pair<SolverPerformance<Type>> sp(solverPerfDictEntry.stream());
residuals.first() = cmptMax(sp.first().initialResidual()); residuals.first() = cmptMax(sp.first().initialResidual());
residuals.last() = cmptMax(sp.last().initialResidual()); residuals.last() = cmptMax(sp.last().initialResidual());

View File

@ -43,7 +43,7 @@ equationInitialResidualCondition::setResidual
if (canSet && mesh.foundObject<volFieldType>(fieldName)) if (canSet && mesh.foundObject<volFieldType>(fieldName))
{ {
const List<SolverPerformance<Type>> sp(dict.lookup(fieldName)); const Pair<SolverPerformance<Type>> sp(dict.lookup(fieldName));
const Type& allComponents = sp.first().initialResidual(); const Type& allComponents = sp.first().initialResidual();
if (componenti != -1) if (componenti != -1)

View File

@ -107,7 +107,7 @@ bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
if (solverDict.found(fieldName)) if (solverDict.found(fieldName))
{ {
const List<solverPerformance> sp(solverDict.lookup(fieldName)); const Pair<solverPerformance> sp(solverDict.lookup(fieldName));
const label nIterations = sp.first().nIterations(); const label nIterations = sp.first().nIterations();
result[fieldi] = nIterations; result[fieldi] = nIterations;

View File

@ -119,7 +119,7 @@ void Foam::functionObjects::solverInfo::updateSolverInfo(const word& fieldName)
if (solverDict.found(fieldName)) if (solverDict.found(fieldName))
{ {
const List<SolverPerformance<Type>> sp const Pair<SolverPerformance<Type>> sp
( (
solverDict.lookup(fieldName) solverDict.lookup(fieldName)
); );