From fbbf775d584f6585c601ed682b5e0614c523049c Mon Sep 17 00:00:00 2001
From: renchao_lu <renchao.lu@gmail.com>
Date: Tue, 4 Jun 2019 19:13:30 +0200
Subject: [PATCH] [PL] Perform chemical calculation.

---
 ChemistryLib/PhreeqcIO.cpp | 17 +++++++++++++++++
 ChemistryLib/PhreeqcIO.h   |  3 +++
 ProcessLib/TimeLoop.cpp    | 10 ++++++++++
 3 files changed, 30 insertions(+)

diff --git a/ChemistryLib/PhreeqcIO.cpp b/ChemistryLib/PhreeqcIO.cpp
index 9936ce309ef..6a3580b6de1 100644
--- a/ChemistryLib/PhreeqcIO.cpp
+++ b/ChemistryLib/PhreeqcIO.cpp
@@ -19,6 +19,23 @@
 
 namespace ChemistryLib
 {
+void PhreeqcIO::doWaterChemistryCalculation(
+    std::vector<GlobalVector*>& process_solutions, double const dt)
+{
+    setAqueousSolutionsOrUpdateProcessSolutions(
+        process_solutions, Status::SettingAqueousSolutions);
+    setTimeStep(dt);
+
+    writeInputsToFile();
+
+    execute();
+
+    readOutputsFromFile();
+
+    setAqueousSolutionsOrUpdateProcessSolutions(
+        process_solutions, Status::UpdatingProcessSolutions);
+}
+
 void PhreeqcIO::setAqueousSolutionsOrUpdateProcessSolutions(
     std::vector<GlobalVector*> const& process_solutions, Status const status)
 {
diff --git a/ChemistryLib/PhreeqcIO.h b/ChemistryLib/PhreeqcIO.h
index 230a0ba16b2..10e431d4bac 100644
--- a/ChemistryLib/PhreeqcIO.h
+++ b/ChemistryLib/PhreeqcIO.h
@@ -49,6 +49,9 @@ public:
     {
     }
 
+    void doWaterChemistryCalculation(
+        std::vector<GlobalVector*>& process_solutions, double const dt);
+
     void setAqueousSolutionsOrUpdateProcessSolutions(
         std::vector<GlobalVector*> const& process_solutions,
         Status const status);
diff --git a/ProcessLib/TimeLoop.cpp b/ProcessLib/TimeLoop.cpp
index efd338064c4..ba4850a7fc0 100644
--- a/ProcessLib/TimeLoop.cpp
+++ b/ProcessLib/TimeLoop.cpp
@@ -725,6 +725,16 @@ TimeLoop::solveCoupledEquationSystemsByStaggeredScheme(
             timestep_id, t);
     }
 
+    if (_chemical_system != nullptr)
+    {
+        // Sequential non-iterative approach applied here to perform water
+        // chemistry calculation followed by resolving component transport
+        // process.
+        // TODO: move into a global loop to consider both mass balance over
+        // space and localized chemical equilibrium between solutes.
+        _chemical_system->doWaterChemistryCalculation(_process_solutions, dt);
+    }
+
     int process_id = 0;
     for (auto& process_data : _per_process_data)
     {
-- 
GitLab