diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-01-08 14:05:28 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2017-06-01 16:33:39 +0800 |
commit | 480ae1b0caa2b5d8260df21dc7f541e6c79fdec6 (patch) | |
tree | c39ade13692ac553094a5eff29e3495140cd3ea3 /fg21sim/extragalactic/clusters/solver.py | |
parent | ce23ecbd28487824bbae5ae3d9f20b7781e6cd32 (diff) | |
download | fg21sim-480ae1b0caa2b5d8260df21dc7f541e6c79fdec6.tar.bz2 |
solver.py: Avoid possible overflow when w is too large
Diffstat (limited to 'fg21sim/extragalactic/clusters/solver.py')
-rw-r--r-- | fg21sim/extragalactic/clusters/solver.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/fg21sim/extragalactic/clusters/solver.py b/fg21sim/extragalactic/clusters/solver.py index 9d4a781..21b9a68 100644 --- a/fg21sim/extragalactic/clusters/solver.py +++ b/fg21sim/extragalactic/clusters/solver.py @@ -216,6 +216,16 @@ class FokkerPlanckSolver: C_mhalf = self.X_mhalf(C) w_phalf = dx_phalf * B_phalf / C_phalf w_mhalf = dx_mhalf * B_mhalf / C_mhalf + # Avoid overflow when w is too large + w_max = 300 + with np.errstate(invalid="ignore"): + mask_phalf = (np.abs(w_phalf) > w_max) + mask_mhalf = (np.abs(w_mhalf) > w_max) + w_phalf[mask_phalf] = w_max * (np.sign(w_phalf[mask_phalf])) + w_mhalf[mask_mhalf] = w_max * (np.sign(w_mhalf[mask_mhalf])) + logger.warning("Fixed too large w values: " + + "%d+%d" % (len(mask_phalf), len(mask_mhalf))) + # W_phalf = self.W(w_phalf) W_mhalf = self.W(w_mhalf) Wplus_phalf = W_phalf * np.exp(w_phalf/2) |