Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
polynomial_space.h
1 // ---------------------------------------------------------------------
2 // @f$Id: polynomial_space.h 30766 2013-09-17 14:38:55Z kronbichler @f$
3 //
4 // Copyright (C) 2002 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__polynomial_space_h
18 #define __deal2__polynomial_space_h
19 
20 
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/tensor.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/polynomial.h>
26 #include <deal.II/base/smartpointer.h>
27 
28 #include <vector>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
88 template <int dim>
89 class PolynomialSpace
90 {
91 public:
98  static const unsigned int dimension = dim;
99 
114  template <class Pol>
115  PolynomialSpace (const std::vector<Pol> &pols);
116 
121  template <class STREAM>
122  void output_indices(STREAM &out) const;
123 
131  void set_numbering(const std::vector<unsigned int> &renumber);
132 
158  void compute (const Point<dim> &unit_point,
159  std::vector<double> &values,
160  std::vector<Tensor<1,dim> > &grads,
161  std::vector<Tensor<2,dim> > &grad_grads) const;
162 
170  double compute_value (const unsigned int i,
171  const Point<dim> &p) const;
172 
180  Tensor<1,dim> compute_grad (const unsigned int i,
181  const Point<dim> &p) const;
182 
191  Tensor<2,dim> compute_grad_grad (const unsigned int i,
192  const Point<dim> &p) const;
193 
206  unsigned int n () const;
207 
218  unsigned int degree () const;
219 
225  static unsigned int compute_n_pols (const unsigned int n);
226 
227 protected:
228 
238  void compute_index (const unsigned int n,
239  unsigned int (&index)[dim>0?dim:1]) const;
240 
241 private:
247  const std::vector<Polynomials::Polynomial<double> > polynomials;
248 
254  const unsigned int n_pols;
255 
260  std::vector<unsigned int> index_map;
261 
266  std::vector<unsigned int> index_map_inverse;
267 };
268 
269 
270 /* -------------- declaration of explicit specializations --- */
271 
272 template <>
273 void PolynomialSpace<1>::compute_index(const unsigned int n,
274  unsigned int (&index)[1]) const;
275 template <>
276 void PolynomialSpace<2>::compute_index(const unsigned int n,
277  unsigned int (&index)[2]) const;
278 template <>
279 void PolynomialSpace<3>::compute_index(const unsigned int n,
280  unsigned int (&index)[3]) const;
281 
282 
283 
284 /* -------------- inline and template functions ------------- */
285 
286 template <int dim>
287 template <class Pol>
288 PolynomialSpace<dim>::PolynomialSpace (const std::vector<Pol> &pols)
289  :
290  polynomials (pols.begin(), pols.end()),
291  n_pols (compute_n_pols(polynomials.size())),
292  index_map(n_pols),
293  index_map_inverse(n_pols)
294 {
295  // per default set this index map
296  // to identity. This map can be
297  // changed by the user through the
298  // set_numbering function
299  for (unsigned int i=0; i<n_pols; ++i)
300  {
301  index_map[i]=i;
302  index_map_inverse[i]=i;
303  }
304 }
305 
306 
307 template<int dim>
308 inline
309 unsigned int
311 {
312  return n_pols;
313 }
314 
315 
316 
317 template<int dim>
318 inline
319 unsigned int
321 {
322  return polynomials.size();
323 }
324 
325 
326 template <int dim>
327 template <class STREAM>
328 void
330 {
331  unsigned int ix[dim];
332  for (unsigned int i=0; i<n_pols; ++i)
333  {
334  compute_index(i,ix);
335  out << i << "\t";
336  for (unsigned int d=0; d<dim; ++d)
337  out << ix[d] << " ";
338  out << std::endl;
339  }
340 }
341 
342 
343 DEAL_II_NAMESPACE_CLOSE
344 
345 #endif
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const
unsigned int degree() const
void set_numbering(const std::vector< unsigned int > &renumber)
void output_indices(STREAM &out) const
static unsigned int compute_n_pols(const unsigned int n)
void compute_index(const unsigned int n, unsigned int(&index)[dim >0?dim:1]) const
static const unsigned int dimension
std::vector< unsigned int > index_map_inverse
const unsigned int n_pols
unsigned int n() const
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const
PolynomialSpace(const std::vector< Pol > &pols)
void compute(const Point< dim > &unit_point, std::vector< double > &values, std::vector< Tensor< 1, dim > > &grads, std::vector< Tensor< 2, dim > > &grad_grads) const
std::vector< unsigned int > index_map
const std::vector< Polynomials::Polynomial< double > > polynomials
double compute_value(const unsigned int i, const Point< dim > &p) const