aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/LaserParticleContainer.cpp
diff options
context:
space:
mode:
authorGravatar Luca Fedeli <luca.fedeli@cea.fr> 2021-09-09 02:12:23 +0200
committerGravatar GitHub <noreply@github.com> 2021-09-09 02:12:23 +0200
commit7a4001b63d159c70810f08eab464a1a6451f5b00 (patch)
tree3c2ba71ec4ede7d8201f35d04642c0648a8718f1 /Source/Particles/LaserParticleContainer.cpp
parent4551f33916f6dae93db7227fb6ecf22cb3c896f9 (diff)
downloadWarpX-7a4001b63d159c70810f08eab464a1a6451f5b00.tar.gz
WarpX-7a4001b63d159c70810f08eab464a1a6451f5b00.tar.zst
WarpX-7a4001b63d159c70810f08eab464a1a6451f5b00.zip
Fix floating point exception issue in single precision (#2284)
* fix fpe issue in single precision * fixed bug * fixed bug * make prettier * fixed bug * fixed bug * fixed bug * using constexpr as suggested by NZaim
Diffstat (limited to 'Source/Particles/LaserParticleContainer.cpp')
-rw-r--r--Source/Particles/LaserParticleContainer.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp
index c2f23a0b0..d7f645f2c 100644
--- a/Source/Particles/LaserParticleContainer.cpp
+++ b/Source/Particles/LaserParticleContainer.cpp
@@ -64,6 +64,7 @@
#include <numeric>
#include <string>
#include <vector>
+#include <type_traits>
using namespace amrex;
using namespace WarpXLaserProfiles;
@@ -618,7 +619,12 @@ LaserParticleContainer::ComputeSpacing (int lev, Real& Sx, Real& Sy) const
const std::array<Real,3>& dx = WarpX::CellSize(lev);
#if !(defined WARPX_DIM_RZ)
- const Real eps = static_cast<Real>(dx[0]*1.e-50);
+ constexpr float small_float_coeff = 1.e-25f;
+ constexpr double small_double_coeff = 1.e-50;
+ constexpr Real small_coeff = std::is_same<Real,float>::value ?
+ static_cast<Real>(small_float_coeff) :
+ static_cast<Real>(small_double_coeff);
+ const auto eps = static_cast<Real>(dx[0]*small_coeff);
#endif
#if (AMREX_SPACEDIM == 3)
Sx = std::min(std::min(dx[0]/(std::abs(m_u_X[0])+eps),