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_rkck.h"
12#include "evolver_rkdp45.h"
13#include "thermodynamics.h"
14
15#define _scalars_ (ppt->has_scalars && (index_md == index_md_scalars_))
16#define _vectors_ (ppt->has_vectors && (index_md == index_md_vectors_))
17#define _tensors_ (ppt->has_tensors && (index_md == index_md_tensors_))
18
19//TODO: Remove those when possible!
20#define _scalarsEXT_ (ppt->has_scalars && (index_md == perturbations_module_->index_md_scalars_))
21#define _vectorsEXT_ (ppt->has_vectors && (index_md == perturbations_module_->index_md_vectors_))
22#define _tensorsEXT_ (ppt->has_tensors && (index_md == perturbations_module_->index_md_tensors_))
23
24#define _set_source_(index) \
25 sources_[index_md][index_ic * tp_size_[index_md] + index][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 tca_idm_drmd_flags { tca_idm_drmd_on, tca_idm_drmd_off };
44enum rsa_idr_flags { rsa_idr_off, rsa_idr_on };
45enum ufa_flags { ufa_off, ufa_on };
46enum ncdmfa_flags { ncdmfa_off, ncdmfa_on };
47
49
55
56enum idr_method { idr_free_streaming, idr_fluid }; /* for the idm-idr case */
57enum tensor_methods { tm_photons_only, tm_massless_approximation, tm_exact };
58
60
66
67enum class possible_gauges {
68 newtonian,
70};
71
73
75
79#define _SELECTION_NUM_MAX_ 100
80enum selection_type { gaussian, tophat, dirac };
81
83
85
89#define _MAX_NUMBER_OF_K_FILES_ 30
90
92
100struct perturbs {
107
110 bool
113 bool has_scalars = true;
114 bool has_vectors = false;
115 bool has_tensors = false;
117 bool has_ad = true;
118 bool has_bi = false;
119 bool has_cdi = false;
120 bool has_nid = false;
121 bool has_niv = false;
123 /* perturbed recombination */
127 enum tensor_methods tensor_method =
128 tm_massless_approximation;
133 false;
135 true;
137 false;
138 bool has_cl_number_count = false;
139 bool has_pk_matter = false;
141 false;
143 false;
145 false;
147 false;
150 false;
152 bool has_nc_density = false;
153 bool has_nc_rsd = false;
154 bool has_nc_lens = false;
155 bool has_nc_gr = false;
157 int l_scalar_max = 2500;
158 int l_vector_max = 500;
159 int l_tensor_max = 500;
161 300;
163 1.;
167 enum selection_type selection = gaussian;
171 0.1};
174 1;
176 1;
178 1;
179 int switch_dop = 1;
181 1;
183 120;
191 1.;
193 1.;
194 double G_eff_ur = 0.;
195
196 double z_max_pk =
197 0.;
200
204
209
214
215 double
217 double
220 double
223 double*
225 double*
228 double*
232
236
238 0;
241};
242
251 // Per-species perturbation layouts, parallel to all_species_ (lex-key order).
252 // Each thread allocates its own pv, so this storage is per-thread.
253 std::vector<std::unique_ptr<BaseSpecies::PerturbLayout>> species_layouts;
254
255 // Non-owning view into species_layouts: the species that registered ≥1
256 // perturbation variable in THIS pv's mode (no-ops like Lambda excluded).
257 // Scalar-mode construction keeps scalar fields last so their Newtonian
258 // stress-energy evaluation sees the complete shear accumulated from other
259 // species. Consumed by the scalar/vector/tensor RHS dispatch loops.
260 struct ActiveSpecies {
261 const BaseSpecies* species;
262 const BaseSpecies::PerturbLayout* layout;
263 };
264 std::vector<ActiveSpecies> active_species;
265
266 // Non-owning view into species_layouts: the species that emit a per-species
267 // transfer source (delta_g, delta_cdm, delta_ncdm, ...), in lex-key order.
268 // Source-column membership is k-independent (fixed in
269 // perturb_indices_of_perturbs); this list materialises it per pv so
270 // perturb_sources_member dispatches FillSources by pointer. Empty in runs
271 // without dTk/mTk/k_output, so that per-sample loop is skipped entirely.
272 struct SourceSpecies {
273 const BaseSpecies* species;
274 const BaseSpecies::PerturbLayout* layout;
275 };
276 std::vector<SourceSpecies> source_species;
277
278 // Always-present species, resolved once per pv (non-owning, into
279 // species_layouts). Base-typed because perturbations.h cannot see the nested
280 // PhotonsSpecies/BaryonsSpecies::PerturbLayout types (photons.h/baryons.h
281 // include perturbations.h). Read sites static_cast to the concrete type.
282 BaseSpecies::PerturbLayout* photon_layout = nullptr;
283 BaseSpecies::PerturbLayout* baryon_layout = nullptr;
284 BaseSpecies::PerturbLayout* cdm_layout = nullptr;
285
286 /* Photons bare fields removed — use pv->species_layouts[g_i] (PhotonsSpecies::PerturbLayout). */
287 /* Baryons bare fields removed — use pv->species_layouts[b_i] (BaryonsSpecies::PerturbLayout). */
288 /* CDM bare fields removed — use pv->species_layouts[cdm_i] (CDMSpecies::PerturbLayout). */
289 /* IDM_DR bare fields removed — use
290 IDM_DR_IDR_Species::idm_dr_layout(*pv->species_layouts[idm_dr_idr_i]). */
291 /* IDM_DRMD bare fields removed — use
292 IDM_DRMD_IDR_DRMD_Species::idm_drmd_layout(*pv->species_layouts[idm_drmd_idr_drmd_i]). */
293 /* DCDM bare fields removed — use DCDM_DR_Species::dcdm_layout(*pv->species_layouts[dcdm_dr_i]). */
294 /* UR bare fields removed — use pv->species_layouts[ur_i] (UltraRelativisticSpecies::PerturbLayout). */
295 /* IDR bare fields removed — use
296 IDM_DR_IDR_Species::idr_layout(*pv->species_layouts[idm_dr_idr_i]). */
297 /* IDR_DRMD bare fields removed — use
298 IDM_DRMD_IDR_DRMD_Species::idr_drmd_layout(*pv->species_layouts[idm_drmd_idr_drmd_i]). */
299
300 /* perturbed recombination */
320 int idx_delta = -1;
321 int idx_theta = -1;
322 int idx_shear = -1;
323 int idx_l3 = -1;
324 int l_max = -1;
325 } tensor_ur_layout;
326
329 std::vector<double> y;
330 std::vector<double> dy;
332 std::vector<int> used_in_sources;
335};
336
350
364
370
371 std::vector<double> pvecback;
372 std::vector<double> pvecthermo;
373 std::vector<double> pvecmetric;
374 /* Single owner of the perturb_vector; species methods receive a
375 non-owning raw pointer via pv.get() (used transiently while the
376 workspace is alive, never stored or shared). */
377 std::unique_ptr<perturb_vector> pv;
381 double delta_rho;
384 double delta_p;
388 double
393 /* Module-owned approximation closures. Computed by the perturbations module
394 (perturb_tca_slip_and_shear and perturb_rsa_* / perturb_rsa_idr_*, the
395 latter run inside perturb_einstein after the metric solve because they
396 depend on h'/phi') and then read — read-only — by the relevant species
397 (photons, ultra-relativistic, IDM_DR). These are not per-species private
398 state despite the species-suffixed names: they live here because the module
399 owns the approximation machinery and several consumers cross species. */
400 double tca_shear_g;
401 double tca_slip;
402 double rsa_delta_g;
403 double rsa_theta_g;
406 double
408 double
411 double delta_m;
412 double theta_m;
414 double delta_cb;
415 double theta_cb;
417 /* Module-owned PPF dark-energy closure. Written by FluidSpecies::ComputePpf
418 during stress-energy assembly (it depends on the totals of every other
419 species), then read back by the module totals and by the fluid's own
420 derivs/sources. PPF fluid is defined relative to the global stress-energy,
421 so this is genuine module-level coupling state, not fluid-private scratch.
422 (The S quantity of eq. 15 in 0808.3125 is a ComputePpf-internal temporary,
423 no longer stored here.) */
425 double delta_p_fld;
433
437 PerturbScalarContext scalar_ctx;
439
443
444 short
451
455
465 std::vector<int>
469
473
475 std::vector<double>
477 double
481};
482
483#endif
Definition base_species.h:76
enum selection_type selection
Definition perturbations.h:167
int index_pt_perturbed_recombination_delta_temp
Definition perturbations.h:301
int ap_size
Definition perturbations.h:463
int selection_num
Definition perturbations.h:165
bool want_lcmb_full_limber
Definition perturbations.h:134
bool has_nc_density
Definition perturbations.h:152
double rsa_theta_idr
Definition perturbations.h:409
double cotKgen
Definition perturbations.h:478
double rsa_theta_g
Definition perturbations.h:403
bool has_ad
Definition perturbations.h:117
int index_pt_eta
Definition perturbations.h:304
bool has_niv
Definition perturbations.h:121
int store_perturbations
Definition perturbations.h:185
double selection_mean[_SELECTION_NUM_MAX_]
Definition perturbations.h:168
double theta_cb
Definition perturbations.h:415
double delta_p
Definition perturbations.h:384
int index_ap_ufa
Definition perturbations.h:461
int switch_sw
Definition perturbations.h:173
#define _MAX_NUMBER_OF_K_FILES_
Definition perturbations.h:89
int switch_eisw
Definition perturbations.h:175
double delta_rho_fld
Definition perturbations.h:424
bool has_pk_matter
Definition perturbations.h:139
bool has_density_transfers
Definition perturbations.h:140
double rho_plus_p_theta_fld
Definition perturbations.h:426
possible_gauges gauge
Definition perturbations.h:205
bool has_vectors
Definition perturbations.h:114
int index_ap_tca
Definition perturbations.h:456
double Gamma_prime_fld
Definition perturbations.h:427
double * selection_tau
Definition perturbations.h:227
double z_max_pk
Definition perturbations.h:196
bool has_nid
Definition perturbations.h:120
double delta_rho
Definition perturbations.h:381
int index_ap_rsa_idr
Definition perturbations.h:460
double vector_source_pi
Definition perturbations.h:390
int pt_size
Definition perturbations.h:327
possible_gauges
Definition perturbations.h:67
int index_mt_h_prime_prime
Definition perturbations.h:354
int switch_pol
Definition perturbations.h:180
bool has_nc_rsd
Definition perturbations.h:153
bool has_nc_lens
Definition perturbations.h:154
bool has_cl_cmb_polarization
Definition perturbations.h:131
int index_pt_gwdot
Definition perturbations.h:310
bool has_cdi
Definition perturbations.h:119
double rho_plus_p_theta
Definition perturbations.h:382
bool has_Nbody_gauge_transfers
Definition perturbations.h:146
idr_method
Definition perturbations.h:56
int idx_delta
Definition perturbations.h:320
bool has_cl_number_count
Definition perturbations.h:138
bool has_perturbations
Definition perturbations.h:108
double rsa_delta_g
Definition perturbations.h:402
int index_ap_tca_idm_drmd
Definition perturbations.h:459
std::vector< double > pvecmetric
Definition perturbations.h:373
int idx_shear
Definition perturbations.h:322
bool has_bi
Definition perturbations.h:118
int index_mt_eta_prime
Definition perturbations.h:355
int last_index_back
Definition perturbations.h:447
double * selection_tau_min
Definition perturbations.h:224
int l_max
Definition perturbations.h:324
enum tensor_methods tensor_method
Definition perturbations.h:127
double k_max_for_pk
Definition perturbations.h:162
int last_index_thermo
Definition perturbations.h:448
double rsa_delta_ur
Definition perturbations.h:404
tca_flags
Definition perturbations.h:40
int index_pt_hv_prime
Definition perturbations.h:306
double selection_min_of_tau_min
Definition perturbations.h:216
int index_ap_ncdmfa
Definition perturbations.h:462
double three_cvis2_ur
Definition perturbations.h:192
std::vector< double > s_l
Definition perturbations.h:476
int index_mt_phi_prime
Definition perturbations.h:352
double tca_slip
Definition perturbations.h:401
int index_pt_V
Definition perturbations.h:307
int index_mt_gw_prime_prime
Definition perturbations.h:358
double k_output_values[_MAX_NUMBER_OF_K_FILES_]
Definition perturbations.h:188
double delta_cb
Definition perturbations.h:414
std::unique_ptr< perturb_vector > pv
Definition perturbations.h:377
double rsa_delta_idr
Definition perturbations.h:407
int index_mt_hv_prime_prime
Definition perturbations.h:360
int index_mt_h_prime
Definition perturbations.h:353
int index_mt_V_prime
Definition perturbations.h:359
int index_ap_rsa
Definition perturbations.h:457
std::vector< double > dy
Definition perturbations.h:330
double rho_plus_p_shear
Definition perturbations.h:383
bool has_cl_lensing_potential
Definition perturbations.h:136
int max_l_max
Definition perturbations.h:474
double rsa_theta_ur
Definition perturbations.h:405
bool has_scalars
Definition perturbations.h:113
int index_ap_tca_idm_dr
Definition perturbations.h:458
int index_mt_alpha
Definition perturbations.h:356
std::vector< int > approx
Definition perturbations.h:466
std::vector< double > y
Definition perturbations.h:329
double delta_p_fld
Definition perturbations.h:425
bool has_cls
Definition perturbations.h:111
int switch_lisw
Definition perturbations.h:177
short inter_mode
Definition perturbations.h:445
double rho_plus_p_tot
Definition perturbations.h:386
bool has_nc_gr
Definition perturbations.h:155
int index_pt_gw
Definition perturbations.h:309
short perturbations_verbose
Definition perturbations.h:237
bool has_perturbed_recombination
Definition perturbations.h:125
bool has_tensors
Definition perturbations.h:115
int index_ikout
Definition perturbations.h:430
int switch_dop
Definition perturbations.h:179
double vector_source_v
Definition perturbations.h:391
double theta_m
Definition perturbations.h:412
double selection_delta_tau
Definition perturbations.h:221
bool has_nl_corrections_based_on_delta_m
Definition perturbations.h:149
int l_scalar_max
Definition perturbations.h:157
int index_pt_perturbed_recombination_delta_chi
Definition perturbations.h:302
std::vector< double > pvecback
Definition perturbations.h:371
int l_lss_max
Definition perturbations.h:160
bool has_cl_cmb_lensing_potential
Definition perturbations.h:132
double gw_source
Definition perturbations.h:389
int mt_size
Definition perturbations.h:361
int k_output_values_num
Definition perturbations.h:186
int l_vector_max
Definition perturbations.h:158
double delta_m
Definition perturbations.h:411
double three_ceff2_ur
Definition perturbations.h:190
int index_mt_alpha_prime
Definition perturbations.h:357
double selection_width[_SELECTION_NUM_MAX_]
Definition perturbations.h:170
int l_tensor_max
Definition perturbations.h:159
FILE * perturb_output_file
Definition perturbations.h:429
double tca_shear_g
Definition perturbations.h:400
int idx_l3
Definition perturbations.h:323
int idx_theta
Definition perturbations.h:321
double selection_max_of_tau_max
Definition perturbations.h:218
bool has_metricpotential_transfers
Definition perturbations.h:144
std::vector< int > used_in_sources
Definition perturbations.h:332
bool has_velocity_transfers
Definition perturbations.h:142
bool has_cl_cmb_temperature
Definition perturbations.h:130
double * selection_function
Definition perturbations.h:229
#define _SELECTION_NUM_MAX_
Definition perturbations.h:79
int index_mt_psi
Definition perturbations.h:351
int index_pt_phi
Definition perturbations.h:305
double * selection_tau_max
Definition perturbations.h:226
std::vector< double > pvecthermo
Definition perturbations.h:372
double eisw_lisw_split_z
Definition perturbations.h:182
Definition perturbations.h:250
Definition perturbations.h:319
Definition perturbations.h:344
Definition perturbations.h:100
Definition base_species.h:89
Definition perturb_source_context.h:20