Skip to content
Snippets Groups Projects
Commit a8dc6e61 authored by Tom Fischer's avatar Tom Fischer
Browse files

[T/MaL] Adjustment to new LinearSolverOptionsParser.

parent bee0ed51
No related branches found
No related tags found
No related merge requests found
...@@ -20,19 +20,18 @@ ...@@ -20,19 +20,18 @@
#include "MathLib/LinAlg/Eigen/EigenLinearSolver.h" #include "MathLib/LinAlg/Eigen/EigenLinearSolver.h"
#include "MathLib/LinAlg/Eigen/EigenMatrix.h" #include "MathLib/LinAlg/Eigen/EigenMatrix.h"
#include "MathLib/LinAlg/Eigen/EigenVector.h" #include "MathLib/LinAlg/Eigen/EigenVector.h"
#include "MathLib/LinAlg/Eigen/LinearSolverOptionsParser.h"
#include "MathLib/LinAlg/FinalizeMatrixAssembly.h" #include "MathLib/LinAlg/FinalizeMatrixAssembly.h"
#include "MathLib/LinAlg/LinAlg.h" #include "MathLib/LinAlg/LinAlg.h"
#if defined(USE_LIS)
#include "MathLib/LinAlg/EigenLis/EigenLisLinearSolver.h"
#endif
#ifdef USE_LIS #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" #include "MathLib/LinAlg/Lis/LisVector.h"
#endif #endif
#ifdef USE_PETSC #ifdef USE_PETSC
#include "MathLib/LinAlg/PETSc/LinearSolverOptionsParser.h"
#include "MathLib/LinAlg/PETSc/PETScLinearSolver.h" #include "MathLib/LinAlg/PETSc/PETScLinearSolver.h"
#include "MathLib/LinAlg/PETSc/PETScMatrix.h" #include "MathLib/LinAlg/PETSc/PETScMatrix.h"
#include "MathLib/LinAlg/PETSc/PETScVector.h" #include "MathLib/LinAlg/PETSc/PETScVector.h"
...@@ -208,8 +207,12 @@ void checkLinearSolverInterface(T_MATRIX& A, ...@@ -208,8 +207,12 @@ void checkLinearSolverInterface(T_MATRIX& A,
MathLib::finalizeMatrixAssembly(A); MathLib::finalizeMatrixAssembly(A);
// solve auto const linear_solver_parser =
T_LINEAR_SOLVER ls("dummy_name", &ls_option); 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); ls.solve(A, rhs, x);
ASSERT_ARRAY_NEAR(ex1.exH, x, ex1.dim_eqs, 1e-5); ASSERT_ARRAY_NEAR(ex1.exH, x, ex1.dim_eqs, 1e-5);
...@@ -273,7 +276,12 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, ...@@ -273,7 +276,12 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b,
// solve // solve
T_VECTOR y(b, deep_copy); T_VECTOR y(b, deep_copy);
y.setZero(); 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_TRUE(ls.solve(A, b, y));
EXPECT_GT(ls.getNumberOfIterations(), 0u); EXPECT_GT(ls.getNumberOfIterations(), 0u);
...@@ -286,6 +294,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b, ...@@ -286,6 +294,7 @@ void checkLinearSolverInterface(T_MATRIX& A, T_VECTOR& b,
} // end namespace } // end namespace
#if not defined(USE_LIS) and not defined(USE_PETSC)
TEST(Math, CheckInterface_Eigen) TEST(Math, CheckInterface_Eigen)
{ {
// set solver options using Boost property tree // set solver options using Boost property tree
...@@ -305,6 +314,7 @@ TEST(Math, CheckInterface_Eigen) ...@@ -305,6 +314,7 @@ TEST(Math, CheckInterface_Eigen)
checkLinearSolverInterface<MathLib::EigenMatrix, MathLib::EigenVector, checkLinearSolverInterface<MathLib::EigenMatrix, MathLib::EigenVector,
MathLib::EigenLinearSolver, IntType>(A, conf); MathLib::EigenLinearSolver, IntType>(A, conf);
} }
#endif
#if defined(USE_LIS) #if defined(USE_LIS)
TEST(Math, CheckInterface_EigenLis) TEST(Math, CheckInterface_EigenLis)
......
...@@ -25,23 +25,31 @@ ...@@ -25,23 +25,31 @@
namespace TestODEInt 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() 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 #else
std::unique_ptr<GlobalLinearSolver> createLinearSolver() std::unique_ptr<GlobalLinearSolver> createLinearSolver()
{ {
const char xml[] = auto const solver_options =
"<petsc><parameters>" MathLib::LinearSolverOptionsParser<GlobalLinearSolver>{}
"-ksp_type bcgs -pc_type sor -ksp_rtol 1e-24 -ksp_max_it 100 " .parseNameAndOptions("", nullptr);
"-ksp_initial_guess_nonzero false" return std::make_unique<GlobalLinearSolver>(std::get<0>(solver_options),
"</parameters></petsc>"; std::get<1>(solver_options));
auto const ptree = Tests::readXml(xml);
BaseLib::ConfigTree config(ptree, "", BaseLib::ConfigTree::onerror,
BaseLib::ConfigTree::onwarning);
return std::make_unique<GlobalLinearSolver>("", &config);
} }
#endif #endif
......
...@@ -127,7 +127,12 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem) ...@@ -127,7 +127,12 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem)
BaseLib::ConfigTree conf(t_root, "", BaseLib::ConfigTree::onerror, BaseLib::ConfigTree conf(t_root, "", BaseLib::ConfigTree::onerror,
BaseLib::ConfigTree::onwarning); 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); ls.solve(*A, *rhs, *x);
// copy solution to double vector // copy solution to double vector
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment