14#ifndef dealii_simplex_barycentric_polynomials_h
15#define dealii_simplex_barycentric_polynomials_h
29#include <Kokkos_Macros.hpp>
94template <
int dim,
typename Number =
double>
107 const Number coefficient);
122 print(std::ostream &out)
const;
139 template <
typename Number2>
146 template <
typename Number2>
153 template <
typename Number2>
160 template <
typename Number2>
192 derivative(
const unsigned int coordinate)
const;
293 std::vector<double> &values,
355 name()
const override;
360 virtual std::unique_ptr<ScalarPolynomialsBase<dim>>
361 clone()
const override;
376template <
int dim,
typename Number1,
typename Number2>
380 return bp * Number1(a);
386template <
int dim,
typename Number1,
typename Number2>
390 return bp + Number1(a);
396template <
int dim,
typename Number1,
typename Number2>
400 return bp - Number1(a);
406template <
int dim,
typename Number>
417template <
int dim,
typename Number>
421 for (
unsigned int d = 0; d < dim + 1; ++d)
423 coefficients.reinit(extents);
430template <
int dim,
typename Number>
433 const Number coefficient)
436 for (
unsigned int d = 0; d < dim + 1; ++d)
437 extents[d] = powers[d] + 1;
438 coefficients.reinit(extents);
440 coefficients(powers) = coefficient;
445template <
int dim,
typename Number>
457template <
int dim,
typename Number>
461 const auto &coeffs = this->coefficients;
462 auto first = index_to_indices(0, coeffs.size());
463 bool print_plus =
false;
464 if (coeffs(
first) != Number())
466 out << coeffs(
first);
469 for (std::size_t i = 1; i < coeffs.n_elements(); ++i)
471 const auto indices = index_to_indices(i, coeffs.size());
472 if (coeffs(indices) == Number())
476 out << coeffs(indices);
477 for (
unsigned int d = 0; d < dim + 1; ++d)
480 out <<
" * t" << d <<
'^' << indices[d];
491template <
int dim,
typename Number>
495 auto deg = coefficients.size();
496 for (
unsigned int d = 0; d < dim + 1; ++d)
503template <
int dim,
typename Number>
507 return *
this * Number(-1);
512template <
int dim,
typename Number>
513template <
typename Number2>
525template <
int dim,
typename Number>
526template <
typename Number2>
535template <
int dim,
typename Number>
536template <
typename Number2>
546 for (std::size_t i = 0; i < result.
coefficients.n_elements(); ++i)
548 const auto index = index_to_indices(i, result.
coefficients.size());
557template <
int dim,
typename Number>
558template <
typename Number2>
563 return *
this * (Number(1) / Number(a));
568template <
int dim,
typename Number>
574 for (
unsigned int d = 0; d < dim + 1; ++d)
582 for (std::size_t i = 0; i < in.n_elements(); ++i)
584 const auto index = index_to_indices(i, in.size());
589 add_coefficients(this->coefficients);
596template <
int dim,
typename Number>
601 return *
this + (-augend);
606template <
int dim,
typename Number>
612 for (
unsigned int d = 0; d < dim + 1; ++d)
614 deg[d] = multiplicand.
degrees()[d] + degrees()[d];
619 const auto &coef_1 = this->coefficients;
623 for (std::size_t i1 = 0; i1 < coef_1.n_elements(); ++i1)
625 const auto index_1 = index_to_indices(i1, coef_1.size());
626 for (std::size_t i2 = 0; i2 < coef_2.n_elements(); ++i2)
628 const auto index_2 = index_to_indices(i2, coef_2.size());
631 for (
unsigned int d = 0; d < dim + 1; ++d)
632 index_out[d] = index_1[d] + index_2[d];
633 coef_out(index_out) += coef_1(index_1) * coef_2(index_2);
642template <
int dim,
typename Number>
645 const unsigned int coordinate)
const
649 if (degrees()[coordinate] == 0)
652 auto deg = degrees();
653 deg[coordinate] -= 1;
655 std::numeric_limits<Number>::max());
656 const auto &coeffs_in = coefficients;
658 for (std::size_t i = 0; i < coeffs_out.n_elements(); ++i)
660 const auto out_index = index_to_indices(i, coeffs_out.size());
661 auto input_index = out_index;
662 input_index[coordinate] += 1;
664 coeffs_out(out_index) = coeffs_in(input_index) * input_index[coordinate];
672template <
int dim,
typename Number>
675 const unsigned int coordinate)
const
678 return -barycentric_derivative(0) + barycentric_derivative(coordinate + 1);
683template <
int dim,
typename Number>
693 std::array<Number, dim + 1> b_point;
695 for (
unsigned int d = 0; d < dim; ++d)
697 b_point[0] -= point[d];
698 b_point[d + 1] = point[d];
702 for (std::size_t i = 0; i < coefficients.n_elements(); ++i)
704 const auto indices = index_to_indices(i, coefficients.size());
705 const auto coef = coefficients(indices);
706 if (coef == Number())
709 auto temp = Number(1);
710 for (
unsigned int d = 0; d < dim + 1; ++d)
712 result += coef * temp;
720template <
int dim,
typename Number>
724 return coefficients.memory_consumption();
729template <
int dim,
typename Number>
732 const std::size_t &index,
738 for (
unsigned int n = 0; n < dim + 1; ++n)
740 std::size_t slice_size = 1;
741 for (
unsigned int n2 = n + 1; n2 < dim + 1; ++n2)
742 slice_size *= extents[n2];
743 result[n] = temp / slice_size;
* * reference operator*() const
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
virtual ~BarycentricPolynomials()
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)