Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename T to temperature #1961

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tardis/analysis/opacities.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,15 @@ def _calc_planck_mean_opacity(self):

for i in range(self.nshells):
delta_nu = self.nu_bins[1:] - self.nu_bins[:-1]
T = self.mdl.plasma.t_rad[i]
bb_nu = Blackbody(T)
temperature = self.mdl.plasma.t_rad[i]
bb_nu = Blackbody(temperature)

tmp = (
bb_nu(self.nu_bins[:-1])
* delta_nu
* self.kappa_tot[:, 0]
).sum()
tmp /= (bb_nu(self.nu_bins[:-1], T) * delta_nu).sum()
tmp /= (bb_nu(self.nu_bins[:-1], temperature) * delta_nu).sum()

kappa_planck_mean[i] = tmp

Expand Down
4 changes: 2 additions & 2 deletions tardis/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _initialize_geometry_arrays(self, model):
self.r_outer_cgs = model.r_outer.to("cm").value
self.v_inner_cgs = model.v_inner.to("cm/s").value

def _initialize_packets(self, T, no_of_packets, iteration, radius):
def _initialize_packets(self, temperature, no_of_packets, iteration, radius):
# the iteration is added each time to preserve randomness
# across different simulations with the same temperature,
# for example. We seed the random module instead of the numpy module
Expand All @@ -213,7 +213,7 @@ def _initialize_packets(self, T, no_of_packets, iteration, radius):
rng = np.random.default_rng(seed=seed)
seeds = rng.choice(MAX_SEED_VAL, no_of_packets, replace=True)
radii, nus, mus, energies = self.packet_source.create_packets(
T, no_of_packets, rng, radius
temperature, no_of_packets, rng, radius
)
mc_config_module.packet_seeds = seeds
self.input_r = radii
Expand Down
6 changes: 3 additions & 3 deletions tardis/montecarlo/montecarlo_numba/formal_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,12 @@ def trapezoid_integration(array, h):


@njit(**njit_dict_no_parallel)
def intensity_black_body(nu, T):
def intensity_black_body(nu, temperature):
"""Get the black body intensity at frequency nu
and temperature T"""
and temperature"""
if nu == 0:
return np.nan # to avoid ZeroDivisionError
beta_rad = 1 / (KB_CGS * T)
beta_rad = 1 / (KB_CGS * temperature)
coefficient = 2 * H_CGS * C_INV * C_INV
return coefficient * nu * nu * nu / (np.exp(H_CGS * nu * beta_rad) - 1)

Expand Down
8 changes: 4 additions & 4 deletions tardis/montecarlo/montecarlo_numba/formal_integral_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,23 @@ def trapezoid_integration_cuda(arr, dx):


@cuda.jit(device=True)
def intensity_black_body_cuda(nu, T):
def intensity_black_body_cuda(nu, temperature):
"""
Get the black body intensity at frequency nu
and temperature T
and temperature

Parameters
----------
nu : float64
T : float64
temperature : float64

Returns
-------
float64
"""
if nu == 0:
return np.nan # to avoid ZeroDivisionError
beta_rad = 1 / (KB_CGS * T)
beta_rad = 1 / (KB_CGS * temperature)
coefficient = 2 * H_CGS * C_INV * C_INV
return coefficient * nu * nu * nu / (math.exp(H_CGS * nu * beta_rad) - 1)

Expand Down
4 changes: 2 additions & 2 deletions tardis/montecarlo/montecarlo_numba/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def sample_nu_free_free(numba_plasma, shell):
Frequency of the free-free emission process

"""
T = numba_plasma.t_electrons[shell]
temperature = numba_plasma.t_electrons[shell]
zrand = np.random.random()
return -K_B * T / H * np.log(zrand)
return -K_B * temperature / H * np.log(zrand)

@njit(**njit_dict_no_parallel)
def sample_nu_free_bound(numba_plasma, shell, continuum_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@
not GPUs_available, reason="No GPU is available to test CUDA function"
)
@pytest.mark.parametrize(
["nu", "T"],
["nu", "temperature"],
[
(1e14, 1e4),
(0, 1),
(1, 1),
],
)
def test_intensity_black_body_cuda(nu, T):
def test_intensity_black_body_cuda(nu, temperature):
"""
Initializes the test of the cuda version
against the numba implementation of the
intensity_black_body to 15 decimals. This
is done as both results have 15 digits of precision.
"""
actual = np.zeros(3)
black_body_caller[1, 3](nu, T, actual)
black_body_caller[1, 3](nu, temperature, actual)

expected = formal_integral_numba.intensity_black_body(nu, T)
expected = formal_integral_numba.intensity_black_body(nu, temperature)

ntest.assert_allclose(actual, expected, rtol=1e-14)


@cuda.jit
def black_body_caller(nu, T, actual):
def black_body_caller(nu, temperature, actual):
"""
This calls the CUDA function and fills out
the array
"""
x = cuda.grid(1)
actual[x] = formal_integral_cuda.intensity_black_body_cuda(nu, T)
actual[x] = formal_integral_cuda.intensity_black_body_cuda(nu, temperature)


@pytest.mark.skipif(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
from tardis.montecarlo.montecarlo_numba.numba_interface import NumbaModel

@pytest.mark.parametrize(
["nu", "T"],
["nu", "temperature"],
[
(1e14, 1e4),
(0, 1),
(1, 1),
],
)
def test_intensity_black_body(nu, T):
def test_intensity_black_body(nu, temperature):
func = formal_integral.intensity_black_body
actual = func(nu, T)
actual = func(nu, temperature)
print(actual, type(actual))
expected = intensity_black_body(nu, T)
expected = intensity_black_body(nu, temperature)
ntest.assert_almost_equal(actual, expected)


Expand Down
14 changes: 6 additions & 8 deletions tardis/montecarlo/packet_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_uniform_packet_energies(no_of_packets, rng):
return np.ones(no_of_packets) / no_of_packets

@staticmethod
def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000):
def create_blackbody_packet_nus(temperature, no_of_packets, rng, l_samples=1000):
"""
Create packet :math:`\\nu` distributed using the algorithm described in
Bjorkman & Wood 2001 (page 4) which references
Expand All @@ -76,8 +76,7 @@ def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000):

Parameters
----------
T : float
temperature
temperature : float
no_of_packets : int
l_samples : int
number of l_samples needed in the algorithm
Expand All @@ -100,7 +99,7 @@ def create_blackbody_packet_nus(T, no_of_packets, rng, l_samples=1000):
xis_prod = np.prod(xis[1:], 0)
x = ne.evaluate("-log(xis_prod)/l")

return x * (const.k_B.cgs.value * T) / const.h.cgs.value
return x * (const.k_B.cgs.value * temperature) / const.h.cgs.value


class BlackBodySimpleSource(BasePacketSource):
Expand All @@ -109,13 +108,12 @@ class BlackBodySimpleSource(BasePacketSource):
part.
"""

def create_packets(self, T, no_of_packets, rng, radius):
def create_packets(self, temperature, no_of_packets, rng, radius):
"""Generate black-body packet properties as arrays

Parameters
----------
T : float64
Temperature
temperature : float64
no_of_packets : int
Number of packets
rng : numpy random number generator
Expand All @@ -134,7 +132,7 @@ def create_packets(self, T, no_of_packets, rng, radius):
Packet energies
"""
radii = np.ones(no_of_packets) * radius
nus = self.create_blackbody_packet_nus(T, no_of_packets, rng)
nus = self.create_blackbody_packet_nus(temperature, no_of_packets, rng)
mus = self.create_zero_limb_darkening_packet_mus(no_of_packets, rng)
energies = self.create_uniform_packet_energies(no_of_packets, rng)

Expand Down
4 changes: 2 additions & 2 deletions tardis/plasma/properties/continuum_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,9 @@ def calculate(self, t_electrons):
@njit(error_model="numpy", fastmath=True)
def nu_ff(shell):

T = t_electrons[shell]
temperature = t_electrons[shell]
zrand = np.random.random()
return -K_B * T / H * np.log(zrand)
return -K_B * temperature / H * np.log(zrand)

return nu_ff

Expand Down
6 changes: 3 additions & 3 deletions tardis/util/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def create_synpp_yaml(radial1d_mdl, fname, shell_no=0, lines_db=None):
yaml.dump(yaml_reference, stream=f, explicit_start=True)


def intensity_black_body(nu, T):
def intensity_black_body(nu, temperature):
"""
Calculate the intensity of a black-body according to the following formula

Expand All @@ -297,15 +297,15 @@ def intensity_black_body(nu, T):
----------
nu : float
Frequency of light
T : float
temperature : float
Temperature in kelvin

Returns
-------
Intensity : float
Returns the intensity of the black body
"""
beta_rad = 1 / (k_B_cgs * T)
beta_rad = 1 / (k_B_cgs * temperature)
coefficient = 2 * h_cgs / c_cgs**2
intensity = ne.evaluate(
"coefficient * nu**3 / " "(exp(h_cgs * nu * beta_rad) -1 )"
Expand Down