Skip to content

Commit 8285ba0

Browse files
authored
Fix acoustic-source NaN for unfocused 2D sources (undefined negative-base pow) (#1640)
1 parent c7685a2 commit 8285ba0

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/simulation/m_acoustic_src.fpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,16 @@ contains
344344
! i.e. Spherical support -> 1/r scaling; Cylindrical support -> 1/sqrt(r) [empirical correction: ^-0.5 -> ^-0.85]
345345
integer, parameter :: mass_label = 1
346346

347-
if (n == 0) then
347+
! An unfocused source leaves foc_length at its unset default (dflt_real < 0, or 0): apply no
348+
! radial amplitude scaling. This guards every branch against the silent-corruption the default
349+
! would otherwise cause - foc_length(ai)**(-0.85) = pow(negative, non-integer) = NaN on some
350+
! compilers (e.g. nvhpc <= 24.3) in 2D, and 1/foc_length = wrong-sign or Inf in 3D/cylindrical.
351+
if (n == 0 .or. foc_length(ai) <= 0._wp) then
348352
foc_length_factor = 1._wp
349-
else if (p == 0 .and. (.not. cyl_coord)) then ! 2D axisymmetric case is physically 3D
350-
foc_length_factor = foc_length(ai)**(-0.85_wp) ! Empirical correction
351-
else
352-
foc_length_factor = 1/foc_length(ai)
353+
else if (p == 0 .and. (.not. cyl_coord)) then ! 2D Cartesian: cylindrical (line-source) spreading
354+
foc_length_factor = foc_length(ai)**(-0.85_wp) ! Empirical correction to 1/sqrt(r)
355+
else ! 3D or axisymmetric: spherical spreading
356+
foc_length_factor = 1._wp/foc_length(ai)
353357
end if
354358

355359
source = 0._wp

0 commit comments

Comments
 (0)