16 #include <deal.II/lac/trilinos_index_access.h> 17 #include <deal.II/lac/trilinos_precondition.h> 19 #ifdef DEAL_II_WITH_TRILINOS 21 # include <deal.II/lac/sparse_matrix.h> 22 # include <deal.II/lac/trilinos_index_access.h> 23 # include <deal.II/lac/trilinos_sparse_matrix.h> 24 # include <deal.II/lac/vector.h> 26 # include <Epetra_MultiVector.h> 28 # include <Ifpack_Chebyshev.h> 29 # include <Teuchos_ParameterList.hpp> 30 # include <Teuchos_RCP.hpp> 31 # include <ml_MultiLevelPreconditioner.h> 32 # include <ml_include.h> 34 DEAL_II_NAMESPACE_OPEN
42 const bool higher_order_elements,
43 const unsigned int n_cycles,
45 const double aggregation_threshold,
46 const std::vector<std::vector<bool>> &constant_modes,
47 const unsigned int smoother_sweeps,
48 const unsigned int smoother_overlap,
49 const bool output_details,
50 const char * smoother_type,
51 const char * coarse_type)
53 , higher_order_elements(higher_order_elements)
56 , aggregation_threshold(aggregation_threshold)
57 , constant_modes(constant_modes)
58 , smoother_sweeps(smoother_sweeps)
59 , smoother_overlap(smoother_overlap)
60 , output_details(output_details)
61 , smoother_type(smoother_type)
62 , coarse_type(coarse_type)
69 Teuchos::ParameterList & parameter_list,
70 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
71 const Epetra_RowMatrix & matrix)
const 75 ML_Epetra::SetDefaults(
"SA", parameter_list);
85 if (higher_order_elements)
86 parameter_list.set(
"aggregation: type",
"Uncoupled");
90 ML_Epetra::SetDefaults(
"NSSA", parameter_list);
91 parameter_list.set(
"aggregation: type",
"Uncoupled");
92 parameter_list.set(
"aggregation: block scaling",
true);
95 parameter_list.set(
"smoother: type", smoother_type);
96 parameter_list.set(
"coarse: type", coarse_type);
100 # if DEAL_II_TRILINOS_VERSION_GTE(12, 4, 0) 101 parameter_list.set(
"initialize random seed",
true);
104 parameter_list.set(
"smoother: sweeps", static_cast<int>(smoother_sweeps));
105 parameter_list.set(
"cycle applications", static_cast<int>(n_cycles));
107 parameter_list.set(
"prec type",
"MGW");
109 parameter_list.set(
"prec type",
"MGV");
111 parameter_list.set(
"smoother: Chebyshev alpha", 10.);
112 parameter_list.set(
"smoother: ifpack overlap",
113 static_cast<int>(smoother_overlap));
114 parameter_list.set(
"aggregation: threshold", aggregation_threshold);
115 parameter_list.set(
"coarse: max size", 2000);
118 parameter_list.set(
"ML output", 10);
120 parameter_list.set(
"ML output", 0);
122 set_operator_null_space(parameter_list, distributed_constant_modes, matrix);
129 Teuchos::ParameterList & parameter_list,
130 std::unique_ptr<Epetra_MultiVector> &ptr_distributed_constant_modes,
131 const Epetra_RowMatrix & matrix)
const 133 const Epetra_Map &domain_map = matrix.OperatorDomainMap();
135 const size_type constant_modes_dimension = constant_modes.size();
136 ptr_distributed_constant_modes.reset(
new Epetra_MultiVector(
137 domain_map, constant_modes_dimension > 0 ? constant_modes_dimension : 1));
139 Epetra_MultiVector &distributed_constant_modes =
140 *ptr_distributed_constant_modes;
142 if (constant_modes_dimension > 0)
148 static_cast<size_type>(
152 distributed_constant_modes)));
153 const bool constant_modes_are_global =
154 constant_modes[0].size() == global_size;
155 const size_type my_size = domain_map.NumMyElements();
160 constant_modes_are_global ? global_size : my_size;
161 for (
size_type d = 0; d < constant_modes_dimension; ++d)
163 Assert(constant_modes[d].size() == expected_mode_size,
165 expected_mode_size));
166 for (
size_type row = 0; row < my_size; ++row)
168 const TrilinosWrappers::types::int_type mode_index =
169 constant_modes_are_global ?
172 distributed_constant_modes[d][row] =
173 constant_modes[d][mode_index];
176 (void)expected_mode_size;
178 parameter_list.set(
"null space: type",
"pre-computed");
179 parameter_list.set(
"null space: dimension",
180 distributed_constant_modes.NumVectors());
181 parameter_list.set(
"null space: vectors",
182 distributed_constant_modes.Values());
190 Teuchos::ParameterList & parameter_list,
191 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
194 return set_parameters(parameter_list,
195 distributed_constant_modes,
196 matrix.trilinos_matrix());
203 Teuchos::ParameterList & parameter_list,
204 std::unique_ptr<Epetra_MultiVector> &distributed_constant_modes,
207 return set_operator_null_space(parameter_list,
208 distributed_constant_modes,
209 matrix.trilinos_matrix());
226 initialize(matrix.trilinos_matrix(), additional_data);
236 Teuchos::ParameterList ml_parameters;
237 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
239 distributed_constant_modes,
246 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
247 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
249 Assert(multilevel_operator !=
nullptr,
251 multilevel_operator->PrintUnused(0);
259 const Teuchos::ParameterList &ml_parameters)
261 initialize(matrix.trilinos_matrix(), ml_parameters);
268 const Teuchos::ParameterList &ml_parameters)
271 new ML_Epetra::MultiLevelPreconditioner(matrix, ml_parameters));
276 template <
typename number>
279 const ::SparseMatrix<number> &deal_ii_sparse_matrix,
281 const double drop_tolerance,
282 const ::SparsityPattern * use_this_sparsity)
285 const size_type n_rows = deal_ii_sparse_matrix.m();
292 static_cast<TrilinosWrappers::types::int_type
>(n_rows), 0,
communicator);
299 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);
345 const AdditionalData &,
347 const ::SparsityPattern *);
350 const AdditionalData &,
352 const ::SparsityPattern *);
358 DEAL_II_NAMESPACE_CLOSE
360 #endif // DEAL_II_WITH_TRILINOS AdditionalData(const bool elliptic=true, const bool higher_order_elements=false, const unsigned int n_cycles=1, const bool w_cyle=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")
::types::global_dof_index size_type
void set_parameters(Teuchos::ParameterList ¶meter_list, std::unique_ptr< Epetra_MultiVector > &distributed_constant_modes, const Epetra_RowMatrix &matrix) const
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
std::shared_ptr< Epetra_Map > vector_distributor
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
TrilinosWrappers::types::int_type n_global_rows(const Epetra_CrsGraph &graph)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
size_type memory_consumption() const
~PreconditionAMG() override
std::shared_ptr< SparseMatrix > trilinos_matrix
void initialize(const SparseMatrix &matrix, const AdditionalData &additional_data=AdditionalData())
void set_operator_null_space(Teuchos::ParameterList ¶meter_list, std::unique_ptr< Epetra_MultiVector > &distributed_constant_modes, const Epetra_RowMatrix &matrix) const
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
Epetra_MpiComm communicator
Teuchos::RCP< Epetra_Operator > preconditioner