17 #include <deal.II/base/function.h> 18 #include <deal.II/base/logstream.h> 20 #include <deal.II/dofs/dof_accessor.h> 21 #include <deal.II/dofs/dof_tools.h> 23 #include <deal.II/fe/fe.h> 25 #include <deal.II/grid/tria.h> 26 #include <deal.II/grid/tria_iterator.h> 28 #include <deal.II/lac/block_sparse_matrix.h> 29 #include <deal.II/lac/block_vector.h> 30 #include <deal.II/lac/dynamic_sparsity_pattern.h> 31 #include <deal.II/lac/la_parallel_block_vector.h> 32 #include <deal.II/lac/la_parallel_vector.h> 33 #include <deal.II/lac/sparse_matrix.h> 34 #include <deal.II/lac/sparsity_tools.h> 35 #include <deal.II/lac/trilinos_epetra_vector.h> 36 #include <deal.II/lac/trilinos_parallel_block_vector.h> 37 #include <deal.II/lac/trilinos_vector.h> 38 #include <deal.II/lac/vector.h> 40 #include <deal.II/multigrid/mg_tools.h> 41 #include <deal.II/multigrid/mg_transfer.h> 45 DEAL_II_NAMESPACE_OPEN
48 template <
typename VectorType>
52 this->mg_constrained_dofs = &mg_c;
57 template <
typename VectorType>
62 this->mg_constrained_dofs = &mg_c;
67 template <
typename VectorType>
72 this->mg_constrained_dofs = &mg_c;
77 template <
typename VectorType>
83 initialize_constraints(mg_c);
88 template <
typename VectorType>
93 prolongation_matrices.resize(0);
94 prolongation_sparsities.resize(0);
95 interface_dofs.resize(0);
100 template <
typename VectorType>
104 const VectorType & src)
const 106 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
107 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
109 prolongation_matrices[to_level - 1]->vmult(dst, src);
114 template <
typename VectorType>
118 const VectorType & src)
const 120 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
121 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
124 prolongation_matrices[from_level - 1]->Tvmult_add(dst, src);
136 const unsigned int level,
137 std::vector<types::global_dof_index> &dof_indices)
139 if (mg_constrained_dofs !=
nullptr &&
141 for (
auto &ind : dof_indices)
157 template <
typename VectorType>
158 template <
int dim,
int spacedim>
164 const unsigned int dofs_per_cell = mg_dof.
get_fe().dofs_per_cell;
166 this->sizes.resize(n_levels);
167 for (
unsigned int l = 0; l < n_levels; ++l)
168 this->sizes[l] = mg_dof.
n_dofs(l);
180 prolongation_matrices.resize(0);
181 prolongation_sparsities.resize(0);
182 prolongation_matrices.reserve(n_levels - 1);
183 prolongation_sparsities.reserve(n_levels - 1);
185 for (
unsigned int i = 0; i < n_levels - 1; ++i)
187 prolongation_sparsities.emplace_back(
189 prolongation_matrices.emplace_back(
196 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
197 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
198 std::vector<types::global_dof_index> entries(dofs_per_cell);
205 for (
unsigned int level = 0; level < n_levels - 1; ++level)
217 level_p1_relevant_dofs);
220 level_p1_relevant_dofs);
222 for (cell = mg_dof.
begin(level); cell != endc; ++cell)
223 if (cell->has_children() &&
226 cell->level_subdomain_id() ==
229 cell->get_mg_dof_indices(dof_indices_parent);
231 replace(this->mg_constrained_dofs, level, dof_indices_parent);
233 Assert(cell->n_children() ==
236 for (
unsigned int child = 0; child < cell->n_children(); ++child)
240 mg_dof.
get_fe().get_prolongation_matrix(
241 child, cell->refinement_case());
243 Assert(prolongation.
n() != 0, ExcNoProlongation());
245 cell->child(child)->get_mg_dof_indices(dof_indices_child);
247 replace(this->mg_constrained_dofs,
254 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
257 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
258 if (prolongation(i, j) != 0)
259 entries.push_back(dof_indices_parent[j]);
267 #ifdef DEAL_II_WITH_MPI 268 if (internal::MatrixSelector<
269 VectorType>::requires_distributed_sparsity_pattern)
280 MPI_Comm communicator = dist_tria !=
nullptr ?
285 const std::vector<::IndexSet>
286 &locally_owned_mg_dofs_per_processor =
288 std::vector<::types::global_dof_index>
289 n_locally_owned_mg_dofs_per_processor(
290 locally_owned_mg_dofs_per_processor.size(), 0);
292 for (std::size_t index = 0;
293 index < n_locally_owned_mg_dofs_per_processor.size();
296 n_locally_owned_mg_dofs_per_processor[index] =
297 locally_owned_mg_dofs_per_processor[index].n_elements();
301 ::SparsityTools::distribute_sparsity_pattern(
303 n_locally_owned_mg_dofs_per_processor,
309 internal::MatrixSelector<VectorType>::reinit(
310 *prolongation_matrices[level],
311 *prolongation_sparsities[level],
328 for (cell = mg_dof.
begin(level); cell != endc; ++cell)
329 if (cell->has_children() &&
332 cell->level_subdomain_id() ==
335 cell->get_mg_dof_indices(dof_indices_parent);
337 replace(this->mg_constrained_dofs, level, dof_indices_parent);
339 Assert(cell->n_children() ==
342 for (
unsigned int child = 0; child < cell->n_children(); ++child)
345 prolongation = mg_dof.
get_fe().get_prolongation_matrix(
346 child, cell->refinement_case());
348 if (this->mg_constrained_dofs !=
nullptr &&
350 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
352 level, dof_indices_parent[j]))
353 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
354 prolongation(i, j) = 0.;
356 cell->child(child)->get_mg_dof_indices(dof_indices_child);
358 replace(this->mg_constrained_dofs,
363 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
364 prolongation_matrices[level]->
set(dof_indices_child[i],
366 dof_indices_parent.data(),
374 this->fill_and_communicate_copy_indices(mg_dof);
379 template <
typename VectorType>
383 for (
unsigned int level = 0; level < prolongation_matrices.size(); ++level)
385 os <<
"Level " << level << std::endl;
386 prolongation_matrices[level]->print(os);
393 template <
typename VectorType>
398 for (
unsigned int i = 0; i < prolongation_matrices.size(); ++i)
399 result += prolongation_matrices[i]->memory_consumption() +
400 prolongation_sparsities[i]->memory_consumption();
407 #include "mg_transfer_prebuilt.inst" 410 DEAL_II_NAMESPACE_CLOSE
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
MGTransferPrebuilt()=default
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
const Triangulation< dim, spacedim > & get_triangulation() const
const types::subdomain_id invalid_subdomain_id
std::size_t memory_consumption() const
cell_iterator begin(const unsigned int level=0) const
void build_matrices(const DoFHandler< dim, spacedim > &mg_dof)
bool is_boundary_index(const unsigned int level, const types::global_dof_index index) const
cell_iterator end() const
const std::vector< IndexSet > & locally_owned_mg_dofs_per_processor(const unsigned int level) const
const AffineConstraints< double > & get_level_constraints(const unsigned int level) const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
size_type n_constraints() const
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
void print_matrices(std::ostream &os) const
std::size_t memory_consumption() const
#define Assert(cond, exc)
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
virtual MPI_Comm get_communicator() const
const IndexSet & row_index_set() const
types::global_dof_index n_dofs() const
bool is_identity_constrained(const size_type line_n) const
virtual void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line_n) const
static ::ExceptionBase & ExcNotImplemented()
bool have_boundary_indices() const
static ::ExceptionBase & ExcInternalError()