AutoPas  3.0.0
Loading...
Searching...
No Matches
SPHKernels.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <algorithm>
10#include <array>
11#include <cmath>
12
14
15namespace sphLib {
20 static constexpr double pi = M_PI; // atan(1.0) * 4.0;
21 static constexpr double kernelSupportRadius = 2.5;
22 // const double C_CFL = 0.3;
23 public:
28 static inline double getKernelSupportRadius() { return kernelSupportRadius; }
29
37 static inline double W(const std::array<double, 3> &dr, const double h) {
38 const double dr2 = autopas::utils::ArrayMath::dot(dr, dr);
39 return W(dr2, h);
40 }
41
48 static inline double W(const double dr2, const double h) {
49 const double H = kernelSupportRadius * h;
50 if (dr2 < H * H) {
51 const double s = sqrt(dr2) / H; // sqrt(dr * dr) / H;
52 const double s1 = 1.0 - s; // (1.0 - s < 0) ? 0 : 1.0 - s;
53 const double s2 = std::max(0., 0.5 - s);
54 double r_value = (s1 * s1 * s1) - 4.0 * (s2 * s2 * s2); // pow(s1, 3) - 4.0 * pow(s2, 3);
55 // if # of dimension == 3
56 r_value *= 16.0 / pi / (H * H * H);
57 return r_value;
58 } else {
59 return 0.;
60 }
61 }
62
67 static unsigned long getFlopsW();
68
75 static inline std::array<double, 3> gradW(const std::array<double, 3> &dr, const double h) {
76 using namespace autopas::utils::ArrayMath::literals;
77
78 const double H = kernelSupportRadius * h;
79 const double drabs = autopas::utils::ArrayMath::L2Norm(dr);
80 const double s = drabs / H; // sqrt(dr * dr) / H;
81 const double s1 = (1.0 - s < 0) ? 0 : 1.0 - s;
82 const double s2 = (0.5 - s < 0) ? 0 : 0.5 - s;
83 double r_value = -3.0 * (s1 * s1) + 12.0 * (s2 * s2); // - 3.0 * pow(s1, 2) + 12.0 * pow(s2, 2);
84 // if # of dimension == 3
85 r_value *= 16.0 / pi / (H * H * H);
86 const double scale = r_value / (drabs * H + 1.0e-6 * h);
87 return dr * scale; // dr * r_value / (sqrt(dr * dr) * H + 1.0e-6 * h);
88 }
89};
90} // namespace sphLib
class to define a kernel function for SPH simulations
Definition: SPHKernels.h:19
static double W(const double dr2, const double h)
A kernel function for sph simulations.
Definition: SPHKernels.h:48
static unsigned long getFlopsW()
returns the flops for one full calculation of the kernel
Definition: SPHKernels.cpp:11
static std::array< double, 3 > gradW(const std::array< double, 3 > &dr, const double h)
gradient of the kernel function W
Definition: SPHKernels.h:75
static double W(const std::array< double, 3 > &dr, const double h)
A kernel function for SPH simulations.
Definition: SPHKernels.h:37
static double getKernelSupportRadius()
Get the kernelSupportRadius.
Definition: SPHKernels.h:28
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
constexpr T L2Norm(const std::array< T, SIZE > &a)
Computes the L2Norm / Euclidean norm.
Definition: ArrayMath.h:265