From 9ad0eab91003edc3735cb26f13f60f73d3845f97 Mon Sep 17 00:00:00 2001
From: renchao_lu <renchao.lu@gmail.com>
Date: Sun, 31 May 2020 17:10:46 +0200
Subject: [PATCH] [CL] Remove mapping process id to component name.

---
 .../CreateChemicalSolverInterface.cpp         | 10 +--
 ChemistryLib/CreateChemicalSolverInterface.h  |  2 -
 ChemistryLib/PhreeqcIO.cpp                    | 89 ++++++++-----------
 ChemistryLib/PhreeqcIO.h                      |  6 +-
 .../PhreeqcIOData/CreateAqueousSolution.cpp   |  8 +-
 .../PhreeqcIOData/CreateAqueousSolution.h     |  8 +-
 .../PhreeqcIOData/CreateSolutionComponent.cpp | 33 +------
 .../PhreeqcIOData/CreateSolutionComponent.h   |  5 +-
 8 files changed, 43 insertions(+), 118 deletions(-)

diff --git a/ChemistryLib/CreateChemicalSolverInterface.cpp b/ChemistryLib/CreateChemicalSolverInterface.cpp
index bd080a09972..da0bb97b329 100644
--- a/ChemistryLib/CreateChemicalSolverInterface.cpp
+++ b/ChemistryLib/CreateChemicalSolverInterface.cpp
@@ -67,8 +67,6 @@ template <>
 std::unique_ptr<ChemicalSolverInterface>
 createChemicalSolverInterface<ChemicalSolver::Phreeqc>(
     std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map,
     BaseLib::ConfigTree const& config, std::string const& output_directory)
 {
     auto mesh_name =
@@ -92,8 +90,7 @@ createChemicalSolverInterface<ChemicalSolver::Phreeqc>(
     // solution
     auto aqueous_solution = PhreeqcIOData::createAqueousSolution(
         //! \ogs_file_param{prj__chemical_system__solution}
-        config.getConfigSubtree("solution"),
-        process_id_to_component_name_map);
+        config.getConfigSubtree("solution"));
 
     // kinetic reactants
     auto chemical_system_map =
@@ -158,16 +155,13 @@ createChemicalSolverInterface<ChemicalSolver::Phreeqc>(
         std::move(path_to_database), std::move(aqueous_solutions),
         std::move(equilibrium_reactants), std::move(kinetic_reactants),
         std::move(reaction_rates), std::move(surface), std::move(user_punch),
-        std::move(output), std::move(dump), std::move(knobs),
-        process_id_to_component_name_map);
+        std::move(output), std::move(dump), std::move(knobs));
 }
 
 template <>
 std::unique_ptr<ChemicalSolverInterface>
 createChemicalSolverInterface<ChemicalSolver::PhreeqcKernel>(
     std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map,
     BaseLib::ConfigTree const& config, std::string const& /*output_directory*/)
 {
     auto mesh = *meshes[0];
diff --git a/ChemistryLib/CreateChemicalSolverInterface.h b/ChemistryLib/CreateChemicalSolverInterface.h
index 39615caae60..16af2b92eb9 100644
--- a/ChemistryLib/CreateChemicalSolverInterface.h
+++ b/ChemistryLib/CreateChemicalSolverInterface.h
@@ -33,7 +33,5 @@ class ChemicalSolverInterface;
 template <ChemicalSolver chemical_solver>
 std::unique_ptr<ChemicalSolverInterface> createChemicalSolverInterface(
     std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map,
     BaseLib::ConfigTree const& config, std::string const& output_directory);
 }  // namespace ChemistryLib
diff --git a/ChemistryLib/PhreeqcIO.cpp b/ChemistryLib/PhreeqcIO.cpp
index 1735c5f6104..8f6999744f2 100644
--- a/ChemistryLib/PhreeqcIO.cpp
+++ b/ChemistryLib/PhreeqcIO.cpp
@@ -56,9 +56,7 @@ PhreeqcIO::PhreeqcIO(std::string const project_file_name,
                      std::unique_ptr<UserPunch>&& user_punch,
                      std::unique_ptr<Output>&& output,
                      std::unique_ptr<Dump>&& dump,
-                     Knobs&& knobs,
-                     std::vector<std::pair<int, std::string>> const&
-                         process_id_to_component_name_map)
+                     Knobs&& knobs)
     : _phreeqc_input_file(project_file_name + "_phreeqc.inp"),
       _mesh(mesh),
       _database(std::move(database)),
@@ -70,8 +68,7 @@ PhreeqcIO::PhreeqcIO(std::string const project_file_name,
       _user_punch(std::move(user_punch)),
       _output(std::move(output)),
       _dump(std::move(dump)),
-      _knobs(std::move(knobs)),
-      _process_id_to_component_name_map(process_id_to_component_name_map)
+      _knobs(std::move(knobs))
 {
     // initialize phreeqc instance
     if (CreateIPhreeqc() != phreeqc_instance_id)
@@ -159,61 +156,45 @@ void PhreeqcIO::setAqueousSolutionsOrUpdateProcessSolutions(
         // Loop over transport process id map to retrieve component
         // concentrations from process solutions or to update process solutions
         // after chemical calculation by Phreeqc
-        for (auto const& process_id_to_component_name_map_element :
-             _process_id_to_component_name_map)
-        {
-            auto const& transport_process_id =
-                process_id_to_component_name_map_element.first;
-            auto const& transport_process_variable =
-                process_id_to_component_name_map_element.second;
 
+        for (unsigned component_id = 0; component_id < components.size();
+             ++component_id)
+        {
+            auto& component = components[component_id];
             auto& transport_process_solution =
-                process_solutions[transport_process_id];
-
-            auto component =
-                std::find_if(components.begin(), components.end(),
-                             [&transport_process_variable](Component const& c) {
-                                 return c.name == transport_process_variable;
-                             });
-
-            if (component != components.end())
+                process_solutions[component_id + 1];
+            switch (status)
             {
-                switch (status)
-                {
-                    case Status::SettingAqueousSolutions:
-                        // Set component concentrations.
-                        component->amount =
-                            transport_process_solution->get(global_id);
-                        break;
-                    case Status::UpdatingProcessSolutions:
-                        // Update solutions of component transport processes.
-                        transport_process_solution->set(global_id,
-                                                        component->amount);
-                        break;
-                }
+                case Status::SettingAqueousSolutions:
+                    // Set component concentrations.
+                    component.amount =
+                        transport_process_solution->get(global_id);
+                    break;
+                case Status::UpdatingProcessSolutions:
+                    // Update solutions of component transport processes.
+                    transport_process_solution->set(global_id,
+                                                    component.amount);
+                    break;
             }
+        }
 
-            if (transport_process_variable == "H")
+        switch (status)
+        {
+            case Status::SettingAqueousSolutions:
             {
-                switch (status)
-                {
-                    case Status::SettingAqueousSolutions:
-                    {
-                        // Set pH value by hydrogen concentration.
-                        aqueous_solution.pH = -std::log10(
-                            transport_process_solution->get(global_id));
-                        break;
-                    }
-                    case Status::UpdatingProcessSolutions:
-                    {
-                        // Update hydrogen concentration by pH value.
-                        auto hydrogen_concentration =
-                            std::pow(10, -aqueous_solution.pH);
-                        transport_process_solution->set(global_id,
-                                                        hydrogen_concentration);
-                        break;
-                    }
-                }
+                // Set pH value by hydrogen concentration.
+                aqueous_solution.pH =
+                    -std::log10(process_solutions.back()->get(global_id));
+                break;
+            }
+            case Status::UpdatingProcessSolutions:
+            {
+                // Update hydrogen concentration by pH value.
+                auto hydrogen_concentration =
+                    std::pow(10, -aqueous_solution.pH);
+                process_solutions.back()->set(global_id,
+                                              hydrogen_concentration);
+                break;
             }
         }
     }
diff --git a/ChemistryLib/PhreeqcIO.h b/ChemistryLib/PhreeqcIO.h
index 7bf70f58f5c..2db34efab46 100644
--- a/ChemistryLib/PhreeqcIO.h
+++ b/ChemistryLib/PhreeqcIO.h
@@ -53,9 +53,7 @@ public:
               std::unique_ptr<UserPunch>&& user_punch,
               std::unique_ptr<Output>&& output,
               std::unique_ptr<Dump>&& dump,
-              Knobs&& knobs,
-              std::vector<std::pair<int, std::string>> const&
-                  process_id_to_component_name_map);
+              Knobs&& knobs);
 
     void executeInitialCalculation(
         std::vector<GlobalVector*>& process_solutions) override;
@@ -101,8 +99,6 @@ private:
     std::unique_ptr<Output> const _output;
     std::unique_ptr<Dump> const _dump;
     Knobs const _knobs;
-    std::vector<std::pair<int, std::string>> const&
-        _process_id_to_component_name_map;
     double _dt = std::numeric_limits<double>::quiet_NaN();
     const int phreeqc_instance_id = 0;
 };
diff --git a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp
index 907eea1885e..70a7e2c6157 100644
--- a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp
+++ b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp
@@ -18,10 +18,7 @@ namespace ChemistryLib
 {
 namespace PhreeqcIOData
 {
-AqueousSolution createAqueousSolution(
-    BaseLib::ConfigTree const& config,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map)
+AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config)
 {
     //! \ogs_file_param{prj__chemical_system__solution__temperature}
     auto const temperature = config.getConfigParameter<double>("temperature");
@@ -32,8 +29,7 @@ AqueousSolution createAqueousSolution(
     //! \ogs_file_param{prj__chemical_system__solution__pe}
     auto const pe = config.getConfigParameter<double>("pe");
 
-    auto components =
-        createSolutionComponents(config, process_id_to_component_name_map);
+    auto components = createSolutionComponents(config);
 
     auto charge_balance = createChargeBalance(config);
 
diff --git a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h
index 787d4196fb6..8e0d680f276 100644
--- a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h
+++ b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h
@@ -10,9 +10,6 @@
 
 #pragma once
 
-#include <string>
-#include <vector>
-
 namespace BaseLib
 {
 class ConfigTree;
@@ -24,9 +21,6 @@ namespace PhreeqcIOData
 {
 struct AqueousSolution;
 
-AqueousSolution createAqueousSolution(
-    BaseLib::ConfigTree const& config,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map);
+AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config);
 }  // namespace PhreeqcIOData
 }  // namespace ChemistryLib
diff --git a/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.cpp b/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.cpp
index 66430c61ddb..44c0fce8422 100644
--- a/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.cpp
+++ b/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.cpp
@@ -11,16 +11,13 @@
 #include "CreateSolutionComponent.h"
 #include "AqueousSolution.h"
 #include "BaseLib/ConfigTree.h"
-#include "BaseLib/Error.h"
 
 namespace ChemistryLib
 {
 namespace PhreeqcIOData
 {
 std::vector<Component> createSolutionComponents(
-    BaseLib::ConfigTree const& config,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map)
+    BaseLib::ConfigTree const& config)
 {
     std::vector<Component> components;
     //! \ogs_file_param{prj__chemical_system__solution__components}
@@ -33,34 +30,6 @@ std::vector<Component> createSolutionComponents(
         components.emplace_back(component_name);
     }
 
-    for (auto const& component : components)
-    {
-        auto process_id_to_component_name_map_element = std::find_if(
-            process_id_to_component_name_map.begin(),
-            process_id_to_component_name_map.end(),
-            [&component](std::pair<int, std::string> const& map_element) {
-                return map_element.second == component.name;
-            });
-
-        if (process_id_to_component_name_map_element ==
-            process_id_to_component_name_map.end())
-        {
-            OGS_FATAL(
-                "Component {:s} given in <solution>/<components> is not found "
-                "in "
-                "specified coupled processes (see "
-                "<process>/<process_variables>/<concentration>).",
-                component.name);
-        }
-    }
-    if (components.size() + 1 != process_id_to_component_name_map.size())
-    {
-        OGS_FATAL(
-            "The number of components given in <solution>/<components> is not "
-            "in line with the number of transport processes - 1 which stands "
-            "for the transport process of hydrogen.");
-    }
-
     return components;
 }
 }  // namespace PhreeqcIOData
diff --git a/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.h b/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.h
index 66151c5d671..417450e9dac 100644
--- a/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.h
+++ b/ChemistryLib/PhreeqcIOData/CreateSolutionComponent.h
@@ -10,7 +10,6 @@
 
 #pragma once
 
-#include <string>
 #include <vector>
 
 namespace BaseLib
@@ -25,8 +24,6 @@ namespace PhreeqcIOData
 struct Component;
 
 std::vector<Component> createSolutionComponents(
-    BaseLib::ConfigTree const& config,
-    std::vector<std::pair<int, std::string>> const&
-        process_id_to_component_name_map);
+    BaseLib::ConfigTree const& config);
 }  // namespace PhreeqcIOData
 }  // namespace ChemistryLib
-- 
GitLab