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
polynomial_space.h
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) 2002 - 2024 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#ifndef dealii_polynomial_space_h
14#define dealii_polynomial_space_h
15
16
17#include <deal.II/base/config.h>
18
22#include <deal.II/base/point.h>
25#include <deal.II/base/tensor.h>
26
27#include <vector>
28
30
94template <int dim>
96{
97public:
102 static constexpr unsigned int dimension = dim;
103
111 template <class Pol>
112 PolynomialSpace(const std::vector<Pol> &pols);
113
117 template <typename StreamType>
118 void
119 output_indices(StreamType &out) const;
120
125 void
126 set_numbering(const std::vector<unsigned int> &renumber);
127
141 void
142 evaluate(const Point<dim> &unit_point,
143 std::vector<double> &values,
144 std::vector<Tensor<1, dim>> &grads,
145 std::vector<Tensor<2, dim>> &grad_grads,
146 std::vector<Tensor<3, dim>> &third_derivatives,
147 std::vector<Tensor<4, dim>> &fourth_derivatives) const override;
148
155 double
156 compute_value(const unsigned int i, const Point<dim> &p) const override;
157
166 template <int order>
168 compute_derivative(const unsigned int i, const Point<dim> &p) const;
169
173 virtual Tensor<1, dim>
174 compute_1st_derivative(const unsigned int i,
175 const Point<dim> &p) const override;
176
180 virtual Tensor<2, dim>
181 compute_2nd_derivative(const unsigned int i,
182 const Point<dim> &p) const override;
183
187 virtual Tensor<3, dim>
188 compute_3rd_derivative(const unsigned int i,
189 const Point<dim> &p) const override;
190
194 virtual Tensor<4, dim>
195 compute_4th_derivative(const unsigned int i,
196 const Point<dim> &p) const override;
197
205 compute_grad(const unsigned int i, const Point<dim> &p) const override;
206
214 compute_grad_grad(const unsigned int i, const Point<dim> &p) const override;
215
222 static unsigned int
223 n_polynomials(const unsigned int n);
224
228 std::string
229 name() const override;
230
234 virtual std::unique_ptr<ScalarPolynomialsBase<dim>>
235 clone() const override;
236
237protected:
246 std::array<unsigned int, dim>
247 compute_index(const unsigned int n) const;
248
249private:
253 const std::vector<Polynomials::Polynomial<double>> polynomials;
254
258 std::vector<unsigned int> index_map;
259
263 std::vector<unsigned int> index_map_inverse;
264};
265
266
267/* -------------- declaration of explicit specializations --- */
268
269template <>
270std::array<unsigned int, 1>
271PolynomialSpace<1>::compute_index(const unsigned int n) const;
272template <>
273std::array<unsigned int, 2>
274PolynomialSpace<2>::compute_index(const unsigned int n) const;
275template <>
276std::array<unsigned int, 3>
277PolynomialSpace<3>::compute_index(const unsigned int n) const;
278
279
280
281/* -------------- inline and template functions ------------- */
282
283template <int dim>
284template <class Pol>
285PolynomialSpace<dim>::PolynomialSpace(const std::vector<Pol> &pols)
286 : ScalarPolynomialsBase<dim>(pols.size(), n_polynomials(pols.size()))
287 , polynomials(pols.begin(), pols.end())
288 , index_map(n_polynomials(pols.size()))
289 , index_map_inverse(n_polynomials(pols.size()))
290{
291 // per default set this index map
292 // to identity. This map can be
293 // changed by the user through the
294 // set_numbering function
295 for (unsigned int i = 0; i < this->n(); ++i)
296 {
297 index_map[i] = i;
298 index_map_inverse[i] = i;
299 }
300}
301
302
303
304template <int dim>
305inline std::string
307{
308 return "PolynomialSpace";
309}
310
311
312template <int dim>
313template <typename StreamType>
314void
316{
317 for (unsigned int i = 0; i < this->n(); ++i)
318 {
319 const std::array<unsigned int, dim> ix = compute_index(i);
320 out << i << "\t";
321 for (unsigned int d = 0; d < dim; ++d)
322 out << ix[d] << ' ';
323 out << std::endl;
324 }
325}
326
327template <int dim>
328template <int order>
331 const Point<dim> &p) const
332{
333 const std::array<unsigned int, dim> indices = compute_index(i);
334
336 {
337 std::vector<double> tmp(order + 1);
338 for (unsigned int d = 0; d < dim; ++d)
339 {
340 polynomials[indices[d]].value(p[d], tmp);
341 for (unsigned int j = 0; j < order + 1; ++j)
342 v[d][j] = tmp[j];
343 }
344 }
345
346 if constexpr (order == 1)
347 {
348 Tensor<1, dim> derivative;
349 for (unsigned int d = 0; d < dim; ++d)
350 {
351 derivative[d] = 1.;
352 for (unsigned int x = 0; x < dim; ++x)
353 {
354 unsigned int x_order = 0;
355 if (d == x)
356 ++x_order;
357
358 derivative[d] *= v[x][x_order];
359 }
360 }
361
362 return derivative;
363 }
364 else if constexpr (order == 2)
365 {
366 Tensor<2, dim> derivative;
367 for (unsigned int d1 = 0; d1 < dim; ++d1)
368 for (unsigned int d2 = 0; d2 < dim; ++d2)
369 {
370 derivative[d1][d2] = 1.;
371 for (unsigned int x = 0; x < dim; ++x)
372 {
373 unsigned int x_order = 0;
374 if (d1 == x)
375 ++x_order;
376 if (d2 == x)
377 ++x_order;
378
379 derivative[d1][d2] *= v[x][x_order];
380 }
381 }
382
383 return derivative;
384 }
385 else if constexpr (order == 3)
386 {
387 Tensor<3, dim> derivative;
388 for (unsigned int d1 = 0; d1 < dim; ++d1)
389 for (unsigned int d2 = 0; d2 < dim; ++d2)
390 for (unsigned int d3 = 0; d3 < dim; ++d3)
391 {
392 derivative[d1][d2][d3] = 1.;
393 for (unsigned int x = 0; x < dim; ++x)
394 {
395 unsigned int x_order = 0;
396 if (d1 == x)
397 ++x_order;
398 if (d2 == x)
399 ++x_order;
400 if (d3 == x)
401 ++x_order;
402
403 derivative[d1][d2][d3] *= v[x][x_order];
404 }
405 }
406
407 return derivative;
408 }
409 else if constexpr (order == 4)
410 {
411 Tensor<4, dim> derivative;
412 for (unsigned int d1 = 0; d1 < dim; ++d1)
413 for (unsigned int d2 = 0; d2 < dim; ++d2)
414 for (unsigned int d3 = 0; d3 < dim; ++d3)
415 for (unsigned int d4 = 0; d4 < dim; ++d4)
416 {
417 derivative[d1][d2][d3][d4] = 1.;
418 for (unsigned int x = 0; x < dim; ++x)
419 {
420 unsigned int x_order = 0;
421 if (d1 == x)
422 ++x_order;
423 if (d2 == x)
424 ++x_order;
425 if (d3 == x)
426 ++x_order;
427 if (d4 == x)
428 ++x_order;
429
430 derivative[d1][d2][d3][d4] *= v[x][x_order];
431 }
432 }
433
434 return derivative;
435 }
436 else
437 {
439 return {};
440 }
441}
442
443
444
445template <int dim>
446inline Tensor<1, dim>
448 const Point<dim> &p) const
449{
450 return compute_derivative<1>(i, p);
451}
452
453
454
455template <int dim>
456inline Tensor<2, dim>
458 const Point<dim> &p) const
459{
460 return compute_derivative<2>(i, p);
461}
462
463
464
465template <int dim>
466inline Tensor<3, dim>
468 const Point<dim> &p) const
469{
470 return compute_derivative<3>(i, p);
471}
472
473
474
475template <int dim>
476inline Tensor<4, dim>
478 const Point<dim> &p) const
479{
480 return compute_derivative<4>(i, p);
481}
482
484
485#endif
*  iterator end()
*  *  iterator begin()
Definition point.h:111
const std::vector< Polynomials::Polynomial< double > > polynomials
void output_indices(StreamType &out) const
Tensor< order, dim > compute_derivative(const unsigned int i, const Point< dim > &p) const
PolynomialSpace(const std::vector< Pol > &pols)
double compute_value(const unsigned int i, const Point< dim > &p) const override
static constexpr unsigned int dimension
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const override
void set_numbering(const std::vector< unsigned int > &renumber)
static unsigned int n_polynomials(const unsigned int n)
std::array< unsigned int, dim > compute_index(const unsigned int n) const
std::string name() const override
virtual Tensor< 2, dim > compute_2nd_derivative(const unsigned int i, const Point< dim > &p) const override
virtual Tensor< 1, dim > compute_1st_derivative(const unsigned int i, const Point< dim > &p) const override
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const override
virtual Tensor< 3, dim > compute_3rd_derivative(const unsigned int i, const Point< dim > &p) const override
std::vector< unsigned int > index_map
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() 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
std::vector< unsigned int > index_map_inverse
virtual Tensor< 4, dim > compute_4th_derivative(const unsigned int i, const Point< dim > &p) 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()
std::size_t size
Definition mpi.cc:733
typename internal::ndarray::HelperArray< T, Ns... >::type ndarray
Definition ndarray.h:105