diff --git a/src/foam/matrices/solution/solution.C b/src/foam/matrices/solution/solution.C index 100d0713a..f8d0fa2ac 100644 --- a/src/foam/matrices/solution/solution.C +++ b/src/foam/matrices/solution/solution.C @@ -127,6 +127,15 @@ void Foam::solution::read(const dictionary& dict) { solverPerformance_ = dict.subDict("solverPerformance"); } + + if (dict.found("residuals")) + { + storeAllResiduals_ = + dict.subDict("residuals").lookupOrDefault + ( + "storeAllResiduals", false + ); + } } @@ -153,7 +162,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName) eqnRelaxDefault_(0), solvers_(dictionary::null), solverPerformance_(dictionary::null), - prevTimeIndex_(0) + prevTimeIndex_(0), + storeAllResiduals_(false) { if (!headerOk()) { diff --git a/src/foam/matrices/solution/solution.H b/src/foam/matrices/solution/solution.H index 8461d3c07..d1c3aab04 100644 --- a/src/foam/matrices/solution/solution.H +++ b/src/foam/matrices/solution/solution.H @@ -82,6 +82,10 @@ class solution //- Previously used time-index, used for reset between iterations mutable label prevTimeIndex_; + //- Switch for storing residuals of every iteration inside a single + // timestep + bool storeAllResiduals_; + // Private Member Functions diff --git a/src/foam/matrices/solution/solutionTemplates.C b/src/foam/matrices/solution/solutionTemplates.C index 6f85c4166..1287cfb18 100644 --- a/src/foam/matrices/solution/solutionTemplates.C +++ b/src/foam/matrices/solution/solutionTemplates.C @@ -65,8 +65,20 @@ void Foam::solution::setSolverPerformance solverPerformance_.readIfPresent(name, perfs); } - // Append to list - perfs.setSize(perfs.size() + 1, sp); + // If storeAllResiduals_ is true, we are storing residual of every iteration + // inside a single time step. Otherwise, only the first iteration residual + // and the current iteration residual are required, so the current + // iteration residual replaces the previous one and only the first iteration + // residual is always present, VS 2018-02-11 + if (storeAllResiudals_ || perfs.size() < 2) + { + // Append to list + perfs.setSize(perfs.size() + 1, sp); + } + else + { + perfs.last() = sp; + } solverPerformance_.set(name, perfs); }