Reference documentation for deal.II version 9.2.0
\(\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\}}\)
tensor_product_polynomials_bubbles.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2012 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_tensor_product_polynomials_bubbles_h
17 #define dealii_tensor_product_polynomials_bubbles_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/point.h>
25 #include <deal.II/base/tensor.h>
27 #include <deal.II/base/utilities.h>
28 
29 #include <vector>
30 
32 
46 template <int dim>
48 {
49 public:
54  static const unsigned int dimension = dim;
55 
61  template <class Pol>
62  TensorProductPolynomialsBubbles(const std::vector<Pol> &pols);
63 
67  void
68  output_indices(std::ostream &out) const;
69 
75  void
76  set_numbering(const std::vector<unsigned int> &renumber);
77 
81  const std::vector<unsigned int> &
82  get_numbering() const;
83 
87  const std::vector<unsigned int> &
88  get_numbering_inverse() const;
89 
102  void
103  evaluate(const Point<dim> & unit_point,
104  std::vector<double> & values,
105  std::vector<Tensor<1, dim>> &grads,
106  std::vector<Tensor<2, dim>> &grad_grads,
107  std::vector<Tensor<3, dim>> &third_derivatives,
108  std::vector<Tensor<4, dim>> &fourth_derivatives) const override;
109 
122  double
123  compute_value(const unsigned int i, const Point<dim> &p) const;
124 
137  template <int order>
139  compute_derivative(const unsigned int i, const Point<dim> &p) const;
140 
154  compute_grad(const unsigned int i, const Point<dim> &p) const;
155 
169  compute_grad_grad(const unsigned int i, const Point<dim> &p) const;
170 
177  unsigned int
178  n() const;
179 
184  std::string
185  name() const override;
186 
190  virtual std::unique_ptr<ScalarPolynomialsBase<dim>>
191  clone() const override;
192 
193 private:
198 
202  std::vector<unsigned int> index_map;
203 
207  std::vector<unsigned int> index_map_inverse;
208 };
209 
213 /* ---------------- template and inline functions ---------- */
214 
215 #ifndef DOXYGEN
216 
217 template <int dim>
218 template <class Pol>
220  const std::vector<Pol> &pols)
221  : ScalarPolynomialsBase<dim>(1,
222  Utilities::fixed_power<dim>(pols.size()) + dim)
223  , tensor_polys(pols)
224  , index_map(tensor_polys.n() +
225  ((tensor_polys.polynomials.size() <= 2) ? 1 : dim))
227  ((tensor_polys.polynomials.size() <= 2) ? 1 : dim))
228 {
229  const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
230  const unsigned int n_bubbles = ((q_degree <= 1) ? 1 : dim);
231  // append index for renumbering
232  for (unsigned int i = 0; i < tensor_polys.n() + n_bubbles; ++i)
233  {
234  index_map[i] = i;
235  index_map_inverse[i] = i;
236  }
237 }
238 
239 
240 template <int dim>
241 inline unsigned int
243 {
244  return tensor_polys.n() + dim;
245 }
246 
247 
248 template <>
249 inline unsigned int
251 {
253 }
254 
255 
256 template <int dim>
257 inline const std::vector<unsigned int> &
259 {
260  return index_map;
261 }
262 
263 
264 template <int dim>
265 inline const std::vector<unsigned int> &
267 {
268  return index_map_inverse;
269 }
270 
271 
272 template <int dim>
273 inline std::string
275 {
276  return "TensorProductPolynomialsBubbles";
277 }
278 
279 
280 template <int dim>
281 template <int order>
284  const unsigned int i,
285  const Point<dim> & p) const
286 {
287  const unsigned int q_degree = tensor_polys.polynomials.size() - 1;
288  const unsigned int max_q_indices = tensor_polys.n();
289  Assert(i < max_q_indices + /* n_bubbles= */ ((q_degree <= 1) ? 1 : dim),
290  ExcInternalError());
291 
292  // treat the regular basis functions
293  if (i < max_q_indices)
294  return tensor_polys.template compute_derivative<order>(i, p);
295 
296  const unsigned int comp = i - tensor_polys.n();
297 
298  Tensor<order, dim> derivative;
299  switch (order)
300  {
301  case 1:
302  {
303  Tensor<1, dim> &derivative_1 =
304  *reinterpret_cast<Tensor<1, dim> *>(&derivative);
305 
306  for (unsigned int d = 0; d < dim; ++d)
307  {
308  derivative_1[d] = 1.;
309  // compute grad(4*\prod_{i=1}^d (x_i(1-x_i)))(p)
310  for (unsigned j = 0; j < dim; ++j)
311  derivative_1[d] *=
312  (d == j ? 4 * (1 - 2 * p(j)) : 4 * p(j) * (1 - p(j)));
313  // and multiply with (2*x_i-1)^{r-1}
314  for (unsigned int i = 0; i < q_degree - 1; ++i)
315  derivative_1[d] *= 2 * p(comp) - 1;
316  }
317 
318  if (q_degree >= 2)
319  {
320  // add \prod_{i=1}^d 4*(x_i(1-x_i))(p)
321  double value = 1.;
322  for (unsigned int j = 0; j < dim; ++j)
323  value *= 4 * p(j) * (1 - p(j));
324  // and multiply with grad(2*x_i-1)^{r-1}
325  double tmp = value * 2 * (q_degree - 1);
326  for (unsigned int i = 0; i < q_degree - 2; ++i)
327  tmp *= 2 * p(comp) - 1;
328  derivative_1[comp] += tmp;
329  }
330 
331  return derivative;
332  }
333  case 2:
334  {
335  Tensor<2, dim> &derivative_2 =
336  *reinterpret_cast<Tensor<2, dim> *>(&derivative);
337 
338  double v[dim + 1][3];
339  {
340  for (unsigned int c = 0; c < dim; ++c)
341  {
342  v[c][0] = 4 * p(c) * (1 - p(c));
343  v[c][1] = 4 * (1 - 2 * p(c));
344  v[c][2] = -8;
345  }
346 
347  double tmp = 1.;
348  for (unsigned int i = 0; i < q_degree - 1; ++i)
349  tmp *= 2 * p(comp) - 1;
350  v[dim][0] = tmp;
351 
352  if (q_degree >= 2)
353  {
354  double tmp = 2 * (q_degree - 1);
355  for (unsigned int i = 0; i < q_degree - 2; ++i)
356  tmp *= 2 * p(comp) - 1;
357  v[dim][1] = tmp;
358  }
359  else
360  v[dim][1] = 0.;
361 
362  if (q_degree >= 3)
363  {
364  double tmp = 4 * (q_degree - 2) * (q_degree - 1);
365  for (unsigned int i = 0; i < q_degree - 3; ++i)
366  tmp *= 2 * p(comp) - 1;
367  v[dim][2] = tmp;
368  }
369  else
370  v[dim][2] = 0.;
371  }
372 
373  // calculate (\partial_j \partial_k \psi) * monomial
374  Tensor<2, dim> grad_grad_1;
375  for (unsigned int d1 = 0; d1 < dim; ++d1)
376  for (unsigned int d2 = 0; d2 < dim; ++d2)
377  {
378  grad_grad_1[d1][d2] = v[dim][0];
379  for (unsigned int x = 0; x < dim; ++x)
380  {
381  unsigned int derivative = 0;
382  if (d1 == x || d2 == x)
383  {
384  if (d1 == d2)
385  derivative = 2;
386  else
387  derivative = 1;
388  }
389  grad_grad_1[d1][d2] *= v[x][derivative];
390  }
391  }
392 
393  // calculate (\partial_j \psi) *(\partial_k monomial)
394  // and (\partial_k \psi) *(\partial_j monomial)
395  Tensor<2, dim> grad_grad_2;
396  Tensor<2, dim> grad_grad_3;
397  for (unsigned int d = 0; d < dim; ++d)
398  {
399  grad_grad_2[d][comp] = v[dim][1];
400  grad_grad_3[comp][d] = v[dim][1];
401  for (unsigned int x = 0; x < dim; ++x)
402  {
403  grad_grad_2[d][comp] *= v[x][d == x];
404  grad_grad_3[comp][d] *= v[x][d == x];
405  }
406  }
407 
408  // calculate \psi *(\partial j \partial_k monomial) and sum
409  double psi_value = 1.;
410  for (unsigned int x = 0; x < dim; ++x)
411  psi_value *= v[x][0];
412 
413  for (unsigned int d1 = 0; d1 < dim; ++d1)
414  for (unsigned int d2 = 0; d2 < dim; ++d2)
415  derivative_2[d1][d2] =
416  grad_grad_1[d1][d2] + grad_grad_2[d1][d2] + grad_grad_3[d1][d2];
417  derivative_2[comp][comp] += psi_value * v[dim][2];
418 
419  return derivative;
420  }
421  default:
422  {
423  Assert(false, ExcNotImplemented());
424  return derivative;
425  }
426  }
427 }
428 
429 
430 #endif // DOXYGEN
432 
433 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:191
std::vector< PolynomialType > polynomials
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const
T fixed_power(const T t)
Definition: utilities.h:1072
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
void set_numbering(const std::vector< unsigned int > &renumber)
#define Assert(cond, exc)
Definition: exceptions.h:1419
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
std::string name() const override
TensorProductPolynomialsBubbles(const std::vector< Pol > &pols)
Tensor< order, dim > compute_derivative(const unsigned int i, const Point< dim > &p) const
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
Definition: cuda.h:31
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
double compute_value(const unsigned int i, const Point< dim > &p) const
static ::ExceptionBase & ExcNotImplemented()
const std::vector< unsigned int > & get_numbering_inverse() const
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() const override
static const bool value
static ::ExceptionBase & ExcInternalError()
const std::vector< unsigned int > & get_numbering() const