// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2013 - 2023 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_tensor_product_polynomials_const_h #define dealii_tensor_product_polynomials_const_h #include #include #include #include #include #include #include #include DEAL_II_NAMESPACE_OPEN /** * @addtogroup Polynomials * @{ */ /** * Tensor product of given polynomials and a locally constant function. This * class inherits most of its functionality from TensorProductPolynomials. It * works similarly to that class but adds a constant function for the last * index. */ template class TensorProductPolynomialsConst : public ScalarPolynomialsBase { public: /** * Access to the dimension of this object, for checking and automatic * setting of dimension in other classes. */ static constexpr unsigned int dimension = dim; /** * Constructor. pols is a vector of objects that should be derived * or otherwise convertible to one-dimensional polynomial objects. It will * be copied element by element into a private variable. */ template TensorProductPolynomialsConst(const std::vector &pols); /** * Print the list of tensor_polys indices to out. */ void output_indices(std::ostream &out) const; /** * Set the ordering of the polynomials. Requires * renumber.size()==tensor_polys.n(). Stores a copy of * renumber. */ void set_numbering(const std::vector &renumber); /** * Give read access to the renumber vector. */ const std::vector & get_numbering() const; /** * Give read access to the inverse renumber vector. */ const std::vector & get_numbering_inverse() const; /** * Compute the value and the first and second derivatives of each tensor * product polynomial at unit_point. * * The size of the vectors must either be equal 0 or equal n(). In the first * case, the function will not compute these values. * * If you need values or derivatives of all tensor product polynomials then * use this function, rather than using any of the compute_value(), * compute_grad() or compute_grad_grad() functions, see below, in a loop * over all tensor product polynomials. */ void evaluate(const Point &unit_point, std::vector &values, std::vector> &grads, std::vector> &grad_grads, std::vector> &third_derivatives, std::vector> &fourth_derivatives) const override; /** * Compute the value of the ith tensor product polynomial at * unit_point. Here i is given in tensor product * numbering. * * Note, that using this function within a loop over all tensor product * polynomials is not efficient, because then each point value of the * underlying (one-dimensional) polynomials is (unnecessarily) computed * several times. Instead use the evaluate() function with * values.size()==n() to get the point values of all tensor * polynomials all at once and in a much more efficient way. */ double compute_value(const unsigned int i, const Point &p) const override; /** * Compute the orderth derivative of the ith tensor * product polynomial at unit_point. Here i is given in * tensor product numbering. * * Note, that using this function within a loop over all tensor product * polynomials is not efficient, because then each derivative value of the * underlying (one-dimensional) polynomials is (unnecessarily) computed * several times. Instead use the evaluate() function, see above, with the * size of the appropriate parameter set to n() to get the point value of * all tensor polynomials all at once and in a much more efficient way. * * @tparam order The derivative order. */ template Tensor compute_derivative(const unsigned int i, const Point &p) const; /** * @copydoc ScalarPolynomialsBase::compute_1st_derivative() */ virtual Tensor<1, dim> compute_1st_derivative(const unsigned int i, const Point &p) const override; /** * @copydoc ScalarPolynomialsBase::compute_2nd_derivative() */ virtual Tensor<2, dim> compute_2nd_derivative(const unsigned int i, const Point &p) const override; /** * @copydoc ScalarPolynomialsBase::compute_3rd_derivative() */ virtual Tensor<3, dim> compute_3rd_derivative(const unsigned int i, const Point &p) const override; /** * @copydoc ScalarPolynomialsBase::compute_4th_derivative() */ virtual Tensor<4, dim> compute_4th_derivative(const unsigned int i, const Point &p) const override; /** * Compute the grad of the ith tensor product polynomial at * unit_point. Here i is given in tensor product * numbering. * * Note, that using this function within a loop over all tensor product * polynomials is not efficient, because then each derivative value of the * underlying (one-dimensional) polynomials is (unnecessarily) computed * several times. Instead use the evaluate() function, see above, with * grads.size()==n() to get the point value of all tensor * polynomials all at once and in a much more efficient way. */ Tensor<1, dim> compute_grad(const unsigned int i, const Point &p) const override; /** * Compute the second derivative (grad_grad) of the ith tensor * product polynomial at unit_point. Here i is given in * tensor product numbering. * * Note, that using this function within a loop over all tensor product * polynomials is not efficient, because then each derivative value of the * underlying (one-dimensional) polynomials is (unnecessarily) computed * several times. Instead use the evaluate() function, see above, with * grad_grads.size()==n() to get the point value of all tensor * polynomials all at once and in a much more efficient way. */ Tensor<2, dim> compute_grad_grad(const unsigned int i, const Point &p) const override; /** * Return the number of tensor product polynomials plus the constant * function. For n 1d polynomials this is ndim+1. */ unsigned int n() const; /** * Return the name of the space, which is * TensorProductPolynomialsConst. */ std::string name() const override; /** * @copydoc ScalarPolynomialsBase::clone() */ virtual std::unique_ptr> clone() const override; private: /** * The TensorProductPolynomials object */ TensorProductPolynomials tensor_polys; /** * Index map for reordering the polynomials. */ std::vector index_map; /** * Index map for reordering the polynomials. */ std::vector index_map_inverse; }; /** @} */ /* ---------------- template and inline functions ---------- */ #ifndef DOXYGEN template template inline TensorProductPolynomialsConst::TensorProductPolynomialsConst( const std::vector &pols) : ScalarPolynomialsBase(1, Utilities::fixed_power(pols.size()) + 1) , tensor_polys(pols) , index_map(tensor_polys.n() + 1) , index_map_inverse(tensor_polys.n() + 1) {} template inline unsigned int TensorProductPolynomialsConst::n() const { return tensor_polys.n() + 1; } template inline const std::vector & TensorProductPolynomialsConst::get_numbering() const { return index_map; } template inline const std::vector & TensorProductPolynomialsConst::get_numbering_inverse() const { return index_map_inverse; } template inline std::string TensorProductPolynomialsConst::name() const { return "TensorProductPolynomialsConst"; } template <> inline unsigned int TensorProductPolynomialsConst<0>::n() const { return numbers::invalid_unsigned_int; } template template Tensor TensorProductPolynomialsConst::compute_derivative( const unsigned int i, const Point &p) const { const unsigned int max_indices = tensor_polys.n(); Assert(i <= max_indices, ExcInternalError()); // treat the regular basis functions if (i < max_indices) return tensor_polys.template compute_derivative(i, p); else // this is for the constant function return Tensor(); } template inline Tensor<1, dim> TensorProductPolynomialsConst::compute_1st_derivative( const unsigned int i, const Point &p) const { return compute_derivative<1>(i, p); } template inline Tensor<2, dim> TensorProductPolynomialsConst::compute_2nd_derivative( const unsigned int i, const Point &p) const { return compute_derivative<2>(i, p); } template inline Tensor<3, dim> TensorProductPolynomialsConst::compute_3rd_derivative( const unsigned int i, const Point &p) const { return compute_derivative<3>(i, p); } template inline Tensor<4, dim> TensorProductPolynomialsConst::compute_4th_derivative( const unsigned int i, const Point &p) const { return compute_derivative<4>(i, p); } #endif // DOXYGEN DEAL_II_NAMESPACE_CLOSE #endif