Skip to content

Commit 35e6da1

Browse files
Create softening.h
1 parent 4e3a56b commit 35e6da1

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/dt/softening.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
#include <cmath>
3+
4+
inline real nextSoftening(real nodeSize,
5+
real nodeMass,
6+
real dist)
7+
{
8+
// Base softening from node size (dominant term)
9+
real eps_size = nodeSize * real(0.015);
10+
11+
// Mass-based softening (heavier nodes get slightly more smoothing)
12+
real eps_mass = std::cbrt(nodeMass) * real(0.002);
13+
14+
// Distance-based tapering:
15+
// - strong softening at r → 0
16+
// - fades out smoothly as r grows
17+
real eps_taper = real(1.0) / (real(1.0) + dist * real(10.0));
18+
19+
// Combine components
20+
real eps = (eps_size + eps_mass) * eps_taper;
21+
22+
// Minimum floor to avoid zero-softening singularities
23+
const real eps_min = real(1e-4);
24+
if (eps < eps_min)
25+
eps = eps_min;
26+
27+
return eps;
28+
}

0 commit comments

Comments
 (0)