| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
|
| 16 |
#ifndef dealii_matrix_free_evaluation_kernels_common_h |
| 17 |
#define dealii_matrix_free_evaluation_kernels_common_h |
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/utilities.h> |
| 22 |
|
| 23 |
#include <deal.II/matrix_free/fe_evaluation_data.h> |
| 24 |
|
| 25 |
|
| 26 |
DEAL_II_NAMESPACE_OPEN |
| 27 |
|
| 28 |
|
| 29 |
namespace internal |
| 30 |
{ |
| 31 |
template <int dim, int fe_degree, typename Number, bool is_face> |
| 32 |
inline void |
| 33 |
embed_truncated_into_full_tensor_product( |
| 34 |
const unsigned int n_components, |
| 35 |
Number *values_dofs, |
| 36 |
const Number *values_dofs_actual, |
| 37 |
FEEvaluationData<dim, Number, is_face> &fe_eval) |
| 38 |
{ |
| 39 |
const auto &shape_info = fe_eval.get_shape_info(); |
| 40 |
const auto &shape_data = shape_info.data.front(); |
| 41 |
|
| 42 |
const std::size_t dofs_per_comp = |
| 43 |
Utilities::pow(shape_data.fe_degree + 1, dim); |
| 44 |
const std::size_t n_dofs_per_comp = shape_info.dofs_per_component_on_cell; |
| 45 |
const int degree = fe_degree != -1 ? fe_degree : shape_data.fe_degree; |
| 46 |
|
| 47 |
for (unsigned int c = 0; c < n_components; ++c) |
| 48 |
for (int i = 0, count_p = 0, count_q = 0; i < (dim > 2 ? degree + 1 : 1); |
| 49 |
++i) |
| 50 |
{ |
| 51 |
for (int j = 0; j < (dim > 1 ? degree + 1 - i : 1); ++j) |
| 52 |
{ |
| 53 |
for (int k = 0; k < degree + 1 - j - i; ++k, ++count_p, ++count_q) |
| 54 |
values_dofs[c * dofs_per_comp + count_q] = |
| 55 |
values_dofs_actual[c * n_dofs_per_comp + count_p]; |
| 56 |
for (int k = degree + 1 - j - i; k < degree + 1; ++k, ++count_q) |
| 57 |
values_dofs[c * dofs_per_comp + count_q] = Number(); |
| 58 |
} |
| 59 |
for (int j = degree + 1 - i; j < degree + 1; ++j) |
| 60 |
for (int k = 0; k < degree + 1; ++k, ++count_q) |
| 61 |
values_dofs[c * dofs_per_comp + count_q] = Number(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
template <int dim, int fe_degree, typename Number, bool is_face> |
| 68 |
inline void |
| 69 |
truncate_tensor_product_to_complete_degrees( |
| 70 |
const unsigned int n_components, |
| 71 |
Number *values_dofs_actual, |
| 72 |
const Number *values_dofs, |
| 73 |
FEEvaluationData<dim, Number, is_face> &fe_eval) |
| 74 |
{ |
| 75 |
const auto &shape_info = fe_eval.get_shape_info(); |
| 76 |
const auto &shape_data = shape_info.data.front(); |
| 77 |
|
| 78 |
const unsigned int dofs_per_comp = |
| 79 |
Utilities::fixed_power<dim>(shape_data.fe_degree + 1); |
| 80 |
const std::size_t n_dofs_per_comp = shape_info.dofs_per_component_on_cell; |
| 81 |
const int degree = fe_degree != -1 ? fe_degree : shape_data.fe_degree; |
| 82 |
for (unsigned int c = 0; c < n_components; ++c) |
| 83 |
for (int i = 0, count_p = 0, count_q = 0; i < (dim > 2 ? degree + 1 : 1); |
| 84 |
++i) |
| 85 |
{ |
| 86 |
for (int j = 0; j < (dim > 1 ? degree + 1 - i : 1); ++j) |
| 87 |
{ |
| 88 |
for (int k = 0; k < degree + 1 - j - i; ++k, ++count_p, ++count_q) |
| 89 |
values_dofs_actual[c * n_dofs_per_comp + count_p] = |
| 90 |
values_dofs[c * dofs_per_comp + count_q]; |
| 91 |
count_q += j + i; |
| 92 |
} |
| 93 |
count_q += i * (degree + 1); |
| 94 |
} |
| 95 |
} |
| 96 |
} // end of namespace internal |
| 97 |
|
| 98 |
|
| 99 |
DEAL_II_NAMESPACE_CLOSE |
| 100 |
|
| 101 |
#endif |