KASKADE 7 development version
bezier.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2019-2020 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef BEZIER_HH
14#define BEZIER_HH
15
16#include "dune/common/fvector.hh"
17
18#include "fem/barycentric.hh"
20#include "utilities/power.hh"
21
22
23namespace Kaskade
24{
38 template <int d, class Real>
39 Real bezier(int p, int i, Dune::FieldVector<Real,d> const& x)
40 {
41 auto b = barycentric2(x);
42 if (d==1)
43 return binomial(p,i)*power(b[0],p-i)*power(b[1],i);
44 else if (d==2)
45 {
46 // First get the i-th multiindex of integers such that k[0]+...+k[d-1] <= p.
47 auto ks = multiIndex<d>(p,i);
48 // Then compute k[d] such that k[0]+...+k[d] == p
49 std::array<size_t,d+1> Ks;
50 std::copy(begin(ks),end(ks),begin(Ks));
51 Ks[d] = p - std::accumulate(begin(ks),end(ks),0);
52
53 // Now the Bezier function is multinomial(p,Ks) * lambda_0^Ks[0] * ... * lambda_d^Ks[d].
54
55 Real r = multinomial(Ks);
56 for (int j=0; j<=d; ++j)
57 r *= power(b[j],Ks[j]);
58 return r;
59 }
60
61 static_assert(d<=2,"not yet implemented");
62 return -1; // never get here
63 }
64
65
66
67}
68
69#endif
Dune::FieldVector< CoordType, dim+1 > barycentric2(Dune::FieldVector< CoordType, dim > const &x)
Computes barycentric coordinates of a point in the unit simplex.
Definition: barycentric.hh:90
size_t multinomial(std::array< size_t, m > const &ks)
Computes the multinomial coefficient , where .
constexpr int binomial(int n, int k)
Computes the binomial coefficient .
R power(R base, int exp)
Computes integral powers of values in a multiplicative half-group.
Definition: power.hh:30
Real bezier(int p, int i, Dune::FieldVector< Real, d > const &x)
Computes the i-th Bezier function of order p at the given point in the unit simplex.
Definition: bezier.hh:39