16#ifndef dealii_simplex_barycentric_polynomials_h
17#define dealii_simplex_barycentric_polynomials_h
81template <
int dim,
typename Number =
double>
94 const Number coefficient);
109 print(std::ostream &out)
const;
126 template <
typename Number2>
133 template <
typename Number2>
140 template <
typename Number2>
147 template <
typename Number2>
179 derivative(
const unsigned int coordinate)
const;
272 std::vector<double> &values,
334 name()
const override;
339 virtual std::unique_ptr<ScalarPolynomialsBase<dim>>
340 clone()
const override;
355template <
int dim,
typename Number1,
typename Number2>
359 return bp * Number1(a);
365template <
int dim,
typename Number1,
typename Number2>
369 return bp + Number1(a);
375template <
int dim,
typename Number1,
typename Number2>
379 return bp - Number1(a);
385template <
int dim,
typename Number>
396template <
int dim,
typename Number>
400 for (
unsigned int d = 0; d < dim + 1; ++d)
402 coefficients.reinit(extents);
409template <
int dim,
typename Number>
412 const Number coefficient)
415 for (
unsigned int d = 0; d < dim + 1; ++d)
416 extents[d] = powers[d] + 1;
417 coefficients.reinit(extents);
419 coefficients(powers) = coefficient;
424template <
int dim,
typename Number>
436template <
int dim,
typename Number>
440 const auto &coeffs = this->coefficients;
441 auto first = index_to_indices(0, coeffs.size());
442 bool print_plus =
false;
443 if (coeffs(
first) != Number())
445 out << coeffs(
first);
448 for (std::size_t i = 1; i < coeffs.n_elements(); ++i)
450 const auto indices = index_to_indices(i, coeffs.size());
451 if (coeffs(indices) == Number())
455 out << coeffs(indices);
456 for (
unsigned int d = 0; d < dim + 1; ++d)
459 out <<
" * t" << d <<
'^' << indices[d];
470template <
int dim,
typename Number>
474 auto deg = coefficients.size();
475 for (
unsigned int d = 0; d < dim + 1; ++d)
482template <
int dim,
typename Number>
486 return *
this * Number(-1);
491template <
int dim,
typename Number>
492template <
typename Number2>
504template <
int dim,
typename Number>
505template <
typename Number2>
514template <
int dim,
typename Number>
515template <
typename Number2>
525 for (std::size_t i = 0; i < result.
coefficients.n_elements(); ++i)
527 const auto index = index_to_indices(i, result.
coefficients.size());
536template <
int dim,
typename Number>
537template <
typename Number2>
542 return *
this * (Number(1) / Number(a));
547template <
int dim,
typename Number>
553 for (
unsigned int d = 0; d < dim + 1; ++d)
561 for (std::size_t i = 0; i < in.n_elements(); ++i)
563 const auto index = index_to_indices(i, in.size());
568 add_coefficients(this->coefficients);
575template <
int dim,
typename Number>
580 return *
this + (-augend);
585template <
int dim,
typename Number>
591 for (
unsigned int d = 0; d < dim + 1; ++d)
593 deg[d] = multiplicand.
degrees()[d] + degrees()[d];
598 const auto &coef_1 = this->coefficients;
602 for (std::size_t i1 = 0; i1 < coef_1.n_elements(); ++i1)
604 const auto index_1 = index_to_indices(i1, coef_1.size());
605 for (std::size_t i2 = 0; i2 < coef_2.n_elements(); ++i2)
607 const auto index_2 = index_to_indices(i2, coef_2.size());
610 for (
unsigned int d = 0; d < dim + 1; ++d)
611 index_out[d] = index_1[d] + index_2[d];
612 coef_out(index_out) += coef_1(index_1) * coef_2(index_2);
621template <
int dim,
typename Number>
624 const unsigned int coordinate)
const
628 if (degrees()[coordinate] == 0)
631 auto deg = degrees();
632 deg[coordinate] -= 1;
634 std::numeric_limits<Number>::max());
635 const auto &coeffs_in = coefficients;
637 for (std::size_t i = 0; i < coeffs_out.n_elements(); ++i)
639 const auto out_index = index_to_indices(i, coeffs_out.size());
640 auto input_index = out_index;
641 input_index[coordinate] += 1;
643 coeffs_out(out_index) = coeffs_in(input_index) * input_index[coordinate];
651template <
int dim,
typename Number>
654 const unsigned int coordinate)
const
657 return -barycentric_derivative(0) + barycentric_derivative(coordinate + 1);
662template <
int dim,
typename Number>
672 std::array<Number, dim + 1> b_point;
674 for (
unsigned int d = 0; d < dim; ++d)
676 b_point[0] -= point[d];
677 b_point[d + 1] = point[d];
681 for (std::size_t i = 0; i < coefficients.n_elements(); ++i)
683 const auto indices = index_to_indices(i, coefficients.size());
684 const auto coef = coefficients(indices);
685 if (coef == Number())
688 auto temp = Number(1);
689 for (
unsigned int d = 0; d < dim + 1; ++d)
691 result += coef * temp;
699template <
int dim,
typename Number>
703 return coefficients.memory_consumption();
708template <
int dim,
typename Number>
711 const std::size_t &index,
717 for (
unsigned int n = 0; n < dim + 1; ++n)
719 std::size_t slice_size = 1;
720 for (
unsigned int n2 = n + 1; n2 < dim + 1; ++n2)
721 slice_size *= extents[n2];
722 result[n] = temp / slice_size;
BarycentricPolynomial< dim, Number > operator*(const Number2 &a) const
std::size_t memory_consumption() const
BarycentricPolynomial< dim, Number > operator+(const Number2 &a) const
TableIndices< dim+1 > degrees() const
Table< dim+1, Number > coefficients
BarycentricPolynomial< dim, Number > barycentric_derivative(const unsigned int coordinate) const
Number value(const Point< dim > &point) const
static TableIndices< dim+1 > index_to_indices(const std::size_t &index, const TableIndices< dim+1 > &extents)
BarycentricPolynomial< dim, Number > operator/(const Number2 &a) const
BarycentricPolynomial< dim, Number > operator-() const
void print(std::ostream &out) const
static BarycentricPolynomial< dim, Number > monomial(const unsigned int d)
BarycentricPolynomial< dim, Number > derivative(const unsigned int coordinate) const
std::array< HessianType, dim > ThirdDerivativesType
Tensor< 1, dim > compute_grad(const unsigned int i, const Point< dim > &p) const override
std::array< PolyType, dim > GradType
virtual std::size_t memory_consumption() const override
Tensor< 2, dim > compute_grad_grad(const unsigned int i, const Point< dim > &p) const override
std::array< ThirdDerivativesType, dim > FourthDerivativesType
std::vector< GradType > poly_grads
std::string name() const override
Tensor< 3, dim > compute_3rd_derivative(const unsigned int i, const Point< dim > &p) const override
Tensor< 1, dim > compute_1st_derivative(const unsigned int i, const Point< dim > &p) const override
Tensor< 2, dim > compute_2nd_derivative(const unsigned int i, const Point< dim > &p) const override
static constexpr unsigned int dimension
std::vector< PolyType > polys
void evaluate(const Point< dim > &unit_point, std::vector< double > &values, std::vector< Tensor< 1, dim > > &grads, std::vector< Tensor< 2, dim > > &grad_grads, std::vector< Tensor< 3, dim > > &third_derivatives, std::vector< Tensor< 4, dim > > &fourth_derivatives) const override
double compute_value(const unsigned int i, const Point< dim > &p) const override
const BarycentricPolynomial< dim > & operator[](const std::size_t i) const
std::vector< ThirdDerivativesType > poly_third_derivatives
std::array< GradType, dim > HessianType
virtual std::unique_ptr< ScalarPolynomialsBase< dim > > clone() const override
Tensor< 4, dim > compute_4th_derivative(const unsigned int i, const Point< dim > &p) const override
std::vector< HessianType > poly_hessians
static BarycentricPolynomials< dim > get_fe_p_basis(const unsigned int degree)
std::vector< FourthDerivativesType > poly_fourth_derivatives
virtual unsigned int degree() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcDivideByZero()
constexpr T pow(const T base, const int iexp)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
BarycentricPolynomial< dim, Number1 > operator-(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)
BarycentricPolynomial< dim, Number1 > operator+(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)
std::ostream & operator<<(std::ostream &out, const BarycentricPolynomial< dim, Number > &bp)
BarycentricPolynomial< dim, Number1 > operator*(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)