Skip to content

Commit

Permalink
Avoid FP overflow during Detonation initialization
Browse files Browse the repository at this point in the history
I was getting errors here when running with `amrex.fpe_trap_overflow=1`.
  • Loading branch information
yut23 committed Jul 5, 2024
1 parent 8521f81 commit 14a6784
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Exec/science/Detonation/problem_initialize_state_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ void problem_initialize_state_data (int i, int j, int k,

state(i,j,k,URHO) = problem::dens;

Real sigma = 1.0_rt / (1.0_rt + std::exp(-(c_T - xcen)/ width));
Real sigma_arg = -(c_T - xcen) / width;
// need to avoid FP overflow for sigma_arg >= 709
// 1/(1 + exp(100)) ~= 3e-44, which is much smaller than machine epsilon
if (sigma_arg < 100) {
sigma = 1.0_rt / (1.0_rt + std::exp(sigma_arg));
} else {
sigma = 0.0_rt;
}

state(i,j,k,UTEMP) = problem::T_l + (problem::T_r - problem::T_l) * (1.0_rt - sigma);

Expand Down

0 comments on commit 14a6784

Please sign in to comment.