Skip to content

Commit

Permalink
fix: Trap floating point overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
abensonca committed Sep 18, 2023
1 parent 4260c63 commit 6f74f91
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions source/nodes.operators.physics.CGM.chemistry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,15 @@ subroutine cgmChemistryComputeState(self,node,temperature,chemicalDensities,mass
! Truncate masses to zero to avoid unphysical behavior.
call chemicalMasses%enforcePositive()
massChemicals=chemicalMasses%sumOver()
if ( &
& massChemicals > 0.0d0 &
& .and. &
& massChemicals > hotHalo%mass() &
& ) call chemicalMasses%scale( &
& +hotHalo%mass () &
& / massChemicals &
if ( &
& massChemicals > 0.0d0 &
& .and. &
& massChemicals > hotHalo%mass() &
& .and. &
& -exponent(massChemicals)+exponent(hotHalo%mass()) < maxExponent(0.0d0) &
& ) call chemicalMasses%scale( &
& +hotHalo%mass () &
& / massChemicals &
& )
! Scale all chemical masses by their mass in atomic mass units to get a number density.
call chemicalMasses%massToNumber(chemicalDensities)
Expand Down

0 comments on commit 6f74f91

Please sign in to comment.