aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/extragalactic
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-10-23 21:11:07 +0800
committerAaron LI <aly@aaronly.me>2017-10-23 21:11:07 +0800
commitc1a561a8c05a7e59cdf3a34ac2112eed5ea7c406 (patch)
treedc187a7b7d24f50c9d1a765b2f78be9e827bd301 /fg21sim/extragalactic
parent6fa552dca1ad74f39a7d1d44e55d9eb8eaa4a9b9 (diff)
downloadfg21sim-c1a561a8c05a7e59cdf3a34ac2112eed5ea7c406.tar.bz2
clusters/halo: Use "lru_cache()", also improves some performance
Diffstat (limited to 'fg21sim/extragalactic')
-rw-r--r--fg21sim/extragalactic/clusters/emission.py3
-rw-r--r--fg21sim/extragalactic/clusters/halo.py34
-rw-r--r--fg21sim/extragalactic/clusters/helper.py2
3 files changed, 26 insertions, 13 deletions
diff --git a/fg21sim/extragalactic/clusters/emission.py b/fg21sim/extragalactic/clusters/emission.py
index 5195423..4801eba 100644
--- a/fg21sim/extragalactic/clusters/emission.py
+++ b/fg21sim/extragalactic/clusters/emission.py
@@ -25,6 +25,7 @@ References
"""
import logging
+from functools import lru_cache
import numpy as np
import scipy.special
@@ -102,6 +103,7 @@ class SynchrotronEmission:
self.B = B # [uG]
@property
+ @lru_cache()
def B_gauss(self):
"""
Magnetic field in unit of [G] (i.e., Gauss)
@@ -109,6 +111,7 @@ class SynchrotronEmission:
return self.B * 1e-6 # [uG] -> [G]
@property
+ @lru_cache()
def frequency_larmor(self):
"""
Electron Larmor frequency (a.k.a. gyro frequency):
diff --git a/fg21sim/extragalactic/clusters/halo.py b/fg21sim/extragalactic/clusters/halo.py
index bf8e643..62bb011 100644
--- a/fg21sim/extragalactic/clusters/halo.py
+++ b/fg21sim/extragalactic/clusters/halo.py
@@ -51,6 +51,7 @@ References
"""
import logging
+from functools import lru_cache
import numpy as np
@@ -161,6 +162,7 @@ class RadioHalo:
)
@property
+ @lru_cache()
def gamma(self):
"""
The logarithmic grid adopted for solving the equation.
@@ -184,6 +186,7 @@ class RadioHalo:
return (self.age_obs - self.age_merger) # [Gyr]
@property
+ @lru_cache()
def time_crossing(self):
"""
The time duration of the sub-cluster crossing the main cluster,
@@ -217,6 +220,7 @@ class RadioHalo:
return helper.radius_virial(mass=self.M_sub, z=self.z_merger)
@property
+ @lru_cache()
def radius(self):
"""
The estimated radius for the simulated radio halo.
@@ -253,6 +257,7 @@ class RadioHalo:
return (4*np.pi/3) * self.radius**3
@property
+ @lru_cache()
def magnetic_field(self):
"""
The magnetic field strength at the simulated observation
@@ -264,6 +269,7 @@ class RadioHalo:
return helper.magnetic_field(mass=self.M_obs, z=self.z_obs)
@property
+ @lru_cache()
def kT_main(self):
"""
The mean temperature of the main cluster ICM at ``z_merger``
@@ -274,10 +280,12 @@ class RadioHalo:
return helper.kT_cluster(mass=self.M_main, z=self.z_merger)
@property
+ @lru_cache()
def kT_sub(self):
return helper.kT_cluster(mass=self.M_sub, z=self.z_merger)
@property
+ @lru_cache()
def kT_obs(self):
"""
The "current" cluster ICM mean temperature at ``z_obs``.
@@ -285,6 +293,7 @@ class RadioHalo:
return helper.kT_cluster(self.M_obs, z=self.z_obs) # [keV]
@property
+ @lru_cache()
def Mach_turbulence(self):
"""
The Mach number of the merger-induced turbulence.
@@ -306,6 +315,7 @@ class RadioHalo:
return mach
@property
+ @lru_cache()
def tau_acceleration(self):
"""
Calculate the electron acceleration timescale due to turbulent
@@ -324,20 +334,20 @@ class RadioHalo:
Reference: Ref.[brunetti2016],Eq.(8,9)
"""
- if not hasattr(self, "_tau_acceleration"):
- Mach = self.Mach_turbulence
- Rvir = helper.radius_virial(mass=self.M_main, z=self.z_merger)
- cs = helper.speed_sound(self.kT_main) # [km/s]
- # Turbulence injection scale
- L0 = self.f_lturb * Rvir # [kpc]
- x = cs*AUC.km2cm / AC.c
- fx = x * (x**4/4 + x*x - (1+2*x*x) * np.log(x) - 5/4)
- term1 = self.f_acc * 2.5 / fx / (Mach/0.5)**4
- term2 = (L0/300) / (cs/1500)
- self._tau_acceleration = term1 * term2 / 1000 # [Gyr]
- return self._tau_acceleration
+ Mach = self.Mach_turbulence
+ Rvir = helper.radius_virial(mass=self.M_main, z=self.z_merger)
+ cs = helper.speed_sound(self.kT_main) # [km/s]
+ # Turbulence injection scale
+ L0 = self.f_lturb * Rvir # [kpc]
+ x = cs*AUC.km2cm / AC.c
+ fx = x * (x**4/4 + x*x - (1+2*x*x) * np.log(x) - 5/4)
+ term1 = self.f_acc * 2.5 / fx / (Mach/0.5)**4
+ term2 = (L0/300) / (cs/1500)
+ tau = term1 * term2 / 1000 # [Gyr]
+ return tau
@property
+ @lru_cache()
def injection_rate(self):
"""
The constant electron injection rate assumed.
diff --git a/fg21sim/extragalactic/clusters/helper.py b/fg21sim/extragalactic/clusters/helper.py
index 86662e1..df7809d 100644
--- a/fg21sim/extragalactic/clusters/helper.py
+++ b/fg21sim/extragalactic/clusters/helper.py
@@ -311,7 +311,7 @@ def velocity_impact(M_main, M_sub, z=0.0):
----------
Ref.[cassano2005],Eq.(9)
"""
- eta_v = 4 * (1 + M_main/M_sub) ** (1/3)
+ eta_v = 4 * (1 + M_main/M_sub) ** 0.333333
R_vir = radius_virial(M_main, z) * AUC.kpc2cm # [cm]
vi = np.sqrt(2*AC.G * (1-1/eta_v) *
(M_main+M_sub)*AUC.Msun2g / R_vir) # [cm/s]