13 #if !defined (KRATOS_AMESOS2_SOLVER_H_INCLUDED)
14 #define KRATOS_AMESOS2_SOLVER_H_INCLUDED
17 #include <unordered_map>
20 #include <Teuchos_RCP.hpp>
21 #include "Amesos2.hpp"
41 template<
class TSparseSpaceType,
class TDenseSpaceType,
42 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
44 TDenseSpaceType, TReordererType>
67 "solver_type" : "amesos2",
68 "amesos2_solver_type" : "amesos2_klu2",
69 "trilinos_amesos2_parameter_list" : { }
73 std::unordered_map<std::string, std::string> kratos_to_amesos2_names = {
74 {
"klu2",
"amesos2_klu2"},
76 {
"super_lu_dist2",
"amesos2_superludist"},
77 {
"mumps2",
"amesos2_mumps"}
80 const std::string solver_type = settings[
"solver_type"].
GetString();
82 auto iter_amesos2_name = kratos_to_amesos2_names.find(solver_type);
84 if (iter_amesos2_name != kratos_to_amesos2_names.end()) {
85 if (settings.
Has(
"amesos2_solver_type")) {
86 KRATOS_INFO(
"Amesos2-Solver") <<
"Ignoring setting \"amesos2_solver_type\"" << std::endl;
90 settings[
"amesos2_solver_type"].
SetString(iter_amesos2_name->second);
92 }
else if (solver_type ==
"amesos2") {
99 KRATOS_ERROR <<
"The solver type specified: \"" << solver_type <<
"\" is not supported";
108 mSolverName = settings[
"amesos2_solver_type"].
GetString();
111 <<
"\" unfortunately the current compilation of Trilinos does not include it" << std::endl;
115 Amesos2Solver(
const std::string& SolverName, Teuchos::ParameterList& rParameterList)
117 mParameterList = rParameterList;
118 mSolverName = SolverName;
121 <<
"\" unfortunately the current compilation of Trilinos does not include it" << std::endl;
164 using MAT = Epetra_CrsMatrix;
165 using MV = Epetra_MultiVector;
167 RCP<Amesos2::Solver<MAT,MV> >
solver;
169 RCP<SparseMatrixType> rcp_A = rcp(&rA,
false);
170 RCP<VectorType> rcp_X = rcp(&rX,
false);
171 RCP<VectorType> rcp_B = rcp(&rB,
false);
172 RCP<Teuchos::ParameterList> rcp_params = rcp(&mParameterList,
false);
174 solver = Amesos2::create<MAT,MV>(mSolverName, rcp_A, rcp_X, rcp_B);
176 solver->setParameters(rcp_params);
178 solver->symbolicFactorization().numericFactorization().solve();
208 static bool HasSolver(
const std::string& rAmesosSolverName)
210 return Amesos2::query(rAmesosSolverName);
220 rOStream <<
"Trilinos Amesos2-Solver";
229 Teuchos::ParameterList mParameterList;
230 std::string mSolverName;
237 template<
class TSparseSpaceType,
class TDenseSpaceType,
class TReordererType>
240 TDenseSpaceType, TReordererType>& rThis)
242 rThis.PrintInfo(rOStream);
243 rOStream << std::endl;
244 rThis.PrintData(rOStream);
Wrapper for Trilinos-Amesos2 Direct Solvers.
Definition: amesos2_solver.h:45
static bool HasSolver(const std::string &rAmesosSolverName)
Definition: amesos2_solver.h:208
Amesos2Solver(const std::string &SolverName, Teuchos::ParameterList &rParameterList)
Constructor with solver-name and Teuchos::ParameterList.
Definition: amesos2_solver.h:115
TSparseSpaceType::MatrixType SparseMatrixType
Definition: amesos2_solver.h:53
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: amesos2_solver.h:149
TDenseSpaceType::MatrixType DenseMatrixType
Definition: amesos2_solver.h:57
KRATOS_CLASS_POINTER_DEFINITION(Amesos2Solver)
Pointer definition of Amesos2Solver.
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Definition: amesos2_solver.h:193
~Amesos2Solver() override=default
Destructor.
Amesos2Solver & operator=(const Amesos2Solver &Other)=delete
Assignment operator.
TSparseSpaceType::VectorType VectorType
Definition: amesos2_solver.h:55
Amesos2Solver(const Amesos2Solver &Other)=delete
Copy constructor.
Amesos2Solver(Parameters settings)
Constructor with Parameters.
Definition: amesos2_solver.h:64
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: amesos2_solver.h:218
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void SetString(const std::string &rValue)
This method sets the string contained in the current Parameter.
Definition: kratos_parameters.cpp:811
Parameters AddEmptyValue(const std::string &rEntry)
This method adds an empty parameter.
Definition: kratos_parameters.cpp:471
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_INFO(label)
Definition: logger.h:250
void SetTeuchosParameters(const Parameters rSettings, Teuchos::ParameterList &rParameterlist)
Definition: trilinos_solver_utilities.cpp:22
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
solver
Definition: script.py:98