CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
perturbations.h
Go to the documentation of this file.
1
3#ifndef __PERTURBATIONS__
4#define __PERTURBATIONS__
5
6#include <memory>
7#include <vector>
8
9#include "../species/base_species.h"
10#include "evolver_ndf15.h"
11#include "evolver_options.h"
12#include "thermodynamics.h"
13
14#define _scalars_ (ppt->has_scalars && (index_md == index_md_scalars_))
15#define _vectors_ (ppt->has_vectors && (index_md == index_md_vectors_))
16#define _tensors_ (ppt->has_tensors && (index_md == index_md_tensors_))
17
18//TODO: Remove those when possible!
19#define _scalarsEXT_ (ppt->has_scalars && (index_md == perturbations_module_->index_md_scalars_))
20#define _vectorsEXT_ (ppt->has_vectors && (index_md == perturbations_module_->index_md_vectors_))
21#define _tensorsEXT_ (ppt->has_tensors && (index_md == perturbations_module_->index_md_tensors_))
22
23#define _set_source_(index) \
24 sources_[index_md][index_ic * tp_size_[index_md] + (index)] \
25 [index_tau * k_size_[index_md] + index_k]
26
39
40enum tca_flags { tca_on, tca_off };
41enum rsa_flags { rsa_off, rsa_on };
42enum tca_idm_dr_flags { tca_idm_dr_on, tca_idm_dr_off };
43enum rsa_idr_flags { rsa_idr_off, rsa_idr_on };
44enum ufa_flags { ufa_off, ufa_on };
45enum ncdmfa_flags { ncdmfa_off, ncdmfa_on };
46
48
54
55enum idr_method { idr_free_streaming, idr_fluid }; /* for the idm-idr case */
56enum tensor_methods { tm_photons_only, tm_massless_approximation, tm_exact };
57
59
65
66enum class possible_gauges {
67 newtonian,
69};
70
72
74
78#define _SELECTION_NUM_MAX_ 100
79enum selection_type { gaussian, tophat, dirac, tabulated };
80
82
84
88#define _MAX_NUMBER_OF_K_FILES_ 30
89
91
99struct perturbs {
106
107 bool has_perturbations = false;
109 bool has_cls =
110 false;
112 bool has_scalars = true;
113 bool has_vectors = false;
114 bool has_tensors = false;
116 bool has_ad = true;
117 bool has_bi = false;
118 bool has_cdi = false;
119 bool has_nid = false;
120 bool has_niv = false;
122 /* perturbed recombination */
126 enum tensor_methods tensor_method =
127 tm_massless_approximation;
132 false;
134 true;
136 0.;
138 false;
139 bool has_cl_number_count = false;
140 bool has_pk_matter = false;
142 false;
144 false;
146 false;
148 false;
151 false;
153 bool has_nc_density = false;
154 bool has_nc_rsd = false;
155 bool has_nc_lens = false;
156 bool has_nc_gr = false;
158 int l_scalar_max = 2500;
160 0;
161 int l_vector_max = 500;
162 int l_tensor_max = 500;
164 300;
166 1.;
170 enum selection_type selection = gaussian;
174 0.1};
177 1;
179 1;
181 1;
182 int switch_dop = 1;
184 1;
186 120;
188 bool store_perturbations = false;
194 1.;
196 1.;
197 double G_eff_ur = 0.;
198
199 double z_max_pk =
200 0.;
203
207
212
217
219 0.0;
221 0.0;
224 0.0;
227 nullptr;
229 nullptr;
230 double* selection_tau = nullptr;
232 nullptr;
235
239
241 0;
244};
245
254 // Per-species perturbation layouts, parallel to all_species_ (lex-key order).
255 // Each thread allocates its own pv, so this storage is per-thread.
256 std::vector<std::unique_ptr<BaseSpecies::PerturbLayout>> species_layouts;
257
258 // Non-owning view into species_layouts: the species that registered ≥1
259 // perturbation variable in THIS pv's mode (no-ops like Lambda excluded).
260 // Scalar-mode construction keeps scalar fields last so their Newtonian
261 // stress-energy evaluation sees the complete shear accumulated from other
262 // species. Consumed by the scalar/vector/tensor RHS dispatch loops.
263 struct ActiveSpecies {
264 const BaseSpecies* species;
265 const BaseSpecies::PerturbLayout* layout;
266 };
267 std::vector<ActiveSpecies> active_species;
268
269 // Non-owning view into species_layouts: the species that emit a per-species
270 // transfer source (delta_g, delta_cdm, delta_ncdm, ...), in lex-key order.
271 // Source-column membership is k-independent (fixed in
272 // perturb_indices_of_perturbs); this list materialises it per pv so
273 // perturb_sources dispatches FillSources by pointer. Empty in runs
274 // without dTk/mTk/k_output, so that per-sample loop is skipped entirely.
275 struct SourceSpecies {
276 const BaseSpecies* species;
277 const BaseSpecies::PerturbLayout* layout;
278 };
279 std::vector<SourceSpecies> source_species;
280
281 // Always-present species, resolved once per pv (non-owning, into
282 // species_layouts). Base-typed because perturbations.h cannot see the nested
283 // PhotonsSpecies/BaryonsSpecies::PerturbLayout types (photons.h/baryons.h
284 // include perturbations.h). Read sites static_cast to the concrete type.
285 BaseSpecies::PerturbLayout* photon_layout = nullptr;
286 BaseSpecies::PerturbLayout* baryon_layout = nullptr;
287 BaseSpecies::PerturbLayout* cdm_layout = nullptr;
288
289 /* Photons bare fields removed — use pv->species_layouts[g_i] (PhotonsSpecies::PerturbLayout). */
290 /* Baryons bare fields removed — use pv->species_layouts[b_i] (BaryonsSpecies::PerturbLayout). */
291 /* CDM bare fields removed — use pv->species_layouts[cdm_i] (CDMSpecies::PerturbLayout). */
292 /* IDM_DR bare fields removed — use
293 IDM_DR_IDR_Species::idm_dr_layout(*pv->species_layouts[idm_dr_idr_i]). */
294 /* IDM_DRMD bare fields removed — use
295 IDM_DRMD_IDR_DRMD_Species::idm_drmd_layout(*pv->species_layouts[idm_drmd_idr_drmd_i]). */
296 /* DCDM bare fields removed — use DCDM_DR_Species::dcdm_layout(*pv->species_layouts[dcdm_dr_i]). */
297 /* UR bare fields removed — use pv->species_layouts[ur_i] (UltraRelativisticSpecies::PerturbLayout). */
298 /* IDR bare fields removed — use
299 IDM_DR_IDR_Species::idr_layout(*pv->species_layouts[idm_dr_idr_i]). */
300 /* IDR_DRMD bare fields removed — use
301 IDM_DRMD_IDR_DRMD_Species::idr_drmd_layout(*pv->species_layouts[idm_drmd_idr_drmd_i]). */
302
303 /* perturbed recombination */
307 int index_pt_eta = -1;
308 int index_pt_phi = -1;
310 int index_pt_V = -1;
312 int index_pt_gw = -1;
313 int index_pt_gwdot = -1;
323 int idx_delta = -1;
324 int idx_theta = -1;
325 int idx_shear = -1;
326 int idx_l3 = -1;
327 int l_max = -1;
328 } tensor_ur_layout;
329
330 int pt_size = 0;
332 std::vector<double> y;
333 std::vector<double> dy;
335 std::vector<int> used_in_sources;
338};
339
353
354 int index_mt_psi = -1;
359 int index_mt_alpha = -1;
362 -1;
365 -1;
366 int mt_size = 0;
369
375
376 std::vector<double> pvecback;
377 std::vector<double> pvecthermo;
378 std::vector<double> pvecmetric;
379 /* Single owner of the perturb_vector; species methods receive a
380 non-owning raw pointer via pv.get() (used transiently while the
381 workspace is alive, never stored or shared). */
382 std::unique_ptr<perturb_vector> pv;
392 std::vector<std::unique_ptr<BaseSpecies::PerturbScratch>> species_scratch;
395 std::vector<int> species_approx_index;
396
397 double delta_rho = 0.0;
398 double rho_plus_p_theta = 0.0;
399 double rho_plus_p_shear = 0.0;
400 double delta_p = 0.0;
402 double rho_plus_p_tot = 0.0;
404 double gw_source =
405 0.0;
407 0.0;
409 0.0;
411 /* Module-owned approximation closures. Computed by the perturbations module
412 (perturb_tca_slip_and_shear and perturb_rsa_* / perturb_rsa_idr_*, the
413 latter run inside perturb_einstein after the metric solve because they
414 depend on h'/phi') and then read — read-only — by the relevant species
415 (photons, ultra-relativistic, IDM_DR). These are not per-species private
416 state despite the species-suffixed names: they live here because the module
417 owns the approximation machinery and several consumers cross species. */
418 double tca_shear_g = 0.0;
419 double tca_slip = 0.0;
420 double rsa_delta_g = 0.0;
421 double rsa_theta_g = 0.0;
422 double rsa_delta_ur = 0.0;
423 double rsa_theta_ur = 0.0;
425 0.0;
427 0.0;
429 double delta_m = 0.0;
430 double theta_m = 0.0;
432 double delta_cb = 0.0;
433 double theta_cb = 0.0;
437 double one_plus_w_m = 1.0;
438 double one_plus_w_cb = 1.0;
439
440 /* Module-owned PPF dark-energy closure. Written by FluidSpecies::ComputePpf
441 during stress-energy assembly (it depends on the totals of every other
442 species), then read back by the module totals and by the fluid's own
443 derivs/sources. PPF fluid is defined relative to the global stress-energy,
444 so this is genuine module-level coupling state, not fluid-private scratch.
445 (The S quantity of eq. 15 in 0808.3125 is a ComputePpf-internal temporary,
446 no longer stored here.) */
447 double delta_rho_fld = 0.0;
448 double delta_p_fld = 0.0;
450 0.0;
452 0.0;
454 FILE* perturb_output_file = nullptr;
455 int index_ikout = -1;
458
462 PerturbScalarContext scalar_ctx;
464
468
470 0;
473 0;
475 0;
478
482
483 int index_ap_tca = -1;
484 int index_ap_rsa = -1;
487 int index_ap_ufa = -1;
489 int ap_size = 0;
491 std::vector<int>
495
499
500 int max_l_max = 0;
501 std::vector<double>
503 double cotKgen =
504 0.0;
507};
508
509#endif
Definition base_species.h:90
enum selection_type selection
Definition perturbations.h:170
int index_pt_perturbed_recombination_delta_temp
Definition perturbations.h:304
int ap_size
Definition perturbations.h:489
int selection_num
Definition perturbations.h:168
bool want_lcmb_full_limber
Definition perturbations.h:133
bool has_nc_density
Definition perturbations.h:153
double rsa_theta_idr
Definition perturbations.h:426
double cotKgen
Definition perturbations.h:503
double rsa_theta_g
Definition perturbations.h:421
bool has_ad
Definition perturbations.h:116
int index_pt_eta
Definition perturbations.h:307
bool has_niv
Definition perturbations.h:120
double selection_mean[_SELECTION_NUM_MAX_]
Definition perturbations.h:171
double theta_cb
Definition perturbations.h:433
double delta_p
Definition perturbations.h:400
int index_ap_ufa
Definition perturbations.h:487
int switch_sw
Definition perturbations.h:176
#define _MAX_NUMBER_OF_K_FILES_
Definition perturbations.h:88
int switch_eisw
Definition perturbations.h:178
double delta_rho_fld
Definition perturbations.h:447
bool has_pk_matter
Definition perturbations.h:140
bool has_density_transfers
Definition perturbations.h:141
double rho_plus_p_theta_fld
Definition perturbations.h:449
possible_gauges gauge
Definition perturbations.h:208
bool has_vectors
Definition perturbations.h:113
int index_ap_tca
Definition perturbations.h:483
double Gamma_prime_fld
Definition perturbations.h:451
double * selection_tau
Definition perturbations.h:230
double z_max_pk
Definition perturbations.h:199
bool has_nid
Definition perturbations.h:119
double delta_rho
Definition perturbations.h:397
int index_ap_rsa_idr
Definition perturbations.h:486
double vector_source_pi
Definition perturbations.h:406
int pt_size
Definition perturbations.h:330
possible_gauges
Definition perturbations.h:66
int index_mt_h_prime_prime
Definition perturbations.h:357
std::vector< std::unique_ptr< BaseSpecies::PerturbScratch > > species_scratch
Definition perturbations.h:392
int switch_pol
Definition perturbations.h:183
bool has_nc_rsd
Definition perturbations.h:154
bool has_nc_lens
Definition perturbations.h:155
bool has_cl_cmb_polarization
Definition perturbations.h:130
int index_pt_gwdot
Definition perturbations.h:313
bool has_cdi
Definition perturbations.h:118
double rho_plus_p_theta
Definition perturbations.h:398
bool has_Nbody_gauge_transfers
Definition perturbations.h:147
idr_method
Definition perturbations.h:55
int idx_delta
Definition perturbations.h:323
bool has_cl_number_count
Definition perturbations.h:139
bool has_perturbations
Definition perturbations.h:107
double rsa_delta_g
Definition perturbations.h:420
std::vector< double > pvecmetric
Definition perturbations.h:378
int idx_shear
Definition perturbations.h:325
bool has_bi
Definition perturbations.h:117
int index_mt_eta_prime
Definition perturbations.h:358
int last_index_back
Definition perturbations.h:472
double * selection_tau_min
Definition perturbations.h:226
int l_max
Definition perturbations.h:327
enum tensor_methods tensor_method
Definition perturbations.h:126
double k_max_for_pk
Definition perturbations.h:165
int last_index_thermo
Definition perturbations.h:474
double rsa_delta_ur
Definition perturbations.h:422
tca_flags
Definition perturbations.h:40
int index_pt_hv_prime
Definition perturbations.h:309
double selection_min_of_tau_min
Definition perturbations.h:218
int index_ap_ncdmfa
Definition perturbations.h:488
double three_cvis2_ur
Definition perturbations.h:195
std::vector< double > s_l
Definition perturbations.h:502
int index_mt_phi_prime
Definition perturbations.h:355
double tca_slip
Definition perturbations.h:419
int index_pt_V
Definition perturbations.h:310
int index_mt_gw_prime_prime
Definition perturbations.h:361
double k_output_values[_MAX_NUMBER_OF_K_FILES_]
Definition perturbations.h:191
double delta_cb
Definition perturbations.h:432
std::unique_ptr< perturb_vector > pv
Definition perturbations.h:382
double rsa_delta_idr
Definition perturbations.h:424
int index_mt_hv_prime_prime
Definition perturbations.h:364
int index_mt_h_prime
Definition perturbations.h:356
int index_mt_V_prime
Definition perturbations.h:363
int index_ap_rsa
Definition perturbations.h:484
std::vector< double > dy
Definition perturbations.h:333
double rho_plus_p_shear
Definition perturbations.h:399
bool has_cl_lensing_potential
Definition perturbations.h:137
int max_l_max
Definition perturbations.h:500
double rsa_theta_ur
Definition perturbations.h:423
bool has_scalars
Definition perturbations.h:112
int index_ap_tca_idm_dr
Definition perturbations.h:485
int index_mt_alpha
Definition perturbations.h:359
std::vector< int > approx
Definition perturbations.h:492
bool store_perturbations
Definition perturbations.h:188
std::vector< double > y
Definition perturbations.h:332
double delta_p_fld
Definition perturbations.h:448
bool has_cls
Definition perturbations.h:109
int switch_lisw
Definition perturbations.h:180
short inter_mode
Definition perturbations.h:469
double rho_plus_p_tot
Definition perturbations.h:402
bool has_nc_gr
Definition perturbations.h:156
int index_pt_gw
Definition perturbations.h:312
short perturbations_verbose
Definition perturbations.h:240
bool has_perturbed_recombination
Definition perturbations.h:124
bool has_tensors
Definition perturbations.h:114
int index_ikout
Definition perturbations.h:455
int switch_dop
Definition perturbations.h:182
double vector_source_v
Definition perturbations.h:408
double theta_m
Definition perturbations.h:430
double selection_delta_tau
Definition perturbations.h:223
bool has_nl_corrections_based_on_delta_m
Definition perturbations.h:150
int l_scalar_max
Definition perturbations.h:158
int index_pt_perturbed_recombination_delta_chi
Definition perturbations.h:305
std::vector< double > pvecback
Definition perturbations.h:376
int l_scalar_max_lensing_margin
Definition perturbations.h:159
int l_lss_max
Definition perturbations.h:163
bool has_cl_cmb_lensing_potential
Definition perturbations.h:131
double gw_source
Definition perturbations.h:404
int mt_size
Definition perturbations.h:366
int k_output_values_num
Definition perturbations.h:189
int l_vector_max
Definition perturbations.h:161
double delta_m
Definition perturbations.h:429
std::vector< int > species_approx_index
Definition perturbations.h:395
double three_ceff2_ur
Definition perturbations.h:193
int index_mt_alpha_prime
Definition perturbations.h:360
double selection_width[_SELECTION_NUM_MAX_]
Definition perturbations.h:173
double k_max_lensing_extrapolated
Definition perturbations.h:135
int l_tensor_max
Definition perturbations.h:162
FILE * perturb_output_file
Definition perturbations.h:454
double tca_shear_g
Definition perturbations.h:418
int idx_l3
Definition perturbations.h:326
int idx_theta
Definition perturbations.h:324
double selection_max_of_tau_max
Definition perturbations.h:220
bool has_metricpotential_transfers
Definition perturbations.h:145
std::vector< int > used_in_sources
Definition perturbations.h:335
bool has_velocity_transfers
Definition perturbations.h:143
bool has_cl_cmb_temperature
Definition perturbations.h:129
double * selection_function
Definition perturbations.h:231
#define _SELECTION_NUM_MAX_
Definition perturbations.h:78
double one_plus_w_m
Definition perturbations.h:437
int index_mt_psi
Definition perturbations.h:354
int index_pt_phi
Definition perturbations.h:308
double * selection_tau_max
Definition perturbations.h:228
std::vector< double > pvecthermo
Definition perturbations.h:377
double eisw_lisw_split_z
Definition perturbations.h:185
Definition perturbations.h:253
Definition perturbations.h:322
Definition perturbations.h:347
Definition perturbations.h:99
Definition base_species.h:106
Definition perturb_source_context.h:20