From 52200ee1b3cfc57ad9495efdb91d5e1a86514f5c Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Thu, 22 Sep 2022 10:24:40 +0200 Subject: [PATCH] Clean up weight_fe_q_dofs_by_entity --- .../matrix_free/tensor_product_kernels.h | 49 ++++++++++--------- .../mg_transfer_global_coarsening.templates.h | 22 +++++---- source/multigrid/mg_transfer_matrix_free.cc | 19 +++---- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/include/deal.II/matrix_free/tensor_product_kernels.h b/include/deal.II/matrix_free/tensor_product_kernels.h index 88b0a8b2d5..32cd53edb2 100644 --- a/include/deal.II/matrix_free/tensor_product_kernels.h +++ b/include/deal.II/matrix_free/tensor_product_kernels.h @@ -3324,36 +3324,39 @@ namespace internal } - template + template inline void - weight_fe_q_dofs_by_entity(const VectorizedArray *weights, - const unsigned int n_components, - const int loop_length_non_template, - VectorizedArray *data) + weight_fe_q_dofs_by_entity(const Number * weights, + const unsigned int n_components, + const int n_points_1d_non_template, + Number * data) { - const int loop_length = loop_length_template != -1 ? - loop_length_template : - loop_length_non_template; - - Assert(loop_length > 0, ExcNotImplemented()); - Assert(loop_length < 100, ExcNotImplemented()); - unsigned int degree_to_3[100]; - degree_to_3[0] = 0; - for (int i = 1; i < loop_length - 1; ++i) - degree_to_3[i] = 1; - degree_to_3[loop_length - 1] = 2; + const int n_points_1d = n_points_1d_template != -1 ? + n_points_1d_template : + n_points_1d_non_template; + + Assert(n_points_1d > 0, ExcNotImplemented()); + Assert(n_points_1d < 100, ExcNotImplemented()); + + unsigned int compressed_index[100]; + compressed_index[0] = 0; + for (int i = 1; i < n_points_1d - 1; ++i) + compressed_index[i] = 1; + compressed_index[n_points_1d - 1] = 2; + for (unsigned int c = 0; c < n_components; ++c) - for (int k = 0; k < (dim > 2 ? loop_length : 1); ++k) - for (int j = 0; j < (dim > 1 ? loop_length : 1); ++j) + for (int k = 0; k < (dim > 2 ? n_points_1d : 1); ++k) + for (int j = 0; j < (dim > 1 ? n_points_1d : 1); ++j) { - const unsigned int shift = 9 * degree_to_3[k] + 3 * degree_to_3[j]; + const unsigned int shift = + 9 * compressed_index[k] + 3 * compressed_index[j]; data[0] *= weights[shift]; - // loop bound as int avoids compiler warnings in case loop_length + // loop bound as int avoids compiler warnings in case n_points_1d // == 1 (polynomial degree 0) - for (int i = 1; i < loop_length - 1; ++i) + for (int i = 1; i < n_points_1d - 1; ++i) data[i] *= weights[shift + 1]; - data[loop_length - 1] *= weights[shift + 2]; - data += loop_length; + data[n_points_1d - 1] *= weights[shift + 2]; + data += n_points_1d; } } diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index 08de0842e9..ce52dda65c 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -2590,11 +2590,12 @@ MGTwoLevelTransfer>:: // weight and write into dst vector if (fine_element_is_continuous && this->weights_compressed.size() > 0) { - internal::weight_fe_q_dofs_by_entity( - weights_compressed, - n_components, - scheme.degree_fine + 1, - evaluation_data_fine.begin()); + internal:: + weight_fe_q_dofs_by_entity>( + weights_compressed, + n_components, + scheme.degree_fine + 1, + evaluation_data_fine.begin()); weights_compressed += Utilities::pow(3, dim); } @@ -2725,11 +2726,12 @@ MGTwoLevelTransfer>:: if (fine_element_is_continuous && this->weights_compressed.size() > 0) { - internal::weight_fe_q_dofs_by_entity( - weights_compressed, - n_components, - scheme.degree_fine + 1, - evaluation_data_fine.begin()); + internal:: + weight_fe_q_dofs_by_entity>( + weights_compressed, + n_components, + scheme.degree_fine + 1, + evaluation_data_fine.begin()); weights_compressed += Utilities::pow(3, dim); } diff --git a/source/multigrid/mg_transfer_matrix_free.cc b/source/multigrid/mg_transfer_matrix_free.cc index 6db4b3638b..a131d8846b 100644 --- a/source/multigrid/mg_transfer_matrix_free.cc +++ b/source/multigrid/mg_transfer_matrix_free.cc @@ -511,7 +511,7 @@ MGTransferMatrixFree::do_prolongate_add( internal::weight_fe_q_dofs_by_entity( + VectorizedArray>( &weights_on_refined[to_level - 1][(cell / vec_size) * three_to_dim], n_components, 2 * fe_degree + 1, @@ -592,14 +592,15 @@ MGTransferMatrixFree::do_restrict_add( // perform tensorized operation if (element_is_continuous) { - internal::weight_fe_q_dofs_by_entity< - dim, - degree != -1 ? 2 * degree + 1 : -1, - Number>(&weights_on_refined[from_level - 1] - [(cell / vec_size) * three_to_dim], - n_components, - 2 * fe_degree + 1, - evaluation_data.data()); + internal::weight_fe_q_dofs_by_entity>( + &weights_on_refined[from_level - 1] + [(cell / vec_size) * three_to_dim], + n_components, + 2 * fe_degree + 1, + evaluation_data.data()); for (unsigned int c = 0; c < n_components; ++c) internal::FEEvaluationImplBasisChange< internal::evaluate_general, -- 2.39.5