CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
wdm_decay_product.h
1#pragma once
2#include <memory>
3#include <optional>
4#include <string>
5#include <string_view>
6#include <vector>
7
8#include "../species/ncdm_base_species.h"
9#include "background.h"
10
11class BackgroundModule;
12
35 public:
36 static constexpr std::string_view kTypeName = "dcdm_wdm";
37 static constexpr double kQKick = 10.0; // p/T0, internal convention
38
51 static constexpr double kSparsityFloor = 1e-12;
52
53 // ── Fiducial-cosmology placement helpers ───────────────────────────────────
54 // Placement-only fixed LCDM background — NOT physics. Maps a decay time t (Mpc)
55 // to the scale factor a at which those decays inject, so the momentum grid is a
56 // function of Gamma alone (invariant across the run's cosmology). See spec
57 // docs/superpowers/specs/2026-07-18-dcdm-wdm-adaptive-momentum-grid-design.md.
58 static constexpr double kFidOmegaM = 0.31;
59 static constexpr double kFidOmegaR = 9.2e-5; // photons+nu, T_cmb=2.7255, Neff=3.044
60 static constexpr double kFidH = 0.674; // h
61 static double FiducialCosmicTime(double a); // t(a) [Mpc], radiation+matter
62 static double FiducialScaleFactorAtTime(double t_mpc); // inverse (monotone)
63
65 const std::string& instance_name,
66 const NcdmSettings& settings,
67 const background* pba,
68 const BackgroundModule* bgm);
69
70 double Gamma() const {
71 return Gamma_;
72 }
73 double vkick() const {
74 return vkick_;
75 }
76 double epsilon_retention() const {
77 return eps_;
78 }
79 const std::vector<double>& dq() const {
80 return dq_;
81 }
82 const std::vector<double>& u() const {
83 return u_;
84 }
85 const std::vector<double>& u_edge() const {
86 return u_edge_;
87 }
93 double SigmaAt(double u_cut) const;
94
95 const std::optional<double>& Omega_ini_pending() const {
96 return Omega_ini_pending_;
97 }
98 const std::optional<double>& Omega_combined_pending() const {
99 return Omega_combined_pending_;
100 }
101
116 void FillInjection(double a, double rho_dcdm, double* J, double* dJdlnq) const;
117
118 // ── Background (Task 2) ────────────────────────────────────────────────────
119 void RegisterBackgroundIndices(int& index_bg) override;
120 void RegisterIntegrationIndices(int& index_bi) override;
121 void SetBackgroundInitialConditions(const BackgroundICContext& ctx) override;
122 void ComputeBackground(double a, const double* pvecback_B, double* pvecback) override;
123
124 double Rho(const double* pvecback) const override {
125 return pvecback[index_bg_rho_];
126 }
127 double P(const double* pvecback) const override {
128 return pvecback[index_bg_p_];
129 }
130 double PPrime(double a,
131 double H,
132 const double* pvecback_B,
133 const double* pvecback) const override;
134 double RhoPrimeOverRho(const double* pvecback, double a_prime_over_a) const override;
135
137 void WriteBackgroundData(const double* pvecback, BackgroundColumnWriter& w) const override;
138
139 // ── Decay-product neutrality overrides ─────────────────────────────────────
140 // The daughter starts empty: it contributes nothing to the early-time
141 // radiation budget, fnu, N_eff, or the flatness budget (the combined sector
142 // density is owned by the DCDM_WDM composite).
143 double GetOmega0() const override {
144 return 0.;
145 }
146 double NeutrinoOmega0() const override {
147 return 0.;
148 }
149 double NeffContribution(double /*z*/) const override {
150 return 0.;
151 }
152 bool IsFreestreaming() const override {
153 return false;
154 }
155 double BackgroundAIni(double a_proposed, double /*tol*/) const override {
156 return a_proposed; // empty at early times; no relativistic-start constraint
157 }
158 double DeviationFromRadiation(const double* /*pvecback*/) const override {
159 return 0.;
160 }
161 void PrintNeffInfo() const override;
162 void PrintMassInfo() const override;
163
164 // ── Perturbations (Task 4) ─────────────────────────────────────────────────
165
177
178 std::unique_ptr<BaseSpecies::PerturbLayout> CreatePerturbLayout() const override {
179 return std::make_unique<PerturbLayout>();
180 }
181
182 void RegisterPerturbationIndices(BaseSpecies::PerturbLayout& base,
183 perturb_vector* pv,
184 const precision* ppr,
185 int& index_pt,
186 const perturb_workspace* ppw,
187 int gauge) override;
189 double tau,
190 const double* y,
191 double* dy,
192 const perturb_parameters_and_workspace& ppaw) const override;
194 double* y,
195 const PerturbIcContext& ctx) override;
196 StressEnergyContribution StressEnergy(const BaseSpecies::PerturbLayout& base,
197 const perturb_vector* pv,
198 const double* y,
199 const double* pvecback,
200 const perturb_workspace* ppw) const override;
202 const double* y,
203 const double* dy,
204 PerturbSourceContext& ctx) const override;
206 PerturbColumnWriter& writer,
207 const PerturbationsModule& mod,
208 file_format fmt,
209 TransferColumnSection section = TransferColumnSection::all) const override;
210
214 perturb_vector* /*pv*/,
215 const precision* /*ppr*/,
216 int& /*index_pt*/,
217 const perturb_workspace* /*ppw*/,
218 int /*gauge*/) override {}
222 double* /*y*/,
223 const PerturbIcContext& /*ctx*/) override {}
224
225 // ── Index accessors for the composite ──────────────────────────────────────
226 int bg_f_index() const {
227 return index_bg_f_;
228 }
229 int bg_dfdlnq_index() const {
230 return index_bg_dfdlnq_;
231 }
232 int bg_inj_index() const {
233 return index_bg_inj_;
234 }
235 int bg_number_index() const {
236 return index_bg_number_;
237 }
238 int bi_f_index() const {
239 return index_bi_f_;
240 }
241 int bi_dfdlnq_index() const {
242 return index_bi_dfdlnq_;
243 }
244
245 protected:
247 double GetDlnf0Dlnq(int /*iq*/, const double* /*pvecback*/) const override {
248 return 0.;
249 }
250
251 private:
258 static constexpr double kFSeed = 1e-10;
259
262 void BuildInjectionAdaptedGrid();
268 void GaussWeights(double u_cut, double sigma, double* w) const;
269
270 const background* pba_;
271
272 double Gamma_ = 0.; // decay rate, CLASS units (Mpc^-1 after both conversions)
273 double vkick_ = 0.; // kick velocity in units of c
274 double eps_ = 0.; // total mass retention (m_d = eps*m_parent/2)
275
276 int n_bins_ = 96;
277 double q_edge_tol_ = 1e-3; // decayed-fraction trimmed off each end (grid F-span);
278 // the trimmed tail is clamped into the edge bin, not dropped
279 std::optional<double> q_min_ratio_floor_; // optional hard floor on q_lo/q_kick
280
281 static constexpr double kSigmaMin = 0.03; // ≈ 4 background-table samples (7e-3 in ln a)
282 static constexpr double kSigmaMax = 0.25; // bounds the wide-bin placement bias
283 double F_lo_ = 0.; // realized decayed-fraction span of the grid (0,0 = fallback grid)
284 double F_hi_ = 0.;
285
286 std::vector<double> u_; // ln q_i (bin centres = q(F_mid[i]))
287 std::vector<double> dq_; // cell widths q_edge[i+1] - q_edge[i]
288 std::vector<double> u_edge_; // N+1 cell edges in u (F-quantile edges)
289
290 std::optional<double> Omega_ini_pending_;
291 std::optional<double> Omega_combined_pending_;
292
293 // Background indices (per-bin arrays are n_bins_ long)
294 int index_bg_number_ = -1;
295 int index_bg_pseudo_p_ = -1;
296 int index_bg_f_ = -1;
297 int index_bg_dfdlnq_ = -1;
298 int index_bg_inj_ = -1;
299 int index_bi_f_ = -1;
300 int index_bi_dfdlnq_ = -1;
301
302 mutable std::vector<double> scratch_w_; // erf energy-deposit weights (background thread only)
303};
Definition base_species.h:33
Definition parser.h:23
Definition ncdm_base_species.h:43
Definition perturb_source_context.h:63
Definition wdm_decay_product.h:34
double RhoPrimeOverRho(const double *pvecback, double a_prime_over_a) const override
Definition wdm_decay_product.cpp:520
double DeviationFromRadiation(const double *) const override
Definition wdm_decay_product.h:158
void RegisterBackgroundIndices(int &index_bg) override
Definition wdm_decay_product.cpp:447
void WriteBackgroundData(const double *pvecback, BackgroundColumnWriter &w) const override
Definition wdm_decay_product.cpp:544
void PerturbSynchronousToNewtonian(const BaseSpecies::PerturbLayout &, double *, const PerturbIcContext &) override
Definition wdm_decay_product.h:221
void ApplyInitialConditions(const BaseSpecies::PerturbLayout &base, double *y, const PerturbIcContext &ctx) override
Definition wdm_decay_product.cpp:648
double P(const double *pvecback) const override
Definition wdm_decay_product.h:127
void PrintNeffInfo() const override
Definition wdm_decay_product.cpp:423
void RegisterTensorPerturbationIndices(BaseSpecies::PerturbLayout &, perturb_vector *, const precision *, int &, const perturb_workspace *, int) override
Definition wdm_decay_product.h:213
double PPrime(double a, double H, const double *pvecback_B, const double *pvecback) const override
Definition wdm_decay_product.cpp:502
double NeffContribution(double) const override
Definition wdm_decay_product.h:149
std::unique_ptr< BaseSpecies::PerturbLayout > CreatePerturbLayout() const override
Definition wdm_decay_product.h:178
void SetBackgroundInitialConditions(const BackgroundICContext &ctx) override
Definition wdm_decay_product.cpp:467
void FillSources(const BaseSpecies::PerturbLayout &base, const double *y, const double *dy, PerturbSourceContext &ctx) const override
Definition wdm_decay_product.cpp:709
StressEnergyContribution StressEnergy(const BaseSpecies::PerturbLayout &base, const perturb_vector *pv, const double *y, const double *pvecback, const perturb_workspace *ppw) const override
Definition wdm_decay_product.cpp:669
void WriteOutputColumns(PerturbColumnWriter &writer, const PerturbationsModule &mod, file_format fmt, TransferColumnSection section=TransferColumnSection::all) const override
Definition wdm_decay_product.cpp:766
double GetOmega0() const override
Definition wdm_decay_product.h:143
void ComputeBackground(double a, const double *pvecback_B, double *pvecback) override
Definition wdm_decay_product.cpp:477
void RegisterIntegrationIndices(int &index_bi) override
Definition wdm_decay_product.cpp:460
double GetDlnf0Dlnq(int, const double *) const override
Definition wdm_decay_product.h:247
double Rho(const double *pvecback) const override
Definition wdm_decay_product.h:124
static constexpr double kSparsityFloor
Definition wdm_decay_product.h:51
void FillInjection(double a, double rho_dcdm, double *J, double *dJdlnq) const
Definition wdm_decay_product.cpp:342
bool IsFreestreaming() const override
Definition wdm_decay_product.h:152
void PerturbDerivs(const BaseSpecies::PerturbLayout &base, double tau, const double *y, double *dy, const perturb_parameters_and_workspace &ppaw) const override
Definition wdm_decay_product.cpp:580
void PrintMassInfo() const override
Definition wdm_decay_product.cpp:434
double NeutrinoOmega0() const override
Definition wdm_decay_product.h:146
double SigmaAt(double u_cut) const
Definition wdm_decay_product.cpp:286
double BackgroundAIni(double a_proposed, double) const override
Definition wdm_decay_product.h:155
void WriteBackgroundColumnTitles(BackgroundColumnWriter &w) const override
Definition wdm_decay_product.cpp:535
Definition perturbations.h:253
Definition perturbations.h:347
file_format
Definition precision.h:56
Definition background_ic_context.h:11
Definition base_species.h:106
Definition ncdm_base_species.h:72
Definition perturb_source_context.h:125
Definition perturb_source_context.h:103
Definition wdm_decay_product.h:174
double closure_L
= limber_closure::Order(l_max)
Definition wdm_decay_product.h:175
Definition perturbations_module.h:380
Definition precision.h:79