Skip to content

Commit 7695610

Browse files
code cleanup
1 parent 1205ddf commit 7695610

File tree

15 files changed

+87
-78
lines changed

15 files changed

+87
-78
lines changed

include/mesh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ Coord auto_grid(Ejecta const& jet, Array const& t_obs, Real theta_cut, Real thet
412412
Real theta_max = std::min(jet_edge, theta_cut);
413413

414414
size_t theta_num = std::max<size_t>(static_cast<size_t>((theta_max - theta_min) * 180 / con::pi * theta_resol), 56);
415-
const size_t uniform_theta_num = static_cast<size_t>(theta_num * 0.3);
415+
const size_t uniform_theta_num = static_cast<size_t>(static_cast<Real>(theta_num) * 0.3);
416416
size_t adaptive_theta_num = theta_num - uniform_theta_num;
417417

418418
const Array uniform_theta = xt::linspace(theta_min, theta_max, uniform_theta_num);
@@ -422,7 +422,7 @@ Coord auto_grid(Ejecta const& jet, Array const& t_obs, Real theta_cut, Real thet
422422
// coord.theta = uniform_theta;
423423

424424
const size_t phi_num = std::max<size_t>(static_cast<size_t>(360 * phi_resol), 1);
425-
const size_t uniform_phi_num = static_cast<size_t>(phi_num * 0.3);
425+
const size_t uniform_phi_num = static_cast<size_t>(static_cast<Real>(phi_num) * 0.3);
426426
const size_t adaptive_phi_num = phi_num - uniform_phi_num;
427427

428428
const Array uniform_phi = xt::linspace(0., 2 * con::pi, uniform_phi_num);

include/observer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ Array Observer::specific_flux_series(Array const& t_obs, Array const& nu_obs, Ph
387387
size_t t_idx = 0;
388388
iterate_to(time(i, j, 0), t_obs, t_idx);
389389

390-
size_t k = 0;
391390
InterpState state;
392-
while (t_idx < t_obs_len && k < t_grid - 1) {
391+
for (size_t k = 0; t_idx < t_obs_len && k < t_grid - 1;) {
393392
if (time(i, j, k + 1) < t_obs(t_idx)) {
394393
k++;
395394
} else {

include/simple-shock.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @brief Represents the state vector for the simple shock equation.
1717
* <!-- ************************************************************************************** -->
1818
*/
19-
template <typename Ejecta, typename Medium>
19+
template <typename Ejecta>
2020
struct SimpleState {
2121
static constexpr bool mass_inject = HasDmdt<Ejecta>; ///< whether Ejecta class has dmdt method
2222
static constexpr bool energy_inject = HasDedt<Ejecta>; ///< whether Ejecta class has dedt method
@@ -55,7 +55,7 @@ struct SimpleState {
5555
template <typename Ejecta, typename Medium>
5656
class SimpleShockEqn {
5757
public:
58-
using State = SimpleState<Ejecta, Medium>;
58+
using State = SimpleState<Ejecta>;
5959

6060
/**
6161
* <!-- ************************************************************************************** -->

include/synchrotron.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ void update_electrons_4Y(SynElectronGrid& electrons, Shock const& shock);
231231

232232
/**
233233
* <!-- ************************************************************************************** -->
234-
* @brief Calculates cooling Lorentz factor based on comoving time, magnetic field, and IC parameters
234+
* @brief Calculates a cooling Lorentz factor based on comoving time, magnetic field, and IC parameters
235235
* @details Accounts for synchrotron and inverse Compton cooling using an iterative approach
236-
* to handle the Lorentz factor dependent IC cooling.
237-
* @param t_com Comoving time
236+
* to handle the Lorentz factor-dependent IC cooling.
237+
* @param t_comv Comoving time
238238
* @param B Magnetic field
239239
* @param Ys Inverse Compton Y parameters
240240
* @param p Power-law index for electron energy distribution
241241
* @return The cooling Lorentz factor
242242
* <!-- ************************************************************************************** -->
243243
*/
244-
Real compute_gamma_c(Real t_com, Real B, InverseComptonY const& Ys, Real p);
244+
Real compute_gamma_c(Real t_comv, Real B, InverseComptonY const& Ys, Real p);
245245

246246
/**
247247
* <!-- ************************************************************************************** -->

pybind/mcmc.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ std::vector<size_t> MultiBandData::logscale_screen(PyArray const& data, size_t n
2929
const double log_start = std::log10(static_cast<double>(data(0)));
3030
const double log_end = std::log10(static_cast<double>(data(total_size - 1)));
3131
const double log_range = log_end - log_start;
32-
const size_t total_points = static_cast<size_t>(std::ceil(log_range * num_order)) + 1;
32+
const size_t total_points = static_cast<size_t>(std::ceil(log_range * static_cast<double>(num_order))) + 1;
3333

3434
std::vector<size_t> indices;
3535
indices.reserve(total_points);
3636

3737
// Always include first point
3838
indices.push_back(0);
3939

40-
const double step = log_range / (total_points - 1);
40+
const double step = log_range / static_cast<double>(total_points - 1);
4141

4242
for (size_t i = 1; i < total_points - 1; ++i) {
4343
const double log_target = log_start + i * step;
@@ -59,7 +59,7 @@ std::vector<size_t> MultiBandData::logscale_screen(PyArray const& data, size_t n
5959
}
6060
}
6161

62-
// Always include last point
62+
// Always include the last point
6363
if (total_size > 1) {
6464
indices.push_back(total_size - 1);
6565
}
@@ -152,7 +152,7 @@ Medium MultiBandModel::select_medium(Params const& param) const {
152152
}
153153

154154
void MultiBandData::add_flux_density(double nu, PyArray const& t, PyArray const& Fv_obs, PyArray const& Fv_err,
155-
std::optional<PyArray> weights) {
155+
std::optional<PyArray> const& weights) {
156156
AFTERGLOW_REQUIRE(t.size() == Fv_obs.size() && t.size() == Fv_err.size(), "light curve array inconsistent length!");
157157

158158
Array w = xt::ones<Real>({t.size()});
@@ -169,7 +169,7 @@ void MultiBandData::add_flux_density(double nu, PyArray const& t, PyArray const&
169169
}
170170

171171
void MultiBandData::add_flux(double nu_min, double nu_max, size_t num_points, PyArray const& t, PyArray const& Fv_obs,
172-
PyArray const& Fv_err, std::optional<PyArray> weights) {
172+
PyArray const& Fv_err, const std::optional<PyArray>& weights) {
173173
AFTERGLOW_REQUIRE(t.size() == Fv_obs.size() && t.size() == Fv_err.size(), "light curve array inconsistent length!");
174174
AFTERGLOW_REQUIRE(is_ascending(t), "Time array must be in ascending order!");
175175
AFTERGLOW_REQUIRE(nu_min < nu_max, "nu_min must be less than nu_max!");
@@ -195,7 +195,7 @@ void MultiBandData::add_flux(double nu_min, double nu_max, size_t num_points, Py
195195
}
196196

197197
void MultiBandData::add_spectrum(double t, PyArray const& nu, PyArray const& Fv_obs, PyArray const& Fv_err,
198-
std::optional<PyArray> weights) {
198+
const std::optional<PyArray>& weights) {
199199
AFTERGLOW_REQUIRE(nu.size() == Fv_obs.size() && nu.size() == Fv_err.size(), "spectrum array inconsistent length!");
200200

201201
Array w = xt::ones<Real>({nu.size()});

pybind/mcmc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct MultiBandData {
8282
* <!-- ************************************************************************************** -->
8383
*/
8484
void add_flux_density(double nu, PyArray const& t, PyArray const& Fv_obs, PyArray const& Fv_err,
85-
std::optional<PyArray> weights = std::nullopt);
85+
std::optional<PyArray> const& weights = std::nullopt);
8686

8787
/**
8888
* <!-- ************************************************************************************** -->
@@ -100,7 +100,7 @@ struct MultiBandData {
100100
* <!-- ************************************************************************************** -->
101101
*/
102102
void add_flux(double nu_min, double nu_max, size_t num_points, PyArray const& t, PyArray const& Fv_obs,
103-
PyArray const& Fv_err, std::optional<PyArray> weights = std::nullopt);
103+
PyArray const& Fv_err, const std::optional<PyArray>& weights = std::nullopt);
104104

105105
/**
106106
* <!-- ************************************************************************************** -->
@@ -116,7 +116,7 @@ struct MultiBandData {
116116
* <!-- ************************************************************************************** -->
117117
*/
118118
void add_spectrum(double t, PyArray const& nu, PyArray const& Fv_obs, PyArray const& Fv_err,
119-
std::optional<PyArray> weights = std::nullopt);
119+
const std::optional<PyArray>& weights = std::nullopt);
120120

121121
/**
122122
* <!-- ************************************************************************************** -->
@@ -150,7 +150,7 @@ struct MultiBandData {
150150
* @return size_t Total number of observational data points
151151
* <!-- ************************************************************************************** -->
152152
*/
153-
size_t data_points_num() const;
153+
[[nodiscard]] size_t data_points_num() const;
154154

155155
Array times; ///< Consolidated array of all observation times [seconds]
156156
Array frequencies; ///< Consolidated array of all observation frequencies [Hz]

pybind/pymodel.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "xtensor/misc/xsort.hpp"
1616

1717
Ejecta PyTophatJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading, Real duration,
18-
std::optional<PyMagnetar> magnetar) {
18+
const std::optional<PyMagnetar>& magnetar) {
1919
Ejecta jet;
2020
jet.eps_k = math::tophat(theta_c, E_iso);
2121
jet.Gamma0 = math::tophat_plus_one(theta_c, Gamma0 - 1);
@@ -30,7 +30,7 @@ Ejecta PyTophatJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading, Real d
3030
}
3131

3232
Ejecta PyGaussianJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading, Real duration,
33-
std::optional<PyMagnetar> magnetar) {
33+
const std::optional<PyMagnetar>& magnetar) {
3434
Ejecta jet;
3535
jet.eps_k = math::gaussian(theta_c, E_iso);
3636
jet.Gamma0 = math::gaussian_plus_one(theta_c, Gamma0 - 1);
@@ -45,7 +45,7 @@ Ejecta PyGaussianJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading, Real
4545
}
4646

4747
Ejecta PyPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real k_e, Real k_g, bool spreading, Real duration,
48-
std::optional<PyMagnetar> magnetar) {
48+
const std::optional<PyMagnetar>& magnetar) {
4949
Ejecta jet;
5050
jet.eps_k = math::powerlaw(theta_c, E_iso, k_e);
5151
jet.Gamma0 = math::powerlaw_plus_one(theta_c, Gamma0 - 1, k_g);
@@ -70,7 +70,7 @@ Ejecta PyPowerLawWing(Real theta_c, Real E_iso_w, Real Gamma0_w, Real k_e, Real
7070
}
7171

7272
Ejecta PyStepPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real E_iso_w, Real Gamma0_w, Real k_e, Real k_g,
73-
bool spreading, Real duration, std::optional<PyMagnetar> magnetar) {
73+
bool spreading, Real duration, const std::optional<PyMagnetar>& magnetar) {
7474
Ejecta jet;
7575
jet.eps_k = math::step_powerlaw(theta_c, E_iso, E_iso_w, k_e);
7676
jet.Gamma0 = math::step_powerlaw_plus_one(theta_c, Gamma0 - 1, Gamma0_w - 1, k_g);
@@ -86,7 +86,7 @@ Ejecta PyStepPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real E_iso_w, Re
8686
}
8787

8888
Ejecta PyTwoComponentJet(Real theta_c, Real E_iso, Real Gamma0, Real theta_w, Real E_iso_w, Real Gamma0_w,
89-
bool spreading, Real duration, std::optional<PyMagnetar> magnetar) {
89+
bool spreading, Real duration, const std::optional<PyMagnetar>& magnetar) {
9090
Ejecta jet;
9191
jet.eps_k = math::two_component(theta_c, theta_w, E_iso, E_iso_w);
9292

@@ -319,7 +319,7 @@ auto PyModel::generate_exposure_sampling(PyArray const& t, PyArray const& nu, Py
319319
// Generate time-frequency samples within each exposure window
320320
for (size_t i = 0, j = 0; i < t.size() && j < total_points; ++i) {
321321
const Real t_start = t(i);
322-
const Real dt = expo_time(i) / (num_points - 1);
322+
const Real dt = expo_time(i) / static_cast<Real>(num_points - 1);
323323

324324
for (size_t k = 0; k < num_points && j < total_points; ++k, ++j) {
325325
t_obs(j) = t_start + k * dt;
@@ -375,15 +375,15 @@ auto PyModel::flux_density_exposures(PyArray const& t, PyArray const& nu, PyArra
375375
"time, frequency, and exposure time arrays must have the same size");
376376
AFTERGLOW_REQUIRE(num_points >= 2, "num_points must be at least 2 to sample within each exposure time");
377377

378-
const auto sampling = generate_exposure_sampling(t, nu, expo_time, num_points);
378+
const auto [t_obs_sorted, nu_obs_sorted, idx_sorted] = generate_exposure_sampling(t, nu, expo_time, num_points);
379379

380380
auto flux_func = [](Observer& obs, Array const& time, Array const& freq, auto& photons) -> XTArray {
381381
return obs.specific_flux_series(time, freq, photons) / unit::flux_den_cgs;
382382
};
383383

384-
auto result = compute_emission(sampling.t_obs_sorted, sampling.nu_obs_sorted, flux_func);
384+
auto result = compute_emission(t_obs_sorted, nu_obs_sorted, flux_func);
385385

386-
average_exposure_flux(result, sampling.idx_sorted, t.size(), num_points);
386+
average_exposure_flux(result, idx_sorted, t.size(), num_points);
387387

388388
result.calc_total();
389389
return result;

pybind/pymodel.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct PyMagnetar {
6262
* <!-- ************************************************************************************** -->
6363
*/
6464
Ejecta PyTophatJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading = false, Real duration = 1,
65-
std::optional<PyMagnetar> magnetar = std::nullopt);
65+
const std::optional<PyMagnetar>& magnetar = std::nullopt);
6666

6767
/**
6868
* <!-- ************************************************************************************** -->
@@ -82,7 +82,7 @@ Ejecta PyTophatJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading = false
8282
* <!-- ************************************************************************************** -->
8383
*/
8484
Ejecta PyGaussianJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading = false, Real duration = 1,
85-
std::optional<PyMagnetar> magnetar = std::nullopt);
85+
const std::optional<PyMagnetar>& magnetar = std::nullopt);
8686

8787
/**
8888
* <!-- ************************************************************************************** -->
@@ -104,7 +104,7 @@ Ejecta PyGaussianJet(Real theta_c, Real E_iso, Real Gamma0, bool spreading = fal
104104
* <!-- ************************************************************************************** -->
105105
*/
106106
Ejecta PyPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real k_e, Real k_g, bool spreading = false,
107-
Real duration = 1, std::optional<PyMagnetar> magnetar = std::nullopt);
107+
Real duration = 1, const std::optional<PyMagnetar>& magnetar = std::nullopt);
108108

109109
/**
110110
* <!-- ************************************************************************************** -->
@@ -147,7 +147,7 @@ Ejecta PyPowerLawWing(Real theta_c, Real E_iso_w, Real Gamma0_w, Real k_e, Real
147147
* <!-- ************************************************************************************** -->
148148
*/
149149
Ejecta PyStepPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real E_iso_w, Real Gamma0_w, Real k_e, Real k_g,
150-
bool spreading, Real duration, std::optional<PyMagnetar> magnetar);
150+
bool spreading, Real duration, const std::optional<PyMagnetar>& magnetar);
151151

152152
/**
153153
* <!-- ************************************************************************************** -->
@@ -169,7 +169,8 @@ Ejecta PyStepPowerLawJet(Real theta_c, Real E_iso, Real Gamma0, Real E_iso_w, Re
169169
* <!-- ************************************************************************************** -->
170170
*/
171171
Ejecta PyTwoComponentJet(Real theta_c, Real E_iso, Real Gamma0, Real theta_w, Real E_iso_w, Real Gamma0_w,
172-
bool spreading = false, Real duration = 1, std::optional<PyMagnetar> magnetar = std::nullopt);
172+
bool spreading = false, Real duration = 1,
173+
const std::optional<PyMagnetar>& magnetar = std::nullopt);
173174

174175
/**
175176
* <!-- ************************************************************************************** -->
@@ -399,13 +400,13 @@ class PyModel {
399400
* @param axisymmetric Whether to assume axisymmetric jet structure (default: true)
400401
* <!-- ************************************************************************************** -->
401402
*/
402-
PyModel(Ejecta jet, Medium medium, PyObserver observer, PyRadiation fwd_rad,
403-
std::optional<PyRadiation> rvs_rad = std::nullopt,
404-
std::tuple<Real, Real, Real> resolutions = std::make_tuple(0.3, 1, 10), Real rtol = 1e-5,
403+
PyModel(Ejecta jet, Medium medium, const PyObserver& observer, const PyRadiation& fwd_rad,
404+
const std::optional<PyRadiation>& rvs_rad = std::nullopt,
405+
const std::tuple<Real, Real, Real>& resolutions = std::make_tuple(0.3, 1, 10), Real rtol = 1e-5,
405406
bool axisymmetric = true)
406407
: jet_(std::move(jet)),
407408
medium_(std::move(medium)),
408-
obs_setup(std::move(observer)),
409+
obs_setup(observer),
409410
fwd_rad(fwd_rad),
410411
rvs_rad_opt(rvs_rad),
411412
phi_resol(std::get<0>(resolutions)),

script/mcmc.ipynb

Lines changed: 25 additions & 14 deletions
Large diffs are not rendered by default.

script/quick.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 3,
17+
"execution_count": 2,
1818
"id": "9fb5c06d",
1919
"metadata": {},
2020
"outputs": [],
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": 4,
40+
"execution_count": 3,
4141
"id": "85de1437",
4242
"metadata": {},
4343
"outputs": [

0 commit comments

Comments
 (0)