Debian Codegraph @

include/deal.II/base/tensor_product_polynomials_const.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2013 - 2023 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 #ifndef dealii_tensor_product_polynomials_const_h
16 #define dealii_tensor_product_polynomials_const_h
17
18
19 #include <deal.II/base/config.h>
20
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/point.h>
23 #include <deal.II/base/polynomial.h>
24 #include <deal.II/base/tensor.h>
25 #include <deal.II/base/tensor_product_polynomials.h>
26 #include <deal.II/base/utilities.h>
27
28 #include <vector>
29
30 DEAL_II_NAMESPACE_OPEN
31
32
33 /**
34 * @addtogroup Polynomials
35 * @{
36 */
37
38 /**
39 * Tensor product of given polynomials and a locally constant function. This
40 * class inherits most of its functionality from TensorProductPolynomials. It
41 * works similarly to that class but adds a constant function for the last
42 * index.
43 */
44 template <int dim>
45 class TensorProductPolynomialsConst : public ScalarPolynomialsBase<dim>
46 {
47 public:
48 /**
49 * Access to the dimension of this object, for checking and automatic
50 * setting of dimension in other classes.
51 */
52 static constexpr unsigned int dimension = dim;
53
54 /**
55 * Constructor. <tt>pols</tt> is a vector of objects that should be derived
56 * or otherwise convertible to one-dimensional polynomial objects. It will
57 * be copied element by element into a private variable.
58 */
59 template <class Pol>
60 TensorProductPolynomialsConst(const std::vector<Pol> &pols);
61
62 /**
63 * Print the list of <tt>tensor_polys</tt> indices to <tt>out</tt>.
64 */
65 void
66 output_indices(std::ostream &out) const;
67
68 /**
69 * Set the ordering of the polynomials. Requires
70 * <tt>renumber.size()==tensor_polys.n()</tt>. Stores a copy of
71 * <tt>renumber</tt>.
72 */
73 void
74 set_numbering(const std::vector<unsigned int> &renumber);
75
76 /**
77 * Give read access to the renumber vector.
78 */
79 const std::vector<unsigned int> &
80 get_numbering() const;
81
82 /**
83 * Give read access to the inverse renumber vector.
84 */
85 const std::vector<unsigned int> &
86 get_numbering_inverse() const;
87
88 /**
89 * Compute the value and the first and second derivatives of each tensor
90 * product polynomial at <tt>unit_point</tt>.
91 *
92 * The size of the vectors must either be equal 0 or equal n(). In the first
93 * case, the function will not compute these values.
94 *
95 * If you need values or derivatives of all tensor product polynomials then
96 * use this function, rather than using any of the compute_value(),
97 * compute_grad() or compute_grad_grad() functions, see below, in a loop
98 * over all tensor product polynomials.
99 */
100 void
101 evaluate(const Point<dim> &unit_point,
102 std::vector<double> &values,
103 std::vector<Tensor<1, dim>> &grads,
104 std::vector<Tensor<2, dim>> &grad_grads,
105 std::vector<Tensor<3, dim>> &third_derivatives,
106 std::vector<Tensor<4, dim>> &fourth_derivatives) const override;
107
108 /**
109 * Compute the value of the <tt>i</tt>th tensor product polynomial at
110 * <tt>unit_point</tt>. Here <tt>i</tt> is given in tensor product
111 * numbering.
112 *
113 * Note, that using this function within a loop over all tensor product
114 * polynomials is not efficient, because then each point value of the
115 * underlying (one-dimensional) polynomials is (unnecessarily) computed
116 * several times. Instead use the evaluate() function with
117 * <tt>values.size()==</tt>n() to get the point values of all tensor
118 * polynomials all at once and in a much more efficient way.
119 */
120 double
121 compute_value(const unsigned int i, const Point<dim> &p) const override;
122
123 /**
124 * Compute the <tt>order</tt>th derivative of the <tt>i</tt>th tensor
125 * product polynomial at <tt>unit_point</tt>. Here <tt>i</tt> is given in
126 * tensor product numbering.
127 *
128 * Note, that using this function within a loop over all tensor product
129 * polynomials is not efficient, because then each derivative value of the
130 * underlying (one-dimensional) polynomials is (unnecessarily) computed
131 * several times. Instead use the evaluate() function, see above, with the
132 * size of the appropriate parameter set to n() to get the point value of
133 * all tensor polynomials all at once and in a much more efficient way.
134 *
135 * @tparam order The derivative order.
136 */
137 template <int order>
138 Tensor<order, dim>
139 compute_derivative(const unsigned int i, const Point<dim> &p) const;
140
141 /**
142 * @copydoc ScalarPolynomialsBase::compute_1st_derivative()
143 */
144 virtual Tensor<1, dim>
145 compute_1st_derivative(const unsigned int i,
146 const Point<dim> &p) const override;
147
148 /**
149 * @copydoc ScalarPolynomialsBase::compute_2nd_derivative()
150 */
151 virtual Tensor<2, dim>
152 compute_2nd_derivative(const unsigned int i,
153 const Point<dim> &p) const override;
154
155 /**
156 * @copydoc ScalarPolynomialsBase::compute_3rd_derivative()
157 */
158 virtual Tensor<3, dim>
159 compute_3rd_derivative(const unsigned int i,
160 const Point<dim> &p) const override;
161
162 /**
163 * @copydoc ScalarPolynomialsBase::compute_4th_derivative()
164 */
165 virtual Tensor<4, dim>
166 compute_4th_derivative(const unsigned int i,
167 const Point<dim> &p) const override;
168
169 /**
170 * Compute the grad of the <tt>i</tt>th tensor product polynomial at
171 * <tt>unit_point</tt>. Here <tt>i</tt> is given in tensor product
172 * numbering.
173 *
174 * Note, that using this function within a loop over all tensor product
175 * polynomials is not efficient, because then each derivative value of the
176 * underlying (one-dimensional) polynomials is (unnecessarily) computed
177 * several times. Instead use the evaluate() function, see above, with
178 * <tt>grads.size()==</tt>n() to get the point value of all tensor
179 * polynomials all at once and in a much more efficient way.
180 */
181 Tensor<1, dim>
182 compute_grad(const unsigned int i, const Point<dim> &p) const override;
183
184 /**
185 * Compute the second derivative (grad_grad) of the <tt>i</tt>th tensor
186 * product polynomial at <tt>unit_point</tt>. Here <tt>i</tt> is given in
187 * tensor product numbering.
188 *
189 * Note, that using this function within a loop over all tensor product
190 * polynomials is not efficient, because then each derivative value of the
191 * underlying (one-dimensional) polynomials is (unnecessarily) computed
192 * several times. Instead use the evaluate() function, see above, with
193 * <tt>grad_grads.size()==</tt>n() to get the point value of all tensor
194 * polynomials all at once and in a much more efficient way.
195 */
196 Tensor<2, dim>
197 compute_grad_grad(const unsigned int i, const Point<dim> &p) const override;
198
199 /**
200 * Return the number of tensor product polynomials plus the constant
201 * function. For <i>n</i> 1d polynomials this is <i>n<sup>dim</sup>+1</i>.
202 */
203 unsigned int
204 n() const;
205
206 /**
207 * Return the name of the space, which is
208 * <tt>TensorProductPolynomialsConst</tt>.
209 */
210 std::string
211 name() const override;
212
213 /**
214 * @copydoc ScalarPolynomialsBase::clone()
215 */
216 virtual std::unique_ptr<ScalarPolynomialsBase<dim>>
217 clone() const override;
218
219 private:
220 /**
221 * The TensorProductPolynomials object
222 */
223 TensorProductPolynomials<dim> tensor_polys;
224
225 /**
226 * Index map for reordering the polynomials.
227 */
228 std::vector<unsigned int> index_map;
229
230 /**
231 * Index map for reordering the polynomials.
232 */
233 std::vector<unsigned int> index_map_inverse;
234 };
235
236 /** @} */
237
238
239 /* ---------------- template and inline functions ---------- */
240
241 #ifndef DOXYGEN
242
243 template <int dim>
244 template <class Pol>
245 inline TensorProductPolynomialsConst<dim>::TensorProductPolynomialsConst(
246 const std::vector<Pol> &pols)
247 : ScalarPolynomialsBase<dim>(1, Utilities::fixed_power<dim>(pols.size()) + 1)
248 , tensor_polys(pols)
249 , index_map(tensor_polys.n() + 1)
250 , index_map_inverse(tensor_polys.n() + 1)
251 {}
252
253
254
255 template <int dim>
256 inline unsigned int
257 TensorProductPolynomialsConst<dim>::n() const
258 {
259 return tensor_polys.n() + 1;
260 }
261
262
263
264 template <int dim>
265 inline const std::vector<unsigned int> &
266 TensorProductPolynomialsConst<dim>::get_numbering() const
267 {
268 return index_map;
269 }
270
271
272 template <int dim>
273 inline const std::vector<unsigned int> &
274 TensorProductPolynomialsConst<dim>::get_numbering_inverse() const
275 {
276 return index_map_inverse;
277 }
278
279
280 template <int dim>
281 inline std::string
282 TensorProductPolynomialsConst<dim>::name() const
283 {
284 return "TensorProductPolynomialsConst";
285 }
286
287
288 template <>
289 inline unsigned int
290 TensorProductPolynomialsConst<0>::n() const
291 {
292 return numbers::invalid_unsigned_int;
293 }
294
295
296 template <int dim>
297 template <int order>
298 Tensor<order, dim>
299 TensorProductPolynomialsConst<dim>::compute_derivative(
300 const unsigned int i,
301 const Point<dim> &p) const
302 {
303 const unsigned int max_indices = tensor_polys.n();
304 Assert(i <= max_indices, ExcInternalError());
305
306 // treat the regular basis functions
307 if (i < max_indices)
308 return tensor_polys.template compute_derivative<order>(i, p);
309 else
310 // this is for the constant function
311 return Tensor<order, dim>();
312 }
313
314
315
316 template <int dim>
317 inline Tensor<1, dim>
318 TensorProductPolynomialsConst<dim>::compute_1st_derivative(
319 const unsigned int i,
320 const Point<dim> &p) const
321 {
322 return compute_derivative<1>(i, p);
323 }
324
325
326
327 template <int dim>
328 inline Tensor<2, dim>
329 TensorProductPolynomialsConst<dim>::compute_2nd_derivative(
330 const unsigned int i,
331 const Point<dim> &p) const
332 {
333 return compute_derivative<2>(i, p);
334 }
335
336
337
338 template <int dim>
339 inline Tensor<3, dim>
340 TensorProductPolynomialsConst<dim>::compute_3rd_derivative(
341 const unsigned int i,
342 const Point<dim> &p) const
343 {
344 return compute_derivative<3>(i, p);
345 }
346
347
348
349 template <int dim>
350 inline Tensor<4, dim>
351 TensorProductPolynomialsConst<dim>::compute_4th_derivative(
352 const unsigned int i,
353 const Point<dim> &p) const
354 {
355 return compute_derivative<4>(i, p);
356 }
357
358 #endif // DOXYGEN
359 DEAL_II_NAMESPACE_CLOSE
360
361 #endif