Reference documentation for deal.II version GIT 4efb66ecd0 2023-02-07 13:45:02+00:00
polynomials_bernstein.cc
Go to the documentation of this file.
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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15
17
18 #include <boost/math/special_functions/binomial.hpp>
19
20 #include <vector>
21
23
24 namespace
25 {
26  template <typename number>
27  std::vector<number>
28  get_bernstein_coefficients(const unsigned int k, const unsigned int n)
29  {
30  Assert(n > 0,
31  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 } // namespace
43
44 template <typename number>
46  const unsigned int degree)
47  : Polynomials::Polynomial<number>(
48  get_bernstein_coefficients<number>(index, degree))
49 {}
50
51
52 #include "polynomials_bernstein.inst"
53
PolynomialsBernstein(const unsigned int index, const unsigned int degree)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:462
#define Assert(cond, exc)
Definition: exceptions.h:1583
#define AssertIndexRange(index, range)
Definition: exceptions.h:1821
static ::ExceptionBase & ExcMessage(std::string arg1)