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/vector.h> 22 # include <deal.II/lac/sparse_matrix.h> 23 # include <deal.II/lac/trilinos_sparse_matrix.h> 24 # include <deal.II/lac/trilinos_index_access.h> 27 # include <Ifpack_Chebyshev.h> 28 # include <Teuchos_ParameterList.hpp> 29 # include <Teuchos_RCP.hpp> 30 # include <Epetra_MultiVector.h> 31 # include <ml_include.h> 32 # include <ml_MultiLevelPreconditioner.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)
54 higher_order_elements (higher_order_elements),
57 aggregation_threshold (aggregation_threshold),
58 constant_modes (constant_modes),
59 smoother_sweeps (smoother_sweeps),
60 smoother_overlap (smoother_overlap),
61 output_details (output_details),
62 smoother_type (smoother_type),
63 coarse_type (coarse_type)
79 initialize(matrix.trilinos_matrix(), additional_data);
89 Teuchos::ParameterList parameter_list;
91 if (additional_data.
elliptic ==
true)
93 ML_Epetra::SetDefaults(
"SA",parameter_list);
104 parameter_list.set(
"aggregation: type",
"Uncoupled");
108 ML_Epetra::SetDefaults(
"NSSA",parameter_list);
109 parameter_list.set(
"aggregation: type",
"Uncoupled");
110 parameter_list.set(
"aggregation: block scaling",
true);
113 parameter_list.set(
"smoother: type", additional_data.
smoother_type);
114 parameter_list.set(
"coarse: type", additional_data.
coarse_type);
118 #if DEAL_II_TRILINOS_VERSION_GTE(12,4,0) 119 parameter_list.set(
"initialize random seed",
true);
122 parameter_list.set(
"smoother: sweeps",
124 parameter_list.set(
"cycle applications",
125 static_cast<int>(additional_data.
n_cycles));
126 if (additional_data.
w_cycle ==
true)
127 parameter_list.set(
"prec type",
"MGW");
129 parameter_list.set(
"prec type",
"MGV");
131 parameter_list.set(
"smoother: Chebyshev alpha",10.);
132 parameter_list.set(
"smoother: ifpack overlap",
134 parameter_list.set(
"aggregation: threshold",
136 parameter_list.set(
"coarse: max size", 2000);
139 parameter_list.set(
"ML output", 10);
141 parameter_list.set(
"ML output", 0);
143 const Epetra_Map &domain_map = matrix.OperatorDomainMap();
145 const size_type constant_modes_dimension =
147 Epetra_MultiVector distributed_constant_modes (domain_map,
148 constant_modes_dimension > 0 ?
149 constant_modes_dimension : 1);
150 std::vector<double> dummy (constant_modes_dimension);
152 if (constant_modes_dimension > 0)
160 const bool constant_modes_are_global
162 const size_type my_size = domain_map.NumMyElements();
167 constant_modes_are_global ? global_size : my_size;
168 for (
size_type d=0; d<constant_modes_dimension; ++d)
172 for (
size_type row=0; row<my_size; ++row)
174 const TrilinosWrappers::types::int_type mode_index =
176 distributed_constant_modes[d][row] =
180 (void)expected_mode_size;
182 parameter_list.set(
"null space: type",
"pre-computed");
183 parameter_list.set(
"null space: dimension",
184 distributed_constant_modes.NumVectors());
186 parameter_list.set(
"null space: vectors",
187 distributed_constant_modes.Values());
191 parameter_list.set(
"null space: vectors",
199 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
200 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
> (
preconditioner.get());
201 Assert (multilevel_operator !=
nullptr,
203 multilevel_operator->PrintUnused(0);
211 const Teuchos::ParameterList &ml_parameters)
213 initialize(matrix.trilinos_matrix(), ml_parameters);
220 const Teuchos::ParameterList &ml_parameters)
223 preconditioner = std::make_shared<ML_Epetra::MultiLevelPreconditioner>
224 (matrix, ml_parameters);
229 template <
typename number>
232 initialize (const ::SparseMatrix<number> &deal_ii_sparse_matrix,
234 const double drop_tolerance,
235 const ::SparsityPattern *use_this_sparsity)
238 const size_type n_rows = deal_ii_sparse_matrix.m();
245 (
static_cast<TrilinosWrappers::types::int_type
>(n_rows),
252 deal_ii_sparse_matrix, drop_tolerance,
true,
262 ML_Epetra::MultiLevelPreconditioner *multilevel_operator =
263 dynamic_cast<ML_Epetra::MultiLevelPreconditioner *
> (
preconditioner.get());
264 multilevel_operator->ReComputePreconditioner();
280 unsigned int memory =
sizeof(*this);
294 const AdditionalData &,
const double,
295 const ::SparsityPattern *);
297 const AdditionalData &,
const double,
298 const ::SparsityPattern *);
307 DEAL_II_NAMESPACE_CLOSE
309 #endif // DEAL_II_WITH_TRILINOS
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
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)
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")
size_type memory_consumption() const
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
::types::global_dof_index size_type
Epetra_MpiComm communicator
bool higher_order_elements