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_abf.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) 2005 - 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
16
17#include <iomanip>
18#include <iostream>
19#include <memory>
20
21
23
24
25
26namespace
27{
28 template <int dim>
29 std::vector<std::vector<Polynomials::Polynomial<double>>>
30 get_abf_polynomials(const unsigned int k)
31 {
32 std::vector<std::vector<Polynomials::Polynomial<double>>> pols(dim);
34
35 if (k == 0)
36 for (unsigned int d = 1; d < dim; ++d)
38 else
39 for (unsigned int d = 1; d < dim; ++d)
41
42 return pols;
43 }
44} // namespace
45
46template <int dim>
48 : TensorPolynomialsBase<dim>(k, n_polynomials(k))
49 , polynomial_space(get_abf_polynomials<dim>(k))
50{
51 // check that the dimensions match. we only store one of the 'dim'
52 // anisotropic polynomials that make up the vector-valued space, so
53 // multiply by 'dim'
55}
56
57
58
59template <int dim>
60void
62 const Point<dim> &unit_point,
63 std::vector<Tensor<1, dim>> &values,
64 std::vector<Tensor<2, dim>> &grads,
65 std::vector<Tensor<3, dim>> &grad_grads,
66 std::vector<Tensor<4, dim>> &third_derivatives,
67 std::vector<Tensor<5, dim>> &fourth_derivatives) const
68{
69 Assert(values.size() == this->n() || values.empty(),
70 ExcDimensionMismatch(values.size(), this->n()));
71 Assert(grads.size() == this->n() || grads.empty(),
72 ExcDimensionMismatch(grads.size(), this->n()));
73 Assert(grad_grads.size() == this->n() || grad_grads.empty(),
74 ExcDimensionMismatch(grad_grads.size(), this->n()));
75 Assert(third_derivatives.size() == this->n() || third_derivatives.empty(),
76 ExcDimensionMismatch(third_derivatives.size(), this->n()));
77 Assert(fourth_derivatives.size() == this->n() || fourth_derivatives.empty(),
78 ExcDimensionMismatch(fourth_derivatives.size(), this->n()));
79
80 const unsigned int n_sub = polynomial_space.n();
81 // guard access to the scratch
82 // arrays in the following block
83 // using a mutex to make sure they
84 // are not used by multiple threads
85 // at once
86 std::scoped_lock lock(mutex);
87
88 p_values.resize((values.empty()) ? 0 : n_sub);
89 p_grads.resize((grads.empty()) ? 0 : n_sub);
90 p_grad_grads.resize((grad_grads.empty()) ? 0 : n_sub);
91 p_third_derivatives.resize((third_derivatives.empty()) ? 0 : n_sub);
92 p_fourth_derivatives.resize((fourth_derivatives.empty()) ? 0 : n_sub);
93
94 for (unsigned int d = 0; d < dim; ++d)
95 {
96 // First we copy the point. The
97 // polynomial space for
98 // component d consists of
99 // polynomials of degree k+1 in
100 // x_d and degree k in the
101 // other variables. in order to
102 // simplify this, we use the
103 // same AnisotropicPolynomial
104 // space and simply rotate the
105 // coordinates through all
106 // directions.
107 Point<dim> p;
108 for (unsigned int c = 0; c < dim; ++c)
109 p[c] = unit_point[(c + d) % dim];
110
111 polynomial_space.evaluate(p,
112 p_values,
113 p_grads,
114 p_grad_grads,
115 p_third_derivatives,
116 p_fourth_derivatives);
117
118 for (unsigned int i = 0; i < p_values.size(); ++i)
119 values[i + d * n_sub][d] = p_values[i];
120
121 for (unsigned int i = 0; i < p_grads.size(); ++i)
122 for (unsigned int d1 = 0; d1 < dim; ++d1)
123 grads[i + d * n_sub][d][(d1 + d) % dim] = p_grads[i][d1];
124
125 for (unsigned int i = 0; i < p_grad_grads.size(); ++i)
126 for (unsigned int d1 = 0; d1 < dim; ++d1)
127 for (unsigned int d2 = 0; d2 < dim; ++d2)
128 grad_grads[i + d * n_sub][d][(d1 + d) % dim][(d2 + d) % dim] =
129 p_grad_grads[i][d1][d2];
130
131 for (unsigned int i = 0; i < p_third_derivatives.size(); ++i)
132 for (unsigned int d1 = 0; d1 < dim; ++d1)
133 for (unsigned int d2 = 0; d2 < dim; ++d2)
134 for (unsigned int d3 = 0; d3 < dim; ++d3)
135 third_derivatives[i + d * n_sub][d][(d1 + d) % dim]
136 [(d2 + d) % dim][(d3 + d) % dim] =
137 p_third_derivatives[i][d1][d2][d3];
138
139 for (unsigned int i = 0; i < p_fourth_derivatives.size(); ++i)
140 for (unsigned int d1 = 0; d1 < dim; ++d1)
141 for (unsigned int d2 = 0; d2 < dim; ++d2)
142 for (unsigned int d3 = 0; d3 < dim; ++d3)
143 for (unsigned int d4 = 0; d4 < dim; ++d4)
144 fourth_derivatives[i + d * n_sub][d][(d1 + d) % dim]
145 [(d2 + d) % dim][(d3 + d) % dim]
146 [(d4 + d) % dim] =
147 p_fourth_derivatives[i][d1][d2][d3][d4];
148 }
149}
150
151
152template <int dim>
153unsigned int
155{
156 switch (dim)
157 {
158 case 1:
159 // in 1d, we simply have Q_{k+2}, which has dimension k+3
160 return k + 3;
161
162 case 2:
163 // the polynomial space is Q_{k+2,k} \times Q_{k,k+2}, which has
164 // 2(k+3)(k+1) DoFs
165 return 2 * (k + 3) * (k + 1);
166
167 case 3:
168 // the polynomial space is Q_{k+2,k,k} \times Q_{k,k+2,k} \times
169 // Q_{k,k,k+2}, which has 3(k+3)(k+1)(k+1) DoFs
170 return 3 * (k + 3) * (k + 1) * (k + 1);
171
172 default:
174 }
175
176 return 0;
177}
178
179
180template <int dim>
181std::unique_ptr<TensorPolynomialsBase<dim>>
183{
184 return std::make_unique<PolynomialsABF<dim>>(*this);
185}
186
187
188template class PolynomialsABF<1>;
189template class PolynomialsABF<2>;
190template class PolynomialsABF<3>;
191
192
Definition point.h:111
const AnisotropicPolynomials< dim > polynomial_space
PolynomialsABF(const unsigned int k)
static unsigned int n_polynomials(const unsigned int degree)
void evaluate(const Point< dim > &unit_point, std::vector< Tensor< 1, dim > > &values, std::vector< Tensor< 2, dim > > &grads, std::vector< Tensor< 3, dim > > &grad_grads, std::vector< Tensor< 4, dim > > &third_derivatives, std::vector< Tensor< 5, dim > > &fourth_derivatives) const override
virtual std::unique_ptr< TensorPolynomialsBase< dim > > clone() const override
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
#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 & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)