From 4530dc0b3e886726594cd2dfb400b81db391cd3f Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Mon, 7 Sep 2015 16:06:21 +0200
Subject: [PATCH] Extract solveProcess method with added time-loop.

---
 Applications/CLI/ogs.cpp | 52 ++++++++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 7 deletions(-)

diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp
index bf0243cc282..97f7d452b67 100644
--- a/Applications/CLI/ogs.cpp
+++ b/Applications/CLI/ogs.cpp
@@ -28,10 +28,53 @@
 
 #include "ProcessLib/NumericsConfig.h"
 
+void solveProcesses(ProjectData &project)
+{
+	INFO("Solve processes.");
+
+	std::string const out_pref = project.getOutputFilePrefix();
+
+	auto &time_stepper = project.getTimeStepper();
+
+	while (time_stepper.next())  // skips zeroth timestep, but OK since end of
+	                             // first timestep is after first delta t
+	{
+		const auto dt = time_stepper.getTimeStep().dt();
+		const auto current_time = time_stepper.getTimeStep().current();
+		const auto timestep = time_stepper.getTimeStep().steps();
+
+		INFO("=================== timestep %i === %g s ===================",
+		     timestep, current_time);
+
+		bool accepted = true;
+
+		unsigned i = 0;  // process counter, used to distinguish output files
+		for (auto p = project.processesBegin(); p != project.processesEnd();
+		     ++p)
+		{
+			accepted = accepted && (*p)->solve(dt);
+
+			if (!accepted)
+			{
+				ERR("Timestep has not been accepted. Aborting.");
+				break;
+			}
+
+			std::string const output_file_name =
+			    out_pref + "_pcs_" + std::to_string(i) + "_ts_" +
+			    std::to_string(timestep) + ".vtu";
+			(*p)->postTimestep(output_file_name, timestep);
+
+			++i;
+		}
+
+		if (!accepted)
+			break;
+	}
+}
 
 int main(int argc, char *argv[])
 {
-
 	using ConfigTree = boost::property_tree::ptree;
 
 	// logog
@@ -90,12 +133,7 @@ int main(int argc, char *argv[])
 
 	std::string const output_file_name(project.getOutputFilePrefix() + ".vtu");
 
-	INFO("Solve processes.");
-	for (auto p_it = project.processesBegin(); p_it != project.processesEnd(); ++p_it)
-	{
-		(*p_it)->solve();
-		(*p_it)->post(output_file_name);
-	}
+	solveProcesses(project);
 
 	delete fmt;
 	delete logog_cout;
-- 
GitLab