8 #include <boost/numeric/mtl/operation/two_norm.hpp> 9 #include <boost/numeric/mtl/interface/umfpack_solve.hpp> 11 #include <amdis/linearalgebra/mtl/Traits.hpp> 12 #include <amdis/linearalgebra/RunnerInterface.hpp> 13 #include <amdis/linearalgebra/SolverInfo.hpp> 14 #include <amdis/Output.hpp> 27 template <
class Mat,
class Vec>
31 using M =
typename Mat::BaseMatrix;
32 using X =
typename Vec::BaseVector;
33 using Y =
typename Vec::BaseVector;
35 using SolverType = mtl::mat::umfpack::solver<typename Mat::BaseMatrix>;
46 void init(M
const& A)
override 49 if (
bool(solver_) && storeSymbolic_)
50 solver_->update_numeric();
52 solver_ = std::make_shared<SolverType>(A, symmetricStrategy_, allocInit_);
53 }
catch (mtl::mat::umfpack::error
const& e) {
54 umfpack_error_exit(
"factorize", e.code);
63 test_exit(
bool(solver_),
"UmfpackRunner must be initialized.");
66 code = (*solver_)(x, b);
67 }
catch (mtl::mat::umfpack::error& e) {
68 umfpack_error_exit(
"solve", e.code);
75 static void umfpack_error_exit(std::string solutionPhase,
int code)
77 static std::map<int, std::string> error_message = {
78 {UMFPACK_OK,
"UMFPACK was successful"},
79 {UMFPACK_WARNING_singular_matrix,
"Matrix is singular. There are exact zeros on the diagonal."},
80 {UMFPACK_WARNING_determinant_underflow,
"The determinant is nonzero, but smaller in magnitude than the smallest positive floating-point number."},
81 {UMFPACK_WARNING_determinant_overflow,
"The determinant is larger in magnitude than the largest positive floating-point number (IEEE Inf)."},
82 {UMFPACK_ERROR_out_of_memory,
"Not enough memory. The ANSI C malloc or realloc routine failed."},
83 {UMFPACK_ERROR_invalid_Numeric_object,
"Invalid Numeric object."},
84 {UMFPACK_ERROR_invalid_Symbolic_object,
"Invalid Symbolic object."},
85 {UMFPACK_ERROR_argument_missing,
"Some required arguments are missing."},
86 {UMFPACK_ERROR_n_nonpositive,
"The number of rows or columns of the matrix must be greater than zero."},
87 {UMFPACK_ERROR_invalid_matrix,
"The matrix is invalid."},
88 {UMFPACK_ERROR_different_pattern,
"The pattern of the matrix has changed between the symbolic and numeric factorization."},
89 {UMFPACK_ERROR_invalid_system,
"The sys argument provided to one of the solve routines is invalid."},
90 {UMFPACK_ERROR_invalid_permutation,
"The permutation vector provided as input is invalid."},
91 {UMFPACK_ERROR_file_IO,
"Error in file IO"},
92 {UMFPACK_ERROR_ordering_failed,
"The ordering method failed."},
93 {UMFPACK_ERROR_internal_error,
"An internal error has occurred, of unknown cause."}
96 error_exit(
"UMFPACK_ERROR({}, {}) = {}", solutionPhase, code, error_message[code]);
100 std::shared_ptr<SolverType> solver_;
102 bool storeSymbolic_ =
false;
103 int symmetricStrategy_ = 0;
104 double allocInit_ = 0.7;
109 #endif // HAVE_UMFPACK void setAbsResidual(double r)
Sets absResidual_.
Definition: SolverInfo.hpp:80
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Definition: UmfpackRunner.hpp:28
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void exit() override
Is called at the end of a solution procedure.
Definition: UmfpackRunner.hpp:58
int solve(M const &A, X &x, Y const &b, SolverInfo &solverInfo) override
Implements RunnerInterface::solveImpl()
Definition: UmfpackRunner.hpp:61
Definition: SolverInfo.hpp:11
UmfpackRunner(std::string const &prefix)
Constructor. Reads UMFPACK parameters from initfile.
Definition: UmfpackRunner.hpp:39
void init(M const &A) override
Is called at the beginning of a solution procedure.
Definition: UmfpackRunner.hpp:46
void test_exit(bool condition, std::string const &str, Args &&... args)
test for condition and in case of failure print message and exit
Definition: Output.hpp:163
Interface for Runner / Worker types used in solver classes.
Definition: RunnerInterface.hpp:11