Reference documentation for deal.II version 9.0.0
polynomials_bernstein.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 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 #include <deal.II/base/polynomials_bernstein.h>
17 
18 #include <boost/math/special_functions/binomial.hpp>
19 
20 #include <vector>
21 
22 DEAL_II_NAMESPACE_OPEN
23 
24 namespace
25 {
26  template <typename number>
27  std::vector<number>
28  get_bernstein_coefficients (
29  const unsigned int k, const unsigned int n)
30  {
31  Assert(n>0, ExcMessage("Bernstein polynomial needs to be of degree > 0."));
32  AssertIndexRange(k, n+1);
33  std::vector<number> coeff(n + 1, number(0.0));
34  for (unsigned int i = k; i < n + 1; ++i)
35  {
36  coeff[i] = ((i - k) % 2 == 0 ? 1 : -1)
37  * boost::math::binomial_coefficient<number>(n, i)
38  * boost::math::binomial_coefficient<number>(i, k);
39  }
40  return coeff;
41  }
42 }
43 
44 template <typename number>
46  const unsigned int index, const unsigned int degree)
47  :
48  Polynomials::Polynomial<number>(
49  get_bernstein_coefficients<number>(index, degree))
50 {
51 }
52 
53 
54 #include "polynomials_bernstein.inst"
55 
56 DEAL_II_NAMESPACE_CLOSE
#define AssertIndexRange(index, range)
Definition: exceptions.h:1284
PolynomialsBernstein(const unsigned int index, const unsigned int degree)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1142