17 #include <deal.II/base/logstream.h> 18 #include <deal.II/base/function.h> 20 #include <deal.II/lac/vector.h> 21 #include <deal.II/lac/block_vector.h> 22 #include <deal.II/lac/la_parallel_vector.h> 23 #include <deal.II/lac/la_parallel_block_vector.h> 24 #include <deal.II/lac/trilinos_epetra_vector.h> 25 #include <deal.II/lac/trilinos_vector.h> 26 #include <deal.II/lac/trilinos_parallel_block_vector.h> 27 #include <deal.II/lac/sparse_matrix.h> 28 #include <deal.II/lac/block_sparse_matrix.h> 29 #include <deal.II/lac/dynamic_sparsity_pattern.h> 30 #include <deal.II/grid/tria.h> 31 #include <deal.II/grid/tria_iterator.h> 32 #include <deal.II/dofs/dof_tools.h> 33 #include <deal.II/fe/fe.h> 34 #include <deal.II/dofs/dof_accessor.h> 35 #include <deal.II/multigrid/mg_tools.h> 36 #include <deal.II/multigrid/mg_transfer.h> 40 DEAL_II_NAMESPACE_OPEN
43 template <
typename VectorType>
46 this->mg_constrained_dofs = &mg_c;
51 template <
typename VectorType>
54 this->mg_constrained_dofs = &mg_c;
59 template <
typename VectorType>
63 this->mg_constrained_dofs = &mg_c;
68 template <
typename VectorType>
72 initialize_constraints(mg_c);
77 template <
typename VectorType>
81 prolongation_matrices.resize(0);
82 prolongation_sparsities.resize(0);
83 interface_dofs.resize(0);
88 template <
typename VectorType>
91 const VectorType &src)
const 93 Assert ((to_level >= 1) && (to_level<=prolongation_matrices.size()),
96 prolongation_matrices[to_level-1]->vmult (dst, src);
101 template <
typename VectorType>
104 const VectorType &src)
const 106 Assert ((from_level >= 1) && (from_level<=prolongation_matrices.size()),
107 ExcIndexRange (from_level, 1, prolongation_matrices.size()+1));
110 prolongation_matrices[from_level-1]->Tvmult_add (dst, src);
121 const unsigned int level,
122 std::vector<types::global_dof_index> &dof_indices)
124 if (mg_constrained_dofs !=
nullptr &&
126 for (
auto &ind : dof_indices)
136 template <
typename VectorType>
137 template <
int dim,
int spacedim>
142 const unsigned int dofs_per_cell = mg_dof.
get_fe().dofs_per_cell;
144 this->sizes.resize(n_levels);
145 for (
unsigned int l=0; l<n_levels; ++l)
146 this->sizes[l] = mg_dof.
n_dofs(l);
158 prolongation_matrices.resize (0);
159 prolongation_sparsities.resize (0);
160 prolongation_matrices.reserve (n_levels - 1);
161 prolongation_sparsities.reserve (n_levels - 1);
163 for (
unsigned int i=0; i<n_levels-1; ++i)
165 prolongation_sparsities.emplace_back
167 prolongation_matrices.emplace_back
174 std::vector<types::global_dof_index> dof_indices_parent (dofs_per_cell);
175 std::vector<types::global_dof_index> dof_indices_child (dofs_per_cell);
176 std::vector<types::global_dof_index> entries (dofs_per_cell);
183 for (
unsigned int level=0; level<n_levels-1; ++level)
194 level_p1_relevant_dofs);
197 level_p1_relevant_dofs);
199 for (cell=mg_dof.
begin(level); cell != endc; ++cell)
200 if (cell->has_children() &&
202 || cell->level_subdomain_id()==mg_dof.
get_triangulation().locally_owned_subdomain()
205 cell->get_mg_dof_indices (dof_indices_parent);
207 replace(this->mg_constrained_dofs, level, dof_indices_parent);
211 for (
unsigned int child=0; child<cell->n_children(); ++child)
215 = mg_dof.
get_fe().get_prolongation_matrix (child,
216 cell->refinement_case());
218 Assert (prolongation.
n() != 0, ExcNoProlongation());
220 cell->child(child)->get_mg_dof_indices (dof_indices_child);
222 replace(this->mg_constrained_dofs, level+1, dof_indices_child);
227 for (
unsigned int i=0; i<dofs_per_cell; ++i)
230 for (
unsigned int j=0; j<dofs_per_cell; ++j)
231 if (prolongation(i,j) != 0)
232 entries.push_back (dof_indices_parent[j]);
234 entries.begin(), entries.end());
239 internal::MatrixSelector<VectorType>::reinit(*prolongation_matrices[level],
240 *prolongation_sparsities[level],
249 for (cell=mg_dof.
begin(level); cell != endc; ++cell)
250 if (cell->has_children() &&
252 || cell->level_subdomain_id()==mg_dof.
get_triangulation().locally_owned_subdomain())
255 cell->get_mg_dof_indices (dof_indices_parent);
257 replace(this->mg_constrained_dofs, level, dof_indices_parent);
261 for (
unsigned int child=0; child<cell->n_children(); ++child)
265 = mg_dof.
get_fe().get_prolongation_matrix (child,
266 cell->refinement_case());
268 if (this->mg_constrained_dofs !=
nullptr &&
270 for (
unsigned int j=0; j<dofs_per_cell; ++j)
272 for (
unsigned int i=0; i<dofs_per_cell; ++i)
273 prolongation(i,j) = 0.;
275 cell->child(child)->get_mg_dof_indices (dof_indices_child);
277 replace(this->mg_constrained_dofs, level+1, dof_indices_child);
280 for (
unsigned int i=0; i<dofs_per_cell; ++i)
281 prolongation_matrices[level]->
set (dof_indices_child[i],
283 dof_indices_parent.data(),
291 this->fill_and_communicate_copy_indices(mg_dof);
296 template <
typename VectorType>
300 for (
unsigned int level = 0; level<prolongation_matrices.size(); ++level)
302 os <<
"Level " << level << std::endl;
303 prolongation_matrices[level]->print(os);
310 template <
typename VectorType>
315 for (
unsigned int i=0; i<prolongation_matrices.size(); ++i)
316 result += prolongation_matrices[i]->memory_consumption()
317 + prolongation_sparsities[i]->memory_consumption();
324 #include "mg_transfer_prebuilt.inst" 327 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 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
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
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())
size_type n_constraints() const
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
const ConstraintMatrix & get_level_constraint_matrix(const unsigned int level) const
types::global_dof_index n_dofs() const
virtual void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const
bool is_identity_constrained(const size_type index) const
static ::ExceptionBase & ExcNotImplemented()
const Triangulation< dim, spacedim > & get_triangulation() const
const std::vector< std::pair< size_type, double > > * get_constraint_entries(const size_type line) const
bool have_boundary_indices() const
static ::ExceptionBase & ExcInternalError()
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const