From b2fcd6845837a46f4774b6deb6e025010941a1e7 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 8 Jan 2017 19:17:38 +0800 Subject: cosmology.py: Optimize the speed of overdensity_crit() --- fg21sim/extragalactic/clusters/cosmology.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fg21sim/extragalactic/clusters/cosmology.py b/fg21sim/extragalactic/clusters/cosmology.py index 54fa306..12e581a 100644 --- a/fg21sim/extragalactic/clusters/cosmology.py +++ b/fg21sim/extragalactic/clusters/cosmology.py @@ -181,7 +181,7 @@ class Cosmology: Appendix.A, Eq.(A1) """ coef = 3 * (12*np.pi) ** (2/3) / 20 - D0 = self.growth_factor(0) + D0 = self.growth_factor0 D_z = self.growth_factor(z) Om_z = self.Om(z) delta_c = coef * (D0 / D_z) * (1 + 0.0123*np.log10(Om_z)) @@ -201,6 +201,15 @@ class Cosmology: x = x0 / (1 + z) coef = np.sqrt(x**3 + 2) / (x**1.5) integral = integrate.quad(lambda y: y**1.5 * (y**3+2)**(-1.5), - a=0, b=x)[0] + a=0, b=x, epsabs=1e-5, epsrel=1e-5)[0] D = coef * integral return D + + @property + def growth_factor0(self): + """ + Present-day (z=0) growth factor. + """ + if not hasattr(self, "_growth_factor0"): + self._growth_factor0 = self.growth_factor(0) + return self._growth_factor0 -- cgit v1.2.2