betaFeedback

WorksMathematics

Computational performance versus numerical accuracy in the acoustic terms of weakly-compressible SPH

Abstract

Accurate computation of the acoustic terms in weakly-compressible SPH, including the equation of state, its inverse, and the evaluation of the local speed of sound, is essential to ensure energy conservation, robust solid boundary conditions, and correct open boundary behavior. In the classic Cole's equation of state, using values of the polytropic constant γ≠1γ\ne 1 can lead to significant precision loss, particularly when computations are performed in single precision, as is common in GPU implementations. We extend here our previous results on the optimal choice of state variable by introducing a new higher-precision form for all three acoustic terms, denoted explog, and assess its numerical accuracy and computational performance across a variety of devices and test cases. We find that the new form evaluates the acoustic terms with a maximum ULP of~2 for arguments less than 0.1250.125, and has higher errors in less than 1% of the arguments larger than the threshold. Combined with a rewritten expression of the pressure at solid boundary particles in the ``dummy'' model, it provides consistently more accurate results, maintaining deviations from the reference pressure profile to below 2%, even in presence of a rough bottom terrain. Computationally, the new formulation is also faster than the naive one on GPU, and only marginally slower on CPU.

Highlights

  • Weakly-compressible SPH is sensitive to noise in the density and pressure fields;

  • The standard form of the Cole’s equation of state is not numerically robust for small fluctuations;

  • Reformulating the acoustic terms in terms of expm1 and log1p improves numerical robustness;

  • The new explog form has a ULP ≤2\le2 for arguments less than 1/81/8;

  • The new formulation is faster than less accurate choices on GPU, but not on CPU.

Email address: [email protected] (Giuseppe Bilotta)

Introduction

The weakly compressible form of Smoothed Particle Hydrodynamics (WCSPH) is a meshless Lagrangian method well suited for simulating violent flows [1], owing to its natural and implicit treatment of the free surface, including splashing, fragmentation, and merging [2, 3].

Coupled with an explicit integration scheme, WCSPH is also well suited for implementation on high-performance parallel computing hardware, owing to the natural mapping between numerical nodes (particles) and computational work-items. This makes it particularly compatible with the stream processing paradigm commonly used to program Graphic Processing Units (GPUs). Indeed, even before the emergence of general-purpose GPU computing (GPGPU), researchers had already begun to exploit the computational power of these accelerators to model SPH and related particle systems [4, 5].

Although WCSPH as a numerical method and GPUs as computational hardware are well suited for each other, several aspects must be carefully evaluated, as a naive implementation can lead to numerical instabilities or poor performance [6, 7, 8, 9, 10].

One of the key challenges lies in numerical precision. Since GPUs were originally designed for graphics applications, most consumer-grade devices offer very high single-precision but very low double-precision floating-point throughput. The performance ratio between single and double precision typically ranges from 1:8 to 1:32 on consumer GPUs, which can significantly reduce the computational advantages of GPU acceleration. Even many high-end workstation or server GPUs do not reach the 1:2 single-to-double precision performance ratio typical of modern CPUs and are instead limited to ratios of about 1:3 or 1:4, despite their considerably higher cost compared to consumer GPUs.

Implementations of WCSPH for GPUs must therefore balance performance and numerical accuracy. They can either limit computations to single precision, with a potential loss of stability, or adopt double precision for higher accuracy, possibly restricting its use to the most sensitive parts of the code. The latter option, however, often results in a significant drop in performance on lower-end consumer GPUs [11, 12].

A practical compromise is to rely on single-precision computations only and apply numerical tricks that maximize the effective use of the available precision. Such techniques help mitigate rounding and cancellation errors that would otherwise accumulate in single-precision arithmetic. They range from classic approaches, such as compensated summation [13, 14, 15], to appropriate choices of formulations and reference variables [6, 8], and may even extend to redesigning well-established algorithms to avoid catastrophic cancellations [16].

Ultimately, all these approaches share the common feature of requiring some degree of transformation of the analytical formulation, thereby breaking the immediate correspondence between analytical expressions and their implementation. This contrasts with formulations that are designed, already at the analytical level, to reduce the numerical noise that develops in numerical discretizations regardless of precision. Examples include artificial viscosity [17], density diffusion [18, 19, 20, 21, 22, 23], and kernel gradient corrections [24, 25], which are generally introduced a posteriori in the (analytical) discretized equations, sometimes sacrificing strict consistency in favor of improved convergence and stability [26, 27, 28], as discussed recently also in [29].

In WCSPH, the acoustic terms are particularly important at both the computational and analytical levels. Because pressure is computed explicitly from density through an equation of state, numerical fluctuations in the density field can propagate to the velocity field and accumulate over time, undermining the stability of the simulation. This makes it extremely difficult to reproduce simple hydrostatic cases (e.g., still water in a parallelepipedal box). Although these effects are generally of second order in highly dynamic problems, they can still have a negative impact on solid boundary models [30, 31] and on the implementation of open boundary conditions [32, 33].

This behavior is generally independent of the numerical precision adopted in the code, although single-precision computations may lead to such instabilities after fewer iterations. The importance of maintaining a smooth density (and pressure) field has led to the development of several density diffusion schemes in WCSPH, ranging from periodic filtering or reconstruction methods [34, 35] to diffusion terms directly incorporated into the mass conservation equation [19, 20, 22, 36, 23, 37], drawing parallels with the von Neumann artificial viscosity used in the equation of motion [17]. A similar approach can also be used to include damping terms in the viscous contribution, specifically designed to limit the formation of spurious acoustic waves [38] which have been shown to be a significant issue in the application of WCSPH to engineering applications [39]. These issues are further compounded by the contributions to the pressure field coming from the terms needed to model solid boundary conditions, a challenging problem on its own merit within SPH [40].

The work we present here is an analysis of the acoustic terms in WCSPH associated with the classic Cole’s equation of state traditionally used in SPH. We examine both the numerical accuracy and computational performance of the equation in its multiple implementable forms and use this analysis to identify possible numerical optimizations for evaluating the pressure term in common WCSPH formulations, with or without density diffusion, depending on the chosen boundary model.

The paper briefly introduces the SPH method with a focus on the acoustic terms (§ 3). This is followed by a study of the abstract analytical and computational aspects of the evaluation of the acoustic terms (§ 4 and § 5), discussed independently of their specific application to SPH, since these results are of general interest to any numerical code in which the same functional forms appear. § 6 then focuses on the application to SPH and presents a new functional representation for the “dummy” boundary model, leveraging the improved accuracy to achieve more stable and consistent numerical results.

Weakly-compressible SPH

We present here a quick introduction to SPH and its formalism. Further details can be found e.g. in [17, 41].

In SPH, the continuum is discretized as a set of particles, each carrying the physical properties (mass, density, volume, temperature, etc) of a virtual volume of fluid. Scalar and vector fields are approximated via convolution with a family of radial smoothing kernels W(⋅,h)W(\cdot,h) that approximate Dirac’s δ\delta distribution, converging to it in the limit as the smoothing parameter hh goes to 0, and the integral of the convolution is then approximated with a summation over particles:

f(x⃗)=∑jf(x⃗j)W(x⃗−x⃗j,h)Vjf(\vec{x}) = \sum_j f(\vec{x}_j)W(\vec{x}-\vec{x}_j,h)V_j

where VjV_j is the volume of particle jj. Using smoothing kernels with compact support allows such summations to be limited to neighboring particles only.

Gradients can be approximated leveraging Green’s theorem to “shift” the gradient operator from the field to the smoothing kernel:

∇xf(x⃗)=∑jf(x⃗j)∇xW(x⃗−x⃗j,h)Vj+B(x⃗)\nabla_x f(\vec{x}) = \sum_j f(\vec{x}_j)\nabla_x W(\vec{x}-\vec{x}_j,h)V_j + B(\vec{x})

where B(x⃗)B(\vec{x}) is a boundary term. When the smoothing kernel has compact support, we have B(x⃗)=0B(\vec{x})=0 everywhere except for points x⃗\vec{x} whose distance to the boundary is less than the kernel support radius. The kernel gradient expression can be symmetrized in a number of way, e.g. by adding or subtracting 0=f(x⃗)∇10=f(\vec{x})\nabla1, resulting in a variety of expressions for gradients in SPH.

Due to kernel symmetry, we can write ∇xW(x⃗−x⃗j,h)=(x⃗−x⃗j)F(x⃗−x⃗j,h)\nabla_x W(\vec{x}-\vec{x}_j,h)=(\vec{x}-\vec{x}_j)F(\vec{x}-\vec{x}_j,h) where F(r,h)=(1/r)∂W(r,h)/∂rF(r,h)=(1/r)\partial W(r,h)/\partial r. This form improves numerical stability when FF has an analytic representation where the 1/r1/r factor cancels out with radial terms in the derivative of WW.

Using the common SPH shorthand conventions x⃗ij=x⃗i−x⃗j\vec{x}_{ij}=\vec{x}_i-\vec{x}_j, Wij=W(x⃗ij,h)W_{ij}=W(\vec{x}_{ij},h) and Fij=F(x⃗ij,h)F_{ij}=F(\vec{x}_{ij},h), and fij=f(x⃗i)−f(x⃗j)f_{ij}=f(\vec{x}_i)-f(\vec{x}_j) for any field ff, the standard mass and momentum continuity equations in a weak compressibility regime can be discretized in SPH following Monaghan’s “golden rules” [17]:

DρiDt=−∑jmju⃗ij⋅x⃗ijFij(1)\frac{D\rho_i}{Dt}=-\sum_j m_j\vec{u}_{ij}\cdot\vec{x}_{ij}F_{ij} \tag*{(1)}
Du⃗iDt=−∑j((Piρi2+Pjρj2)x⃗ij+2Kmjρiρjμˉijx⃗ij⋅u⃗ijxij2x⃗ij)Fij+g⃗,(2)\frac{D\vec{u}_i}{Dt}=-\sum_j\left(\left(\frac{P_i}{\rho_i^2}+\frac{P_j}{\rho_j^2}\right)\vec{x}_{ij}+2K\frac{m_j}{\rho_i\rho_j}\bar{\mu}_{ij}\frac{\vec{x}_{ij}\cdot\vec{u}_{ij}}{x_{ij}^2}\vec{x}_{ij}\right)F_{ij}+\vec{g}, \tag*{(2)}

optionally with additional terms for artificial viscosity and/or density diffusion; in the above equations, u⃗i\vec{u}_i represents the velocity of particle ii, mim_i, ρi\rho_i, PiP_i its mass, density and pressure, μˉij\bar{\mu}_{ij} the average viscosity between particles i,ji,j, and KK is a constant that depends on the problem dimension and choice of viscosity averaging function [17, 42, 41].

Acoustic terms

The weak compressible formulation of SPH closes the momentum equation with a functional relation between pressure and density under a barotropic assumption. Commonly used is Cole’s equation of state [43, 44] (also known as the Tait–Murnaghan equation or somewhat improperly simply the Tait equation [45]):

P(ρ)=B((ρρ0)γ−1)(3)P(\rho) = B\left(\left(\frac{\rho}{\rho_0}\right)^\gamma- 1\right) \tag*{(3)}

where ρ0\rho_0 is the at-rest density, BB the bulk modulus and γ\gamma the polytropic constant. Conversely, given the pressure PP, the corresponding density can be derived as

ρ(P)=ρ0(1+PB)1/γ.(4)\rho(P) = \rho_0\left(1+\frac{P}{B}\right)^{1/\gamma}. \tag*{(4)}

The speed of sound can be obtained from c(ρ)=∂P/∂ρc(\rho)=\sqrt{\partial P/\partial\rho}:

c(ρ)=Bγρ0(ρρ0)γ−1(5)c(\rho) = \sqrt{\frac{B\gamma}{\rho_0}\left(\frac{\rho}{\rho_0}\right)^{\gamma-1}} \tag*{(5)}

and letting c0c_0 be the sound speed for the fluid at rest, we get

B=ρ0c02γ.(6)B = \frac{\rho_0 c_0^2}{\gamma}. \tag*{(6)}

Since WCSPH is frequently used with explicit integration schemes, for which the speed of sound is often the dominant factor (unless simulating highly viscous fluids at very fine resolutions [16]), the physical speed of sound is rarely used, preferring the adoption of a fictitious sound speed. To ensure the weakly compressible regime is valid, density variations should be less than 1%, for which it is generally sufficient to take c0c_0 at least 10 times higher than the maximum flow velocity, including the so-called hydrostatic limit gH\sqrt{gH}, with HH the reference height, in order to avoid the collapse of a column of water [41].

Boundary conditions

Near the boundary of the fluid domain, the SPH interpolations are defective due to missing contributions to the kernel support from outside the domain. Near the free surface, these missing contributions can generally be ignored assuming that the field values are null, but near solid boundaries, corrective terms must be applied. Among the many forms that boundary conditions can taken in SPH [46, 47, 41], the most common ones are based on a particle discretization similar to the fluid one, with several layers of boundary particles included in the simulation in order to complete the kernel support for fluid particles near the boundary.

The simplest approach (so-called dynamic boundary conditions [48, 49]) has boundary particles behave like fluid particles, evolving the density according to the mass continuity equation, but prescribing velocity based on the rigid body motion (if any) of the boundary. While this is generally sufficient to avoid fluid particles penetrating the boundary, it does not provide the correct stress and strain at the boundary, and can produce artifacts such as a ‘lift’ of the head in a bore, or particles sticking to the wall when fluid retreats.

A more sophisticated approach is the “dummy” boundary model introduced in [30]. In this case, boundary particle properties are computed in order to prescribe both the normal stress and the no-slip conditions. In particular, the boundary particle pressure is obtained from an interpolation of the adjacent fluid pressure, with a correction to compensate for the hydrostatic term:

Pw=∑j(Pj+ρjg⃗⋅x⃗wj)W(x⃗wj,h)∑jW(x⃗wj,h).(7)P_w = \frac{\sum_j (P_j + \rho_j \vec{g} \cdot\vec{x}_{wj}) W(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)}. \tag*{(7)}

The particle density can then be computed from the pressure using the inverse of the equation of state, as needed.

It should be apparent that the accuracy in the computation of the wall pressure PwP_w has a significant impact on the accuracy of this boundary condition term, since incorrect evaluations may lead to the wall attracting (if the pressure is underestimated) or repulsing (if the pressure is overestimated) fluid particles, leading respectively to possible penetration, or to an underestimation of the wall friction term. Improving the evaluation of these terms is the focus of this paper.

Numerical considerations on the acoustic term evaluation

When working with single-precision (32-bit) floating point, with machine epsilon

ϵM,32=2−23≈1.19209289551⋅10−7,\epsilon_{M,32} = 2^{-23} \approx1.19209289551 \cdot10^{-7},

manipulating quantities such as density, pressure and the sound speed of the fluid can lead to low accuracy in the results, due to the amount of precision consumed by the magnitude of the physical quantities. Remember that the machine epsilon is defined as the value of the least significant bit (ULP, Unit of Last Position or equivalently Unit of Least Precision) in the floating-point representation of the value 1. This effectively defines the ratio between the least and most significant digit in any representable number, and the smallest relative change in a value that can be correctly represented.

Now consider e.g. ρ0\rho_0 in the order of 10310^3 (in SI units of kg m−3^{-3}) for liquids: this effectively consumes 3 decimal digits of precision, so that only variations in the order of ϵMρ0\epsilon_M\rho_0 are representable, which in this case means variations in the order of 10−7⋅103=10−410^{-7}\cdot10^3 = 10^{-4} in single precision. If we then take c0c_0 in the order of 10 (in SI units of m s−1^{-1}), c02c_0^2 will consume 2 decimal digits, and BB will be in the order of 10610^6, leaving only one decimal digit for representable absolute variations in the pressure (O(δP)=O(ϵMP)=10−7⋅106=10−1O(\delta P) = O(\epsilon_M P) = 10^{-7}\cdot10^6 = 10^{-1}).

This loss of precision can lead to numerically unstable simulations even for analytically robust formulations, leading to effects ranging from spurious explosions to fluid particles unphysically penetrating the solid boundary layers [50, 6]. Although adimensionalization can help by bringing function arguments within the ranges of higher precision, it does not necessarily improve the representability of variations, since we’re still within machine epsilon of 1.

Among the several numerical strategies that can be adopted to compensate for the loss of precision, the most important for the treatment of the acoustic terms is the shift from the physical density ρ\rho to the relative density variation [6, 8] (also known as the condensation in acoustic wave theory [51]), defined as:

ρ~=ρρ0−1.\widetilde{\rho} = \frac{\rho}{\rho_0} - 1.

In a weakly-compressible regime, ∣ρ~∣≪1|\widetilde{\rho}| \ll1, and this choice allows tracking of density fluctuations as small as the smallest normal number FLT_MIN

fm,32=2−126≈1.17549435082228751⋅10−38(8)f_{m,32} = 2^{-126} \approx1.17549435082228751 \cdot10^{-38} \tag*{(8)}

without loss of precision. It is thus recommended that ρ~\widetilde{\rho} be chosen as state variable, with ρ=ρ0(ρ~+1)\rho= \rho_0(\widetilde{\rho}+1) a derived quantity. The mass continuity equation for example becomes:

Dρ~iDt=−∑jmjρ0,iu⃗ij⋅x⃗ijFij(9)\frac{D\widetilde{\rho}_i}{Dt} = -\sum_j \frac{m_j}{\rho_{0,i}} \vec{u}_{ij}\cdot\vec{x}_{ij}F_{ij} \tag*{(9)}

and the acoustic terms can be rewritten as

P(ρ~)=B((1+ρ~)γ−1)(10)P(\widetilde{\rho}) = B\left((1+\widetilde{\rho})^\gamma- 1\right) \tag*{(10)}

for the equation of state, with inverse

ρ~(P)=(1+PB)1/γ−1,(11)\widetilde{\rho}(P) = \left(1+\frac{P}{B}\right)^{1/\gamma} - 1, \tag*{(11)}

and

c(ρ~)=c0(1+ρ~)(γ−1)/2.(12)c(\tilde{\rho}) = c_0(1+\tilde{\rho})^{(\gamma-1)/2}. \tag*{(12)}

for the sound speed.

If we introduce the scaled density P~=P/B\tilde{P}=P/B the equation of state and its inverse show a beautiful symmetry:

P~(ρ~)=(1+ρ~)γ−1,(13)\tilde{P}(\tilde{\rho}) = (1+\tilde{\rho})^\gamma- 1, \tag*{(13)}
ρ~(P~)=(1+P~)1/γ−1(14)\tilde{\rho}(\tilde{P}) = (1+\tilde{P})^{1/\gamma} - 1 \tag*{(14)}

that, as we will show in § 6, will allow us to improve the numerical accuracy and stability of simulations. We remark that under the condition −1<ρ~<21/γ−1-1<\tilde{\rho}<2^{1/\gamma}-1 we also have ∣P~∣<1|\tilde{P}|<1, since

∣P~∣<1⟺∣(1+ρ~)γ−1∣<1⟺−1<(1+ρ~)γ−1<1⟺0<(1+ρ~)γ<2⟺0<1+ρ~<21/γ⟺−1<ρ~<21/γ−1.\begin{aligned} |\tilde{P}| < 1 &\Longleftrightarrow\\ |(1+\tilde{\rho})^\gamma- 1| < 1 &\Longleftrightarrow\\ -1 < (1+\tilde{\rho})^\gamma- 1 < 1 &\Longleftrightarrow\\ 0 < (1+\tilde{\rho})^\gamma< 2 &\Longleftrightarrow\\ 0 < 1+\tilde{\rho} < 2^{1/\gamma} &\Longleftrightarrow\\ -1 < \tilde{\rho} < 2^{1/\gamma} - 1. \end{aligned}

Computational considerations

Equations (13), (14) and (12) can all be expressed in terms of the function

π1+−1(x,α)=(1+x)α−1,\pi_{1+}^{-1}(x,\alpha) = (1+x)^\alpha- 1,

since we can write:

P~(ρ~)=π1+−1(ρ~,γ),(15)\tilde{P}(\tilde{\rho}) = \pi_{1+}^{-1}(\tilde{\rho},\gamma), \tag*{(15)}
ρ~(P~)=π1+−1(P~,1/γ),(16)\tilde{\rho}(\tilde{P}) = \pi_{1+}^{-1}(\tilde{P},1/\gamma), \tag*{(16)}
c(ρ~)=c0(π1+−1(ρ~,(γ−1)/2)+1).(17)c(\tilde{\rho}) = c_0\left(\pi_{1+}^{-1}(\tilde{\rho},(\gamma-1)/2)+1\right). \tag*{(17)}

It may seem that expression (17) is more complex than the original form (12), but, as we shall see momentarily, the adoption of π1+−1\pi_{1+}^{-1} leads to significant numerical improvements.

In code, we refer to this function as pow1pm1, inspired by the functions expm1, log1p defined by the IEEE-754 standard [52] and corresponding respectively to exp⁡−1(x)=ex−1\operatorname{exp}_{-1}(x)=e^x-1 and log⁡1+(x)=log⁡(1+x)\log_{1+}(x)=\log(1+x), designed to assist developers in computing exponentials and logarithms with higher accuracy as x→0x \to0. In fact, we have:

π1+−1(x,α)=(1+x)α−1=eαlog⁡(1+x)−1=exp⁡−1(αlog⁡1+(x)).\pi^{-1}_{1+}(x,\alpha)=(1+x)^\alpha-1=e^{\alpha\log(1+x)}-1=\operatorname{exp}^{-1}\left(\alpha\log_{1+}(x)\right).

The Taylor series expansion of π1+−1(x,α)\pi^{-1}_{1+}(x,\alpha) around x=0x=0 is

π1+−1(x,α)=αx(1+∑k=1∞∏i=1k(α−i)(k+1)!xk)\pi^{-1}_{1+}(x,\alpha)=\alpha x\left(1+\sum_{k=1}^{\infty}\frac{\prod_{i=1}^{k}(\alpha-i)}{(k+1)!}x^k\right)

that can be written in Horner form [53] as

π1+−1(x,α)=αx(1+α−12x(1+α−23x(1+⋯ ))).(18)\pi^{-1}_{1+}(x,\alpha)=\alpha x\left(1+\frac{\alpha-1}{2}x\left(1+\frac{\alpha-2}{3}x\left(1+\cdots\right)\right)\right). \tag*{(18)}

This fact was leveraged in [6] to optimize the computation of P(ρ)P(\rho) and P(ρ)/ρ2P(\rho)/\rho^2 in the case γ=7\gamma=7, where both expressions can be computed quickly and accurately as polynomials in Horner form using fused multiply-add (FMA) operations.

Computational speed versus accuracy

The polynomial trick considered by [6] can only be applied when π1+−1(x,α)\pi^{-1}_{1+}(x,\alpha) is a polynomial. In the case of the three acoustic terms we are considering (15)–(17) (pressure from density, density from pressure, speed of sound) with exponents respectively γ\gamma, 1/γ1/\gamma, (γ−1)/2(\gamma-1)/2, the only case in which this applies to all of them is for γ=1\gamma=1.

The simplification in the expression of the acoustic terms for γ=1\gamma=1 make it a common choice in SPH, even though the exponent is considerably smaller than the physical polytropic constant of water, γw≈7.5\gamma_w\approx7.5. Outside of the case γ=1\gamma=1, however (e.g. with the other common choice γ=7\gamma=7), not all the acoustic terms can have integer exponents at the same time, and the polynomial simplifications of [6] are only possible for some of them at most. The issue becomes then: what is the fastest and most accurate way to evaluate π1+−1\pi^{-1}_{1+} in the non-polynomial (or in the general) case?

Coding-wise, we can look at π1+−1\pi^{-1}_{1+} as having three possible functional forms, illustrated here for the single-precision float type:

float pow1pm1(float x, float a) /* power form */
{ return powf(1 + x, a) - 1; }
float pow1pm1(float x, float a) /* explog form */
{ return expm1f(a*log1pf(x)); }
float pow1pm1(float x, float a) /* Taylor form */
{ return /* omissis: Horner form Taylor expansion */ }

Additionally, some programming languages and hardware combinations support intrinsics such as __powf that sacrifice accuracy for speed, but can still be used as an alternative in the power form.

While these forms are analytically equivalent, computationally they differ significantly. The power form, which is what is naively used in many codes, will return the value 0 if ∣x∣<ϵM|x| < \epsilon_M, since for such small values of xx we have 1⊕x=11 \oplus x = 1 (indicating by ⊕\oplus the correctly-rounded result of the operation between two floating-point values).

Note that increasing the precision will simply change the threshold below which the actual value of xx will be ignored: ϵM,32=2−23\epsilon_{M,32} = 2^{-23} for single precision, ϵM,64=2−52\epsilon_{M,64} = 2^{-52} for double, ϵM,80=2−63\epsilon_{M,80} = 2^{-63} in the extended 80-bit format supported as ‘long double’ on some architectures, ϵM,128=2−112\epsilon_{M,128} = 2^{-112} for the 128-bit quadruple precision. Note that even with computations done in quadruple precision the power form will fail to return the correct value for single-precision FLT_MIN [8].

The explog form, on the other hand, can be expected to produce very accurate results, assuming the implementations of expm1f and log1pf are correctly rounded, and thus produce results within 1 ULP of the exact value. In this case, the argument to exp⁡−1\exp^{-1} will be accurate to within 1 ULPs, and given the magnitude of the arguments, this will result in an overall error of at most 2 ULPs in the final result. This high accuracy allows us to use the explog in e.g. double or extended precision as reference value for the single precision function in our validation tests.

The accuracy of the Taylor expansion depends on the magnitude of the arguments and the order chosen for the expansion. The Horner form (18) can be mapped easily to a recursive function template in C++ (Listing 1), allowing the selection of the Taylor expansion order based on the preferred compromise between performance and accuracy. Note that the Horner form contains two multiplications and an addition for each nesting; mapping them to FMA therefore requires a choice about which multiplication should be done before the FMA and which one should be done inside, leading to at least three different forms for the Taylor expansion: for them we can expect minor differences in their results, as well as some difference in computational Listing 1: Recursive function template definition for the Horner form of the Taylor expansion of the π+1−1(x,α)\pi_{+1}^{-1}(x,\alpha) function. The m*x*prev + 1 can be decomposed in three different ways as argument to the fused multiply-add: in addition to the one illustrated in code, the forms fmaf(m*prev, x, 1.0f) and fmaf(x*prev, m, 1.0f) are also possible.

template<unsigned order>
float taylor_form(float x, float a, float prev=1.0f);

template<>
float taylor_form<1>(float x, float a, float prev)
{ return a*x*prev; }

template<unsigned order>
float taylor_form(float x, float a, float prev)
{
    float m = (a - (order - 1))/order;
    return taylor_form<order-1>(x, a, fmaf(m*x, prev, 1.0f));
}

performance due to a different degree of instruction-level parallelism. We denote them by “mx” for fmaf(m*x, prev, 1.0f), “mprev” for fmaf(m*prev, x, 1.0f) and “xprev” for the fmaf(x*prev, m, 1.0f) form.

Experimental results

We evaluate both the numerical and computational performance of the different forms of π+1−1(x,α)\pi_{+1}^{-1}(x,\alpha) with x∈[0,1[x \in[0,1[ and a selection of the common values needed for α\alpha, corresponding to γ\gamma, 1/γ1/\gamma and (γ−1)/2(\gamma- 1)/2 for γ=1,3,5,7\gamma= 1,3,5,7. The case α=0\alpha= 0 is not presented here because all forms give the correct result in that case. We also present the results for α=−1,−2\alpha= -1,-2 as they are relevant to the pressure term computation as explained later in § 6.1.

The numerical results are evaluated by comparing the results from the single-precision forms against the results obtained by the long double explog form. The metrics we consider are the number of discrepancies (values for which the single-precision results were different from the long double result), the number of values for which the discrepancy is larger than 1 ULP (in single precision), and the largest relative error in ULPs.

To account for the difference in error distribution for different magnitudes of xx, the [0,1[[0,1[ range has been split into three subranges: denormals [0,fm,32[=[0,f_{m,32}[= [0,2−126[\left[0,2^{-126}\right[, “nano” [fm,32,εM,32[=[2−126,2−23[\left[f_{m,32},\varepsilon_{M,32}\right[=\left[2^{-126},2^{-23}\right[, “micro” [εM,32,2−6[=[2−23,2−6[\left[\varepsilon_{M,32},2^{-6}\right[=\left[2^{-23},2^{-6}\right[, “percent” [2−6,2−3[\left[2^{-6},2^{-3}\right[, and “perten” [2−3,1[\left[2^{-3},1\right[. The marks at 2−6=1.5625⋅10−22^{-6}=1.5625\cdot10^{-2} and 2−3=0.1252^{-3}=0.125 were chosen as the smallest powers of 2 that are not less than 1% and 10% respectively.

The code for these tests is available as auxiliary material to the manuscript.

The performance results refer to a machine with an AMD Ryzen 7 3700X processor that can boost to 4.4GHz, running Linux 5.18 with vulnerability mitigations enabled. The code was compiled with Clang 14, -O3 and machine-specific optimizations enabled (-march=native). Due to the high optimization level, the compiler produces vectorized code and interleaves instructions to maximize throughput where possible, with additional performance benefits for some forms. Additional performance comparisons in more practical contexts, running on GPUs and including the faster and less accurate __powf form will be presented as part of the application to the dummy boundary model in § 6.

Results for the CPU benchmark are collected in Table 1–Table 5. Of note is the marginal performance advantage of the power form over the explog form in the higher ranges, at the expense of an (expected) massive drop in accuracy in the entire domain, and the significant performance advantage of the Taylor forms, that approaches the memory bandwidth limit with a numerical accuracy that is comparable with, and sometimes better than, that of the explog form, with a slight advantage for the ‘mx’ variant both in performance and accuracy. The explog form turns out to be exact in the denormals, and maintains a maximum ULP of 2 until the “perten” range (argument larger than 1/8), and even then it only gets worse results for less than 1% of the values.

Table 1: Performance, in 10910^9 elements (GE) per seconds, and accuracy of the π+1−1\pi_{+1}^{-1} function in the power, explog and Taylor forms in the [0,2−126[[0,2^{-126}[ range, covering 8,388,608 single-precision floating-point values.

α\alphamethodGE/secdiscrepancies>1>1 ULPmax ULPs
−2-2power0.14100%100%>223>2^{23}
explog0.20%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
−1-1power0.16100%100%>222>2^{22}
explog0.220%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
1/71/7power0.16100%100%>220>2^{20}
explog0.220%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
1/51/5power0.16100%100%>220>2^{20}
explog0.220%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
1/31/3power0.16100%100%>221>2^{21}
explog0.220%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
11power0.16100%100%>222>2^{22}
explog0.220%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
22power0.16100%100%>223>2^{23}
explog0.210%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
33power0.16100%100%>223>2^{23}
explog0.20%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
55power0.16100%100%>223>2^{23}
explog0.20%0%0
Taylor mx2.80%0%0
Taylor mprev2.10%0%0
Taylor xprev2.10%0%0
77power0.16100%100%>223>2^{23}
explog0.210%0%0
Taylor mx2.10%0%0
Taylor mprev1.70%0%0
Taylor xprev2.10%0%0

Table 1.

α\alphamethodGE/secdiscrepancies>1>1 ULPmax ULPs
−2-2power0.1598.9%97.8%2242^{24}
−2-2explog0.144.39%9.1e-06%2
−2-2Taylor mx26.21%2.54%>226>2^{26}
−2-2Taylor mprev26.21%2.54%>226>2^{26}
−2-2Taylor xprev26.21%2.54%>226>2^{26}
−1-1power0.1699.1%97.9%2242^{24}
−1-1explog0.147.57%9.88e-05%2
−1-1Taylor mx26%2.31%>223>2^{23}
−1-1Taylor mprev26%2.31%>223>2^{23}
−1-1Taylor xprev25.98%2.31%>223>2^{23}
1/71/7power0.1699.9%99.7%2242^{24}
1/71/7explog0.146.87%0.00435%2
1/71/7Taylor mx27.58%1.97%>219>2^{19}
1/71/7Taylor mprev27.58%1.97%>219>2^{19}
1/71/7Taylor xprev27.58%1.97%>219>2^{19}
1/51/5power0.1699.9%99.6%>223>2^{23}
1/51/5explog0.146.83%0.0344%2
1/51/5Taylor mx27.49%1.89%>218>2^{18}
1/51/5Taylor mprev27.51%1.89%>218>2^{18}
1/51/5Taylor xprev27.51%1.9%>218>2^{18}
1/31/3power0.1699.8%99.3%>223>2^{23}
1/31/3explog0.146.82%0.0223%2
1/31/3Taylor mx27.41%1.82%>218>2^{18}
1/31/3Taylor mprev27.42%1.82%>218>2^{18}
1/31/3Taylor xprev27.42%1.82%>218>2^{18}
1power0.1699.2%98%>223>2^{23}
1explog0.140.758%9.39e-08%2
1Taylor mx20%0%0
1Taylor mprev20%0%0
1Taylor xprev20%0%0
2power0.1699.3%98.2%>223>2^{23}
2explog0.137.94%0.0205%>2>2
2Taylor mx27.07%0%1
2Taylor mprev27.07%0%1
2Taylor xprev27.07%0%1
3power0.1699.3%98.4%>223>2^{23}
3explog0.1313.1%0.273%222^2
3Taylor mx213.5%0.174%2
3Taylor mprev213.5%0.17%2
3Taylor xprev213.5%0.182%>2>2
5power0.1699.3%98.7%>223>2^{23}
5explog0.1311.2%0.423%>22>2^2
5Taylor mx211.7%0.122%>2>2
5Taylor mprev211.7%0.122%>2>2
5Taylor xprev211.8%0.151%222^2
7power0.1699.3%98.9%>223>2^{23}
7explog0.1310.6%0.639%>23>2^3
7Taylor mx211.3%0.167%222^2
7Taylor mprev211.2%0.166%222^2
7Taylor xprev211.2%0.174%>22>2^2

Table 5. Performance, in 10910^9 elements (GE) per seconds, and accuracy of the π1+−1\pi_{1+}^{-1} function in the power, explog and Taylor forms in the [2−3,1[[2^{-3},1[ range, covering 1, 065, 353, 216 single-precision floating-point values.

Aside from the computational performance advantage, that in this case is skewed by the cross-iteration vectorization, a significant advantage of the Taylor forms is the correctly rounded results given for α=1\alpha=1: adopting this form gives the best results for the common case γ=1\gamma=1 even without special-casing the choice of polytropic constant; even though lower orders would also give the same results with some further performance gains, adopting the Taylor expansion at order 8 allows keeping the code generic without particular losses in either performance or accuracy regardless of the choice of γ\gamma.

In fact, the only range/exponent combination in which the Taylor expansion falls significantly short of the explog form in terms of accuracy is in the “perten” range for α<1\alpha<1 (Table 5). In this case, the accuracy achieved with

α\alphamethodGE/secdiscrepancies>1>1 ULPmax ULPs
−2-2power0.15100%100%2242^{24}
explog0.180.693%0%1
Taylor mx2.10.672%0%1
Taylor mprev20.672%0%1
Taylor xprev20.672%0%1
−1-1power0.16100%100%2242^{24}
explog0.181.27%1.15e-07%2
Taylor mx20.621%0%1
Taylor mprev20.621%0%1
Taylor xprev20.621%0%1
1/71/7power0.16100%100%>223>2^{23}
explog0.180.81%0%1
Taylor mx20.901%0%1
Taylor mprev20.901%0%1
Taylor xprev20.901%0%1
1/51/5power0.16100%100%>223>2^{23}
explog0.180.71%0%1
Taylor mx20.854%0%1
Taylor mprev20.854%0%1
Taylor xprev20.854%0%1
1/31/3power0.16100%100%>223>2^{23}
explog0.180.536%0%1
Taylor mx20.641%0%1
Taylor mprev20.641%0%1
Taylor xprev20.641%0%1
11power0.16100%100%>223>2^{23}
explog0.181.15e-07%0%1
Taylor mx20%0%0
Taylor mprev20%0%0
Taylor xprev20%0%0
22power0.16100%100%>223>2^{23}
explog0.181.27%0%1
Taylor mx20.563%0%1
Taylor mprev20.563%0%1
Taylor xprev20.563%0%1
33power0.16100%100%>223>2^{23}
explog0.187.34%0%1
Taylor mx27.39%0.0372%2
Taylor mprev27.39%0.0372%2
Taylor xprev27.39%0.0372%2
55power0.16100%100%>223>2^{23}
explog0.185.09%0.00161%2
Taylor mx25.25%0.0137%2
Taylor mprev25.25%0.0137%2
Taylor xprev25.25%0.0137%2
77power0.16100%100%>223>2^{23}
explog0.184.16%0%1
Taylor mx24.52%0.0182%2
Taylor mprev24.52%0.0182%2
Taylor xprev24.52%0.0182%2

Table 2. Performance, in 10910^9 elements (GE) per seconds, and accuracy of the π+1−1\pi_{+1}^{-1} function in the power, explog and Taylor forms in the [2−126,2−23[[2^{-126}, 2^{-23}[ range, covering 872, 415, 232 single-precision floating-point values.

α\alphamethodGE/secdiscrepancies>1>1 ULPmax ULPs
−2-2power0.15100%100%2242^{24}
explog0.143.46%0%1
Taylor mx23.28%0%1
Taylor mprev23.28%0%1
Taylor xprev23.28%0%1
−1-1power0.16100%100%2242^{24}
explog0.156.71%1.97e-07%2
Taylor mx23.27%0%1
Taylor mprev23.27%0%1
Taylor xprev23.26%0%1
1/71/7power0.16100%100%2242^{24}
explog0.155.46%0.000724%2
Taylor mx24.94%0.000473%2
Taylor mprev24.94%0.000476%2
Taylor xprev1.94.94%0.000475%2
1/51/5power0.16100%100%>223>2^{23}
explog0.155.41%0.0212%2
Taylor mx24.92%0.000223%2
Taylor mprev24.92%0.000227%2
Taylor xprev1.94.92%0.000225%2
1/31/3power0.16100%100%>223>2^{23}
explog0.155.35%0.00742%2
Taylor mx24.85%8.73e-05%2
Taylor mprev24.85%8.79e-05%2
Taylor xprev24.85%8.73e-05%2
11power0.16100%100%>223>2^{23}
explog0.150.0203%0%1
Taylor mx20%0%0
Taylor mprev20%0%0
Taylor xprev20%0%0
22power0.16100%100%>223>2^{23}
explog0.156.72%0%1
Taylor mx25.8%0%1
Taylor mprev25.8%0%1
Taylor xprev25.8%0%1
33power0.16100%100%>223>2^{23}
explog0.1411.4%0.067%2
Taylor mx212.2%0.142%2
Taylor mprev212.2%0.142%2
Taylor xprev212.2%0.142%2
55power0.16100%100%>223>2^{23}
explog0.149.25%0.0176%2
Taylor mx210.3%0.0925%2
Taylor mprev210.3%0.0925%2
Taylor xprev210.3%0.0926%2
77power0.16100%100%>223>2^{23}
explog0.148.4%0.029%2
Taylor mx29.73%0.0905%2
Taylor mprev29.73%0.0905%2
Taylor xprev29.73%0.0905%2

Table 3. Performance, in 10910^9 elements (GE) per seconds, and accuracy of the π+−1\pi_{+}^{-1} function in the power, explog and Taylor forms in the [2−23,2−6[[2^{-23}, 2^{-6}[ range, 1,015,021,568 single-precision floating-point values.

α\alphamethodGE/secdiscrepancies>1>1 ULPmax ULPs
−2-2power0.1599.9%99.6%2242^{24}
explog0.143.95%6.73e-07%2
Taylor mx1.83.94%0.187%>22>2^2
Taylor mprev1.83.94%0.187%>22>2^2
Taylor xprev1.83.94%0.187%>22>2^2
−1-1power0.1699.9%99.7%2242^{24}
explog0.147.13%6.73e-07%2
Taylor mx1.83.72%0.00255%2
Taylor mprev1.83.72%0.00255%2
Taylor xprev1.83.71%0.00175%2
1/71/7power0.16100%100%2242^{24}
explog0.146.15%0.00104%2
Taylor mx1.85.55%0.00245%2
Taylor mprev1.75.55%0.00256%2
Taylor xprev1.75.55%0.00256%2
1/51/5power0.16100%99.9%>223>2^{23}
explog0.146.1%0.0242%2
Taylor mx1.85.5%0.00122%2
Taylor mprev1.75.51%0.00134%2
Taylor xprev1.75.51%0.0013%2
1/31/3power0.16100%99.9%>223>2^{23}
explog0.146.05%0.00914%2
Taylor mx1.85.44%0.00121%2
Taylor mprev1.75.45%0.00128%2
Taylor xprev1.75.45%0.00122%2
1power0.1699.9%99.7%>223>2^{23}
explog0.140.149%0%1
Taylor mx1.80%0%0
Taylor mprev1.80%0%0
Taylor xprev1.80%0%0
2power0.1699.9%99.7%>223>2^{23}
explog0.147.2%0%1
Taylor mx1.86.52%0%1
Taylor mprev1.86.52%0%1
Taylor xprev1.86.52%0%1
3power0.1699.9%99.7%>223>2^{23}
explog0.1412%0.0834%2
Taylor mx1.812.9%0.157%2
Taylor mprev1.812.9%0.157%2
Taylor xprev1.812.9%0.157%2
5power0.1699.9%99.7%>223>2^{23}
explog0.1410%0.0412%2
Taylor mx1.811%0.102%2
Taylor mprev1.811%0.102%2
Taylor xprev1.711%0.103%2
7power0.1699.9%99.7%>223>2^{23}
explog0.149.19%0.0576%2
Taylor mx1.810.4%0.1%2
Taylor mprev1.810.4%0.1%2
Taylor xprev1.810.4%0.1%2

Table 4. Performance, in 10910^9 elements (GE) per seconds, and accuracy of the π+−1\pi_{+}^{-1} function in the power, explog and Taylor forms in the [2−6,2−3[[2^{-6}, 2^{-3}[ range, covering 1,040,187,392 single-precision floating-point values.

an expansion of order 8 quickly drops off as x→1x \to1. Such an application of the π1+−1\pi_{1+}^{-1} function is not expected in the normal applications of WCSPH, but it may be safer to adopt the explog for the inverse of the equation of state for larger values of γ\gamma.

Equation of state round-trip

A second but important measure in the evaluation of the best choice for the expression of the π1+−1\pi_{1+}^{-1} function is the accuracy of the ‘round-trip’, i.e. the accuracy with which one can recover the original (scaled) density from the computed (scaled) pressure by applying the inverse equation of state, or conversely: considering that analytically we should have π1+−1(π1+(x,1/α),α)=x\pi_{1+}^{-1}(\pi_{1+}(x,1/\alpha),\alpha)=x, we can evaluate the round-trip accuracy of the π1+−1\pi_{1+}^{-1} forms for different exponents by comparing the result of the chain evaluation of the function and its inverse against the original argument. Once again, accuracy can be estimated in terms of number of elements for which the results are different, number of elements for which the maximum error is larger than 1 ULP, and the maximum ULPs in the error.

We restrict our analysis to the explog and “Taylor mx” forms, taken (from our previous analysis) respectively as the most accurate in the full range, and

Table 7: Round-trip accuracy of the π−1\pi^{-1} function in the explog and Taylor (mx) forms. This table refers to the range [2−126,2−23[[2^{-126},2^{-23}[ that contains 872, 415, 232 single-precision floating-point values.

α\alphamethoddiscrepancies>1> 1 ULPmax ULPs
−2-2explog3.44e-07%0%1
−2-2Taylor mx1.76%0%1
−1-1explog2.29e-07%1.15e-07%2
−1-1Taylor mx0.962%0%1
1/71/7explog29.9%1.27%222^2
1/71/7Taylor mx30.5%1.53%222^2
1/51/5explog24%0.769%2
1/51/5Taylor mx24.5%0.841%2
1/31/3explog34.1%0%1
1/31/3Taylor mx34.3%0.0801%2
1explog1.15e-07%0%1
1Taylor mx0%0%0
2explog2.29e-07%0%1
2Taylor mx0.962%0%1
3explog33.1%0%1
3Taylor mx33.6%0%1
5explog22.3%0%1
5Taylor mx23.2%0.0881%2
7explog54.3%2.29e-07%2
7Taylor mx54.3%0.381%>2> 2

Table 7.

Table 8: Round-trip accuracy of the π−1\pi^{-1} function in the explog and Taylor (mx) forms. This table refers to the range [2−23,2−6[[2^{-23},2^{-6}[ that contains 1, 015, 021, 568 single-precision floating-point values.

α\alphamethoddiscrepancies>1> 1 ULPmax ULPs
−2-2explog0.0602%0.000435%2
−2-2Taylor mx7.02%0.0291%2
−1-1explog0.0403%0.000229%2
−1-1Taylor mx6.38%0.0282%2
1/71/7explog29.7%1.1%222^2
1/71/7Taylor mx33.8%2.18%222^2
1/51/5explog23.8%0.668%>2> 2
1/51/5Taylor mx28.3%1.54%>2> 2
1/31/3explog34%0.00955%>2> 2
1/31/3Taylor mx37.1%1.35%222^2
1explog0.0203%0.00108%2
1Taylor mx0%0%0
2explog0.0364%0.000214%2
2Taylor mx6.05%0.0254%2
3explog33.1%0.00961%>2> 2
3Taylor mx36.5%0.981%222^2
5explog22.4%0.00867%>2> 2
5Taylor mx27.3%0.927%>2> 2
7explog54.4%0.019%>2> 2
7Taylor mx55.1%1.9%222^2

Table 8.

α\alphamethoddiscrepancies>1>1 ULPmax ULPs
−2-2explog0.413%0.0225%2
Taylor mx8.16%0.547%>25>2^{5}
−1-1explog0.287%0.0118%2
Taylor mx7.25%0.0845%>2>2
1/71/7explog29.7%1.13%222^{2}
Taylor mx34.3%2.28%222^{2}
1/51/5explog23.9%0.693%>2>2
Taylor mx28.8%1.63%>2>2
1/31/3explog34.1%0.0675%>2>2
Taylor mx37.6%1.53%222^{2}
11explog0.149%0.00815%2
Taylor mx0%0%0
22explog0.253%0.00913%2
Taylor mx7.04%0.305%>23>2^{3}
33explog33.3%0.0742%>2>2
Taylor mx37.3%1.79%>29>2^{9}
55explog22.6%0.0732%>2>2
Taylor mx28.6%2.39%>217>2^{17}
77explog54.4%0.139%>2>2
Taylor mx56%3.75%>222>2^{22}

Table 9. Round-trip accuracy of the π1+−1\pi^{-1}_{1+} function in the explog and Taylor (mx) forms. This table refers to the range [2−6,24/3[[2^{-6},2^{4/3}[ that contains 1,040,187,392 single-precision floating-point values.

the fastest. The results are presented in Table 6 to Table 10.

α\alphamethoddiscrepancies>1> 1 ULPmax ULPs
−2-2explog0%0%0
−2-2Taylor mx0%0%0
−1-1explog0%0%0
−1-1Taylor mx0%0%0
1/71/7explog85.7%57.1%222^2
1/71/7Taylor mx85.7%57.1%222^2
1/51/5explog80%40%2
1/51/5Taylor mx80%40%2
1/31/3explog66.7%0%1
1/31/3Taylor mx66.7%0%1
1explog0%0%0
1Taylor mx0%0%0
2explog0%0%0
2Taylor mx0%0%0
3explog8.33%0%1
3Taylor mx8.33%0%1
5explog2.5%0%1
5Taylor mx2.5%0%1
7explog6.55%0%1
7Taylor mx6.55%0%1

Table 6. Round-trip accuracy of the π1+−1\pi_{1+}^{-1} function in the explog and Taylor (mx) forms. This table refers to the range [0,2−126[[0, 2^{-126}[ that contains 8,388,608 single-precision floating-point values.

α\alphamethoddiscrepancies>1>1 ULPmax ULPs
−2-2explog1.55%0.307%>2>2
Taylor mx10.3%2.9%>237>2^{37}
−1-1explog1.2%0.13%>2>2
Taylor mx9.43%2.38%>223>2^{23}
1/71/7explog30.1%1.29%>22>2^{2}
Taylor mx35.7%4.24%>220>2^{20}
1/51/5explog24.3%0.843%>22>2^{2}
Taylor mx30.3%3.53%>219>2^{19}
1/31/3explog34.4%0.263%222^{2}
Taylor mx38.8%3.33%>219>2^{19}
11explog0.758%0.0315%2
Taylor mx0%0%0
22explog0.965%0.0285%>2>2
Taylor mx9.23%2.66%>229>2^{29}
33explog33.6%0.312%222^{2}
Taylor mx38.8%4.11%>240>2^{40}
55explog23%0.222%>2>2
Taylor mx30.3%4.7%>257>2^{57}
77explog54.6%0.532%>2>2
Taylor mx57%6.03%>273>2^{73}

Table 10. Round-trip accuracy of the π1+−1\pi^{-1}_{1+} function in the explog and Taylor (mx) forms. This table refers to the range [2−3,1[[2^{-3},1[ that contains 1,065,353,216 single-precision floating-point values.

It’s interesting to note that the round-trip accuracy is not the same when starting from α\alpha or from 1/α1/\alpha: the error distribution for π1+−1(π1+−1(x,α),1/α)\pi_{1+}^{-1}(\pi_{1+}^{-1}(x,\alpha),1/\alpha) is different from that of π1+−1(π1+−1(x,1/α),α)\pi_{1+}^{-1}(\pi_{1+}^{-1}(x,1/\alpha),\alpha). This can be observed for the exponents 3, 5, 7 for which we also have the results of the round-trip starting from the reciprocals 1/3, 1/5, 1/7.

In the denormals range in particular (Table 6) this affects a majority of the values, due to the fact that starting from the fractional (0<α<1)(0 < \alpha< 1) exponent leads to loss of bits in the mantissa, a loss that is not experienced when starting from exponents α≥1\alpha\ge1.

Despite this asymmetry, the round-trip error is limited to 2 significant bits at most for either form until the percent range, where the Taylor form starts losing accuracy for exponents different from 1, with the effect becoming catastrophic in the perten range: this is expected, as we have already seen that in this range the Taylor form has low accuracy for α<1\alpha< 1, and in the round-trip tests either α\alpha or its reciprocal will be less than 1 whenever α≠1\alpha\ne1. On the upside, the Taylor form gives exact results throughout the whole range for α=1\alpha= 1, whereas explog loses one or two ULPs in the upper subranges.

Applications to the ``dummy'' boundary model

Accurate evaluation of the pressure is essential in all formulations of WCSPH, but it becomes even more important in boundary models where its evaluation is needed for the correct imposition of boundary conditions.

As discussed in § 3.2, this is the case for the dummy boundary model. In this case, it’s important not only that the pressure evaluation is accurate, but also that the round-trip through the inverse of the equation of state does not introduce significant perturbations. Although the formula we present here are specifically intended for the dummy boundary model, similar formulas can be derived for any solid boundary model (or in fact any other context) that requires the computation of the pressure from neighboring particles.

Let us consider at first the pressure interpolation (equation 7) and rewrite it for the scaled pressure, assuming at first that we only have a single fluid with bulk modulus B=ρ0c02/γB = \rho_0 c_0^2/\gamma. Considering that ρj=ρ0(1+ρ~j)\rho_j = \rho_0(1 + \tilde{\rho}_j), we have

P~w=∑j(P~j+(γ/c02)(1+ρ~j)g⃗⋅x⃗wj)W(x⃗wj,h)∑jW(x⃗wj,h)\tilde{P}_w = \frac{\sum_j \left(\tilde{P}_j + (\gamma/c_0^2)(1+\tilde{\rho}_j)\vec{g}\cdot\vec{x}_{wj}\right)W(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)}

Given the potentially different magnitude of the terms, it is better to explicitly split the expression in the interpolating and hydrostatic contributions:

P~w=∑jP~jW(x⃗wj,h)∑jW(x⃗wj,h)+γc02∑j(1+ρ~j)g⃗⋅x⃗wjW(x⃗wj,h)∑jW(x⃗wj,h).(19)\widetilde{P}_w = \frac{\sum_j \widetilde{P}_j W(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)} + \frac{\gamma}{c_0^2}\frac{\sum_j(1+\widetilde{\rho}_j)\vec{g}\cdot\vec{x}_{wj}W(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)}. \tag*{(19)}

If multiple fluids are present, each with their bulk module, reference density, speed of sound, some simplifications will not be possible, and should be replaced with appropriate ratios; we have Pj/Bw=Pj/Bj⋅Bj/Bw=P~j⋅B~j/wP_j/B_w=P_j/B_j\cdot B_j/B_w=\widetilde{P}_j\cdot\widetilde{B}_{j/w} with B~j/w=Bj/Bw\widetilde{B}_{j/w}=B_j/B_w for the pressure interpolation terms, and ρj/Bw=(γ/c0,w2)ρ0,j(1+ρ~j)/ρ0,w=(γ/c0,w2)ρ~0,j/w(1+ρ~j)\rho_j/B_w=(\gamma/c_{0,w}^2)\rho_{0,j}(1+\widetilde{\rho}_j)/\rho_{0,w}=(\gamma/c_{0,w}^2)\widetilde{\rho}_{0,j/w}(1+\widetilde{\rho}_j) with ρ~0,j/w=ρ0,j/ρ0,w\widetilde{\rho}_{0,j/w}=\rho_{0,j}/\rho_{0,w} for the hydrostatic term, so that equation (19) can be rewritten as:

P~w=∑jB~j/wP~jW(x⃗wj,h)∑jW(x⃗wj,h)+γc0,w2∑jρ~0,j/w(1+ρ~j)g⃗⋅x⃗wjW(x⃗wj,h)∑jW(x⃗wj,h).(20)\widetilde{P}_w = \frac{\sum_j \widetilde{B}_{j/w}\widetilde{P}_jW(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)} + \frac{\gamma}{c_{0,w}^2}\frac{\sum_j\widetilde{\rho}_{0,j/w}(1+\widetilde{\rho}_j)\vec{g}\cdot\vec{x}_{wj}W(\vec{x}_{wj},h)}{\sum_j W(\vec{x}_{wj},h)}. \tag*{(20)}

in the multi-fluid case.

The wall particle pressure computed as (19) or (20) is used both to compute the wall boundary contribution to the pressure gradient of neighboring fluid particles, and to compute the density of the wall boundary particles using the inverse equation of state.

In fact, computing the density is important for both uses, since the pressure gradient contribution, is frequently computed as P/ρkP/\rho^k for some exponent kk, with k=2k=2 being a common exponent, such as in the formulation we are using (equation (2)).

Pressure gradient contribution

We have, for any exponent kk and for any particle:

Pρk=BP~ρ0k(1+ρ~)k=c02γρ0k−1P~(1+ρ~)k.(21)\frac{P}{\rho^k}=\frac{B\widetilde{P}}{\rho_0^k(1+\widetilde{\rho})^k}=\frac{c_0^2}{\gamma\rho_0^{k-1}}\frac{\widetilde{P}}{(1+\widetilde{\rho})^k}. \tag*{(21)}

For fluid particles, where the scaled pressure is computed directly from the scaled density using the equation of state, we have:

P~(1+ρ~)k=(1+ρ~)γ−1(1+ρ~)k=(1+ρ~)γ−k−(1+ρ~)−k==((1+ρ~)γ−k−1)−((1+ρ~)−k−1)=π1+−1(ρ~,γ−k)−π1+−1(ρ~,−k)\begin{aligned} \frac{\widetilde{P}}{(1+\widetilde{\rho})^k}=\frac{(1+\widetilde{\rho})^\gamma-1}{(1+\widetilde{\rho})^k}=(1+\widetilde{\rho})^{\gamma-k}-(1+\widetilde{\rho})^{-k}= \\ &=((1+\widetilde{\rho})^{\gamma-k}-1)-((1+\widetilde{\rho})^{-k}-1)=\pi_{1+}^{-1}(\widetilde{\rho},\gamma-k)-\pi_{1+}^{-1}(\widetilde{\rho},-k) \end{aligned}

so that we can express (21) entirely in terms of π1+−1\pi^{-1}_{1+} times a constant that can be precomputed:

Pρk=c02γρ0k−1(π1+−1(ρ~,γ−k)−π1+−1(ρ~,−k))\frac{P}{\rho^{k}}=\frac{c_{0}^{2}}{\gamma\rho_{0}^{k-1}}\left(\pi^{-1}_{1+}(\tilde{\rho},\gamma-k)-\pi^{-1}_{1+}(\tilde{\rho},-k)\right)

For dummy boundary particles, in combination with (19), equation (21) allows some additional simplifications in the hydrostatic contribution:

Pwρwk=c0,w2γρ0,wk−1∑jP~jW(x⃗wj,h)(1+ρ~w)k∑jW(x⃗wj,h)+∑j(1+ρ~j)g⃗⋅x⃗wjW(x⃗wj,h)ρ0,wk−1(1+ρ~w)k∑jW(x⃗wj,h).(22)\frac{P_{w}}{\rho_{w}^{k}}=\frac{c_{0,w}^{2}}{\gamma\rho_{0,w}^{k-1}}\frac{\sum_{j}\tilde{P}_{j}W(\vec{x}_{wj},h)}{(1+\tilde{\rho}_{w})^{k}\sum_{j}W(\vec{x}_{wj},h)}+\frac{\sum_{j}(1+\tilde{\rho}_{j})\vec{g}\cdot\vec{x}_{wj}W(\vec{x}_{wj},h)}{\rho_{0,w}^{k-1}(1+\tilde{\rho}_{w})^{k}\sum_{j}W(\vec{x}_{wj},h)}. \tag*{(22)}

and a similar expression can also be derived for (20) in the multi-fluid case. Note that despite the simplifications, (22) still depends on equation (19) to obtain ρ~w\tilde{\rho}_{w} from P~w\tilde{P}_{w}. It is however possible to compute the common subexpressions once and then produce from them both P~w\tilde{P}_{w} for ρ~w\tilde{\rho}_{w} and P~w/ρwk\tilde{P}_{w}/\rho_{w}^{k} as needed.

The numerical results we will present momentarily also show that simply using the expressions (19)–(22) over the naive ones (equation (7) for the wall boundary, and P/ρkP/\rho^{k}) is sufficient to improve numerical accuracy in the computation of the acoustic terms, regardless of the choice of π1+−1\pi^{-1}_{1+} discussed in section 4.1.

Numerical results

SPHERIC Test Case 2. The first test case is the classic SPHERIC 2 reference case, a classic bore-in-a-box test on a domain which is 3.22×1×1 m33.22 \times1 \times1\,\mathrm{m}^{3}, with a 0.550.55 m water height behind a closed gate positioned 22 m from the back wall. A box (dimensions 0.161×0.403×0.1610.161 \times0.403 \times0.161) is placed with its water-facing side at 1.181.18 m from the gate, centered with respect to the side walls. The box is covered with 8 pressure sensors along the central meridian. Water gages take the water elevation over time at three locations (halfway between the gate and the obstacle, near the front of the obstacle, near the back of the obstacle). Further details about the setup can be found in [54, 55].

We model the test case using the dummy solid boundary formulation (Figure 1). The equation of state for the fluid uses the polytropic constant γ=7\gamma=7, and the Monaghan artificial viscosity is used with α=0.05\alpha=0.05. The particle resolution is set at 30 particles per meter.

Cross-section of the 3D geometry for the SPHERIC 2 Test Case

Figure 1. Cross-section of the 3D geometry for the SPHERIC 2 Test Case. Fluid particles are blue, solid boundary particles realizing the walls are gray, and solid boundary particles realizing the obstacle are black.

Simulations are run with both the naive (power) and explog forms for the acoustic term, and we look at the power density spectra for the pressure oscillations at the prescribed probes. As shown in Figure 2 (bottom) for Probe 6, the explog choice leads to lower frequency oscillations (10 to 20dB/Hz less throughout most of the spectrum), and is missing the large spikes that can be observed in the pressure plot for the naive formulation (Figure 2, top).

Figure 2. Pressure oscillations and their spectral density at Probe 6 of the SPHERIC 2 Test case, when using the naive versus the explog forms of the acoustic terms.

Standing wave. In this test case, we look at energy conservation for a long-running Standing Wave simulation. The simulation is run in 3D, but with a pseudo-2D configuration. The domain box is 1m wide in the wave direction xx, and 1.1m tall; in the cross-wave direction yy, the domain is only long enough to cover 3 influence radii. Periodic boundary conditions are applied in both the xx and yy directions. Solid boundaries are implemented using the dynamic boundary model, and the conservative corrected SPH formulation introduced in [28] is employed to avoid the well-known numerical dissipative effect in standard WCSPH. The initial water level is constant, but particles are initialized with non-zero velocity components uxu_x, uzu_z to realize a wave with wavelength L=1mL = 1\mathrm{m} and amplitude A=1/64mA = 1/64\mathrm{m}.

We run simulations at both a low resolution of 32 particles per meter and a high resolution of 64 particles per meter, again comparing the naive (power) and explog forms for the acoustic terms.

We observe (Figure 3) that the naive expression shows a small but consistent linearly growing trend for the total energy, and that increasing the

Figure 3. Energy conservation in a long-running Standing Wave, using the naive and the explog forms of the acoustic terms, and two different particle spacings of Δp=1/32\Delta p = 1/32 and Δp=1/64\Delta p = 1/64 particles per meter.

resolution makes the energy conservation worse rather than better. Note that, while the total energy variation remains below 10−710^{-7} in this case, the trend would push it to grow over single-precision machine epsilon in longer simulations, with the issue manifesting earlier at finer resolutions. When using the explog form, energy conservation is better overall, and it improves at finer resolutions, as expected for a numerically robust algorithm.

Stillwater with Irregular topography. The stillwater case is a well-known benchmark used to evaluate the capability of different density diffusion options and boundary condition formulations to reproduce the pressure field, since its results can be directly compared with the analytical solution. Prior studies have examined the pressure distribution in a small box of stillwater over a flat bed [30, 56, 57, 58] and a bed with a wedge (sharp corner) [30, 59, 60, 61], showing that the dynamic boundary condition [49, 48] fails to accurately capture the pressure near solid boundaries, and that modifications to the boundary treatment and density diffusion approach are necessary to improve the results. Moreover, Colagrossi et al. [59] investigated the influence of initial particle positioning on the acoustic noise generated during the early stages of the simulation, and introduced the Particle Packing Algorithm, designed to generate high-quality initial particle distributions to reduce spurious currents.

To evaluate the capability of the explog formulation in computing pressure distribution near boundaries, particularly in regions with strong bottom roughness, we model a stillwater testcase where the bottom topography uses a high-resolution bathymetric dataset with rapidly changing bed elevation along the xx direction. As shown in Figure 4, the irregular DEM consists of two flat sections and a rough segment characterized by steep and rapidly changing topography, including a maximum local slope of 89∘89^\circ, and a peak elevation of 2.6m. This DEM was used to simulate a still-water case with a maximum water depth of 4.0 m (Hm=4H_m = 4 m), enabling the examination of pressure fluctuations near the bed in the absence of waves and their comparison with the analytical hydrostatic solution over a total simulation time of 100s. This duration is substantially longer than that used in previous studies, which typically employed simulation times of less than 10s [30, 60, 61].

Instantaneous normalized pressure fields for the still-water test

Figure 4. Instantaneous normalized pressure fields, P/(ρ0gHm)P/(\rho_0 g H_m), for the still-water test: (a) naive and (b) explog at t∗=28.5t^* = 28.5; (c) naive and (d) explog at t∗=37.7t^* = 37.7, where t∗=tg/Hmt^* = t\sqrt{g/H_m}. All panels use the same bathymetry and color range, 0≤(P/ρ0gHm)≤10 \le(P/\rho_0 g H_m) \le1. Purple dotted boxes mark the 1-m-wide particle-extraction windows for Section A (15≤x≤1615 \le x \le16 m) and Section B (25≤x≤2625 \le x \le26 m), which are used to extract the vertical pressure profiles in Figure 5.

Simulations were conducted at a relatively low resolution of 20 particles per meter. Dummy boundary condition was applied to the solid bottom and periodic boundary condition was applied in the alongshore yy direction. In order to avoid the excessive nonphysical energy dissipation in the model,

the CCSPH option introduced in [28] was enabled. Additionally, the δ\delta-SPH model described in [22] was used for the density diffusion to reduce acoustic noise and smooth the pressure field. As shown in Figure 4, pressure distribution was analyzed over time and along the water column at two locations: one in the flat-bed region (Section A: x=15 mx = 15\,\mathrm{m} to x=16 mx = 16\,\mathrm{m}), and another adjacent to the rough-bottom region (Section B: x=25 mx = 25\,\mathrm{m} to x=26 mx = 26\,\mathrm{m}). Two different formulations were tested: the naive formulation where the dummy wall boundary pressure is computed using (7) directly, the pressure contribution to the Navier–Stokes equation is computed as P/ρ2P/\rho^2 without simplifications, and the equation of state is computed naively using __powf, and the explog formulation, with the pressure contribution computed using equations (19)–(22) and the explog form used for π1+−1\pi_{1+}^{-1}.

Figure 4 compares the normalized pressure fields, P/(ρ0gHm)P/(\rho_0 g H_m), obtained with the naive and explog formulations at two normalized time instances, t∗=tg/Hmt^* = t\sqrt{g/H_m}. At t∗=28.5t^* = 28.5 (Figure 4a,Figure 4b), both solutions appear nearly steady. In the naive formulation, however, fluid–boundary interactions over the rough topography generate a localized pressure pulse as numerical errors accumulate. By t∗=37.7t^* = 37.7 (Figure 4c) this pulse has evolved into noticeable pressure fluctuations that originate in the rough section and progressively propagate into the adjacent flat regions. At the same time, the explog formulation (Figure 4d) remains nearly steady and does not exhibit comparable fluctuations, indicating that it limits the growth of the density-related numerical instability triggered by fluid–boundary interactions over the rough topography.

To quantify these pressure fluctuations, instantaneous fluid-particle pressures extracted from the 1-m-wide windows in Sections A and B are shown as vertical scatter profiles in Figure 5. The vertical coordinate zz is measured positive upward from the flat-bed datum, such that the flat bed in Section A is at z=0z = 0 and the undisturbed free surface is at z=Hm=4.0 mz = H_m = 4.0\,\mathrm{m}. For each profile, pressure and vertical position are normalized as Pi∗=Pi/(ρ0gHref)P_i^* = P_i/(\rho_0 g H_{\mathrm{ref}}) and Hi∗=(zi−zb)/HrefH_i^* = (z_i-z_b)/H_{\mathrm{ref}}, where zbz_b is the section reference bottom elevation. In Section A, zb=0z_b = 0 and Href=Hm−zb=4.0 mH_{\mathrm{ref}} = H_m-z_b = 4.0\,\mathrm{m}, whereas in Section B, zb=2.02 mz_b = 2.02\,\mathrm{m} is the minimum bed elevation within the extraction window, and Href=Hm−zb=1.98 mH_{\mathrm{ref}} = H_m-z_b = 1.98\,\mathrm{m} is the corresponding maximum local still-water depth. Using the linear hydrostatic reference, the normalized residual for particle ii is defined as

Normalized instantaneous particle-pressure profiles in Section A and Section B

Figure 5. Normalized instantaneous particle-pressure profiles in Section A [panels (a)–(d)] and Section B [panels (e)–(h)]. Panels (a,e), (b,f), (c,g), and (d,h) correspond to t∗=28.5t^{*} = 28.5, 37.737.7, 109.8109.8, and 119.8119.8, respectively. Blue and orange markers denote fluid-particle pressures computed using the naive and explog formulations, respectively, and the solid black line denotes the analytical hydrostatic solution. Each marker represents one fluid particle within the corresponding 1-m-wide extraction window.

ei∗=Pi−Pref(zi)ρ0gHref,Pref(zi)=ρ0g(Hm−zi),(23)e_i^{*} = \frac{P_i - P_{\mathrm{ref}}(z_i)}{\rho_0 g H_{\mathrm{ref}}}, \qquad P_{\mathrm{ref}}(z_i) = \rho_0 g(H_m-z_i), \tag*{(23)}

where PiP_i denotes the instantaneous pressure computed by GPUSPH for particle ii, and Pref(zi)P_{\mathrm{ref}}(z_i) is the analytical hydrostatic pressure at the location of particle ii. For each pressure profile, the total departure from the analytical hydrostatic solution and the variability of the pressure residuals are quantified using the normalized root-mean-square error, RMSE∗\mathrm{RMSE}^{*}, and the normalized residual standard deviation, SD∗\mathrm{SD}^{*}, respectively:

RMSE∗=1N∑i=1N(ei∗)2,SD∗=1N−1∑i=1N(ei∗−eˉ∗)2,(24)\begin{aligned} \mathrm{RMSE}^{*} &= \sqrt{\frac{1}{N}\sum_{i=1}^{N}(e_i^{*})^2},\\ \mathrm{SD}^{*} &= \sqrt{\frac{1}{N-1}\sum_{i=1}^{N}(e_i^{*}-\bar{e}^{*})^2}, \tag*{(24)} \end{aligned}

where NN is the number of extracted fluid particles and eˉ∗=1N∑i=1Nei∗\bar{e}^{*} = \frac{1}{N}\sum_{i=1}^{N}e_i^{*} is the mean normalized residual. The RMSE∗\mathrm{RMSE}^{*} quantifies the overall mismatch between the particle pressures and the analytical hydrostatic solution, whereas SD∗\mathrm{SD}^{*} quantifies the spread of the residuals about their mean and is used here as a bulk measure of pressure fluctuations. Reporting both metrics distinguishes a smoothly biased profile, which may have a large RMSE∗\mathrm{RMSE}^{*} but a small SD∗\mathrm{SD}^{*}, from a profile with substantial residual scatter.

Figure 5 and Table 11 show that the naive formulation does not remain hydrostatic over the full simulation. At t∗=28.5t^{*}=28.5, both formulations are close to the analytical hydrostatic solution with both RMSE∗\mathrm{RMSE}^{*} and SD∗\mathrm{SD}^{*} below 2.0%. Figure 5a and Figure 5e show that, consistent with previous studies, the model agrees well with the analytical hydrostatic solution over short simulation times. However, at the next sampled time, the naive formulation begins to deviate from the correct solution, and this behavior repeats multiple times throughout the simulation. At t∗=37.7t^{*}=37.7, the naive solution departs substantially from the analytical hydrostatic solution, particularly in Section B [Figure 5(f)], where RMSE∗\mathrm{RMSE}^{*} decreases from 26.65% for the naive formulation to 1.98% for explog, while SD∗\mathrm{SD}^{*} decreases from 16.11% to 1.75%. The naive profiles move closer to the analytical solution at t∗=109.8t^{*}=109.8, but the instability reappears at t∗=119.8t^{*}=119.8; in Section B, the naive RMSE∗\mathrm{RMSE}^{*} and SD∗\mathrm{SD}^{*}

tt (s)t∗t^{*}SectionRMSE∗^{*} (%) NaiveRMSE∗^{*} (%) ExplogSD∗^{*} (%) NaiveSD∗^{*} (%) Explog
18.228.5A0.550.440.490.34
B1.641.941.281.93
24.137.7A3.491.063.010.83
B26.651.9816.111.75
70.1109.8A1.671.121.671.04
B4.201.643.741.54
76.5119.8A4.631.053.091.04
B11.171.596.251.43

Table 11. Normalized pressure-residual metrics for the vertical profiles in Sections A and B. RMSE∗^{*} quantifies the total departure of individual particle pressures from the analytical hydrostatic solution, whereas SD∗^{*} quantifies the spread of the normalized pressure residuals about their mean. Values are percentages.

are 11.17% and 6.25%, respectively, compared with 1.59% and 1.43% for explog. Across all selected times and sections, the explog formulation remains below 2.0% in RMSE∗^{*} and SD∗^{*}.

Overall, the naive formulation does not consistently reproduce the analytical hydrostatic solution over long simulations, with the largest departures occurring in Section B near the steep rough topography. The explog formulation suppresses the growth of the instability observed with the naive formulation, and remains below 2.0% in both RMSE∗^{*} and SD∗^{*} at all selected times and sections, although small residual pressure fluctuations remain.

Performance

We leverage the recently introduced support for CPUs and AMD GPUs in GPUSPH [62] to test the impact of the choice of expression for π1+−1\pi_{1+}^{-1} across a variety of hardware platforms.

The hardware used for these tests, done again on the Standing Wave test case, include:

  • CUDA an NVIDIA RTX 3060 GPU (Compute Capability 8.6) using CUDA 11.6;

  • HIP an AMD Radeon RX 580 GPU (Graphics IP 8) using HIP/ROCm 5.4;

AMD the AMD Ryzen 7 3700X CPU used for the microbenchmarks presented in Table 1–Table 10;

Intel a dual-socket Intel Xeon Silver 4110 CPU (32 threads total);

ARM an 8-core Cortex-A53 CPU.

Since we are interested in the possible performance loss (or gain) related to the use of the explog form, we compute the absolute performance in MIPPS (millions of iterations times particles per second, as detailed in [50]) for each configuration, taking the median across 5 tests (in benchmarking mode, with data output completely disabled to avoid pollution of the results due to I/O latency), and then express our results as the ratio of the performance for a given configuration to the performance of the naive (power form) case on the same hardware. Less than 1% variation was observed in the timings across runs for each configuration.

The results are shown in Figure 6, separately for GPUs and for CPUs. Since both CUDA and HIP define a lower-accuracy, faster version of the power function (__powf), the timing results leveraging this form are also included for these platforms.

Figure 6. Relative performance of the explog and “fast power” expressions for π1+−1\pi_{1+}^{-1} across different GPUs (left) and CPUs (right). Note that the GPU plot uses a truncated scale to highlight the relatively small performance difference.

On GPUs, we observe that the explog form is not only more accurate, but also marginally faster (4% to 5%, depending on platform). The faster power variant achieved even higher performance on CUDA (as expected), but not on HIP, probably due to differences in the way this is implemented on the AMD platform.

The small performance gains observed on GPU are consistent with the microbenchmarks, that show the explog form to be between 30% faster (Table 1) to less than 20% slower (Table 5), depending on argument magnitude, when considering that in a typical WCSPH simulations the arguments will typically be closer to 0.

The CPU results are more surprising in this regard: although the choice of formulation is mostly indifferent on the ARMv8 architecture, the explog performance is consistently worse on the x86-64 architectures, with a drop between 20% and 25%. The reasons for these discrepancies from the microbenchmarks are still under analysis, with higher register consumption being a probable candidate.

Given the hardware-dependent performance ratio between the explog and naive formulations, in GPUSPH we have left the choice to the user, who can then balance their computational and accuracy requirements based on the specific test cases that they need to run.

Conclusions

Adopting the relative density variation (condensation) and a scaled pressure as state variables leads to SPH formulations that are numerically more stable. Additionally, it allows expressing the acoustic terms derived from Cole’s equation of state as a combination of the expm1 and log1p IEEE-754 functions; the resulting explog form achieves higher precision for (relative) values closer to zero, which is the range where condensation and scaled pressure are mostly distributed in a standard WCSPH simulation. The explog form of the acoustic terms can also be leveraged to improve pressure evaluation for boundary terms, which helps reduce spurious pressure oscillations, and improves energy conservation.

While analytical strategies such as artificial viscosity and density diffusion can help diffuse numerical noise, they are insufficient in preventing the accumulation of noise over time, leading to degrading energy conservation and loss of accuracy in long-running simulations. Combining them with the explog form we introduced ensures that energy is conserved to below the machine epsilon limit and hydrostatic density profiles are preserved even for simulations running for hundreds of seconds.

Performance-wise, the new form also provides performance benefits over the IEEE-compliant power function form on GPU, but is slower than the non-compliant and less accurate __powf on CUDA. On CPU, our implementation of the explog form results in a measurable loss in performance, that is currently being investigated.

CRediT

Giuseppe Bilotta: Conceptualization, Methodology, Software, Validation, Formal Analysis, Investigation, Writing - Original Draft, Writing - Review & Editing, Supervision, Project administration, Funding acquisition Alireza Zarei: Software, Validation, Investigation, Writing - Review & Editing, Visualization Roberta Cristofaro: Investigation, Writing - Review & Editing, Visualization Alexis Hérault: Methodology, Software, Formal Analysis, Writing - Review & Editing Élie Saikali: Methodology, Software, Formal Analysis, Writing - Review & Editing Morteza Derakhti: Validation, Writing - Review & Editing, Supervision, Project administration

Acknowledgements

This work was supported by the INGV HARVEST project (BRL 2021, Ob.Fu. 9999.804); and the 2022 Progetto di Ricerca di Rilevante Interesse Nazionale (PRIN 2022) PLastic Transport due to waves and currents ON Emerged and submerged beaches (CUP D53D23004590006, Ob.Fu. 1216.010).

References

  1. [1]J. J. Monaghan, Simulating free surface flows with SPH, Journal of Computational Physics 110 (2) (1994) 399–406. doi:10.1006/jcph.1994.1034.DOI
  2. [2]J. J. Monaghan, Smoothed particle hydrodynamics, Reports on Progress in Physics 68 (8) (2005) 1703–1759. doi:10.1088/0034-4885/68/8/R01.DOI
  3. [3]M. Gómez-Gesteira, B. D. Rogers, R. A. Dalrymple, A. J. C. Crespo, State-of-the-art of classical SPH for free-surface flows, Journal of Hydraulic Research 48 (S1) (2010) 6–27. doi:10.1080/002211686.2010.9641242.
  4. [4]T. Takahashi, H. Fujii, A. Kunimatsu, K. Hiwada, T. Nishita, Real-time particle-based fluid simulation with SPH, in: Computer Graphics International, 2003. Proceedings, IEEE, 2003, pp. 63–70. doi:10.1109/CGI.2003.1214466.
  5. [5]P. Kipfer, R. Westermann, UberFlow: A GPU-based particle engine, in: Proceedings of the ACM SIGGRAPH/EUROGRAPHICS conference on Graphics hardware, ACM, 2004, pp. 115–122. doi:10.2312/EGGH/EGGH04/115-122.DOI
  6. [6]A. Hérault, G. Bilotta, R. A. Dalrymple, Achieving the best accuracy in an SPH implementation, in: Proceedings of the 9th SPHERIC Workshop, Proceedings of the 9th SPHERIC Workshop, Paris, 2014, pp. 134–139.
  7. [7]G. Bilotta, V. Zago, A. Hérault, Design and implementation of particle systems for meshfree methods with high performance, in: S. Chickerur (Ed.), High Performance Parallel Computing, IntechOpen, Rijeka, 2018, Ch. 6. doi:10.5772/intechopen.81755.DOI
  8. [8]E. Saikali, G. Bilotta, A. Hérault, V. Zago, Accuracy improvements for single precision implementations of the SPH method, International Journal of Computational Fluid Dynamics 34 (10) (2020) 774–787. doi:10.1080/10618562.2020.1836357. URL https://doi.org/10.1080/10618562.2020.1836357
  9. [9]G. Bilotta, SPH and GPUs: perfect fit or trap?, SPHERIC Global Seminars (2022).
  10. [10]G. Bilotta, V. Zago, A. Hérault, A. Cappello, G. Ganci, H. D. van Ettinger, C. Del Negro, Optimization of flexible neighbors lists in Smoothed Particle Hydrodynamics on GPU, Advances in Engineering Software 196 (2024) 103711. doi:10.1016/j.advengsoft.2024.103711.DOI
  11. [11]J. M. Domínguez, A. J. C. Crespo, M. Gómez-Gesteira, J.-C. Marongiu, Neighbour lists in smoothed particle hydrodynamics, International Journal for Numerical Methods in Fluids 67 (12) (2011) 2026–2042. doi:10.1002/fld.2481.DOI
  12. [12]J. M. Domínguez, A. J. C. Crespo, A. Barreiro, M. Gómez-Gesteira, B. D. Rogers, Efficient implementation of double precision in gpu computing to simulate realistic cases with high resolution, in: Proceedings of the 9th SPHERIC Workshop, Paris, France, 2014.
  13. [13]W. Kahan, Pracniques: further remarks on reducing truncation errors, Communications of the ACM 8 (1) (1965) 40. doi:10.1145/363707.363723.DOI
  14. [14]A. Neumaier, Rundungsfehleranalyse einiger Verfahren zur Summation endlicher Summen, ZAMM - Journal of Applied Mathematics and Mechanics / Zeitschrift für Angewandte Mathematik und Mechanik 54 (1) (1974) 39–51. doi:10.1002/zamm.19740540106.DOI
  15. [15]A. Klein, A generalized Kahan-Babuška-summation-algorithm, Computing 76 (3-4) (2006) 279–293. doi:10.1007/s00607-005-0139-x.DOI
  16. [16]G. Bilotta, V. Zago, V. Centorrino, R. A. Dalrymple, A. Hérault, C. Del Negro, A numerically robust, parallel-friendly variant of BiCGSTAB for the semi-implicit integration of the viscous term in smoothed particle hydrodynamics, Journal of Computational Physics 446 (2022) 111413. doi:10.1016/j.jcp.2022.111413.DOI
  17. [17]J. J. Monaghan, Smoothed Particle Hydrodynamics, Reports on Progress in Physics 68 (2005) 1703–1759. doi:10.1088/0034-4885/68/8/R01.DOI
  18. [18]J. J. Monaghan, R. A. Gingold, Shock simulation by the particle method SPH, Journal of Computational Physics 52 (2) (1983) 374–389. doi:10.1016/0021-9991(83)90036-0.DOI
  19. [19]D. Molteni, A. Colagrossi, Density diffusion in smoothed particle hydrodynamics simulations of incompressible flows, Journal of Computational Physics 228 (14) (2009) 5480–5492. doi:10.1016/j.jcp.2009.04.027.
  20. [20]D. Molteni, A. Colagrossi, A simple procedure to improve the pressure evaluation in hydrodynamic context using the SPH, Computer Physics Communications 180 (2009). doi:10.1016/j.cpc.2008.12.004.DOI
  21. [21]M. Antuono, A. Colagrossi, S. Marrone, C. Lugni, Propagation of gravity waves through an SPH scheme with numerical diffusive terms, Computer Physics Communication 182 (4) (2011) 866–877. doi:10.1016/j.cpc.2010.12.012.DOI
  22. [22]S. Marrone, M. Antuono, A. Colagrossi, G. Colicchio, D. Le Touzé, G. Graziani, δ-SPH model for simulating violent impact flows, Computer Methods in Applied Mechanics and Engineering 200 (13) (2011) 1526–1542. doi:10.1016/j.cma.2010.12.016.DOI
  23. [23]M. D. Green, R. Vacondio, J. Peiró, A smoothed particle hydrodynamics numerical scheme with a consistent diffusion term for the continuity equation, Computers & Fluids 179 (2019) 632–644. doi:10.1016/j.compfluid.2018.11.020.DOI
  24. [24]J. P. Vila, On particle weighted methods and smooth particle hydrodynamics, Mathematical Models and Methods in Applied Sciences 9 (2) (1999). doi:10.1142/S0218202599000117.DOI
  25. [25]J. K. Chen, J. E. Beraun, C. J. Jih, An improvement for tensile instability in Smoothed Particle Hydrodynamics, Computational Mechanics 23 (4) (1999) 279–287. doi:10.1007/s004660050409.DOI
  26. [26]J. K. Chen, J. E. Beraun, T. C. Carney, A corrective smoothed particle method for boundary value problems in heat conduction, International Journal for Numerical Methods in Engineering 46 (2) (1999) 231–252. doi:10.1002/(SICI)1097-0207(19990920)46:2<231::AID-NME672>3.0.CO;2-K.doi.org/10.1002/(sici)1097-0207(19990920)46:2<231::aid-nme672>3.0.co;2-k
  27. [27]J. Bonet, T.-S. Lok, Variational and momentum preservation aspects of smooth particle hydrodynamic formulations, Computer Methods in Applied Mechanics and Engineering 180 (1) (1999) 97–115. doi:10.1016/S0045-7825(99)00051-1.DOI
  28. [28]V. Zago, L. J. Schulze, N. Almashan, R. A. Dalrymple, Overcoming excessive numerical dissipation in SPH modeling of water waves, Coastal Engineering 170 (2021) 104018. doi:10.1016/j.coastaleng.2021.104018.DOI
  29. [29]D. Le Touzé, A. Colagrossi, Smoothed particle hydrodynamics for free-surface and multiphase flows: a review, Reports on Progress in Physics 88 (3) (2025) 037001. doi:10.1088/1361-6633/ada80f.DOI
  30. [30]S. Adami, X. Y. Hu, N. A. Adams, A generalized wall boundary condition for Smoothed Particle Hydrodynamics, Journal of Computational Physics 231 (21) (2012) 7057–7075. doi:10.1016/j.jcp.2012.05.005.DOI
  31. [31]A. Mayrhofer, M. Ferrand, C. Kassiotis, D. Violeau, F.-X. Morel, Unified semi-analytical wall boundary conditions in SPH: analytical extension to 3-D, Numerical Algorithms 68 (2015) 15–34. doi:10.1007/s11075-014-9835-y.DOI
  32. [32]M. Ferrand, A. Joly, C. Kassiotis, D. Violeau, A. Leroy, F.-X. Morel, B. D. Rogers, Unsteady open boundaries for SPH using semi-analytical conditions and Riemann solver in 2D, Computer Physics Communications 210 (2017) 29–44. doi:https://doi.org/10.1016/j.cpc.2016.09.009.
  33. [33]A. Tafuni, J. M. Dominguez, R. Vacondio, A. J. Crespo, A versatile algorithm for the treatment of open boundary conditions in smoothed particle hydrodynamics gpu models, Computer Methods in Applied Mechanics and Engineering 342 (2018) 604–624. doi:10.1016/j.cma.2018.08.004.DOI
  34. [34]A. Colagrossi, M. Landrini, Numerical simulation of interfacial flows by smoothed particle hydrodynamics, Journal of Computational Physics 191 (2) (2003) 448–475. doi:10.1016/S0021-9991(03)00324–3.DOI
  35. [35]H.-D. Seo, H.-J. Park, J.-I. Kim, P. S. Lee, The particle-attached element interpolation for density correction in smoothed particle hydrodynamics, Advances in Engineering Software 154 (2021) 102972. doi:10.1016/j.advengsoft.2021.102972.DOI
  36. [36]P.-N. Sun, A. Colagrossi, S. Marrone, A. Zhang, The δ+-SPH model: Simple procedures for a further improvement of the SPH scheme, Computer Methods in Applied Mechanics and Engineering 315 (2017) 25–49. doi:10.1016/j.cma.2016.10.028.DOI
  37. [37]P.-N. Sun, A. Colagrossi, S. Marrone, M. Antuono, A. Zhang, Multi-resolution delta-plus-SPH with tensile instability control: Towards high Reynolds number flows, Computer Physics Communications 224 (2018) 63–80. doi:10.1016/j.cpc.2017.11.016.DOI
  38. [38]P.-N. Sun, C. Pilloton, M. Antuono, A. Colagrossi, Inclusion of an acoustic damper term in weakly-compressible SPH models, Journal of Computational Physics 483 (2023) 112056. doi:10.1016/j.jcp.2023.112056.DOI
  39. [39]D. Meringolo, A. Colagrossi, S. Marrone, F. Aristodemo, On the filtering of acoustic components in weakly-compressible SPH simulations, Journal of Fluids and Structures 70 (2017) 1–23. doi:10.1016/j.jfluidstructs.2017.01.005.DOI
  40. [40]R. Vacondio, C. Altomare, M. De Leffe, X. Y. Hu, D. Le Touzé, S. Lind, J.-C. Marongiu, S. Marrone, B. D. Rogers, A. Souto-Iglesias, Grand challenges for smoothed particle hydrodynamics numerical schemes, Computational Particle Mechanics 8 (2021) 575–588. doi:10.1007/s40571-020-00354-1.DOI
  41. [41]V. Damien, Fluid Mechanics and the SPH Method: Theory and Applications, Oxford University Press, 2012.DOI
  42. [42]J. P. Morris, P. J. Fox, Y. Zhu, Modeling low reynolds number incompressible flows using SPH, Journal of Computational Physics 136 (1) (1997) 214–226. doi:10.1006/jcph.1997.5776.DOI
  43. [43]R. H. Cole, Underwater Explosion, Princeton, NJ: Princeton University Press, 1948.
  44. [44]G. K. Batchelor, An introduction to fluid mechanics, Cambridge University Press, 1974. doi:10.1017/CBO9780511800955.
  45. [45]J. R. MacDonald, Some simple isothermal equations of state, Reviews of Modern Physics 38 (4) (1966). doi:10.1103/RevModPhys.38.669.DOI
  46. [46]G. R. Liu, M. B. Liu, Smoothed Particle Hydrodynamics: A Meshfree Particle Method, World Scientific Publishing Company, 2003.
  47. [47]J. J. Monaghan, J. B. Kajtar, SPH particle boundary forces for arbitrary boundaries, Computer Physics Communications 180 (10) (2009) 1811–1820. doi:10.1016/j.cpc.2009.05.008.DOI
  48. [48]R. A. Dalrymple, O. Knio, SPH modelling of water waves, in: Coastal dynamics 2001, 2001, pp. 779–787.DOI
  49. [49]A. J. C. Crespo, M. Gómez-Gesteira, R. A. Dalrymple, Boundary conditions generated by dynamic particles in SPH methods, Computers, Materials, & Continua 5 (3) (2007) 173–184.
  50. [50]E. Rustico, G. Bilotta, A. Hérault, C. Del Negro, G. Gallo, Advances in multi-GPU smoothed particle hydrodynamics simulations, IEEE Transactions on Parallel and Distributed Systems 25 (1) (2014) 43–52. doi: 10.1109/TPDS.2012.340.DOI
  51. [51]L. E. Kinsler, A. R. Frey, A. B. Coppens, J. V. Sanders, Fundamental of Acoustics, 4th Edition, John Wiley & Sons, Inc., 2000.
  52. [52]IEEE Computer Society, IEEE Standard for Floating-Point Arithmetic, IEEE, 2019. doi:10.1109/IEEESTD.2019.8766229.DOI
  53. [53]W. G. Horner, A new method of solving numerical equations of all orders, by continuous approximation, Philosophical Transactions of the Royal Society of London 109 (1819) 308–335. doi:10.1098/rstl.1819.0023.DOI
  54. [54]K. M. T. Kleefsman, G. Fekken, A. E. Veldman, B. Iwanowski, B. Buchner, A volume-of-fluid based simulation method for wave impact problems, Journal of Computational Physics 206 (1) (2005) 363–393. doi:10.1016/j.jcp.2004.12.007.DOI
  55. [55]E.-S. Lee, D. Violeau, R. Issa, S. Ploix, Application of weakly compressible and truly incompressible SPH to 3-D water collapse in waterworks, Journal of Hydraulic Research 48 (sup1) (2010) 50–60. doi:10.1080/00221686.2010.9641245.DOI
  56. [56]M. Antuono, A. Colagrossi, S. Marrone, Numerical diffusive terms in weakly-compressible sph schemes, Computer Physics Communications 183 (12) (2012) 2570–2580. doi:10.1016/j.cpc.2012.07.006.DOI
  57. [57]P. Omidvar, P. K. Stansby, B. D. Rogers, Wave body interaction in 2D using smoothed particle hydrodynamics (sph) with variable particle mass, International Journal for Numerical Methods in Fluids 68 (6) (2012) 686–705. doi:10.1002/fld.2528.DOI
  58. [58]M. Antuono, A. Colagrossi, S. Marrone, D. Molteni, Free-surface flows solved by means of SPH schemes with numerical diffusive terms, Computer Physics Communications 181 (3) (2010) 532–549. doi:10.1016/j.cpc.2009.11.002.DOI
  59. [59]A. Colagrossi, B. Bouscasse, M. Antuono, S. Marrone, Particle packing algorithm for sph schemes, Computer Physics Communications 183 (8) (2012) 1641–1653. doi:10.1016/j.cpc.2012.02.032.DOI
  60. [60]A. English, J. M. Domínguez, R. Vacondio, A. J. C. Crespo, P. K. Stansby, S. J. Lind, L. Chiapponi, M. Gómez-Gesteira, Modified dynamic boundary conditions (mdbc) for general-purpose smoothed particle hydrodynamics (sph): Application to tank sloshing, dam break and fish pass problems, Computational Particle Mechanics 9 (5) (2022) 1–15. doi:10.1007/s40571-021-00403-3.DOI
  61. [61]G. Fourtakas, J. M. Domínguez, R. Vacondio, B. D. Rogers, Local uniform stencil (lust) boundary condition for arbitrary 3-d boundaries in parallel smoothed particle hydrodynamics (sph) models, Computers & Fluids 190 (2019) 346–361. doi:10.1016/j.compfluid.2019.06.009.DOI
  62. [62]G. Bilotta, From GPU to CPU (and beyond): extending hardware support in GPUSPH through a SYCL-inspired interface, Concurrency and Computation: Practice and Experience 37 (2025) e8313. doi:10.1002/cpe.8313.DOI

Paper details

vlnc:W_4ejet28r
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY-SA 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Mathematics

Not recorded for this paper

View statement
Looking for related papers…
Contents