| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2007 - 2023 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_flow_function_h |
| 16 |
#define dealii_flow_function_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/function.h> |
| 22 |
#include <deal.II/base/mutex.h> |
| 23 |
#include <deal.II/base/point.h> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
namespace Functions |
| 28 |
{ |
| 29 |
/** |
| 30 |
* Base class for analytic solutions to incompressible flow problems. |
| 31 |
* |
| 32 |
* Additional to the Function interface, this function provides for an |
| 33 |
* offset of the pressure: if the pressure of the computed solution has an |
| 34 |
* integral mean value different from zero, this value can be given to |
| 35 |
* pressure_adjustment() in order to compute correct pressure errors. |
| 36 |
* |
| 37 |
* @note Derived classes should implement pressures with integral mean value |
| 38 |
* zero always. |
| 39 |
* |
| 40 |
* @note Thread safety: Some of the functions make use of internal data to |
| 41 |
* compute values. Therefore, every thread should obtain its own object of |
| 42 |
* derived classes. |
| 43 |
* |
| 44 |
* @ingroup functions |
| 45 |
*/ |
| 46 |
template <int dim> |
| 47 |
class FlowFunction : public Function<dim> |
| 48 |
{ |
| 49 |
public: |
| 50 |
/** |
| 51 |
* Constructor, setting up some internal data structures. |
| 52 |
*/ |
| 53 |
FlowFunction(); |
| 54 |
|
| 55 |
/** |
| 56 |
* Virtual destructor. |
| 57 |
*/ |
| 58 |
virtual ~FlowFunction() override = default; |
| 59 |
|
| 60 |
/** |
| 61 |
* Store an adjustment for the pressure function, such that its mean value |
| 62 |
* is <tt>p</tt>. |
| 63 |
*/ |
| 64 |
void |
| 65 |
pressure_adjustment(double p); |
| 66 |
|
| 67 |
/** |
| 68 |
* Values in a structure more suitable for vector valued functions. The |
| 69 |
* outer vector is indexed by solution component, the inner by quadrature |
| 70 |
* point. |
| 71 |
*/ |
| 72 |
virtual void |
| 73 |
vector_values(const std::vector<Point<dim>> &points, |
| 74 |
std::vector<std::vector<double>> &values) const override = 0; |
| 75 |
/** |
| 76 |
* Gradients in a structure more suitable for vector valued functions. The |
| 77 |
* outer vector is indexed by solution component, the inner by quadrature |
| 78 |
* point. |
| 79 |
*/ |
| 80 |
virtual void |
| 81 |
vector_gradients( |
| 82 |
const std::vector<Point<dim>> &points, |
| 83 |
std::vector<std::vector<Tensor<1, dim>>> &gradients) const override = 0; |
| 84 |
/** |
| 85 |
* Force terms in a structure more suitable for vector valued functions. |
| 86 |
* The outer vector is indexed by solution component, the inner by |
| 87 |
* quadrature point. |
| 88 |
* |
| 89 |
* @warning This is not the true Laplacian, but the force term to be used |
| 90 |
* as right hand side in Stokes' equations |
| 91 |
*/ |
| 92 |
virtual void |
| 93 |
vector_laplacians(const std::vector<Point<dim>> &points, |
| 94 |
std::vector<std::vector<double>> &values) const = 0; |
| 95 |
|
| 96 |
virtual void |
| 97 |
vector_value(const Point<dim> &points, |
| 98 |
Vector<double> &value) const override; |
| 99 |
virtual double |
| 100 |
value(const Point<dim> &points, |
| 101 |
const unsigned int component) const override; |
| 102 |
virtual void |
| 103 |
vector_value_list(const std::vector<Point<dim>> &points, |
| 104 |
std::vector<Vector<double>> &values) const override; |
| 105 |
virtual void |
| 106 |
vector_gradient_list( |
| 107 |
const std::vector<Point<dim>> &points, |
| 108 |
std::vector<std::vector<Tensor<1, dim>>> &gradients) const override; |
| 109 |
/** |
| 110 |
* The force term in the momentum equation. |
| 111 |
*/ |
| 112 |
virtual void |
| 113 |
vector_laplacian_list(const std::vector<Point<dim>> &points, |
| 114 |
std::vector<Vector<double>> &values) const override; |
| 115 |
|
| 116 |
/** |
| 117 |
* Return an estimate for the memory consumption, in bytes, of this object. |
| 118 |
*/ |
| 119 |
virtual std::size_t |
| 120 |
memory_consumption() const override; |
| 121 |
|
| 122 |
protected: |
| 123 |
/** |
| 124 |
* Mean value of the pressure to be added by derived classes. |
| 125 |
*/ |
| 126 |
double mean_pressure; |
| 127 |
|
| 128 |
private: |
| 129 |
/** |
| 130 |
* A mutex that guards the following scratch arrays. |
| 131 |
*/ |
| 132 |
mutable Threads::Mutex mutex; |
| 133 |
|
| 134 |
/** |
| 135 |
* Auxiliary values for the usual Function interface. |
| 136 |
*/ |
| 137 |
mutable std::vector<std::vector<double>> aux_values; |
| 138 |
|
| 139 |
/** |
| 140 |
* Auxiliary values for the usual Function interface. |
| 141 |
*/ |
| 142 |
mutable std::vector<std::vector<Tensor<1, dim>>> aux_gradients; |
| 143 |
}; |
| 144 |
|
| 145 |
/** |
| 146 |
* Laminar pipe flow in two and three dimensions. The channel stretches |
| 147 |
* along the <i>x</i>-axis and has radius @p radius. The @p Reynolds number |
| 148 |
* is used to scale the pressure properly for a Navier-Stokes problem. |
| 149 |
* |
| 150 |
* @ingroup functions |
| 151 |
*/ |
| 152 |
template <int dim> |
| 153 |
class PoisseuilleFlow : public FlowFunction<dim> |
| 154 |
{ |
| 155 |
public: |
| 156 |
/** |
| 157 |
* Construct an object for the given channel radius <tt>r</tt> and the |
| 158 |
* Reynolds number <tt>Re</tt>. |
| 159 |
*/ |
| 160 |
PoisseuilleFlow(const double r, const double Re); |
| 161 |
|
| 162 |
virtual ~PoisseuilleFlow() override = default; |
| 163 |
|
| 164 |
virtual void |
| 165 |
vector_values(const std::vector<Point<dim>> &points, |
| 166 |
std::vector<std::vector<double>> &values) const override; |
| 167 |
virtual void |
| 168 |
vector_gradients( |
| 169 |
const std::vector<Point<dim>> &points, |
| 170 |
std::vector<std::vector<Tensor<1, dim>>> &gradients) const override; |
| 171 |
virtual void |
| 172 |
vector_laplacians(const std::vector<Point<dim>> &points, |
| 173 |
std::vector<std::vector<double>> &values) const override; |
| 174 |
|
| 175 |
private: |
| 176 |
const double inv_sqr_radius; |
| 177 |
const double Reynolds; |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
/** |
| 182 |
* Artificial divergence free function with homogeneous boundary conditions |
| 183 |
* on the cube [-1,1]<sup>dim</sup>. |
| 184 |
* |
| 185 |
* The function in 2d is |
| 186 |
* @f[ |
| 187 |
* \left(\begin{array}{c}u\\v\\p\end{array}\right) |
| 188 |
* \left(\begin{array}{c}\cos^2x \sin y\cos y\\-\sin x\cos x\cos^2y\\ |
| 189 |
* \sin x\cos x\sin y\cos y\end{array}\right) |
| 190 |
* @f] |
| 191 |
* @ingroup functions |
| 192 |
*/ |
| 193 |
template <int dim> |
| 194 |
class StokesCosine : public FlowFunction<dim> |
| 195 |
{ |
| 196 |
public: |
| 197 |
/** |
| 198 |
* Constructor setting the Reynolds number required for pressure |
| 199 |
* computation and scaling of the right hand side. |
| 200 |
*/ |
| 201 |
StokesCosine(const double viscosity = 1., const double reaction = 0.); |
| 202 |
/** |
| 203 |
* Change the viscosity and the reaction parameter. |
| 204 |
*/ |
| 205 |
void |
| 206 |
set_parameters(const double viscosity, const double reaction); |
| 207 |
|
| 208 |
virtual ~StokesCosine() override = default; |
| 209 |
|
| 210 |
virtual void |
| 211 |
vector_values(const std::vector<Point<dim>> &points, |
| 212 |
std::vector<std::vector<double>> &values) const override; |
| 213 |
virtual void |
| 214 |
vector_gradients( |
| 215 |
const std::vector<Point<dim>> &points, |
| 216 |
std::vector<std::vector<Tensor<1, dim>>> &gradients) const override; |
| 217 |
virtual void |
| 218 |
vector_laplacians(const std::vector<Point<dim>> &points, |
| 219 |
std::vector<std::vector<double>> &values) const override; |
| 220 |
|
| 221 |
private: |
| 222 |
/// The viscosity |
| 223 |
double viscosity; |
| 224 |
/// The reaction parameter |
| 225 |
double reaction; |
| 226 |
}; |
| 227 |
|
| 228 |
|
| 229 |
/** |
| 230 |
* A singular solution to Stokes' equations on a 2d L-shaped domain. |
| 231 |
* |
| 232 |
* This function satisfies $-\triangle \mathbf{u} + \nabla p = 0$ and |
| 233 |
* represents a typical singular solution around a reentrant corner of an |
| 234 |
* L-shaped domain that can be created using GridGenerator::hyper_L(). The |
| 235 |
* velocity vanishes on the two faces of the re-entrant corner and |
| 236 |
* $\nabla\mathbf{u}$ and $p$ are singular at the origin while they are |
| 237 |
* smooth in the rest of the domain because they can be written as a product |
| 238 |
* of a smooth function and the term $r^{\lambda-1}$ where $r$ is the radius |
| 239 |
* and $\lambda \approx 0.54448$ is a fixed parameter. |
| 240 |
* |
| 241 |
* Taken from Houston, Schötzau, Wihler, proceeding ENUMATH 2003. |
| 242 |
* |
| 243 |
* @ingroup functions |
| 244 |
*/ |
| 245 |
class StokesLSingularity : public FlowFunction<2> |
| 246 |
{ |
| 247 |
public: |
| 248 |
/// Constructor setting up some data. |
| 249 |
StokesLSingularity(); |
| 250 |
|
| 251 |
virtual void |
| 252 |
vector_values(const std::vector<Point<2>> &points, |
| 253 |
std::vector<std::vector<double>> &values) const override; |
| 254 |
virtual void |
| 255 |
vector_gradients( |
| 256 |
const std::vector<Point<2>> &points, |
| 257 |
std::vector<std::vector<Tensor<1, 2>>> &gradients) const override; |
| 258 |
virtual void |
| 259 |
vector_laplacians(const std::vector<Point<2>> &points, |
| 260 |
std::vector<std::vector<double>> &values) const override; |
| 261 |
|
| 262 |
private: |
| 263 |
/// The auxiliary function Psi. |
| 264 |
double |
| 265 |
Psi(double phi) const; |
| 266 |
/// The derivative of Psi() |
| 267 |
double |
| 268 |
Psi_1(double phi) const; |
| 269 |
/// The 2nd derivative of Psi() |
| 270 |
double |
| 271 |
Psi_2(double phi) const; |
| 272 |
/// The 3rd derivative of Psi() |
| 273 |
double |
| 274 |
Psi_3(double phi) const; |
| 275 |
/// The 4th derivative of Psi() |
| 276 |
double |
| 277 |
Psi_4(double phi) const; |
| 278 |
/// The angle of the reentrant corner, set to 3*pi/2 |
| 279 |
const double omega; |
| 280 |
/// The exponent of the radius, computed as the solution to |
| 281 |
/// $\sin(\lambda\omega)+\lambda \sin(\omega)=0$ |
| 282 |
static const double lambda; |
| 283 |
/// Cosine of lambda times omega |
| 284 |
const double coslo; |
| 285 |
/// Auxiliary variable 1+lambda |
| 286 |
const double lp; |
| 287 |
/// Auxiliary variable 1-lambda |
| 288 |
const double lm; |
| 289 |
}; |
| 290 |
|
| 291 |
/** |
| 292 |
* Flow solution in 2d by Kovasznay (1947). |
| 293 |
* |
| 294 |
* This function is valid on the half plane right of the line <i>x=1/2</i>. |
| 295 |
* |
| 296 |
* @ingroup functions |
| 297 |
*/ |
| 298 |
class Kovasznay : public FlowFunction<2> |
| 299 |
{ |
| 300 |
public: |
| 301 |
/** |
| 302 |
* Construct an object for the give Reynolds number <tt>Re</tt>. If the |
| 303 |
* parameter <tt>Stokes</tt> is true, the right hand side of the momentum |
| 304 |
* equation returned by vector_laplacians() contains the nonlinearity, |
| 305 |
* such that the Kovasznay solution can be obtained as the solution to a |
| 306 |
* Stokes problem. |
| 307 |
*/ |
| 308 |
Kovasznay(const double Re, bool Stokes = false); |
| 309 |
|
| 310 |
virtual ~Kovasznay() override = default; |
| 311 |
|
| 312 |
virtual void |
| 313 |
vector_values(const std::vector<Point<2>> &points, |
| 314 |
std::vector<std::vector<double>> &values) const override; |
| 315 |
virtual void |
| 316 |
vector_gradients( |
| 317 |
const std::vector<Point<2>> &points, |
| 318 |
std::vector<std::vector<Tensor<1, 2>>> &gradients) const override; |
| 319 |
virtual void |
| 320 |
vector_laplacians(const std::vector<Point<2>> &points, |
| 321 |
std::vector<std::vector<double>> &values) const override; |
| 322 |
|
| 323 |
/// The value of lambda. |
| 324 |
double |
| 325 |
lambda() const; |
| 326 |
|
| 327 |
private: |
| 328 |
const double Reynolds; |
| 329 |
double lbda; |
| 330 |
double p_average; |
| 331 |
const bool stokes; |
| 332 |
}; |
| 333 |
|
| 334 |
} // namespace Functions |
| 335 |
|
| 336 |
DEAL_II_NAMESPACE_CLOSE |
| 337 |
|
| 338 |
#endif |