| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2015 - 2025 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 |
|
| 16 |
#ifndef dealii_polynomials_rannacher_turek_h |
| 17 |
#define dealii_polynomials_rannacher_turek_h |
| 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/scalar_polynomials_base.h> |
| 24 |
#include <deal.II/base/tensor.h> |
| 25 |
|
| 26 |
#include <vector> |
| 27 |
|
| 28 |
DEAL_II_NAMESPACE_OPEN |
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* Basis for polynomial space on the unit square used for lowest order |
| 33 |
* Rannacher Turek element. |
| 34 |
* |
| 35 |
* The i-th basis function is the dual basis element corresponding to the dof |
| 36 |
* which evaluates the function's mean value across the i-th face. The |
| 37 |
* numbering can be found in GeometryInfo. |
| 38 |
* |
| 39 |
* @ingroup Polynomials |
| 40 |
*/ |
| 41 |
template <int dim> |
| 42 |
class PolynomialsRannacherTurek : public ScalarPolynomialsBase<dim> |
| 43 |
{ |
| 44 |
public: |
| 45 |
/** |
| 46 |
* Dimension we are working in. |
| 47 |
*/ |
| 48 |
static constexpr unsigned int dimension = dim; |
| 49 |
|
| 50 |
/** |
| 51 |
* Constructor, checking that the basis is implemented in this dimension. |
| 52 |
*/ |
| 53 |
PolynomialsRannacherTurek(); |
| 54 |
|
| 55 |
/** |
| 56 |
* Value of basis function @p i at @p p. |
| 57 |
*/ |
| 58 |
double |
| 59 |
compute_value(const unsigned int i, const Point<dim> &p) const override; |
| 60 |
|
| 61 |
/** |
| 62 |
* <tt>order</tt>-th of basis function @p i at @p p. |
| 63 |
* |
| 64 |
* Consider using evaluate() instead. |
| 65 |
*/ |
| 66 |
template <int order> |
| 67 |
Tensor<order, dim> |
| 68 |
compute_derivative(const unsigned int i, const Point<dim> &p) const; |
| 69 |
|
| 70 |
/** |
| 71 |
* @copydoc ScalarPolynomialsBase::compute_1st_derivative() |
| 72 |
*/ |
| 73 |
virtual Tensor<1, dim> |
| 74 |
compute_1st_derivative(const unsigned int i, |
| 75 |
const Point<dim> &p) const override; |
| 76 |
|
| 77 |
/** |
| 78 |
* @copydoc ScalarPolynomialsBase::compute_2nd_derivative() |
| 79 |
*/ |
| 80 |
virtual Tensor<2, dim> |
| 81 |
compute_2nd_derivative(const unsigned int i, |
| 82 |
const Point<dim> &p) const override; |
| 83 |
|
| 84 |
/** |
| 85 |
* @copydoc ScalarPolynomialsBase::compute_3rd_derivative() |
| 86 |
*/ |
| 87 |
virtual Tensor<3, dim> |
| 88 |
compute_3rd_derivative(const unsigned int i, |
| 89 |
const Point<dim> &p) const override; |
| 90 |
|
| 91 |
/** |
| 92 |
* @copydoc ScalarPolynomialsBase::compute_4th_derivative() |
| 93 |
*/ |
| 94 |
virtual Tensor<4, dim> |
| 95 |
compute_4th_derivative(const unsigned int i, |
| 96 |
const Point<dim> &p) const override; |
| 97 |
|
| 98 |
/** |
| 99 |
* Gradient of basis function @p i at @p p. |
| 100 |
*/ |
| 101 |
Tensor<1, dim> |
| 102 |
compute_grad(const unsigned int i, const Point<dim> &p) const override; |
| 103 |
|
| 104 |
/** |
| 105 |
* Gradient of gradient of basis function @p i at @p p. |
| 106 |
*/ |
| 107 |
Tensor<2, dim> |
| 108 |
compute_grad_grad(const unsigned int i, const Point<dim> &p) const override; |
| 109 |
|
| 110 |
/** |
| 111 |
* Compute values and derivatives of all basis functions at @p unit_point. |
| 112 |
* |
| 113 |
* Size of the vectors must be either equal to the number of polynomials or |
| 114 |
* zero. A size of zero means that we are not computing the vector entries. |
| 115 |
*/ |
| 116 |
void |
| 117 |
evaluate(const Point<dim> &unit_point, |
| 118 |
std::vector<double> &values, |
| 119 |
std::vector<Tensor<1, dim>> &grads, |
| 120 |
std::vector<Tensor<2, dim>> &grad_grads, |
| 121 |
std::vector<Tensor<3, dim>> &third_derivatives, |
| 122 |
std::vector<Tensor<4, dim>> &fourth_derivatives) const override; |
| 123 |
|
| 124 |
/** |
| 125 |
* Return the name of the space, which is <tt>RannacherTurek</tt>. |
| 126 |
*/ |
| 127 |
std::string |
| 128 |
name() const override; |
| 129 |
|
| 130 |
/** |
| 131 |
* @copydoc ScalarPolynomialsBase::clone() |
| 132 |
*/ |
| 133 |
virtual std::unique_ptr<ScalarPolynomialsBase<dim>> |
| 134 |
clone() const override; |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
namespace internal |
| 139 |
{ |
| 140 |
namespace PolynomialsRannacherTurekImplementation |
| 141 |
{ |
| 142 |
template <int order, int dim> |
| 143 |
inline Tensor<order, dim> |
| 144 |
compute_derivative(const unsigned int, const Point<dim> &) |
| 145 |
{ |
| 146 |
Assert(dim == 2, ExcNotImplemented()); |
| 147 |
return Tensor<order, dim>(); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
template <int order> |
| 152 |
inline Tensor<order, 2> |
| 153 |
compute_derivative(const unsigned int i, const Point<2> &p) |
| 154 |
{ |
| 155 |
const unsigned int dim = 2; |
| 156 |
|
| 157 |
if constexpr (order == 1) |
| 158 |
{ |
| 159 |
Tensor<1, dim> derivative; |
| 160 |
if (i == 0) |
| 161 |
{ |
| 162 |
derivative[0] = -2.5 + 3 * p[0]; |
| 163 |
derivative[1] = 1.5 - 3 * p[1]; |
| 164 |
} |
| 165 |
else if (i == 1) |
| 166 |
{ |
| 167 |
derivative[0] = -0.5 + 3.0 * p[0]; |
| 168 |
derivative[1] = 1.5 - 3.0 * p[1]; |
| 169 |
} |
| 170 |
else if (i == 2) |
| 171 |
{ |
| 172 |
derivative[0] = 1.5 - 3.0 * p[0]; |
| 173 |
derivative[1] = -2.5 + 3.0 * p[1]; |
| 174 |
} |
| 175 |
else if (i == 3) |
| 176 |
{ |
| 177 |
derivative[0] = 1.5 - 3.0 * p[0]; |
| 178 |
derivative[1] = -0.5 + 3.0 * p[1]; |
| 179 |
} |
| 180 |
else |
| 181 |
{ |
| 182 |
DEAL_II_NOT_IMPLEMENTED(); |
| 183 |
} |
| 184 |
return derivative; |
| 185 |
} |
| 186 |
else if constexpr (order == 2) |
| 187 |
{ |
| 188 |
Tensor<2, dim> derivative; |
| 189 |
if (i == 0) |
| 190 |
{ |
| 191 |
derivative[0][0] = 3; |
| 192 |
derivative[0][1] = 0; |
| 193 |
derivative[1][0] = 0; |
| 194 |
derivative[1][1] = -3; |
| 195 |
} |
| 196 |
else if (i == 1) |
| 197 |
{ |
| 198 |
derivative[0][0] = 3; |
| 199 |
derivative[0][1] = 0; |
| 200 |
derivative[1][0] = 0; |
| 201 |
derivative[1][1] = -3; |
| 202 |
} |
| 203 |
else if (i == 2) |
| 204 |
{ |
| 205 |
derivative[0][0] = -3; |
| 206 |
derivative[0][1] = 0; |
| 207 |
derivative[1][0] = 0; |
| 208 |
derivative[1][1] = 3; |
| 209 |
} |
| 210 |
else if (i == 3) |
| 211 |
{ |
| 212 |
derivative[0][0] = -3; |
| 213 |
derivative[0][1] = 0; |
| 214 |
derivative[1][0] = 0; |
| 215 |
derivative[1][1] = 3; |
| 216 |
} |
| 217 |
else |
| 218 |
{ |
| 219 |
DEAL_II_NOT_IMPLEMENTED(); |
| 220 |
} |
| 221 |
return derivative; |
| 222 |
} |
| 223 |
else |
| 224 |
{ |
| 225 |
// higher derivatives are all zero |
| 226 |
return {}; |
| 227 |
} |
| 228 |
} |
| 229 |
} // namespace PolynomialsRannacherTurekImplementation |
| 230 |
} // namespace internal |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
// template functions |
| 235 |
template <int dim> |
| 236 |
template <int order> |
| 237 |
Tensor<order, dim> |
| 238 |
PolynomialsRannacherTurek<dim>::compute_derivative(const unsigned int i, |
| 239 |
const Point<dim> &p) const |
| 240 |
{ |
| 241 |
return internal::PolynomialsRannacherTurekImplementation::compute_derivative< |
| 242 |
order>(i, p); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
template <int dim> |
| 248 |
inline Tensor<1, dim> |
| 249 |
PolynomialsRannacherTurek<dim>::compute_1st_derivative( |
| 250 |
const unsigned int i, |
| 251 |
const Point<dim> &p) const |
| 252 |
{ |
| 253 |
return compute_derivative<1>(i, p); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
template <int dim> |
| 259 |
inline Tensor<2, dim> |
| 260 |
PolynomialsRannacherTurek<dim>::compute_2nd_derivative( |
| 261 |
const unsigned int i, |
| 262 |
const Point<dim> &p) const |
| 263 |
{ |
| 264 |
return compute_derivative<2>(i, p); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
template <int dim> |
| 270 |
inline Tensor<3, dim> |
| 271 |
PolynomialsRannacherTurek<dim>::compute_3rd_derivative( |
| 272 |
const unsigned int i, |
| 273 |
const Point<dim> &p) const |
| 274 |
{ |
| 275 |
return compute_derivative<3>(i, p); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
template <int dim> |
| 281 |
inline Tensor<4, dim> |
| 282 |
PolynomialsRannacherTurek<dim>::compute_4th_derivative( |
| 283 |
const unsigned int i, |
| 284 |
const Point<dim> &p) const |
| 285 |
{ |
| 286 |
return compute_derivative<4>(i, p); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
template <int dim> |
| 292 |
inline std::string |
| 293 |
PolynomialsRannacherTurek<dim>::name() const |
| 294 |
{ |
| 295 |
return "RannacherTurek"; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
DEAL_II_NAMESPACE_CLOSE |
| 300 |
|
| 301 |
#endif |