| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2019 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_scalar_polynomials_base_h |
| 16 |
#define dealii_scalar_polynomials_base_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/exceptions.h> |
| 22 |
#include <deal.II/base/point.h> |
| 23 |
#include <deal.II/base/tensor.h> |
| 24 |
|
| 25 |
#include <memory> |
| 26 |
#include <string> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
DEAL_II_NAMESPACE_OPEN |
| 30 |
|
| 31 |
/** |
| 32 |
* This class provides a framework for the finite element polynomial |
| 33 |
* classes for use with finite element classes that are derived from |
| 34 |
* FE_Poly. An object of this type (or rather of a type derived from |
| 35 |
* this class) is stored as a member variable in each object of type |
| 36 |
* FE_Poly. |
| 37 |
* |
| 38 |
* <h3>Deriving classes</h3> |
| 39 |
* |
| 40 |
* Any derived class must provide the most basic properties for shape |
| 41 |
* functions evaluated on the reference cell. This includes, but is not |
| 42 |
* limited to, implementing the evaluate(), name(), and |
| 43 |
* clone() member functions. These functions are necessary to store the |
| 44 |
* most basic information of how the polynomials in the derived class evaluate |
| 45 |
* at a given point on the reference cell. More information on each function can |
| 46 |
* be found in the corresponding function's documentation. |
| 47 |
* |
| 48 |
* Some classes that derive from this class include |
| 49 |
* <ul> |
| 50 |
* <li> <tt>PolynomialsAdini</tt> |
| 51 |
* <li> <tt>PolynomialsRannacherTurek</tt> |
| 52 |
* <li> <tt>PolynomialsP</tt> |
| 53 |
* <li> <tt>PolynomialSpace</tt> |
| 54 |
* <li> <tt>TensorProductPolynomials</tt> |
| 55 |
* <li> <tt>TensorProductPolynomialsConst</tt> |
| 56 |
* <li> <tt>TensorProductPolynomialsBubbles</tt> |
| 57 |
* </ul> |
| 58 |
* |
| 59 |
* @ingroup Polynomials |
| 60 |
*/ |
| 61 |
template <int dim> |
| 62 |
class ScalarPolynomialsBase |
| 63 |
{ |
| 64 |
public: |
| 65 |
/** |
| 66 |
* Constructor. This takes the degree of the space, @p deg from the finite element |
| 67 |
* class, and @p n, the number of polynomials for the space. |
| 68 |
*/ |
| 69 |
ScalarPolynomialsBase(const unsigned int deg, |
| 70 |
const unsigned int n_polynomials); |
| 71 |
|
| 72 |
/** |
| 73 |
* Move constructor. |
| 74 |
*/ |
| 75 |
ScalarPolynomialsBase(ScalarPolynomialsBase<dim> &&) = default; // NOLINT |
| 76 |
|
| 77 |
/** |
| 78 |
* Copy constructor. |
| 79 |
*/ |
| 80 |
ScalarPolynomialsBase(const ScalarPolynomialsBase<dim> &) = default; |
| 81 |
|
| 82 |
/** |
| 83 |
* Virtual destructor. Makes sure that pointers to this class are deleted |
| 84 |
* properly. |
| 85 |
*/ |
| 86 |
virtual ~ScalarPolynomialsBase() = default; |
| 87 |
|
| 88 |
/** |
| 89 |
* Compute the value and the derivatives of the polynomials at |
| 90 |
* @p unit_point. |
| 91 |
* |
| 92 |
* The size of the vectors must either be zero or equal <tt>n()</tt>. In |
| 93 |
* the first case, the function will not compute these values. |
| 94 |
* |
| 95 |
* If you need values or derivatives of all polynomials then use this |
| 96 |
* function, rather than using any of the <tt>compute_value</tt>, |
| 97 |
* <tt>compute_grad</tt> or <tt>compute_grad_grad</tt> functions, see below, |
| 98 |
* in a loop over all tensor product polynomials. |
| 99 |
*/ |
| 100 |
virtual void |
| 101 |
evaluate(const Point<dim> &unit_point, |
| 102 |
std::vector<double> &values, |
| 103 |
std::vector<Tensor<1, dim>> &grads, |
| 104 |
std::vector<Tensor<2, dim>> &grad_grads, |
| 105 |
std::vector<Tensor<3, dim>> &third_derivatives, |
| 106 |
std::vector<Tensor<4, dim>> &fourth_derivatives) const = 0; |
| 107 |
|
| 108 |
/** |
| 109 |
* Compute the value of the <tt>i</tt>th polynomial at unit point |
| 110 |
* <tt>p</tt>. |
| 111 |
* |
| 112 |
* Consider using evaluate() instead. |
| 113 |
*/ |
| 114 |
virtual double |
| 115 |
compute_value(const unsigned int i, const Point<dim> &p) const = 0; |
| 116 |
|
| 117 |
/** |
| 118 |
* Compute the <tt>order</tt>th derivative of the <tt>i</tt>th polynomial |
| 119 |
* at unit point <tt>p</tt>. |
| 120 |
* |
| 121 |
* Consider using evaluate() instead. |
| 122 |
* |
| 123 |
* @tparam order The order of the derivative. |
| 124 |
*/ |
| 125 |
template <int order> |
| 126 |
Tensor<order, dim> |
| 127 |
compute_derivative(const unsigned int i, const Point<dim> &p) const; |
| 128 |
|
| 129 |
/** |
| 130 |
* Compute the first derivative of the <tt>i</tt>th polynomial |
| 131 |
* at unit point <tt>p</tt>. |
| 132 |
* |
| 133 |
* Consider using evaluate() instead. |
| 134 |
*/ |
| 135 |
virtual Tensor<1, dim> |
| 136 |
compute_1st_derivative(const unsigned int i, const Point<dim> &p) const = 0; |
| 137 |
|
| 138 |
/** |
| 139 |
* Compute the second derivative of the <tt>i</tt>th polynomial |
| 140 |
* at unit point <tt>p</tt>. |
| 141 |
* |
| 142 |
* Consider using evaluate() instead. |
| 143 |
*/ |
| 144 |
virtual Tensor<2, dim> |
| 145 |
compute_2nd_derivative(const unsigned int i, const Point<dim> &p) const = 0; |
| 146 |
|
| 147 |
/** |
| 148 |
* Compute the third derivative of the <tt>i</tt>th polynomial |
| 149 |
* at unit point <tt>p</tt>. |
| 150 |
* |
| 151 |
* Consider using evaluate() instead. |
| 152 |
*/ |
| 153 |
virtual Tensor<3, dim> |
| 154 |
compute_3rd_derivative(const unsigned int i, const Point<dim> &p) const = 0; |
| 155 |
|
| 156 |
/** |
| 157 |
* Compute the fourth derivative of the <tt>i</tt>th polynomial |
| 158 |
* at unit point <tt>p</tt>. |
| 159 |
* |
| 160 |
* Consider using evaluate() instead. |
| 161 |
*/ |
| 162 |
virtual Tensor<4, dim> |
| 163 |
compute_4th_derivative(const unsigned int i, const Point<dim> &p) const = 0; |
| 164 |
|
| 165 |
/** |
| 166 |
* Compute the gradient of the <tt>i</tt>th polynomial at unit point |
| 167 |
* <tt>p</tt>. |
| 168 |
* |
| 169 |
* Consider using evaluate() instead. |
| 170 |
*/ |
| 171 |
virtual Tensor<1, dim> |
| 172 |
compute_grad(const unsigned int /*i*/, const Point<dim> & /*p*/) const = 0; |
| 173 |
|
| 174 |
/** |
| 175 |
* Compute the second derivative (grad_grad) of the <tt>i</tt>th polynomial |
| 176 |
* at unit point <tt>p</tt>. |
| 177 |
* |
| 178 |
* Consider using evaluate() instead. |
| 179 |
*/ |
| 180 |
virtual Tensor<2, dim> |
| 181 |
compute_grad_grad(const unsigned int /*i*/, |
| 182 |
const Point<dim> & /*p*/) const = 0; |
| 183 |
|
| 184 |
/** |
| 185 |
* Return the number of polynomials. |
| 186 |
*/ |
| 187 |
unsigned int |
| 188 |
n() const; |
| 189 |
|
| 190 |
/** |
| 191 |
* Return the highest polynomial degree of polynomials represented by this |
| 192 |
* class. A derived class may override this if its value is different from |
| 193 |
* @p my_degree. |
| 194 |
*/ |
| 195 |
virtual unsigned int |
| 196 |
degree() const; |
| 197 |
|
| 198 |
/** |
| 199 |
* A sort of virtual copy constructor, this function returns a copy of |
| 200 |
* the polynomial space object. Derived classes need to override the function |
| 201 |
* here in this base class and return an object of the same type as the |
| 202 |
* derived class. |
| 203 |
* |
| 204 |
* Some places in the library, for example the constructors of FE_Poly, |
| 205 |
* need to make copies of polynomial spaces without knowing their exact type. |
| 206 |
* They do so through this function. |
| 207 |
*/ |
| 208 |
virtual std::unique_ptr<ScalarPolynomialsBase<dim>> |
| 209 |
clone() const = 0; |
| 210 |
|
| 211 |
/** |
| 212 |
* Return the name of the space. |
| 213 |
*/ |
| 214 |
virtual std::string |
| 215 |
name() const = 0; |
| 216 |
|
| 217 |
/** |
| 218 |
* Return an estimate (in bytes) for the memory consumption of this object. |
| 219 |
*/ |
| 220 |
virtual std::size_t |
| 221 |
memory_consumption() const; |
| 222 |
|
| 223 |
private: |
| 224 |
/** |
| 225 |
* The highest polynomial degree of this functions represented by this object. |
| 226 |
*/ |
| 227 |
const unsigned int polynomial_degree; |
| 228 |
|
| 229 |
/** |
| 230 |
* The number of polynomials represented by this object. |
| 231 |
*/ |
| 232 |
const unsigned int n_pols; |
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
template <int dim> |
| 238 |
inline unsigned int |
| 239 |
ScalarPolynomialsBase<dim>::n() const |
| 240 |
{ |
| 241 |
return n_pols; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
template <int dim> |
| 247 |
inline unsigned int |
| 248 |
ScalarPolynomialsBase<dim>::degree() const |
| 249 |
{ |
| 250 |
return polynomial_degree; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
template <int dim> |
| 256 |
template <int order> |
| 257 |
inline Tensor<order, dim> |
| 258 |
ScalarPolynomialsBase<dim>::compute_derivative(const unsigned int i, |
| 259 |
const Point<dim> &p) const |
| 260 |
{ |
| 261 |
if constexpr (order == 1) |
| 262 |
{ |
| 263 |
return compute_1st_derivative(i, p); |
| 264 |
} |
| 265 |
else if constexpr (order == 2) |
| 266 |
{ |
| 267 |
return compute_2nd_derivative(i, p); |
| 268 |
} |
| 269 |
else if constexpr (order == 3) |
| 270 |
{ |
| 271 |
return compute_3rd_derivative(i, p); |
| 272 |
} |
| 273 |
else if constexpr (order == 4) |
| 274 |
{ |
| 275 |
return compute_4th_derivative(i, p); |
| 276 |
} |
| 277 |
else |
| 278 |
{ |
| 279 |
DEAL_II_NOT_IMPLEMENTED(); |
| 280 |
return {}; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
DEAL_II_NAMESPACE_CLOSE |
| 285 |
|
| 286 |
#endif |