42template <
int dim,
typename Number>
45 , element_is_continuous(false)
47 , n_child_cell_dofs(0)
52template <
int dim,
typename Number>
56 , element_is_continuous(false)
58 , n_child_cell_dofs(0)
65template <
int dim,
typename Number>
70 this->mg_constrained_dofs = &mg_c;
75template <
int dim,
typename Number>
82 element_is_continuous =
false;
84 n_child_cell_dofs = 0;
85 level_dof_indices.clear();
86 parent_child_connect.clear();
87 dirichlet_indices.clear();
88 n_owned_level_cells.clear();
89 prolongation_matrix_1d.clear();
90 evaluation_data.clear();
91 weights_on_refined.clear();
95template <
int dim,
typename Number>
99 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
100 &external_partitioners)
102 this->fill_and_communicate_copy_indices(dof_handler);
104 vector_partitioners.resize(0,
107 for (
unsigned int level = 0;
level <= this->ghosted_level_vector.max_level();
109 vector_partitioners[
level] =
110 this->ghosted_level_vector[
level].get_partitioner();
112 std::vector<std::vector<Number>> weights_unvectorized;
116 internal::MGTransfer::setup_transfer<dim, Number>(
118 this->mg_constrained_dofs,
119 external_partitioners,
122 parent_child_connect,
125 weights_unvectorized,
126 this->copy_indices_global_mine,
127 vector_partitioners);
131 this->ghosted_level_vector.resize(0, vector_partitioners.max_level());
132 for (
unsigned int level = 0;
level <= vector_partitioners.max_level();
134 if (external_partitioners.size() == vector_partitioners.max_level() + 1 &&
135 external_partitioners[
level].get() == vector_partitioners[
level].get())
136 this->ghosted_level_vector[
level].reinit(0);
138 this->ghosted_level_vector[
level].reinit(vector_partitioners[
level]);
153 const unsigned int n_levels =
156 const unsigned int n_weights_per_cell = Utilities::fixed_power<dim>(3);
157 weights_on_refined.resize(n_levels - 1);
160 weights_on_refined[
level - 1].resize(
161 ((n_owned_level_cells[
level - 1] + vec_size - 1) / vec_size) *
164 for (
unsigned int c = 0; c < n_owned_level_cells[
level - 1]; ++c)
166 const unsigned int comp = c / vec_size;
167 const unsigned int v = c % vec_size;
168 for (
unsigned int i = 0; i < n_weights_per_cell; ++i)
170 weights_on_refined[
level - 1][comp * n_weights_per_cell + i][v] =
171 weights_unvectorized[
level - 1][c * n_weights_per_cell + i];
176 evaluation_data.resize(n_child_cell_dofs);
181template <
int dim,
typename Number>
184 const unsigned int to_level,
189 prolongate_and_add(to_level, dst, src);
194template <
int dim,
typename Number>
197 const unsigned int to_level,
201 Assert((to_level >= 1) && (to_level <= level_dof_indices.size()),
205 this->vector_partitioners[to_level - 1].get();
206 if (src_inplace ==
false)
208 if (this->ghosted_level_vector[to_level - 1].get_partitioner().get() !=
209 this->vector_partitioners[to_level - 1].get())
210 this->ghosted_level_vector[to_level - 1].reinit(
211 this->vector_partitioners[to_level - 1]);
212 this->ghosted_level_vector[to_level - 1].copy_locally_owned_data_from(
216 const bool dst_inplace =
217 dst.
get_partitioner().get() == this->vector_partitioners[to_level].get();
218 if (dst_inplace ==
false)
220 if (this->ghosted_level_vector[to_level].get_partitioner().get() !=
221 this->vector_partitioners[to_level].get())
222 this->ghosted_level_vector[to_level].reinit(
223 this->vector_partitioners[to_level]);
224 AssertDimension(this->ghosted_level_vector[to_level].locally_owned_size(),
226 this->ghosted_level_vector[to_level] = 0.;
230 src_inplace ? src : this->ghosted_level_vector[to_level - 1];
232 dst_inplace ? dst : this->ghosted_level_vector[to_level];
239 do_prolongate_add<0>(to_level, dst_vec, src_vec);
240 else if (fe_degree == 1)
241 do_prolongate_add<1>(to_level, dst_vec, src_vec);
242 else if (fe_degree == 2)
243 do_prolongate_add<2>(to_level, dst_vec, src_vec);
244 else if (fe_degree == 3)
245 do_prolongate_add<3>(to_level, dst_vec, src_vec);
246 else if (fe_degree == 4)
247 do_prolongate_add<4>(to_level, dst_vec, src_vec);
248 else if (fe_degree == 5)
249 do_prolongate_add<5>(to_level, dst_vec, src_vec);
250 else if (fe_degree == 6)
251 do_prolongate_add<6>(to_level, dst_vec, src_vec);
252 else if (fe_degree == 7)
253 do_prolongate_add<7>(to_level, dst_vec, src_vec);
254 else if (fe_degree == 8)
255 do_prolongate_add<8>(to_level, dst_vec, src_vec);
256 else if (fe_degree == 9)
257 do_prolongate_add<9>(to_level, dst_vec, src_vec);
258 else if (fe_degree == 10)
259 do_prolongate_add<10>(to_level, dst_vec, src_vec);
261 do_prolongate_add<-1>(to_level, dst_vec, src_vec);
264 if (dst_inplace ==
false)
267 if (src_inplace ==
true)
273template <
int dim,
typename Number>
276 const unsigned int from_level,
280 Assert((from_level >= 1) && (from_level <= level_dof_indices.size()),
283 const bool src_inplace =
284 src.
get_partitioner().get() == this->vector_partitioners[from_level].get();
285 if (src_inplace ==
false)
287 if (this->ghosted_level_vector[from_level].get_partitioner().get() !=
288 this->vector_partitioners[from_level].get())
289 this->ghosted_level_vector[from_level].reinit(
290 this->vector_partitioners[from_level]);
291 this->ghosted_level_vector[from_level].copy_locally_owned_data_from(src);
295 this->vector_partitioners[from_level - 1].get();
296 if (dst_inplace ==
false)
298 if (this->ghosted_level_vector[from_level - 1].get_partitioner().get() !=
299 this->vector_partitioners[from_level - 1].get())
300 this->ghosted_level_vector[from_level - 1].reinit(
301 this->vector_partitioners[from_level - 1]);
303 this->ghosted_level_vector[from_level - 1].locally_owned_size(),
305 this->ghosted_level_vector[from_level - 1] = 0.;
309 src_inplace ? src : this->ghosted_level_vector[from_level];
311 dst_inplace ? dst : this->ghosted_level_vector[from_level - 1];
316 do_restrict_add<0>(from_level, dst_vec, src_vec);
317 else if (fe_degree == 1)
318 do_restrict_add<1>(from_level, dst_vec, src_vec);
319 else if (fe_degree == 2)
320 do_restrict_add<2>(from_level, dst_vec, src_vec);
321 else if (fe_degree == 3)
322 do_restrict_add<3>(from_level, dst_vec, src_vec);
323 else if (fe_degree == 4)
324 do_restrict_add<4>(from_level, dst_vec, src_vec);
325 else if (fe_degree == 5)
326 do_restrict_add<5>(from_level, dst_vec, src_vec);
327 else if (fe_degree == 6)
328 do_restrict_add<6>(from_level, dst_vec, src_vec);
329 else if (fe_degree == 7)
330 do_restrict_add<7>(from_level, dst_vec, src_vec);
331 else if (fe_degree == 8)
332 do_restrict_add<8>(from_level, dst_vec, src_vec);
333 else if (fe_degree == 9)
334 do_restrict_add<9>(from_level, dst_vec, src_vec);
335 else if (fe_degree == 10)
336 do_restrict_add<10>(from_level, dst_vec, src_vec);
339 do_restrict_add<-1>(from_level, dst_vec, src_vec);
342 if (dst_inplace ==
false)
345 if (src_inplace ==
true)
353 template <
int dim,
int degree,
typename Number>
356 const unsigned int n_components,
357 const unsigned int fe_degree,
362 const int loop_length = degree != -1 ? 2 * degree + 1 : 2 * fe_degree + 1;
363 unsigned int degree_to_3[100];
365 for (
int i = 1; i < loop_length - 1; ++i)
367 degree_to_3[loop_length - 1] = 2;
368 for (
unsigned int c = 0; c < n_components; ++c)
369 for (
int k = 0; k < (dim > 2 ? loop_length : 1); ++k)
370 for (
int j = 0; j < (dim > 1 ? loop_length : 1); ++j)
372 const unsigned int shift = 9 * degree_to_3[k] + 3 * degree_to_3[j];
373 data[0] *= weights[
shift];
376 for (
int i = 1; i < loop_length - 1; ++i)
377 data[i] *= weights[
shift + 1];
378 data[loop_length - 1] *= weights[
shift + 2];
386template <
int dim,
typename Number>
390 const unsigned int to_level,
395 const unsigned int degree_size = (degree > -1 ? degree : fe_degree) + 1;
396 const unsigned int n_child_dofs_1d = 2 * degree_size - element_is_continuous;
397 const unsigned int n_scalar_cell_dofs =
398 Utilities::fixed_power<dim>(n_child_dofs_1d);
406 if (this->mg_constrained_dofs !=
nullptr &&
407 this->mg_constrained_dofs->get_user_constraint_matrix(to_level - 1)
414 this->mg_constrained_dofs->get_user_constraint_matrix(to_level - 1)
415 .distribute(copy_src);
425 for (
unsigned int cell = 0; cell < n_owned_level_cells[to_level - 1];
428 const unsigned int n_lanes =
429 (cell + vec_size > n_owned_level_cells[to_level - 1]) ?
430 (n_owned_level_cells[to_level - 1] - cell) :
434 for (
unsigned int v = 0; v < n_lanes; ++v)
436 const unsigned int shift =
437 internal::MGTransfer::compute_shift_within_children<dim>(
438 parent_child_connect[to_level - 1][cell + v].
second,
439 fe_degree + 1 - element_is_continuous,
441 const unsigned int *indices =
442 &level_dof_indices[to_level - 1]
443 [parent_child_connect[to_level - 1][cell + v]
447 for (
unsigned int c = 0, m = 0; c < n_components; ++c)
449 for (
unsigned int k = 0; k < (dim > 2 ? degree_size : 1); ++k)
450 for (
unsigned int j = 0; j < (dim > 1 ? degree_size : 1); ++j)
451 for (
unsigned int i = 0; i < degree_size; ++i, ++m)
453 indices[c * n_scalar_cell_dofs +
454 k * n_child_dofs_1d * n_child_dofs_1d +
455 j * n_child_dofs_1d + i]);
458 for (std::vector<unsigned short>::const_iterator i =
459 dirichlet_indices[to_level - 1][cell + v].
begin();
460 i != dirichlet_indices[to_level - 1][cell + v].end();
462 evaluation_data[*i][v] = 0.;
467 degree_size * n_child_dofs_1d);
469 if (element_is_continuous)
473 for (
int c = n_components - 1; c >= 0; --c)
482 prolongation_matrix_1d,
483 evaluation_data.begin() +
486 evaluation_data.begin() +
487 c * n_scalar_cell_dofs,
490 weight_dofs_on_child<dim, degree, Number>(
491 &weights_on_refined[to_level - 1][(cell / vec_size) * three_to_dim],
494 evaluation_data.begin());
498 for (
int c = n_components - 1; c >= 0; --c)
507 prolongation_matrix_1d,
508 evaluation_data.begin() +
511 evaluation_data.begin() +
512 c * n_scalar_cell_dofs,
518 const unsigned int *indices =
519 &level_dof_indices[to_level][cell * n_child_cell_dofs];
520 for (
unsigned int v = 0; v < n_lanes; ++v)
522 for (
unsigned int i = 0; i < n_child_cell_dofs; ++i)
524 indices += n_child_cell_dofs;
531template <
int dim,
typename Number>
535 const unsigned int from_level,
540 const unsigned int degree_size = (degree > -1 ? degree : fe_degree) + 1;
541 const unsigned int n_child_dofs_1d = 2 * degree_size - element_is_continuous;
542 const unsigned int n_scalar_cell_dofs =
543 Utilities::fixed_power<dim>(n_child_dofs_1d);
546 for (
unsigned int cell = 0; cell < n_owned_level_cells[from_level - 1];
549 const unsigned int n_lanes =
550 (cell + vec_size > n_owned_level_cells[from_level - 1]) ?
551 (n_owned_level_cells[from_level - 1] - cell) :
556 const unsigned int *indices =
557 &level_dof_indices[from_level][cell * n_child_cell_dofs];
558 for (
unsigned int v = 0; v < n_lanes; ++v)
560 for (
unsigned int i = 0; i < n_child_cell_dofs; ++i)
562 indices += n_child_cell_dofs;
567 degree_size * n_child_dofs_1d);
569 if (element_is_continuous)
571 weight_dofs_on_child<dim, degree, Number>(
572 &weights_on_refined[from_level - 1]
573 [(cell / vec_size) * three_to_dim],
576 evaluation_data.data());
577 for (
unsigned int c = 0; c < n_components; ++c)
586 prolongation_matrix_1d,
588 evaluation_data.begin() +
589 c * n_scalar_cell_dofs,
590 evaluation_data.begin() +
599 for (
unsigned int c = 0; c < n_components; ++c)
608 prolongation_matrix_1d,
610 evaluation_data.begin() +
611 c * n_scalar_cell_dofs,
612 evaluation_data.begin() +
621 for (
unsigned int v = 0; v < n_lanes; ++v)
623 const unsigned int shift =
624 internal::MGTransfer::compute_shift_within_children<dim>(
625 parent_child_connect[from_level - 1][cell + v].
second,
626 fe_degree + 1 - element_is_continuous,
629 parent_child_connect[from_level - 1][cell + v].
first *
631 n_child_cell_dofs - 1,
632 level_dof_indices[from_level - 1].size());
633 const unsigned int *indices =
634 &level_dof_indices[from_level - 1]
635 [parent_child_connect[from_level - 1][cell + v]
639 for (
unsigned int c = 0, m = 0; c < n_components; ++c)
642 for (std::vector<unsigned short>::const_iterator i =
643 dirichlet_indices[from_level - 1][cell + v].
begin();
644 i != dirichlet_indices[from_level - 1][cell + v].end();
646 evaluation_data[*i][v] = 0.;
648 for (
unsigned int k = 0; k < (dim > 2 ? degree_size : 1); ++k)
649 for (
unsigned int j = 0; j < (dim > 1 ? degree_size : 1); ++j)
650 for (
unsigned int i = 0; i < degree_size; ++i, ++m)
652 indices[c * n_scalar_cell_dofs +
653 k * n_child_dofs_1d * n_child_dofs_1d +
654 j * n_child_dofs_1d + i]) +=
655 evaluation_data[m][v];
663template <
int dim,
typename Number>
681template <
int dim,
typename Number>
691template <
int dim,
typename Number>
693 const std::vector<MGConstrainedDoFs> &mg_c)
694 : same_for_all(false)
696 for (
const auto &constrained_block_dofs : mg_c)
702template <
int dim,
typename Number>
708 ExcMessage(
"This object was initialized with support for usage with "
709 "one DoFHandler for each block, but this method assumes "
710 "that the same DoFHandler is used for all the blocks!"));
713 matrix_free_transfer_vector[0].initialize_constraints(mg_c);
718template <
int dim,
typename Number>
721 const std::vector<MGConstrainedDoFs> &mg_c)
724 ExcMessage(
"This object was initialized with support for using "
725 "the same DoFHandler for all the blocks, but this "
726 "method assumes that there is a separate DoFHandler "
730 for (
unsigned int i = 0; i < mg_c.size(); ++i)
731 matrix_free_transfer_vector[i].initialize_constraints(mg_c[i]);
736template <
int dim,
typename Number>
740 matrix_free_transfer_vector.clear();
745template <
int dim,
typename Number>
751 matrix_free_transfer_vector[0].build(dof_handler);
756template <
int dim,
typename Number>
761 AssertDimension(matrix_free_transfer_vector.size(), dof_handler.size());
762 for (
unsigned int i = 0; i < dof_handler.size(); ++i)
763 matrix_free_transfer_vector[i].build(*dof_handler[i]);
768template <
int dim,
typename Number>
771 const unsigned int to_level,
783 const unsigned int data_block = same_for_all ? 0 :
b;
784 matrix_free_transfer_vector[data_block].prolongate(to_level,
792template <
int dim,
typename Number>
795 const unsigned int to_level,
807 const unsigned int data_block = same_for_all ? 0 :
b;
808 matrix_free_transfer_vector[data_block].prolongate_and_add(to_level,
816template <
int dim,
typename Number>
819 const unsigned int from_level,
831 const unsigned int data_block = same_for_all ? 0 :
b;
832 matrix_free_transfer_vector[data_block].restrict_and_add(from_level,
840template <
int dim,
typename Number>
844 std::size_t total_memory_consumption = 0;
845 for (
const auto &el : matrix_free_transfer_vector)
846 total_memory_consumption += el.memory_consumption();
847 return total_memory_consumption;
853#include "mg_transfer_matrix_free.inst"
const Triangulation< dim, spacedim > & get_triangulation() const
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< LinearAlgebra::distributed::Vector< Number > > > mg_constrained_dofs
std::vector< MGTransferMatrixFree< dim, Number > > matrix_free_transfer_vector
virtual void prolongate_and_add(const unsigned int to_level, LinearAlgebra::distributed::BlockVector< Number > &dst, const LinearAlgebra::distributed::BlockVector< Number > &src) const override
virtual void restrict_and_add(const unsigned int from_level, LinearAlgebra::distributed::BlockVector< Number > &dst, const LinearAlgebra::distributed::BlockVector< Number > &src) const override
virtual void prolongate(const unsigned int to_level, LinearAlgebra::distributed::BlockVector< Number > &dst, const LinearAlgebra::distributed::BlockVector< Number > &src) const override
std::size_t memory_consumption() const
MGTransferBlockMatrixFree()=default
void build(const DoFHandler< dim, dim > &dof_handler)
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
void do_restrict_add(const unsigned int from_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
void do_prolongate_add(const unsigned int to_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
virtual void prolongate(const unsigned int to_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
void build(const DoFHandler< dim, dim > &dof_handler, const std::vector< std::shared_ptr< const Utilities::MPI::Partitioner > > &external_partitioners=std::vector< std::shared_ptr< const Utilities::MPI::Partitioner > >())
virtual void prolongate_and_add(const unsigned int to_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
std::size_t memory_consumption() const
virtual void restrict_and_add(const unsigned int from_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
virtual unsigned int n_global_levels() const
static constexpr std::size_t size()
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
unsigned int n_blocks() const
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
BlockType & block(const unsigned int i)
static ::ExceptionBase & ExcMessage(std::string arg1)
void zero_out_ghost_values() const
Number local_element(const size_type local_index) const
void update_ghost_values() const
size_type locally_owned_size() const
virtual void compress(::VectorOperation::values operation) override
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
void reinit(const size_type size, const bool omit_zeroing_entries=false)
std::enable_if< IsBlockVector< VectorType >::value, unsignedint >::type n_blocks(const VectorType &vector)
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
VectorType::value_type * begin(VectorType &V)
constexpr T pow(const T base, const int iexp)
std::vector< Number > prolongation_matrix_1d
unsigned int n_child_cell_dofs
bool element_is_continuous
unsigned int n_components