14 #if !defined (KRATOS_MULTILEVEL_SOLVER_H_INCLUDED)
15 #define KRATOS_MULTILEVEL_SOLVER_H_INCLUDED
27 #include "Epetra_LinearProblem.h"
28 #include "ml_include.h"
29 #include "ml_MultiLevelPreconditioner.h"
30 #include "Teuchos_ParameterList.hpp"
44 template<
class TSparseSpaceType,
class TDenseSpaceType,
45 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
47 TDenseSpaceType, TReordererType>
78 "solver_type" : "multi_level",
80 "max_iteration" : 200,
83 "reform_preconditioner_at_each_step" : true,
86 "trilinos_aztec_parameter_list" : {},
87 "trilinos_ml_parameter_list" : {}
93 mTolerance = Settings[
"tolerance"].
GetDouble();
94 mMaxIterations = Settings[
"max_iteration"].
GetInt();
95 mReformPrecAtEachStep = Settings[
"reform_preconditioner_at_each_step"].
GetBool();
98 if (!Settings[
"scaling"].GetBool()) {
103 mAztecParameterList = Teuchos::ParameterList();
104 const int verbosity = Settings[
"verbosity"].
GetInt();
105 if (verbosity == 0) {
106 mAztecParameterList.set(
"AZ_output",
"AZ_none");
108 mAztecParameterList.set(
"AZ_output", verbosity);
111 mMLParameterList = Teuchos::ParameterList();
113 mMLParameterList.set(
"ML output", verbosity);
114 mMLParameterList.set(
"max levels", Settings[
"max_levels"].GetInt());
115 if (!Settings[
"symmetric"].GetBool()) {
116 ML_Epetra::SetDefaults(
"NSSA",mMLParameterList);
117 mMLParameterList.set(
"aggregation: type",
"Uncoupled");
118 mAztecParameterList.set(
"AZ_solver",
"AZ_gmres");
120 ML_Epetra::SetDefaults(
"SA",mMLParameterList);
121 mMLParameterList.set(
"increasing or decreasing",
"increasing");
122 mMLParameterList.set(
"aggregation: type",
"MIS");
123 mMLParameterList.set(
"smoother: type",
"Chebyshev");
124 mMLParameterList.set(
"smoother: sweeps", 3);
125 mMLParameterList.set(
"smoother: pre or post",
"both");
126 mAztecParameterList.set(
"AZ_solver",
"AZ_bicgstab");
136 MultiLevelSolver(Teuchos::ParameterList& rAztecParameterList, Teuchos::ParameterList& rMLParameterList,
double Tolerance,
int MaxIterations)
138 mAztecParameterList = rAztecParameterList;
139 mMLParameterList = rMLParameterList;
140 mTolerance = Tolerance;
141 mMaxIterations = MaxIterations;
166 mScalingType = Value;
176 mReformPrecAtEachStep = Value;
200 Epetra_LinearProblem aztec_problem(&rA,&rX,&rB);
205 Epetra_Vector scaling_vect(rA.RowMap());
206 rA.InvColSums(scaling_vect);
207 aztec_problem.LeftScale(scaling_vect);
210 mMLParameterList.set(
"PDE equations", mNumDof);
219 if (mReformPrecAtEachStep || !mpMLPrec) {
221 MLPreconditionerPointerType
tmp(Kratos::make_unique<ML_Epetra::MultiLevelPreconditioner>(rA, mMLParameterList,
true));
226 AztecOO aztec_solver(aztec_problem);
227 aztec_solver.SetParameters(mAztecParameterList);
230 aztec_solver.SetPrecOperator(&(*mpMLPrec));
232 aztec_solver.Iterate(mMaxIterations, mTolerance);
277 unsigned int old_node_id = rdof_set.
begin()->Id();
279 for (
auto it = rdof_set.
begin(); it!=rdof_set.
end(); it++) {
280 unsigned int id = it->Id();
281 if (
id != old_node_id) {
283 if (old_ndof == -1) {
285 }
else if (old_ndof != ndof) {
297 if (old_ndof == -1) {
307 rOStream <<
"Trilinos MultiLevel-Solver";
310 static void SetDefaults(Teuchos::ParameterList& rParameterlist,
const std::string& rSettingsName)
312 ML_Epetra::SetDefaults(rSettingsName.c_str(), rParameterlist);
319 Teuchos::ParameterList mAztecParameterList;
320 Teuchos::ParameterList mMLParameterList;
323 bool mReformPrecAtEachStep =
true;
333 template<
class TSparseSpaceType,
class TDenseSpaceType,
class TReordererType>
336 TDenseSpaceType, TReordererType>& rThis)
338 rThis.PrintInfo(rOStream);
339 rOStream << std::endl;
340 rThis.PrintData(rOStream);
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
TSparseSpaceType::MatrixType SparseMatrixType
Definition: linear_solver.h:73
TDenseSpaceType::MatrixType DenseMatrixType
Definition: linear_solver.h:81
TSparseSpaceType::MatrixPointerType SparseMatrixPointerType
Definition: linear_solver.h:75
TSparseSpaceType::VectorType VectorType
Definition: linear_solver.h:77
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
Wrapper for Trilinos-ML preconditioner using the Aztec-Solver.
Definition: ml_solver.h:48
BaseType::VectorType VectorType
Definition: ml_solver.h:62
void SetReformPrecAtEachStep(bool Value)
Definition: ml_solver.h:174
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: ml_solver.h:197
MultiLevelSolver(const MultiLevelSolver &Other)=delete
Copy constructor.
MultiLevelSolver(Teuchos::ParameterList &rAztecParameterList, Teuchos::ParameterList &rMLParameterList, double Tolerance, int MaxIterations)
Definition: ml_solver.h:136
BaseType::SparseMatrixType SparseMatrixType
Definition: ml_solver.h:60
void ResetPreconditioner()
Definition: ml_solver.h:179
MultiLevelSolver & operator=(const MultiLevelSolver &Other)=delete
Assignment operator.
ScalingType
Definition: ml_solver.h:56
@ LeftScaling
Definition: ml_solver.h:56
@ NoScaling
Definition: ml_solver.h:56
static void SetDefaults(Teuchos::ParameterList &rParameterlist, const std::string &rSettingsName)
Definition: ml_solver.h:310
void ProvideAdditionalData(SparseMatrixType &rA, VectorType &rX, VectorType &rB, typename ModelPart::DofsArrayType &rdof_set, ModelPart &r_model_part) override
Definition: ml_solver.h:268
BaseType::DenseMatrixType DenseMatrixType
Definition: ml_solver.h:64
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: ml_solver.h:305
LinearSolver< TSparseSpaceType, TDenseSpaceType, TReordererType > BaseType
Definition: ml_solver.h:58
bool AdditionalPhysicalDataIsNeeded() override
Definition: ml_solver.h:257
void Clear() override
Definition: ml_solver.h:184
KRATOS_CLASS_POINTER_DEFINITION(MultiLevelSolver)
Pointer definition of MultiLevelSolver.
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Definition: ml_solver.h:246
MultiLevelSolver(Parameters Settings)
Constructor with Parameters.
Definition: ml_solver.h:75
BaseType::SparseMatrixPointerType SparseMatrixPointerType
Definition: ml_solver.h:66
ScalingType GetScalingType()
Definition: ml_solver.h:169
~MultiLevelSolver() override
Destructor.
Definition: ml_solver.h:148
void SetScalingType(ScalingType Value)
Definition: ml_solver.h:164
Kratos::unique_ptr< ML_Epetra::MultiLevelPreconditioner > MLPreconditionerPointerType
Definition: ml_solver.h:68
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
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
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::unique_ptr< T > unique_ptr
Definition: smart_pointers.h:33
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98