From a8dc6e61969764d364f6a7bd1cfe831cdd5ba83d Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Mon, 20 Dec 2021 08:46:21 +0100
Subject: [PATCH] [T/MaL] Adjustment to new LinearSolverOptionsParser.

---
 Tests/MathLib/TestLinearSolver.cpp      | 26 ++++++++++++++-------
 Tests/NumLib/TestODEInt.cpp             | 30 ++++++++++++++++---------
 Tests/NumLib/TestSerialLinearSolver.cpp |  7 +++++-
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/Tests/MathLib/TestLinearSolver.cpp b/Tests/MathLib/TestLinearSolver.cpp
index a2a95006fb6..fe7d529e8b6 100644
--- a/Tests/MathLib/TestLinearSolver.cpp
+++ b/Tests/MathLib/TestLinearSolver.cpp
@@ -20,19 +20,18 @@
 #include "MathLib/LinAlg/Eigen/EigenLinearSolver.h"
 #include "MathLib/LinAlg/Eigen/EigenMatrix.h"
 #include "MathLib/LinAlg/Eigen/EigenVector.h"
+#include "MathLib/LinAlg/Eigen/LinearSolverOptionsParser.h"
 #include "MathLib/LinAlg/FinalizeMatrixAssembly.h"
 #include "MathLib/LinAlg/LinAlg.h"
 
-#if defined(USE_LIS)
-#include "MathLib/LinAlg/EigenLis/EigenLisLinearSolver.h"
-#endif
-
 #ifdef USE_LIS
-#include "MathLib/LinAlg/Lis/LisLinearSolver.h"
+#include "MathLib/LinAlg/EigenLis/EigenLisLinearSolver.h"
+#include "MathLib/LinAlg/EigenLis/LinearSolverOptionsParser.h"
 #include "MathLib/LinAlg/Lis/LisVector.h"
 #endif
 
 #ifdef USE_PETSC
+#include "MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h"
 #include "MathLib/LinAlg/PETSc/PETScLinearSolver.h"
 #include "MathLib/LinAlg/PETSc/PETScMatrix.h"
 #include "MathLib/LinAlg/PETSc/PETScVector.h"
@@ -208,8 +207,12 @@ void checkLinearSolverInterface(T_MATRIX& A,
 
     MathLib::finalizeMatrixAssembly(A);
 
-    // solve
-    T_LINEAR_SOLVER ls("dummy_name", &ls_option);
+    auto const linear_solver_parser =
+        MathLib::LinearSolverOptionsParser<T_LINEAR_SOLVER>{};
+    auto const solver_options =
+        linear_solver_parser.parseNameAndOptions("", &ls_option);
+    T_LINEAR_SOLVER ls{std::get<0>(solver_options),
+                       std::get<1>(solver_options)};
     ls.solve(A, rhs, x);
 
     ASSERT_ARRAY_NEAR(ex1.exH, x, ex1.dim_eqs, 1e-5);
@@ -273,7 +276,12 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b,
     // solve
     T_VECTOR y(b, deep_copy);
     y.setZero();
-    T_LINEAR_SOLVER ls(prefix_name, &ls_option);
+    std::string temp_prefix_name = prefix_name;
+    auto const solver_options =
+        MathLib::LinearSolverOptionsParser<T_LINEAR_SOLVER>{}
+            .parseNameAndOptions(std::move(temp_prefix_name), &ls_option);
+    T_LINEAR_SOLVER ls(std::get<0>(solver_options),
+                       std::get<1>(solver_options));
     EXPECT_TRUE(ls.solve(A, b, y));
 
     EXPECT_GT(ls.getNumberOfIterations(), 0u);
@@ -286,6 +294,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b,
 
 }  // end namespace
 
+#if not defined(USE_LIS) and not defined(USE_PETSC)
 TEST(Math, CheckInterface_Eigen)
 {
     // set solver options using Boost property tree
@@ -305,6 +314,7 @@ TEST(Math, CheckInterface_Eigen)
     checkLinearSolverInterface<MathLib::EigenMatrix, MathLib::EigenVector,
                                MathLib::EigenLinearSolver, IntType>(A, conf);
 }
+#endif
 
 #if defined(USE_LIS)
 TEST(Math, CheckInterface_EigenLis)
diff --git a/Tests/NumLib/TestODEInt.cpp b/Tests/NumLib/TestODEInt.cpp
index a6f10074e06..3b918f11e02 100644
--- a/Tests/NumLib/TestODEInt.cpp
+++ b/Tests/NumLib/TestODEInt.cpp
@@ -25,23 +25,31 @@
 
 namespace TestODEInt
 {
-#ifndef USE_PETSC
+#if defined(USE_PETSC)
+std::unique_ptr<GlobalLinearSolver> createLinearSolver()
+{
+    std::string const petsc_options =
+        "-ksp_type bcgs -pc_type sor -ksp_rtol 1e-24 -ksp_max_it 100 "
+        "-ksp_initial_guess_nonzero false";
+    return std::make_unique<GlobalLinearSolver>("", petsc_options);
+}
+#elif defined(USE_LIS)
 std::unique_ptr<GlobalLinearSolver> createLinearSolver()
 {
-    return std::make_unique<GlobalLinearSolver>("", nullptr);
+    auto const solver_options =
+        MathLib::LinearSolverOptionsParser<GlobalLinearSolver>{}
+            .parseNameAndOptions("", nullptr);
+    return std::make_unique<GlobalLinearSolver>(std::get<0>(solver_options),
+                                                std::get<1>(solver_options));
 }
 #else
 std::unique_ptr<GlobalLinearSolver> createLinearSolver()
 {
-    const char xml[] =
-        "<petsc><parameters>"
-        "-ksp_type bcgs -pc_type sor -ksp_rtol 1e-24 -ksp_max_it 100 "
-        "-ksp_initial_guess_nonzero false"
-        "</parameters></petsc>";
-    auto const ptree = Tests::readXml(xml);
-    BaseLib::ConfigTree config(ptree, "", BaseLib::ConfigTree::onerror,
-                               BaseLib::ConfigTree::onwarning);
-    return std::make_unique<GlobalLinearSolver>("", &config);
+    auto const solver_options =
+        MathLib::LinearSolverOptionsParser<GlobalLinearSolver>{}
+            .parseNameAndOptions("", nullptr);
+    return std::make_unique<GlobalLinearSolver>(std::get<0>(solver_options),
+                                                std::get<1>(solver_options));
 }
 #endif
 
diff --git a/Tests/NumLib/TestSerialLinearSolver.cpp b/Tests/NumLib/TestSerialLinearSolver.cpp
index 4855833954d..13739dd3645 100644
--- a/Tests/NumLib/TestSerialLinearSolver.cpp
+++ b/Tests/NumLib/TestSerialLinearSolver.cpp
@@ -127,7 +127,12 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem)
     BaseLib::ConfigTree conf(t_root, "", BaseLib::ConfigTree::onerror,
                              BaseLib::ConfigTree::onwarning);
 
-    GlobalLinearSolver ls("solver_name", &conf);
+    auto const linear_solver_parser =
+        MathLib::LinearSolverOptionsParser<GlobalLinearSolver>{};
+    auto const solver_options =
+        linear_solver_parser.parseNameAndOptions("", &conf);
+    GlobalLinearSolver ls{std::get<0>(solver_options),
+                          std::get<1>(solver_options)};
     ls.solve(*A, *rhs, *x);
 
     // copy solution to double vector
-- 
GitLab