14 #if !defined (KRATOS_AZTEC_SOLVER_H_INCLUDED)
15 #define KRATOS_AZTEC_SOLVER_H_INCLUDED
28 #include "Epetra_LinearProblem.h"
29 #include "Teuchos_ParameterList.hpp"
31 #include "Ifpack_ConfigDefs.h"
53 template<
class TSparseSpaceType,
class TDenseSpaceType,
54 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
56 TDenseSpaceType, TReordererType>
79 "solver_type" : "aztec",
81 "max_iteration" : 200,
82 "preconditioner_type" : "none",
84 "gmres_krylov_space_dimension" : 100,
87 "trilinos_aztec_parameter_list" : {},
88 "trilinos_preconditioner_parameter_list" : {}
94 mTolerance = settings[
"tolerance"].
GetDouble();
95 mMaxIterations = settings[
"max_iteration"].
GetDouble();
98 mOverlapLevel = settings[
"overlap_level"].
GetInt();
101 if (!settings[
"scaling"].GetBool()) {
106 mAztecParameterList = Teuchos::ParameterList();
108 if (settings[
"verbosity"].GetInt() == 0) {
109 mAztecParameterList.set(
"AZ_output",
"AZ_none");
111 mAztecParameterList.set(
"AZ_output", settings[
"verbosity"].GetInt());
115 const std::string solver_type = settings[
"solver_type"].
GetString();
116 if (solver_type ==
"CGSolver" || solver_type ==
"cg") {
117 mAztecParameterList.set(
"AZ_solver",
"AZ_cg");
118 }
else if (solver_type ==
"BICGSTABSolver" || solver_type ==
"bicgstab") {
119 mAztecParameterList.set(
"AZ_solver",
"AZ_bicgstab");
120 }
else if (solver_type ==
"GMRESSolver" || solver_type ==
"gmres") {
121 mAztecParameterList.set(
"AZ_solver",
"AZ_gmres");
122 mAztecParameterList.set(
"AZ_kspace", settings[
"gmres_krylov_space_dimension"].GetInt());
123 }
else if (solver_type ==
"AztecSolver" || solver_type ==
"aztec") {
127 KRATOS_ERROR <<
"The \"solver_type\" specified: \"" << solver_type <<
"\" is not supported\n"
128 <<
" Available options are: \"cg\", \"bicgstab\", \"gmres\", \"aztec\"" << std::endl;
134 mPreconditionerParameterList = Teuchos::ParameterList();
135 const std::string preconditioner_type = settings[
"preconditioner_type"].
GetString();
136 if (preconditioner_type ==
"diagonal" || preconditioner_type ==
"DiagonalPreconditioner") {
137 mIFPreconditionerType =
"AZ_none";
138 }
else if (preconditioner_type ==
"ilu0" || preconditioner_type ==
"ILU0") {
139 mIFPreconditionerType =
"ILU";
140 mPreconditionerParameterList.set(
"fact: drop tolerance", 1
e-9);
141 mPreconditionerParameterList.set(
"fact: level-of-fill", 1);
142 }
else if (preconditioner_type ==
"ilut" || preconditioner_type ==
"ILUT") {
143 mIFPreconditionerType =
"ILU";
144 mPreconditionerParameterList.set(
"fact: drop tolerance", 1
e-9);
145 mPreconditionerParameterList.set(
"fact: level-of-fill", 10);
146 }
else if (preconditioner_type ==
"icc" || preconditioner_type ==
"ICC") {
147 mIFPreconditionerType =
"ICC";
148 mPreconditionerParameterList.set(
"fact: drop tolerance", 1
e-9);
149 mPreconditionerParameterList.set(
"fact: level-of-fill", 10);
150 }
else if (preconditioner_type ==
"amesos" || preconditioner_type ==
"AmesosPreconditioner") {
151 mIFPreconditionerType =
"Amesos";
152 mPreconditionerParameterList.set(
"amesos: solver type",
"Amesos_Klu");
153 }
else if (preconditioner_type ==
"none" || preconditioner_type ==
"None") {
154 mIFPreconditionerType =
"AZ_none";
156 KRATOS_ERROR <<
"The \"preconditioner_type\" specified: \"" << preconditioner_type <<
"\" is not supported\n"
157 <<
" Available options are: \"diagonal\", \"ilu0\", \"ilut\", \"icc\", \"amesos\", \"none\"" << std::endl;
164 AztecSolver(Teuchos::ParameterList& aztec_parameter_list, std::string IFPreconditionerType, Teuchos::ParameterList& preconditioner_parameter_list,
double tol,
int nit_max,
int overlap_level)
167 mAztecParameterList = aztec_parameter_list;
169 mMaxIterations = nit_max;
172 mIFPreconditionerType = IFPreconditionerType;
173 mPreconditionerParameterList = preconditioner_parameter_list;
174 mOverlapLevel = overlap_level;
197 mScalingType = scaling_type;
213 Epetra_LinearProblem aztec_problem(&rA,&rX,&rB);
217 KRATOS_ERROR <<
"something wrong with the scaling, to be further teststed" << std::endl;
218 Epetra_Vector scaling_vect(rA.RowMap());
219 rA.InvColSums(scaling_vect);
221 for (
int i=0;
i<scaling_vect.MyLength(); ++
i) scaling_vect[
i] = std::sqrt(scaling_vect[
i]);
223 aztec_problem.LeftScale(scaling_vect);
224 aztec_problem.RightScale(scaling_vect);
226 Epetra_Vector scaling_vect(rA.RowMap());
227 rA.InvColSums(scaling_vect);
229 aztec_problem.LeftScale(scaling_vect);
232 AztecOO aztec_solver(aztec_problem);
233 aztec_solver.SetParameters(mAztecParameterList);
236 if (mIFPreconditionerType != std::string(
"AZ_none")) {
238 Ifpack preconditioner_factory;
240 std::string preconditioner_type = mIFPreconditionerType;
241 Ifpack_Preconditioner* p_preconditioner = preconditioner_factory.Create(preconditioner_type, &rA, mOverlapLevel);
242 KRATOS_ERROR_IF(p_preconditioner == 0) <<
"Preconditioner-initialization went wrong" << std::endl;
244 IFPACK_CHK_ERR(p_preconditioner->SetParameters(mPreconditionerParameterList));
245 IFPACK_CHK_ERR(p_preconditioner->Initialize());
246 IFPACK_CHK_ERR(p_preconditioner->Compute());
249 aztec_solver.SetPrecOperator(p_preconditioner);
252 aztec_solver.Iterate(mMaxIterations,mTolerance);
254 delete p_preconditioner;
256 aztec_solver.Iterate(mMaxIterations,mTolerance);
281 rOStream <<
"Trilinos Aztec-Solver";
289 Teuchos::ParameterList mAztecParameterList;
294 std::string mIFPreconditionerType;
296 Teuchos::ParameterList mPreconditionerParameterList;
304 template<
class TSparseSpaceType,
class TDenseSpaceType,
class TReordererType>
307 TDenseSpaceType, TReordererType>& rThis)
309 rThis.PrintInfo(rOStream);
310 rOStream << std::endl;
311 rThis.PrintData(rOStream);
Wrapper for Trilinos-Aztec Iterative Solvers.
Definition: aztec_solver.h:57
AztecSolver(Parameters settings)
Constructor with Parameters.
Definition: aztec_solver.h:76
TDenseSpaceType::MatrixType DenseMatrixType
Definition: aztec_solver.h:69
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: aztec_solver.h:279
AztecSolver(Teuchos::ParameterList &aztec_parameter_list, std::string IFPreconditionerType, Teuchos::ParameterList &preconditioner_parameter_list, double tol, int nit_max, int overlap_level)
Definition: aztec_solver.h:164
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: aztec_solver.h:208
AztecSolver & operator=(const AztecSolver &Other)=delete
Assignment operator.
~AztecSolver() override=default
Destructor.
void SetScalingType(AztecScalingType scaling_type)
Definition: aztec_solver.h:195
KRATOS_CLASS_POINTER_DEFINITION(AztecSolver)
Pointer definition of AztecSolver.
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Definition: aztec_solver.h:273
TSparseSpaceType::VectorType VectorType
Definition: aztec_solver.h:67
AztecSolver(const AztecSolver &Other)=delete
Copy constructor.
TSparseSpaceType::MatrixType SparseMatrixType
Definition: aztec_solver.h:65
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
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
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
#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(conditional)
Definition: exception.h:162
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
AztecScalingType
Definition: aztec_solver.h:38
@ LeftScaling
Definition: aztec_solver.h:38
@ NoScaling
Definition: aztec_solver.h:38
@ SymmetricScaling
Definition: aztec_solver.h:38
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int tol
Definition: hinsberg_optimization.py:138
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31