PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
delta.cpp
Go to the documentation of this file.
1
8#include <cmath>
9
10#include <petibm/delta.h>
11
12namespace petibm
13{
14namespace delta
15{
16// Regularized delta function from Roma et al. (1999).
17PetscReal Roma_et_al_1999(const PetscReal &r, const PetscReal &dr)
18{
19 PetscReal x = std::abs(r) / dr;
20
21 if (x > 1.5) return 0.0;
22
23 if (x > 0.5 && x <= 1.5)
24 return (5 - 3 * x - std::sqrt(-3 * (1 - x) * (1 - x) + 1)) / (6 * dr);
25
26 return (1 + std::sqrt(-3 * x * x + 1)) / (3 * dr);
27} // Roma_et_al_1999
28
29// Regularized delta function Peskin (2002).
30PetscReal Peskin_2002(const PetscReal &r, const PetscReal &dr)
31{
32 PetscReal x = std::abs(r) / dr;
33
34 if (x >= 0.0 && x <= 1.0)
35 return (3 - 2 * x + std::sqrt(1 + 4 * x - 4 * x * x)) / (8 * dr);
36 else if (x >= 1.0 && x <= 2.0)
37 return (5 - 2 * x - std::sqrt(-7 + 12 * x - 4 * x * x)) / (8 * dr);
38 return 0.0;
39} // Peskin_2002
40
41// Get the delta kernel and size to use
42PetscErrorCode getKernel(const std::string &name,
43 DeltaKernel &kernel, PetscInt &size)
44{
45 PetscFunctionBeginUser;
46
47 if (name == "ROMA_ET_AL_1999")
48 {
49 kernel = Roma_et_al_1999;
50 size = 2;
51 }
52 else if (name == "PESKIN_2002")
53 {
54 kernel = Peskin_2002;
55 size = 3;
56 }
57 else
58 SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_UNKNOWN_TYPE,
59 "No support for delta kernel `%s`.\n", name.c_str());
60
61 PetscFunctionReturn(0);
62} // getKernel
63
64// Discrete delta function.
65PetscReal delta(const std::vector<PetscReal> &source,
66 const std::vector<PetscReal> &target,
67 const std::vector<PetscReal> &widths,
68 const DeltaKernel &kernel)
69{
70 PetscReal phi = 1.0;
71 for (unsigned int d = 0; d < widths.size(); ++d)
72 phi *= kernel(source[d] - target[d], widths[d]);
73 return phi;
74} // delta
75
76} // end of namespace delta
77} // end of namespace petibm
Prototype of Delta functions.
PetscReal delta(const std::vector< PetscReal > &source, const std::vector< PetscReal > &target, const std::vector< PetscReal > &widths, const DeltaKernel &kernel)
Discrete delta function.
Definition: delta.cpp:65
PetscReal Roma_et_al_1999(const PetscReal &r, const PetscReal &dr)
Regularized delta function from Roma et al. (1999).
Definition: delta.cpp:17
PetscReal Peskin_2002(const PetscReal &r, const PetscReal &dr)
Regularized delta function from Peskin (2002).
Definition: delta.cpp:30
PetscErrorCode getKernel(const std::string &name, DeltaKernel &kernel, PetscInt &size)
Get the delta kernel and size providing the name.
Definition: delta.cpp:42
std::function< PetscReal(const PetscReal &r, const PetscReal &dr)> DeltaKernel
Typedef to choose the regularized delta kernel to use.
Definition: delta.h:47
A toolbox for building flow solvers.
Definition: bodypack.h:52