deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
polynomials_hermite.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2023 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#include <deal.II/base/config.h>
14
19
20#include <Kokkos_Macros.hpp>
21
23
24namespace Polynomials
25{
26 namespace
27 {
28 std::vector<double>
29 hermite_poly_coeffs(const unsigned int regularity, const unsigned int index)
30 {
31 AssertIndexRange(index, 2 * regularity + 2);
32
33 const unsigned int curr_index = index % (regularity + 1);
34 const unsigned int side = (index > regularity) ? 1 : 0;
35
36 // Signed ints are used here to protect against underflow errors
37 const int loop_control_1 = static_cast<int>(regularity + 1 - curr_index);
38 const int loop_control_2 = (side == 1) ?
39 static_cast<int>(curr_index + 1) :
40 static_cast<int>(regularity + 2);
41
42 std::vector<double> poly_coeffs(2 * regularity + 2, 0.0);
43
44 if (side == 1) // right side: g polynomials
45 {
46 int binomial_1 = (curr_index % 2) ? -1 : 1;
47
48 for (int i = 0; i < loop_control_2; ++i)
49 {
50 int inv_binomial = 1;
51
52 for (int j = 0; j < loop_control_1; ++j)
53 {
54 int binomial_2 = 1;
55
56 for (int k = 0; k < j + 1; ++k)
57 {
58 poly_coeffs[regularity + i + k + 1] +=
59 binomial_1 * inv_binomial * binomial_2;
60 binomial_2 *= k - j;
61 binomial_2 /= k + 1;
62 }
63 inv_binomial *= regularity + j + 1;
64 inv_binomial /= j + 1;
65 }
66 // ints used here to protect against underflow errors
67 binomial_1 *= -static_cast<int>(curr_index - i);
68 binomial_1 /= i + 1;
69 }
70 }
71 else // left side: f polynomials
72 {
73 int binomial = 1;
74
75 for (int i = 0; i < loop_control_2; ++i)
76 {
77 int inv_binomial = 1;
78
79 for (int j = 0; j < loop_control_1; ++j)
80 {
81 poly_coeffs[curr_index + i + j] += binomial * inv_binomial;
82 inv_binomial *= regularity + j + 1;
83 inv_binomial /= j + 1;
84 }
85 // Protection needed here against underflow errors
86 binomial *= -static_cast<int>(regularity + 1 - i);
87 binomial /= i + 1;
88 }
89 }
90
91 // rescale coefficients by a factor of 4^curr_index to account for reduced
92 // L2-norms
93 double precond_factor = Utilities::pow(4, curr_index);
94 for (auto &it : poly_coeffs)
95 it *= precond_factor;
96
97 return poly_coeffs;
98 }
99 } // namespace
100
101
102
103 PolynomialsHermite::PolynomialsHermite(const unsigned int regularity,
104 const unsigned int index)
105 : Polynomial<double>(hermite_poly_coeffs(regularity, index))
106 , degree(2 * regularity + 1)
107 , regularity(regularity)
108 , side_index(index % (regularity + 1))
109 , side((index >= regularity + 1) ? 1 : 0)
110 {
111 AssertIndexRange(index, 2 * (regularity + 1));
112 }
113
114
115
116 std::vector<Polynomial<double>>
117 PolynomialsHermite::generate_complete_basis(const unsigned int regularity)
118 {
119 std::vector<Polynomial<double>> polys;
120 const unsigned int sz = 2 * regularity + 2;
121 polys.reserve(sz);
122
123 for (unsigned int i = 0; i < sz; ++i)
124 polys.emplace_back(PolynomialsHermite(regularity, i));
125
126 return polys;
127 }
128} // namespace Polynomials
129
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int regularity)
PolynomialsHermite(const unsigned int regularity, const unsigned int index)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertIndexRange(index, range)
constexpr T pow(const T base, const int iexp)
Definition utilities.h:966