载入中...
搜索中...
未找到
FluidMath.h
浏览该文件的文档.
1#pragma once
2
13#include <glm/glm.hpp>
14
15#include <cmath>
16
17namespace eve::fluids {
18
28 float particleRadius = 0.05f;
30 float supportRadius = 0.20f;
32 float restDensity = 1.0f;
34 glm::vec3 gravity{0.f, -9.8f, 0.f};
36 float viscosity = 0.02f;
38 float yieldStress = 0.0f;
40 float cohesion = 0.0f;
42 float adhesion = 0.0f;
44 float damping = 0.0f;
46 float maxVelocity = 20.f;
48 int iterations = 1;
51};
52
55 glm::vec3 pos{0.f};
56 glm::vec3 vel{0.f};
57};
58
65inline float fluidPoly6(float r2, float h) {
66 float h2 = h * h;
67 if (r2 >= h2 || r2 <= 0.f) return 0.f;
68 float q = h2 - r2;
69 return 315.f / (64.f * 3.14159265358979f * std::pow(h, 9.f)) * q * q * q;
70}
71
78inline glm::vec3 fluidSpikyGrad(const glm::vec3& dx, float h) {
79 float r2 = glm::dot(dx, dx);
80 if (r2 >= h * h || r2 <= 1e-12f) return glm::vec3(0.f);
81 float r = std::sqrt(r2);
82 float q = h - r;
83 float k = -45.f / (3.14159265358979f * std::pow(h, 6.f));
84 return dx * (k * q * q / r);
85}
86
93inline float fluidViscLaplacian(float r, float h) {
94 if (r >= h || r <= 1e-9f) return 0.f;
95 return 45.f / (3.14159265358979f * std::pow(h, 6.f)) * (1.f - r / h);
96}
97
104inline float fluidCohesionKernel(float r, float h) {
105 if (r >= h || r <= 1e-9f) return 0.f;
106 const float q = h - r;
107 return 32.f / (3.14159265358979f * std::pow(h, 9.f)) * q * q * q * r * r * r;
108}
109
113inline glm::vec3 fluidClampSpeed(const glm::vec3& v, float maxSpeed) {
114 float s = glm::length(v);
115 if (s > maxSpeed && s > 1e-9f) return v * (maxSpeed / s);
116 return v;
117}
118
119} // namespace eve::fluids
const std::string & s
std::array< double, 10 > q
double r
float v
int h
float dx
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
float fluidPoly6(float r2, float h)
Poly6 kernel value W(r2, h).
Definition FluidMath.h:65
float fluidViscLaplacian(float r, float h)
Viscosity Laplacian kernel value.
Definition FluidMath.h:93
float fluidCohesionKernel(float r, float h)
Akinci-style cohesion kernel C(r) for droplet surface tension.
Definition FluidMath.h:104
glm::vec3 fluidClampSpeed(const glm::vec3 &v, float maxSpeed)
Clamp a vector's magnitude to maxSpeed.
Definition FluidMath.h:113
glm::vec3 fluidSpikyGrad(const glm::vec3 &dx, float h)
Spiky gradient of the kernel w.r.t. particle i position.
Definition FluidMath.h:78
Tuning knobs of one fluid simulation.
Definition FluidMath.h:26
float damping
Linear air damping applied each substep.
Definition FluidMath.h:44
float restDensity
Rest density; normalized to 1.
Definition FluidMath.h:32
float supportRadius
SPH support radius h (kernel cutoff), typically 4x particleRadius.
Definition FluidMath.h:30
float particleRadius
Resting particle radius in world units.
Definition FluidMath.h:28
float adhesion
Fluid-surface adhesion strength (contact angle / sticking).
Definition FluidMath.h:42
int pbfIterations
PBF density-constraint relaxation passes per substep.
Definition FluidMath.h:50
float cohesion
Fluid-fluid cohesion strength (droplet formation).
Definition FluidMath.h:40
int iterations
Solver substeps per call to step(dt).
Definition FluidMath.h:48
float viscosity
XSPH viscosity strength (0 = inviscid).
Definition FluidMath.h:36
float maxVelocity
Velocity clamp after integration.
Definition FluidMath.h:46
float yieldStress
Bingham yield stress: below this shear rate particles "freeze".
Definition FluidMath.h:38
glm::vec3 gravity
Gravity vector in world units / s^2.
Definition FluidMath.h:34
One simulated particle (CPU reference layout).
Definition FluidMath.h:54