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 prolongation_matrices.resize(0);
73 prolongation_sparsities.resize(0);
74 interface_dofs.resize(0);
79 template <
typename VectorType>
85 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
86 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
89 if (this->mg_constrained_dofs !=
nullptr)
90 Assert(this->mg_constrained_dofs->get_user_constraint_matrix(to_level - 1)
96 prolongation_matrices[to_level - 1]->vmult(dst, src);
101 template <
typename VectorType>
107 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
108 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
111 prolongation_matrices[from_level - 1]->Tvmult_add(dst, src);
123 const unsigned int level,
124 std::vector<types::global_dof_index> &dof_indices)
126 if (mg_constrained_dofs !=
nullptr &&
128 for (
auto &ind : dof_indices)
144 template <
typename VectorType>
145 template <
int dim,
int spacedim>
150 const unsigned int n_levels =
152 const unsigned int dofs_per_cell = dof_handler.
get_fe().dofs_per_cell;
154 this->sizes.resize(n_levels);
155 for (
unsigned int l = 0;
l < n_levels; ++
l)
156 this->sizes[
l] = dof_handler.
n_dofs(
l);
168 prolongation_matrices.resize(0);
169 prolongation_sparsities.resize(0);
170 prolongation_matrices.reserve(n_levels - 1);
171 prolongation_sparsities.reserve(n_levels - 1);
173 for (
unsigned int i = 0; i < n_levels - 1; ++i)
175 prolongation_sparsities.emplace_back(
177 prolongation_matrices.emplace_back(
184 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
185 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
186 std::vector<types::global_dof_index> entries(dofs_per_cell);
205 level_p1_relevant_dofs);
208 level_p1_relevant_dofs);
210 endc = dof_handler.
end(level);
211 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
212 if (cell->has_children() &&
215 cell->level_subdomain_id() ==
218 cell->get_mg_dof_indices(dof_indices_parent);
220 replace(this->mg_constrained_dofs, level, dof_indices_parent);
222 Assert(cell->n_children() ==
225 for (
unsigned int child = 0; child < cell->n_children(); ++child)
229 dof_handler.
get_fe().get_prolongation_matrix(
230 child, cell->refinement_case());
232 Assert(prolongation.
n() != 0, ExcNoProlongation());
234 cell->child(child)->get_mg_dof_indices(dof_indices_child);
236 replace(this->mg_constrained_dofs,
243 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
246 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
247 if (prolongation(i, j) != 0)
248 entries.push_back(dof_indices_parent[j]);
256 #ifdef DEAL_II_WITH_MPI 258 VectorType>::requires_distributed_sparsity_pattern)
269 MPI_Comm communicator = dist_tria !=
nullptr ?
283 *prolongation_matrices[level],
284 *prolongation_sparsities[level],
301 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
302 if (cell->has_children() &&
305 cell->level_subdomain_id() ==
308 cell->get_mg_dof_indices(dof_indices_parent);
310 replace(this->mg_constrained_dofs, level, dof_indices_parent);
312 Assert(cell->n_children() ==
315 for (
unsigned int child = 0; child < cell->n_children(); ++child)
318 prolongation = dof_handler.
get_fe().get_prolongation_matrix(
319 child, cell->refinement_case());
321 if (this->mg_constrained_dofs !=
nullptr &&
322 this->mg_constrained_dofs->have_boundary_indices())
323 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
324 if (this->mg_constrained_dofs->is_boundary_index(
325 level, dof_indices_parent[j]))
326 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
327 prolongation(i, j) = 0.;
329 cell->child(child)->get_mg_dof_indices(dof_indices_child);
331 replace(this->mg_constrained_dofs,
336 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
337 prolongation_matrices[level]->
set(dof_indices_child[i],
339 dof_indices_parent.data(),
347 this->fill_and_communicate_copy_indices(dof_handler);
352 template <
typename VectorType>
353 template <
int dim,
int spacedim>
363 template <
typename VectorType>
367 for (
unsigned int level = 0;
level < prolongation_matrices.size(); ++
level)
369 os <<
"Level " <<
level << std::endl;
370 prolongation_matrices[
level]->print(os);
377 template <
typename VectorType>
382 for (
unsigned int i = 0; i < prolongation_matrices.size(); ++i)
384 prolongation_sparsities[i]->memory_consumption();
391 #include "mg_transfer_prebuilt.inst" 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
static void reinit(Matrix &matrix, Sparsity &sparsity, int level, const SparsityPatternType &sp, const DoFHandlerType &)
cell_iterator end() 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())
const IndexSet & row_index_set() const
void build(const DoFHandler< dim, spacedim > &dof_handler)
#define DEAL_II_NAMESPACE_CLOSE
types::global_dof_index n_dofs() const
void build_matrices(const DoFHandler< dim, spacedim > &dof_handler)
const IndexSet & locally_owned_mg_dofs(const unsigned int level) const
bool is_identity_constrained(const size_type line_n) const
virtual const MPI_Comm & get_communicator() 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
#define DEAL_II_NAMESPACE_OPEN
static ::ExceptionBase & ExcNotImplemented()
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()