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
tensor_product_polynomials_const.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) 2013 - 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
14#include <deal.II/base/config.h>
15
19#include <deal.II/base/tensor.h>
22
23#include <Kokkos_Macros.hpp>
24
25#include <array>
26#include <memory>
27#include <ostream>
28#include <vector>
29
31
32
33
34/* ------------------- TensorProductPolynomialsConst -------------- */
35
36
37
38template <int dim>
39void
41{
42 std::array<unsigned int, dim> ix;
43 for (unsigned int i = 0; i < tensor_polys.n(); ++i)
44 {
45 tensor_polys.compute_index(i, ix);
46 out << i << "\t";
47 for (unsigned int d = 0; d < dim; ++d)
48 out << ix[d] << " ";
49 out << std::endl;
50 }
51}
52
53
54
55template <int dim>
56void
58 const std::vector<unsigned int> &renumber)
59{
60 Assert(renumber.size() == index_map.size(),
61 ExcDimensionMismatch(renumber.size(), index_map.size()));
62
63 index_map = renumber;
64 for (unsigned int i = 0; i < index_map.size(); ++i)
65 index_map_inverse[index_map[i]] = i;
66
67 std::vector<unsigned int> renumber_base;
68 renumber_base.reserve(tensor_polys.n());
69 for (unsigned int i = 0; i < tensor_polys.n(); ++i)
70 renumber_base.push_back(renumber[i]);
71
72 tensor_polys.set_numbering(renumber_base);
73}
74
75
76template <int dim>
77double
79 const Point<dim> &p) const
80{
81 const unsigned int max_indices = tensor_polys.n();
82 Assert(i <= max_indices, ExcInternalError());
83
84 // treat the regular basis functions
85 if (i < max_indices)
86 return tensor_polys.compute_value(i, p);
87 else
88 // this is for the constant function
89 return 1.;
90}
91
92
93
94template <int dim>
97 const Point<dim> &p) const
98{
99 if constexpr (dim == 0)
100 {
101 (void)i;
102 (void)p;
104 return {};
105 }
106 else
107 {
108 const unsigned int max_indices = tensor_polys.n();
109 Assert(i <= max_indices, ExcInternalError());
110
111 // treat the regular basis functions
112 if (i < max_indices)
113 return tensor_polys.compute_grad(i, p);
114 else
115 // this is for the constant function
116 return Tensor<1, dim>();
117 }
118}
119
120template <int dim>
123 const Point<dim> &p) const
124{
125 const unsigned int max_indices = tensor_polys.n();
126 Assert(i <= max_indices, ExcInternalError());
127
128 // treat the regular basis functions
129 if (i < max_indices)
130 return tensor_polys.compute_grad_grad(i, p);
131 else
132 // this is for the constant function
133 return Tensor<2, dim>();
134}
135
136template <int dim>
137void
139 const Point<dim> &p,
140 std::vector<double> &values,
141 std::vector<Tensor<1, dim>> &grads,
142 std::vector<Tensor<2, dim>> &grad_grads,
143 std::vector<Tensor<3, dim>> &third_derivatives,
144 std::vector<Tensor<4, dim>> &fourth_derivatives) const
145{
146 Assert(values.size() == tensor_polys.n() + 1 || values.empty(),
147 ExcDimensionMismatch2(values.size(), tensor_polys.n() + 1, 0));
148 Assert(grads.size() == tensor_polys.n() + 1 || grads.empty(),
149 ExcDimensionMismatch2(grads.size(), tensor_polys.n() + 1, 0));
150 Assert(grad_grads.size() == tensor_polys.n() + 1 || grad_grads.empty(),
151 ExcDimensionMismatch2(grad_grads.size(), tensor_polys.n() + 1, 0));
152 Assert(third_derivatives.size() == tensor_polys.n() + 1 ||
153 third_derivatives.empty(),
154 ExcDimensionMismatch2(third_derivatives.size(),
155 tensor_polys.n() + 1,
156 0));
157 Assert(fourth_derivatives.size() == tensor_polys.n() + 1 ||
158 fourth_derivatives.empty(),
159 ExcDimensionMismatch2(fourth_derivatives.size(),
160 tensor_polys.n() + 1,
161 0));
162
163 // remove slot for const value, go into the base class compute method and
164 // finally append the const value again
165 bool do_values = false, do_grads = false, do_grad_grads = false;
166 bool do_3rd_derivatives = false, do_4th_derivatives = false;
167 if (values.empty() == false)
168 {
169 values.pop_back();
170 do_values = true;
171 }
172 if (grads.empty() == false)
173 {
174 grads.pop_back();
175 do_grads = true;
176 }
177 if (grad_grads.empty() == false)
178 {
179 grad_grads.pop_back();
180 do_grad_grads = true;
181 }
182 if (third_derivatives.empty() == false)
183 {
184 third_derivatives.resize(tensor_polys.n());
185 do_3rd_derivatives = true;
186 }
187 if (fourth_derivatives.empty() == false)
188 {
189 fourth_derivatives.resize(tensor_polys.n());
190 do_4th_derivatives = true;
191 }
192
193 tensor_polys.evaluate(
194 p, values, grads, grad_grads, third_derivatives, fourth_derivatives);
195
196 // for dgq node: values =1, grads=0, grads_grads=0, third_derivatives=0,
197 // fourth_derivatives=0
198 if (do_values)
199 values.push_back(1.);
200 if (do_grads)
201 grads.emplace_back();
202 if (do_grad_grads)
203 grad_grads.emplace_back();
204 if (do_3rd_derivatives)
205 third_derivatives.emplace_back();
206 if (do_4th_derivatives)
207 fourth_derivatives.emplace_back();
208}
209
210
211
212template <int dim>
213std::unique_ptr<ScalarPolynomialsBase<dim>>
215{
216 return std::make_unique<TensorProductPolynomialsConst<dim>>(*this);
217}
218
219
220/* ------------------- explicit instantiations -------------- */
224
Definition point.h:111
double compute_value(const unsigned int i, const Point< dim > &p) const override
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const override
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() const override
void set_numbering(const std::vector< unsigned int > &renumber)
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const override
void evaluate(const Point< dim > &unit_point, std::vector< double > &values, std::vector< Tensor< 1, dim > > &grads, std::vector< Tensor< 2, dim > > &grad_grads, std::vector< Tensor< 3, dim > > &third_derivatives, std::vector< Tensor< 4, dim > > &fourth_derivatives) const override
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch2(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)