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)
88 Teuchos::ParameterList parameter_list;
90 if (additional_data.
elliptic ==
true)
92 ML_Epetra::SetDefaults(
"SA", parameter_list);
103 parameter_list.set(
"aggregation: type",
"Uncoupled");
107 ML_Epetra::SetDefaults(
"NSSA", parameter_list);
108 parameter_list.set(
"aggregation: type",
"Uncoupled");
109 parameter_list.set(
"aggregation: block scaling",
true);
112 parameter_list.set(
"smoother: type", additional_data.
smoother_type);
113 parameter_list.set(
"coarse: type", additional_data.
coarse_type);
117 # if DEAL_II_TRILINOS_VERSION_GTE(12, 4, 0) 118 parameter_list.set(
"initialize random seed",
true);
121 parameter_list.set(
"smoother: sweeps",
123 parameter_list.set(
"cycle applications",
124 static_cast<int>(additional_data.
n_cycles));
125 if (additional_data.
w_cycle ==
true)
126 parameter_list.set(
"prec type",
"MGW");
128 parameter_list.set(
"prec type",
"MGV");
130 parameter_list.set(
"smoother: Chebyshev alpha", 10.);
131 parameter_list.set(
"smoother: ifpack overlap",
133 parameter_list.set(
"aggregation: threshold",
135 parameter_list.set(
"coarse: max size", 2000);
138 parameter_list.set(
"ML output", 10);
140 parameter_list.set(
"ML output", 0);
142 const Epetra_Map &domain_map = matrix.OperatorDomainMap();
144 const size_type constant_modes_dimension =
146 Epetra_MultiVector distributed_constant_modes(
147 domain_map, constant_modes_dimension > 0 ? constant_modes_dimension : 1);
148 std::vector<double> dummy(constant_modes_dimension);
150 if (constant_modes_dimension > 0)
156 static_cast<size_type>(
160 distributed_constant_modes)));
161 const bool constant_modes_are_global =
163 const size_type my_size = domain_map.NumMyElements();
168 constant_modes_are_global ? global_size : my_size;
169 for (
size_type d = 0; d < constant_modes_dimension; ++d)
174 expected_mode_size));
175 for (
size_type row = 0; row < my_size; ++row)
177 const TrilinosWrappers::types::int_type mode_index =
178 constant_modes_are_global ?
181 distributed_constant_modes[d][row] =
185 (void)expected_mode_size;
187 parameter_list.set(
"null space: type",
"pre-computed");
188 parameter_list.set(
"null space: dimension",
189 distributed_constant_modes.NumVectors());
191 parameter_list.set(
"null space: vectors",
192 distributed_constant_modes.Values());
196 parameter_list.set(
"null space: vectors", dummy.data());
203 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
204 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
206 Assert(multilevel_operator !=
nullptr,
208 multilevel_operator->PrintUnused(0);
216 const Teuchos::ParameterList &ml_parameters)
225 const Teuchos::ParameterList &ml_parameters)
229 std::make_shared<ML_Epetra::MultiLevelPreconditioner>(matrix,
235 template <
typename number>
238 const ::SparseMatrix<number> &deal_ii_sparse_matrix,
240 const double drop_tolerance,
241 const ::SparsityPattern * use_this_sparsity)
244 const size_type n_rows = deal_ii_sparse_matrix.m();
251 static_cast<TrilinosWrappers::types::int_type
>(n_rows), 0,
communicator);
258 deal_ii_sparse_matrix,
271 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
272 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
>(
preconditioner.get());
273 multilevel_operator->ReComputePreconditioner();
290 unsigned int memory =
sizeof(*this);
306 const ::SparsityPattern *);
311 const ::SparsityPattern *);
317 DEAL_II_NAMESPACE_CLOSE
319 #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
const Epetra_CrsMatrix & trilinos_matrix() const
double aggregation_threshold
std::vector< std::vector< bool > > constant_modes
TrilinosWrappers::types::int_type global_length(const Epetra_MultiVector &vector)
unsigned int smoother_overlap
std::shared_ptr< Epetra_Map > vector_distributor
unsigned int smoother_sweeps
size_type memory_consumption() const
static::ExceptionBase & ExcMessage(std::string arg1)
TrilinosWrappers::types::int_type n_global_rows(const Epetra_CrsGraph &graph)
const char * smoother_type
#define Assert(cond, exc)
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
~PreconditionAMG() override
std::shared_ptr< SparseMatrix > trilinos_matrix
void initialize(const SparseMatrix &matrix, const AdditionalData &additional_data=AdditionalData())
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
std::shared_ptr< Epetra_Operator > preconditioner
Epetra_MpiComm communicator
bool higher_order_elements