numerics
Loading...
Searching...
No Matches
heat.cpp
Go to the documentation of this file.
1/// @file backends/seq/heat.cpp
2/// @brief Sequential heat diffusion backend
3
4#include "impl.hpp"
5#include "kernel.hpp"
6#include <cmath>
7#include <algorithm>
8
10
11void heat_compute(std::vector<Particle>& particles,
12 const std::vector<RigidBody>& bodies,
13 const SpatialHash& grid,
14 const HeatParams& params) {
15 const float h = params.h;
16 const float alpha = params.alpha_T;
17 const float m = params.mass;
18 const float h_conv = params.h_conv;
19 const float supp_sq = 4.0f * h * h;
20 const float eps2 = 0.01f * h * h;
21 const int n = static_cast<int>(particles.size());
22
23 for (int i = 0; i < n; ++i) {
24 Particle& pi = particles[i];
25 float dT = 0.0f;
26
27 grid.query(pi.x, pi.y, [&](int j) {
28 if (j == i) return;
29 const Particle& pj = particles[j];
30 const float rx = pi.x - pj.x, ry = pi.y - pj.y;
31 const float r2 = rx * rx + ry * ry;
32 if (r2 >= supp_sq || r2 < 1e-10f) return;
33 const float r = std::sqrt(r2);
34 const float rij_dot_gradW = Kernel::dW_dr(r, h) * r;
35 dT += 2.0f * alpha * (m / pj.density)
36 * (pi.temperature - pj.temperature)
37 * rij_dot_gradW / (r2 + eps2);
38 });
39
40 for (const RigidBody& body : bodies) {
41 const float dx = pi.x - body.x, dy = pi.y - body.y;
42 const float d = std::sqrt(dx * dx + dy * dy);
43 if (d < body.radius + 2.0f * h) {
44 const float excess = std::max(0.0f, d - body.radius);
45 const float phi = 1.0f - excess / (2.0f * h);
46 dT += h_conv * (body.temperature - pi.temperature) * phi;
47 }
48 }
49
50 pi.dT_dt = dT;
51 }
52}
53
54} // namespace physics::backends::seq
void query(float px, float py, F &&f) const
void heat_compute(std::vector< Particle > &particles, const std::vector< RigidBody > &bodies, const SpatialHash &grid, const HeatParams &params)
Definition heat.cpp:11
std::experimental::simd butterfly for FFT.
float mass
Particle mass [kg].
Definition heat.hpp:14
float h
Smoothing length [m].
Definition heat.hpp:11
float h_conv
Convective heat transfer coefficient [1/s].
Definition heat.hpp:13
float alpha_T
Thermal diffusivity [m^2/s].
Definition heat.hpp:12
static float dW_dr(float r, float h)
Definition kernel.hpp:16
A single SPH fluid particle (float precision for performance)
Definition particle.hpp:8
float y
Position [m].
Definition particle.hpp:9
float temperature
Temperature T_i [ degC].
Definition particle.hpp:16
float density
SPH density rho_i [kg/m^3].
Definition particle.hpp:14
A rigid spherical body that interacts with fluid particles.
Definition rigid_body.hpp:8