Reference documentation for deal.II version 9.1.0-pre
polynomials_raviart_thomas.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2015 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 
17 #include <deal.II/base/polynomials_raviart_thomas.h>
18 #include <deal.II/base/quadrature_lib.h>
19 #include <deal.II/base/thread_management.h>
20 
21 #include <iomanip>
22 #include <iostream>
23 
24 // TODO[WB]: This class is not thread-safe: it uses mutable member variables
25 // that contain temporary state. this is not what one would want when one uses a
26 // finite element object in a number of different contexts on different threads:
27 // finite element objects should be stateless
28 // TODO:[GK] This can be achieved by writing a function in Polynomial space
29 // which does the rotated fill performed below and writes the data into the
30 // right data structures. The same function would be used by Nedelec
31 // polynomials.
32 
33 DEAL_II_NAMESPACE_OPEN
34 
35 
36 template <int dim>
38  : my_degree(k)
39  , polynomial_space(create_polynomials(k))
40  , n_pols(compute_n_pols(k))
41 {}
42 
43 
44 
45 template <int dim>
46 std::vector<std::vector<Polynomials::Polynomial<double>>>
48 {
49  std::vector<std::vector<Polynomials::Polynomial<double>>> pols(dim);
51  if (k == 0)
52  for (unsigned int d = 1; d < dim; ++d)
54  else
55  for (unsigned int d = 1; d < dim; ++d)
57 
58  return pols;
59 }
60 
61 
62 template <int dim>
63 void
65  const Point<dim> & unit_point,
66  std::vector<Tensor<1, dim>> &values,
67  std::vector<Tensor<2, dim>> &grads,
68  std::vector<Tensor<3, dim>> &grad_grads,
69  std::vector<Tensor<4, dim>> &third_derivatives,
70  std::vector<Tensor<5, dim>> &fourth_derivatives) const
71 {
72  Assert(values.size() == n_pols || values.size() == 0,
73  ExcDimensionMismatch(values.size(), n_pols));
74  Assert(grads.size() == n_pols || grads.size() == 0,
75  ExcDimensionMismatch(grads.size(), n_pols));
76  Assert(grad_grads.size() == n_pols || grad_grads.size() == 0,
77  ExcDimensionMismatch(grad_grads.size(), n_pols));
78  Assert(third_derivatives.size() == n_pols || third_derivatives.size() == 0,
79  ExcDimensionMismatch(third_derivatives.size(), n_pols));
80  Assert(fourth_derivatives.size() == n_pols || fourth_derivatives.size() == 0,
81  ExcDimensionMismatch(fourth_derivatives.size(), n_pols));
82 
83  // have a few scratch
84  // arrays. because we don't want to
85  // re-allocate them every time this
86  // function is called, we make them
87  // static. however, in return we
88  // have to ensure that the calls to
89  // the use of these variables is
90  // locked with a mutex. if the
91  // mutex is removed, several tests
92  // (notably
93  // deal.II/create_mass_matrix_05)
94  // will start to produce random
95  // results in multithread mode
96  static Threads::Mutex mutex;
97  Threads::Mutex::ScopedLock lock(mutex);
98 
99  static std::vector<double> p_values;
100  static std::vector<Tensor<1, dim>> p_grads;
101  static std::vector<Tensor<2, dim>> p_grad_grads;
102  static std::vector<Tensor<3, dim>> p_third_derivatives;
103  static std::vector<Tensor<4, dim>> p_fourth_derivatives;
104 
105  const unsigned int n_sub = polynomial_space.n();
106  p_values.resize((values.size() == 0) ? 0 : n_sub);
107  p_grads.resize((grads.size() == 0) ? 0 : n_sub);
108  p_grad_grads.resize((grad_grads.size() == 0) ? 0 : n_sub);
109  p_third_derivatives.resize((third_derivatives.size() == 0) ? 0 : n_sub);
110  p_fourth_derivatives.resize((fourth_derivatives.size() == 0) ? 0 : n_sub);
111 
112  for (unsigned int d = 0; d < dim; ++d)
113  {
114  // First we copy the point. The
115  // polynomial space for
116  // component d consists of
117  // polynomials of degree k+1 in
118  // x_d and degree k in the
119  // other variables. in order to
120  // simplify this, we use the
121  // same AnisotropicPolynomial
122  // space and simply rotate the
123  // coordinates through all
124  // directions.
125  Point<dim> p;
126  for (unsigned int c = 0; c < dim; ++c)
127  p(c) = unit_point((c + d) % dim);
128 
129  polynomial_space.compute(p,
130  p_values,
131  p_grads,
132  p_grad_grads,
133  p_third_derivatives,
134  p_fourth_derivatives);
135 
136  for (unsigned int i = 0; i < p_values.size(); ++i)
137  values[i + d * n_sub][d] = p_values[i];
138 
139  for (unsigned int i = 0; i < p_grads.size(); ++i)
140  for (unsigned int d1 = 0; d1 < dim; ++d1)
141  grads[i + d * n_sub][d][(d1 + d) % dim] = p_grads[i][d1];
142 
143  for (unsigned int i = 0; i < p_grad_grads.size(); ++i)
144  for (unsigned int d1 = 0; d1 < dim; ++d1)
145  for (unsigned int d2 = 0; d2 < dim; ++d2)
146  grad_grads[i + d * n_sub][d][(d1 + d) % dim][(d2 + d) % dim] =
147  p_grad_grads[i][d1][d2];
148 
149  for (unsigned int i = 0; i < p_third_derivatives.size(); ++i)
150  for (unsigned int d1 = 0; d1 < dim; ++d1)
151  for (unsigned int d2 = 0; d2 < dim; ++d2)
152  for (unsigned int d3 = 0; d3 < dim; ++d3)
153  third_derivatives[i + d * n_sub][d][(d1 + d) % dim]
154  [(d2 + d) % dim][(d3 + d) % dim] =
155  p_third_derivatives[i][d1][d2][d3];
156 
157  for (unsigned int i = 0; i < p_fourth_derivatives.size(); ++i)
158  for (unsigned int d1 = 0; d1 < dim; ++d1)
159  for (unsigned int d2 = 0; d2 < dim; ++d2)
160  for (unsigned int d3 = 0; d3 < dim; ++d3)
161  for (unsigned int d4 = 0; d4 < dim; ++d4)
162  fourth_derivatives[i + d * n_sub][d][(d1 + d) % dim]
163  [(d2 + d) % dim][(d3 + d) % dim]
164  [(d4 + d) % dim] =
165  p_fourth_derivatives[i][d1][d2][d3][d4];
166  }
167 }
168 
169 
170 template <int dim>
171 unsigned int
173 {
174  if (dim == 1)
175  return k + 1;
176  if (dim == 2)
177  return 2 * (k + 1) * (k + 2);
178  if (dim == 3)
179  return 3 * (k + 1) * (k + 1) * (k + 2);
180 
181  Assert(false, ExcNotImplemented());
182  return 0;
183 }
184 
185 
186 template class PolynomialsRaviartThomas<1>;
187 template class PolynomialsRaviartThomas<2>;
188 template class PolynomialsRaviartThomas<3>;
189 
190 
191 DEAL_II_NAMESPACE_CLOSE
PolynomialsRaviartThomas(const unsigned int k)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Definition: polynomial.cc:866
const AnisotropicPolynomials< dim > polynomial_space
static unsigned int compute_n_pols(unsigned int degree)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Definition: polynomial.cc:800
#define Assert(cond, exc)
Definition: exceptions.h:1227
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void compute(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
static std::vector< std::vector< Polynomials::Polynomial< double > > > create_polynomials(const unsigned int k)
static::ExceptionBase & ExcNotImplemented()