From d2c485876a900eb4c1e9fcc64ea192a078353a93 Mon Sep 17 00:00:00 2001
From: renchao_lu <renchao.lu@gmail.com>
Date: Sun, 31 May 2020 19:16:39 +0200
Subject: [PATCH] [App] Swap chemical solver interface parser and process
 parser.

---
 Applications/ApplicationsLib/ProjectData.cpp | 130 +++++++++----------
 1 file changed, 58 insertions(+), 72 deletions(-)

diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index 271658f2387..adc6a899d39 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -48,9 +48,6 @@
 
 #ifdef OGS_BUILD_PROCESS_COMPONENTTRANSPORT
 #include "ChemistryLib/CreateChemicalSolverInterface.h"
-// The ComponenTransportProcess is needed for the instantiation of the chemical
-// solver.
-#include "ProcessLib/ComponentTransport/ComponentTransportProcess.h"
 #include "ProcessLib/ComponentTransport/CreateComponentTransportProcess.h"
 #endif
 #ifdef OGS_BUILD_PROCESS_STEADYSTATEDIFFUSION
@@ -331,6 +328,11 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
     //! \ogs_file_param{prj__media}
     parseMedia(project_config.getConfigSubtreeOptional("media"));
 
+    parseChemicalSolverInterface(
+        //! \ogs_file_param{prj__chemical_system}
+        project_config.getConfigSubtreeOptional("chemical_system"),
+        output_directory);
+
     //! \ogs_file_param{prj__processes}
     parseProcesses(project_config.getConfigSubtree("processes"),
                    project_directory, output_directory);
@@ -341,11 +343,6 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
     //! \ogs_file_param{prj__nonlinear_solvers}
     parseNonlinearSolvers(project_config.getConfigSubtree("nonlinear_solvers"));
 
-    parseChemicalSolverInterface(
-        //! \ogs_file_param{prj__chemical_system}
-        project_config.getConfigSubtreeOptional("chemical_system"),
-        output_directory);
-
     //! \ogs_file_param{prj__time_loop}
     parseTimeLoop(project_config.getConfigSubtree("time_loop"),
                   output_directory);
@@ -503,6 +500,59 @@ void ProjectData::parseMedia(
     }
 }
 
+void ProjectData::parseChemicalSolverInterface(
+    boost::optional<BaseLib::ConfigTree> const& config,
+    std::string const& output_directory)
+{
+    if (!config)
+    {
+        return;
+    }
+
+#ifdef OGS_BUILD_PROCESS_COMPONENTTRANSPORT
+    INFO(
+        "Ready for initializing interface to a chemical solver for water "
+        "chemistry calculation.");
+
+    auto const chemical_solver =
+        //! \ogs_file_attr{prj__chemical_system__chemical_solver}
+        config->getConfigAttribute<std::string>("chemical_solver");
+
+    if (boost::iequals(chemical_solver, "Phreeqc"))
+    {
+        INFO(
+            "Configuring phreeqc interface for water chemistry "
+            "calculation using file-based approach.");
+
+        _chemical_solver_interface =
+            ChemistryLib::createChemicalSolverInterface<
+                ChemistryLib::ChemicalSolver::Phreeqc>(_mesh_vec, *config,
+                                                       output_directory);
+    }
+    else if (boost::iequals(chemical_solver, "PhreeqcKernel"))
+    {
+        OGS_FATAL(
+            "The chemical solver option of PhreeqcKernel is not accessible "
+            "for the time being. Please set 'Phreeqc'' as the chemical "
+            "solver for reactive transport modeling.");
+    }
+    else
+    {
+        OGS_FATAL(
+            "Unknown chemical solver. Please specify either Phreeqc or "
+            "PhreeqcKernel as the solver for water chemistry calculation "
+            "instead.");
+    }
+#else
+    (void)output_directory;
+
+    OGS_FATAL(
+        "The specified type of the process to be solved is not component "
+        "transport process so that water chemistry calculation could not "
+        "be activated.");
+#endif
+}
+
 void ProjectData::parseProcesses(BaseLib::ConfigTree const& processes_config,
                                  std::string const& project_directory,
                                  std::string const& output_directory)
@@ -1048,67 +1098,3 @@ void ProjectData::parseCurves(
             "The curve name is not unique.");
     }
 }
-
-void ProjectData::parseChemicalSolverInterface(
-    boost::optional<BaseLib::ConfigTree> const& config,
-    std::string const& output_directory)
-{
-    if (!config)
-    {
-        return;
-    }
-
-#ifdef OGS_BUILD_PROCESS_COMPONENTTRANSPORT
-    INFO(
-        "Ready for initializing interface to a chemical solver for water "
-        "chemistry calculation.");
-
-    if (auto const* component_transport_process = dynamic_cast<
-            ProcessLib::ComponentTransport::ComponentTransportProcess const*>(
-            _processes[0].get()))
-    {
-        auto const& process_id_to_component_name_map =
-            component_transport_process->getProcessIDToComponentNameMap();
-
-        auto const chemical_solver =
-            //! \ogs_file_attr{prj__chemical_system__chemical_solver}
-            config->getConfigAttribute<std::string>("chemical_solver");
-
-        if (boost::iequals(chemical_solver, "Phreeqc"))
-        {
-            INFO(
-                "Configuring phreeqc interface for water chemistry "
-                "calculation using file-based approach.");
-
-            _chemical_solver_interface =
-                ChemistryLib::createChemicalSolverInterface<
-                    ChemistryLib::ChemicalSolver::Phreeqc>(
-                    _mesh_vec, process_id_to_component_name_map, *config,
-                    output_directory);
-        }
-        else if (boost::iequals(chemical_solver, "PhreeqcKernel"))
-        {
-            OGS_FATAL(
-                "The chemical solver option of PhreeqcKernel is not accessible "
-                "for the time being. Please set 'Phreeqc'' as the chemical "
-                "solver for reactive transport modeling.");
-        }
-        else
-        {
-            OGS_FATAL(
-                "Unknown chemical solver. Please specify either Phreeqc or "
-                "PhreeqcKernel as the solver for water chemistry calculation "
-                "instead.");
-        }
-    }
-    else
-#endif
-    {
-        (void)output_directory;
-
-        OGS_FATAL(
-            "The specified type of the process to be solved is not component "
-            "transport process so that water chemistry calculation could not "
-            "be activated.");
-    }
-}
-- 
GitLab