From 12eca54491cf47cf1469b917c75dccb50f4b7e45 Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Fri, 3 Dec 2021 09:40:55 +0100
Subject: [PATCH] [PL] Use isOutputProcess also for nonlinear iteration output

---
 ProcessLib/Output/Output.cpp | 15 +++++++--------
 ProcessLib/Output/Output.h   |  6 ++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/ProcessLib/Output/Output.cpp b/ProcessLib/Output/Output.cpp
index 183d6a03be7..4fc1a5fdf41 100644
--- a/ProcessLib/Output/Output.cpp
+++ b/ProcessLib/Output/Output.cpp
@@ -211,13 +211,16 @@ bool Output::isOutputStep(int timestep, double const t) const
 }
 bool Output::isOutputProcess(const int process_id, const Process& process) const
 {
+    auto const n_processes = static_cast<int>(_process_to_pvd_file.size() /
+                                              _mesh_names_for_output.size());
+
+    auto const is_last_process = process_id == n_processes - 1;
+
     return process.isMonolithicSchemeUsed()
            // For the staggered scheme for the coupling, only the last process,
            // which gives the latest solution within a coupling loop, is allowed
            // to make output.
-           || process_id == static_cast<int>(_process_to_pvd_file.size() /
-                                             _mesh_names_for_output.size()) -
-                                1;
+           || is_last_process;
 }
 
 Output::Output(std::string directory, OutputType file_type,
@@ -491,11 +494,7 @@ void Output::doOutputNonlinearIteration(Process const& process,
     addProcessDataToMesh(t, xs, process_id, process_output_data,
                          output_secondary_variable, _output_data_specification);
 
-    // For the staggered scheme for the coupling, only the last process, which
-    // gives the latest solution within a coupling loop, is allowed to make
-    // output.
-    if (!(process_id == static_cast<int>(_process_to_pvd_file.size()) - 1 ||
-          process.isMonolithicSchemeUsed()))
+    if (!isOutputProcess(process_id, process))
     {
         return;
     }
diff --git a/ProcessLib/Output/Output.h b/ProcessLib/Output/Output.h
index fbb5e36978a..154496a0425 100644
--- a/ProcessLib/Output/Output.h
+++ b/ProcessLib/Output/Output.h
@@ -161,6 +161,12 @@ private:
     //! Given times that steps have to reach.
     std::vector<double> const _fixed_output_times;
 
+    //! Holds the PVD files associated with each process.
+    //!
+    //! Each \c process_id of each Process (in the current simulation) has a PVD
+    //! file in this map for each element of #_mesh_names_for_output. I.e., the
+    //! number of elements in this map is (roughly):
+    //! <no. of processes> x <no. of process IDs per process> x <no. of meshes>.
     std::multimap<Process const*, MeshLib::IO::PVDFile> _process_to_pvd_file;
 
     OutputDataSpecification const _output_data_specification;
-- 
GitLab