18#ifdef DEAL_II_WITH_TRILINOS
24# include <Epetra_MultiVector.h>
26# include <Ifpack_Chebyshev.h>
27# include <Teuchos_ParameterList.hpp>
28# include <Teuchos_RCP.hpp>
29# include <ml_MultiLevelPreconditioner.h>
30# include <ml_include.h>
40 const bool higher_order_elements,
41 const unsigned int n_cycles,
43 const double aggregation_threshold,
44 const std::vector<std::vector<bool>> &constant_modes,
45 const unsigned int smoother_sweeps,
46 const unsigned int smoother_overlap,
47 const bool output_details,
48 const char *smoother_type,
49 const char *coarse_type)
51 , higher_order_elements(higher_order_elements)
54 , aggregation_threshold(aggregation_threshold)
55 , constant_modes(constant_modes)
56 , smoother_sweeps(smoother_sweeps)
57 , smoother_overlap(smoother_overlap)
58 , output_details(output_details)
59 , smoother_type(smoother_type)
60 , coarse_type(coarse_type)
67 Teuchos::ParameterList ¶meter_list,
68 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
69 const Epetra_RowMatrix &matrix)
const
73 ML_Epetra::SetDefaults(
"SA", parameter_list);
83 if (higher_order_elements)
84 parameter_list.set(
"aggregation: type",
"Uncoupled");
88 ML_Epetra::SetDefaults(
"NSSA", parameter_list);
89 parameter_list.set(
"aggregation: type",
"Uncoupled");
90 parameter_list.set(
"aggregation: block scaling",
true);
93 parameter_list.set(
"smoother: type", smoother_type);
94 parameter_list.set(
"coarse: type", coarse_type);
98# if DEAL_II_TRILINOS_VERSION_GTE(12, 4, 0)
99 parameter_list.set(
"initialize random seed",
true);
102 parameter_list.set(
"smoother: sweeps",
static_cast<int>(smoother_sweeps));
103 parameter_list.set(
"cycle applications",
static_cast<int>(n_cycles));
105 parameter_list.set(
"prec type",
"MGW");
107 parameter_list.set(
"prec type",
"MGV");
109 parameter_list.set(
"smoother: Chebyshev alpha", 10.);
110 parameter_list.set(
"smoother: ifpack overlap",
111 static_cast<int>(smoother_overlap));
112 parameter_list.set(
"aggregation: threshold", aggregation_threshold);
113 parameter_list.set(
"coarse: max size", 2000);
116 parameter_list.set(
"ML output", 10);
118 parameter_list.set(
"ML output", 0);
120 set_operator_null_space(parameter_list, distributed_constant_modes, matrix);
127 Teuchos::ParameterList ¶meter_list,
128 std::unique_ptr<Epetra_MultiVector> &ptr_distributed_constant_modes,
129 const Epetra_RowMatrix &matrix)
const
131 const Epetra_Map &domain_map = matrix.OperatorDomainMap();
133 const size_type constant_modes_dimension = constant_modes.size();
134 ptr_distributed_constant_modes = std::make_unique<Epetra_MultiVector>(
135 domain_map, constant_modes_dimension > 0 ? constant_modes_dimension : 1);
137 Epetra_MultiVector &distributed_constant_modes =
138 *ptr_distributed_constant_modes;
140 if (constant_modes_dimension > 0)
150 distributed_constant_modes)));
151 const bool constant_modes_are_global =
152 constant_modes[0].size() == global_size;
153 const size_type my_size = domain_map.NumMyElements();
158 constant_modes_are_global ? global_size : my_size;
159 for (
size_type d = 0; d < constant_modes_dimension; ++d)
161 Assert(constant_modes[d].size() == expected_mode_size,
163 expected_mode_size));
164 for (
size_type row = 0; row < my_size; ++row)
167 constant_modes_are_global ?
170 distributed_constant_modes[d][row] =
171 static_cast<double>(constant_modes[d][mode_index]);
174 (void)expected_mode_size;
176 parameter_list.set(
"null space: type",
"pre-computed");
177 parameter_list.set(
"null space: dimension",
178 distributed_constant_modes.NumVectors());
179 parameter_list.set(
"null space: vectors",
180 distributed_constant_modes.Values());
188 Teuchos::ParameterList ¶meter_list,
189 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
192 return set_parameters(parameter_list,
193 distributed_constant_modes,
194 matrix.trilinos_matrix());
201 Teuchos::ParameterList ¶meter_list,
202 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
205 return set_operator_null_space(parameter_list,
206 distributed_constant_modes,
207 matrix.trilinos_matrix());
224 initialize(matrix.trilinos_matrix(), additional_data);
234 Teuchos::ParameterList ml_parameters;
235 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
237 distributed_constant_modes,
244 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
245 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
247 Assert(multilevel_operator !=
nullptr,
249 multilevel_operator->PrintUnused(0);
257 const Teuchos::ParameterList &ml_parameters)
259 initialize(matrix.trilinos_matrix(), ml_parameters);
266 const Teuchos::ParameterList &ml_parameters)
269 new ML_Epetra::MultiLevelPreconditioner(matrix, ml_parameters));
274 template <
typename number>
277 const ::SparseMatrix<number> &deal_ii_sparse_matrix,
279 const double drop_tolerance,
280 const ::SparsityPattern *use_this_sparsity)
283 const size_type n_rows = deal_ii_sparse_matrix.m();
288 const unsigned int n_mpi_processes =
communicator.NumProc();
290 distributor.
add_range(my_id * n_rows / n_mpi_processes,
291 (my_id + 1) * n_rows / n_mpi_processes);
298 deal_ii_sparse_matrix,
312 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
313 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
preconditioner.get());
314 multilevel_operator->ReComputePreconditioner();
331 unsigned int memory =
sizeof(*this);
346 const AdditionalData &,
348 const ::SparsityPattern *);
351 const AdditionalData &,
353 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