19#ifdef DEAL_II_WITH_TRILINOS
25# include <Epetra_MultiVector.h>
27# include <Ifpack_Chebyshev.h>
28# include <Teuchos_ParameterList.hpp>
29# include <Teuchos_RCP.hpp>
30# include <ml_MultiLevelPreconditioner.h>
31# include <ml_include.h>
41 const bool higher_order_elements,
42 const unsigned int n_cycles,
44 const double aggregation_threshold,
45 const std::vector<std::vector<bool>> &constant_modes,
46 const unsigned int smoother_sweeps,
47 const unsigned int smoother_overlap,
48 const bool output_details,
49 const char * smoother_type,
50 const char * coarse_type)
52 , higher_order_elements(higher_order_elements)
55 , aggregation_threshold(aggregation_threshold)
56 , constant_modes(constant_modes)
57 , smoother_sweeps(smoother_sweeps)
58 , smoother_overlap(smoother_overlap)
59 , output_details(output_details)
60 , smoother_type(smoother_type)
61 , coarse_type(coarse_type)
68 Teuchos::ParameterList & parameter_list,
69 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
70 const Epetra_RowMatrix & matrix)
const
74 ML_Epetra::SetDefaults(
"SA", parameter_list);
84 if (higher_order_elements)
85 parameter_list.set(
"aggregation: type",
"Uncoupled");
89 ML_Epetra::SetDefaults(
"NSSA", parameter_list);
90 parameter_list.set(
"aggregation: type",
"Uncoupled");
91 parameter_list.set(
"aggregation: block scaling",
true);
94 parameter_list.set(
"smoother: type", smoother_type);
95 parameter_list.set(
"coarse: type", coarse_type);
99# if DEAL_II_TRILINOS_VERSION_GTE(12, 4, 0)
100 parameter_list.set(
"initialize random seed",
true);
103 parameter_list.set(
"smoother: sweeps",
static_cast<int>(smoother_sweeps));
104 parameter_list.set(
"cycle applications",
static_cast<int>(n_cycles));
106 parameter_list.set(
"prec type",
"MGW");
108 parameter_list.set(
"prec type",
"MGV");
110 parameter_list.set(
"smoother: Chebyshev alpha", 10.);
111 parameter_list.set(
"smoother: ifpack overlap",
112 static_cast<int>(smoother_overlap));
113 parameter_list.set(
"aggregation: threshold", aggregation_threshold);
114 parameter_list.set(
"coarse: max size", 2000);
117 parameter_list.set(
"ML output", 10);
119 parameter_list.set(
"ML output", 0);
121 set_operator_null_space(parameter_list, distributed_constant_modes, matrix);
128 Teuchos::ParameterList & parameter_list,
129 std::unique_ptr<Epetra_MultiVector> &ptr_distributed_constant_modes,
130 const Epetra_RowMatrix & matrix)
const
132 const Epetra_Map &domain_map = matrix.OperatorDomainMap();
134 const size_type constant_modes_dimension = constant_modes.size();
135 ptr_distributed_constant_modes = std::make_unique<Epetra_MultiVector>(
136 domain_map, constant_modes_dimension > 0 ? constant_modes_dimension : 1);
138 Epetra_MultiVector &distributed_constant_modes =
139 *ptr_distributed_constant_modes;
141 if (constant_modes_dimension > 0)
151 distributed_constant_modes)));
152 const bool constant_modes_are_global =
153 constant_modes[0].size() == global_size;
154 const size_type my_size = domain_map.NumMyElements();
159 constant_modes_are_global ? global_size : my_size;
160 for (
size_type d = 0; d < constant_modes_dimension; ++d)
162 Assert(constant_modes[d].size() == expected_mode_size,
164 expected_mode_size));
165 for (
size_type row = 0; row < my_size; ++row)
168 constant_modes_are_global ?
171 distributed_constant_modes[d][row] =
172 static_cast<double>(constant_modes[d][mode_index]);
175 (void)expected_mode_size;
177 parameter_list.set(
"null space: type",
"pre-computed");
178 parameter_list.set(
"null space: dimension",
179 distributed_constant_modes.NumVectors());
180 parameter_list.set(
"null space: vectors",
181 distributed_constant_modes.Values());
189 Teuchos::ParameterList & parameter_list,
190 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
193 return set_parameters(parameter_list,
194 distributed_constant_modes,
195 matrix.trilinos_matrix());
202 Teuchos::ParameterList & parameter_list,
203 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
206 return set_operator_null_space(parameter_list,
207 distributed_constant_modes,
208 matrix.trilinos_matrix());
225 initialize(matrix.trilinos_matrix(), additional_data);
235 Teuchos::ParameterList ml_parameters;
236 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
238 distributed_constant_modes,
245 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
246 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
248 Assert(multilevel_operator !=
nullptr,
250 multilevel_operator->PrintUnused(0);
258 const Teuchos::ParameterList &ml_parameters)
260 initialize(matrix.trilinos_matrix(), ml_parameters);
267 const Teuchos::ParameterList &ml_parameters)
270 new ML_Epetra::MultiLevelPreconditioner(matrix, ml_parameters));
275 template <
typename number>
278 const ::SparseMatrix<number> &deal_ii_sparse_matrix,
280 const double drop_tolerance,
281 const ::SparsityPattern * use_this_sparsity)
284 const size_type n_rows = deal_ii_sparse_matrix.m();
289 const unsigned int n_mpi_processes =
communicator.NumProc();
291 distributor.
add_range(my_id * n_rows / n_mpi_processes,
292 (my_id + 1) * n_rows / n_mpi_processes);
299 deal_ii_sparse_matrix,
313 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
314 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
preconditioner.get());
315 multilevel_operator->ReComputePreconditioner();
332 unsigned int memory =
sizeof(*this);
347 const AdditionalData &,
349 const ::SparsityPattern *);
352 const AdditionalData &,
354 const ::SparsityPattern *);
void add_range(const size_type begin, const size_type end)
~PreconditionAMG() override
std::shared_ptr< SparseMatrix > trilinos_matrix
size_type memory_consumption() const
void initialize(const SparseMatrix &matrix, const AdditionalData &additional_data=AdditionalData())
Epetra_MpiComm communicator
Teuchos::RCP< Epetra_Operator > preconditioner
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
TrilinosWrappers::types::int_type n_global_rows(const Epetra_CrsGraph &graph)
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
AdditionalData(const bool elliptic=true, const bool higher_order_elements=false, const unsigned int n_cycles=1, const bool w_cycle=false, const double aggregation_threshold=1e-4, const std::vector< std::vector< bool > > &constant_modes=std::vector< std::vector< bool > >(0), const unsigned int smoother_sweeps=2, const unsigned int smoother_overlap=0, const bool output_details=false, const char *smoother_type="Chebyshev", const char *coarse_type="Amesos-KLU")
void set_operator_null_space(Teuchos::ParameterList ¶meter_list, std::unique_ptr< Epetra_MultiVector > &distributed_constant_modes, const Epetra_RowMatrix &matrix) const
void set_parameters(Teuchos::ParameterList ¶meter_list, std::unique_ptr< Epetra_MultiVector > &distributed_constant_modes, const Epetra_RowMatrix &matrix) const