Reference documentation for deal.II version 8.4.2
polynomials_abf.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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/polynomials_abf.h>
18 #include <deal.II/base/quadrature_lib.h>
19 #include <iostream>
20 #include <iomanip>
21 
22 
23 DEAL_II_NAMESPACE_OPEN
24 
25 
26 template <int dim>
28  :
29  my_degree(k),
30  n_pols(compute_n_pols(k))
31 {
32  std::vector<std::vector< Polynomials::Polynomial< double > > > pols(dim);
34  if (k == 0)
35  for (unsigned int d=1; d<dim; ++d)
37  else
38  for (unsigned int d=1; d<dim; ++d)
41 }
42 
43 
44 template <int dim>
46 {
47  delete polynomial_space;
48 }
49 
50 
51 template <int dim>
52 void
54  std::vector<Tensor<1,dim> > &values,
55  std::vector<Tensor<2,dim> > &grads,
56  std::vector<Tensor<3,dim> > &grad_grads,
57  std::vector<Tensor<4,dim> > &third_derivatives,
58  std::vector<Tensor<5,dim> > &fourth_derivatives) const
59 {
60  Assert(values.size()==n_pols || values.size()==0,
61  ExcDimensionMismatch(values.size(), n_pols));
62  Assert(grads.size()==n_pols|| grads.size()==0,
63  ExcDimensionMismatch(grads.size(), n_pols));
64  Assert(grad_grads.size()==n_pols|| grad_grads.size()==0,
65  ExcDimensionMismatch(grad_grads.size(), n_pols));
66  Assert(third_derivatives.size()==n_pols|| third_derivatives.size()==0,
67  ExcDimensionMismatch(third_derivatives.size(), n_pols));
68  Assert(fourth_derivatives.size()==n_pols|| fourth_derivatives.size()==0,
69  ExcDimensionMismatch(fourth_derivatives.size(), n_pols));
70 
71  const unsigned int n_sub = polynomial_space->n();
72  // guard access to the scratch
73  // arrays in the following block
74  // using a mutex to make sure they
75  // are not used by multiple threads
76  // at once
78 
79  p_values.resize((values.size() == 0) ? 0 : n_sub);
80  p_grads.resize((grads.size() == 0) ? 0 : n_sub);
81  p_grad_grads.resize((grad_grads.size() == 0) ? 0 : n_sub);
82  p_third_derivatives.resize((third_derivatives.size() == 0) ? 0 : n_sub);
83  p_fourth_derivatives.resize((fourth_derivatives.size() == 0) ? 0 : n_sub);
84 
85  for (unsigned int d=0; d<dim; ++d)
86  {
87  // First we copy the point. The
88  // polynomial space for
89  // component d consists of
90  // polynomials of degree k+1 in
91  // x_d and degree k in the
92  // other variables. in order to
93  // simplify this, we use the
94  // same AnisotropicPolynomial
95  // space and simply rotate the
96  // coordinates through all
97  // directions.
98  Point<dim> p;
99  for (unsigned int c=0; c<dim; ++c)
100  p(c) = unit_point((c+d)%dim);
101 
104 
105  for (unsigned int i=0; i<p_values.size(); ++i)
106  values[i+d*n_sub][d] = p_values[i];
107 
108  for (unsigned int i=0; i<p_grads.size(); ++i)
109  for (unsigned int d1=0; d1<dim; ++d1)
110  grads[i+d*n_sub][d][(d1+d)%dim] = p_grads[i][d1];
111 
112  for (unsigned int i=0; i<p_grad_grads.size(); ++i)
113  for (unsigned int d1=0; d1<dim; ++d1)
114  for (unsigned int d2=0; d2<dim; ++d2)
115  grad_grads[i+d*n_sub][d][(d1+d)%dim][(d2+d)%dim]
116  = p_grad_grads[i][d1][d2];
117 
118  for (unsigned int i=0; i<p_third_derivatives.size(); ++i)
119  for (unsigned int d1=0; d1<dim; ++d1)
120  for (unsigned int d2=0; d2<dim; ++d2)
121  for (unsigned int d3=0; d3<dim; ++d3)
122  third_derivatives[i+d*n_sub][d][(d1+d)%dim][(d2+d)%dim][(d3+d)%dim]
123  = p_third_derivatives[i][d1][d2][d3];
124 
125  for (unsigned int i=0; i<p_fourth_derivatives.size(); ++i)
126  for (unsigned int d1=0; d1<dim; ++d1)
127  for (unsigned int d2=0; d2<dim; ++d2)
128  for (unsigned int d3=0; d3<dim; ++d3)
129  for (unsigned int d4=0; d4<dim; ++d4)
130  fourth_derivatives[i+d*n_sub][d][(d1+d)%dim][(d2+d)%dim][(d3+d)%dim][(d4+d)%dim]
131  = p_fourth_derivatives[i][d1][d2][d3][d4];
132  }
133 }
134 
135 
136 template <int dim>
137 unsigned int
139 {
140  if (dim == 1) return k+1;
141  if (dim == 2) return 2*(k+1)*(k+3);
142  //TODO:Check what are the correct numbers ...
143  if (dim == 3) return 3*(k+1)*(k+1)*(k+2);
144 
145  Assert(false, ExcNotImplemented());
146  return 0;
147 }
148 
149 
150 template class PolynomialsABF<1>;
151 template class PolynomialsABF<2>;
152 template class PolynomialsABF<3>;
153 
154 
155 DEAL_II_NAMESPACE_CLOSE
std::vector< Tensor< 4, dim > > p_fourth_derivatives
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Definition: polynomial.cc:1009
std::vector< Tensor< 2, dim > > p_grad_grads
std::vector< Tensor< 1, dim > > p_grads
AnisotropicPolynomials< dim > * polynomial_space
std::vector< double > p_values
std::vector< Tensor< 3, dim > > p_third_derivatives
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Definition: polynomial.cc:795
#define Assert(cond, exc)
Definition: exceptions.h:294
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
unsigned int n_pols
static unsigned int compute_n_pols(unsigned int degree)
PolynomialsABF(const unsigned int k)
Threads::Mutex mutex