numerics
Loading...
Searching...
No Matches
fluid3d.hpp
Go to the documentation of this file.
1/// @file fluid3d.hpp
2/// @brief 3D WCSPH fluid solver -- public interface and dispatch hub
3///
4/// FluidSolver3D is a data container + dispatch hub, mirroring fluid.hpp.
5/// All physics computation lives in backends/{seq,omp}/.
6///
7/// @par Execution policies (params.policy)
8/// Backend::seq -- Newton pair traversal via iterate_pairs(), O(n*k/2)
9/// Backend::omp -- parallel for over particles, per-particle query, O(n*k)
10#pragma once
11
12#include "particle3d.hpp"
13#include "rigid_body3d.hpp"
14#include "spatial_hash3d.hpp"
15#include "heat3d.hpp"
16#include "core/policy.hpp"
17#include <vector>
18
19namespace physics {
20
22 float h = 0.05f; ///< Smoothing length [m]
23 float rho0 = 1000.0f; ///< Rest density [kg/m^3]
24 int gamma = 7; ///< Tait EOS exponent
25 float c0 = 10.0f; ///< Speed of sound [m/s]
26 float mu = 10.0f; ///< Dynamic viscosity [Pa*s]
27 float mass = 0.064f; ///< Particle mass [kg] (~= rho_0*(0.8h)^3)
28
29 float gx = 0.0f, gy = -9.81f, gz = 0.0f;
30 float dt = 0.001f;
31
32 float xmin = 0.0f, xmax = 0.8f;
33 float ymin = 0.0f, ymax = 0.8f;
34 float zmin = 0.0f, zmax = 0.8f;
35 float restitution = 0.01f;
36
37 float alpha_T = 0.005f; ///< Thermal diffusivity [m^2/s]
38 float h_conv = 8.0f; ///< Convective coefficient with rigid bodies [1/s]
39
40 num::Backend policy = num::Backend::seq; ///< seq = Newton pairs; omp = parallel
41};
42
44public:
45 explicit FluidSolver3D(const FluidParams3D& p);
46
47 void add_particle(float x, float y, float z,
48 float vx, float vy, float vz, float T);
49 void add_body(const RigidBody3D& b);
50 void clear();
51
52 /// Advance by one timestep. Dispatches to seq or omp backends.
53 void step();
54
55 const std::vector<Particle3D>& particles() const { return particles_; }
56 const std::vector<RigidBody3D>& bodies() const { return bodies_; }
57 std::vector<RigidBody3D>& bodies() { return bodies_; }
58 const FluidParams3D& params() const { return params_; }
59 FluidParams3D& params_mut() { return params_; }
60 float min_temp() const { return T_min_; }
61 float max_temp() const { return T_max_; }
62
63private:
64 FluidParams3D params_;
65 std::vector<Particle3D> particles_;
66 std::vector<RigidBody3D> bodies_;
67 SpatialHash3D grid_;
68 float T_min_ = 0.0f, T_max_ = 100.0f;
69};
70
71} // namespace physics
float min_temp() const
Definition fluid3d.hpp:60
void step()
Advance by one timestep. Dispatches to seq or omp backends.
Definition fluid3d.cpp:47
void add_body(const RigidBody3D &b)
Definition fluid3d.cpp:42
FluidParams3D & params_mut()
Definition fluid3d.hpp:59
const std::vector< Particle3D > & particles() const
Definition fluid3d.hpp:55
float max_temp() const
Definition fluid3d.hpp:61
const FluidParams3D & params() const
Definition fluid3d.hpp:58
std::vector< RigidBody3D > & bodies()
Definition fluid3d.hpp:57
const std::vector< RigidBody3D > & bodies() const
Definition fluid3d.hpp:56
void add_particle(float x, float y, float z, float vx, float vy, float vz, float T)
Definition fluid3d.cpp:29
Heat transfer parameters for the 3D SPH backends.
Backend
Selects which backend handles a linalg operation.
Definition policy.hpp:19
@ seq
Naive textbook loops – always available.
Backend enum for linear algebra operations.
3D SPH neighbour search – powered by num::CellList3D
float mu
Dynamic viscosity [Pa*s].
Definition fluid3d.hpp:26
float c0
Speed of sound [m/s].
Definition fluid3d.hpp:25
float alpha_T
Thermal diffusivity [m^2/s].
Definition fluid3d.hpp:37
float h
Smoothing length [m].
Definition fluid3d.hpp:22
float h_conv
Convective coefficient with rigid bodies [1/s].
Definition fluid3d.hpp:38
int gamma
Tait EOS exponent.
Definition fluid3d.hpp:24
num::Backend policy
seq = Newton pairs; omp = parallel
Definition fluid3d.hpp:40
float mass
Particle mass [kg] (~= rho_0*(0.8h)^3)
Definition fluid3d.hpp:27
float rho0
Rest density [kg/m^3].
Definition fluid3d.hpp:23
3D rigid spherical body that interacts with SPH particles