CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
perturbations_module.h
1#ifndef PERTURBATIONS_MODULE_H
2#define PERTURBATIONS_MODULE_H
3
4#include <vector>
5
6#include "base_module.h"
7#include "input_module.h"
8
9class PpfFluid;
11class IDM_DRMD_IDR_DRMD_Species;
12
13/* Resolved-once views into PerturbationsModule's frozen all_species_ collection.
14 The module owns several numerical approximation schemes (TCA/RSA/UFA/ncdmfa),
15 the Einstein/metric equations, and output conventions that legitimately
16 reference specific named species; these handles give that module-owned logic
17 O(1) access to the relevant species' data, replacing per-step/per-sample/per-k
18 O(n) string-keyed scans of all_species_ (frozen after construction) and the
19 per-step downcasts that accompanied them. Resolved by ResolveSpecies() in the
20 ctor. Defined at file scope (not nested in the class) so the cclassy.pxd
21 generator (generate_wrapper.py) does not mistake its closing brace for the end
22 of the PerturbationsModule class and truncate the harvested member list. */
23struct ResolvedSpecies {
24 const IDM_DR_IDR_Species* idm_dr_idr = nullptr; // TCA-idm_dr, RSA-idr
25 std::size_t idm_dr_idr_index = static_cast<std::size_t>(-1); // its species_layouts[] index
26 const IDM_DRMD_IDR_DRMD_Species* idm_drmd = nullptr; // TCA-idm_drmd
27 PpfFluid* ppf_fluid = nullptr; // PPF fluid (absorbs ppf_fluid_)
28 const BaseSpecies* ur = nullptr; // UFA, RSA-ur, tensor rho
29 const BaseSpecies* lambda = nullptr; // excluded from rho_tot (delta_tot)
30 int idr_nature = idr_free_streaming; // absorbs idr_nature_
31 std::size_t cdm_index = static_cast<std::size_t>(-1); // h source (sync gauge)
32};
33
34class PerturbationsModule : public BaseModule {
35 public:
36 // The single PPF fluid, or nullptr. PPF is a modified-gravity closure defined
37 // relative to the whole universe (intrinsically singular), so the module owns
38 // it; non-PPF fluids are ordinary species. Resolved once in the ctor.
39 PpfFluid* ppf_fluid() const {
40 return resolved_.ppf_fluid;
41 }
42
43 PerturbationsModule(InputModulePtr input_module,
44 BackgroundModulePtr background_module,
45 ThermodynamicsModulePtr thermodynamics_module);
46 ~PerturbationsModule();
47 void perturb_output_data(file_format output_format,
48 double z,
49 int number_of_titles,
50 double* data) const;
51 void perturb_output_titles(file_format output_format, std::string& titles) const;
52 void perturb_output_firstline_and_ic_suffix(int index_ic,
53 std::string& first_line,
54 std::string& ic_suffix) const;
55
57 const background* GetBackground() const noexcept {
58 return pba;
59 }
60 const perturbs* GetPerturbs() const noexcept {
61 return ppt;
62 }
63 const precision* GetPrecision() const noexcept {
64 return ppr;
65 }
66 BackgroundModulePtr GetBackgroundModule() const {
67 return background_module_;
68 }
69 ThermodynamicsModulePtr GetThermodynamicsModule() const {
70 return thermodynamics_module_;
71 }
72
74 void SetSourceValue(
75 int index_md, int index_ic, int index_tp, int index_tau, int index_k, double value) {
76 sources_[index_md][index_ic * tp_size_[index_md] + index_tp]
77 [index_tau * k_size_[index_md] + index_k] = value;
78 }
79
82 int index_md_scalars_;
83 int index_md_tensors_;
84 int index_md_vectors_;
85 int md_size_;
89 int index_ic_ad_ = -1;
90 int index_ic_cdi_ = -1;
91 int index_ic_bi_ = -1;
92 int index_ic_nid_ = -1;
93 int index_ic_niv_ = -1;
94 int index_ic_ten_ = -1;
95 std::vector<int>
96 ic_size_;
101
102 /* remember that the temperature source function includes three
103 terms that we call 0,1,2 (since the strategy in class v > 1.7 is
104 to avoid the integration by part that would reduce the source to
105 a single term) */
106 int index_tp_t0_;
107 int index_tp_t1_;
108 int index_tp_t2_;
109 int index_tp_p_;
110 int index_tp_delta_tot_;
111 int index_tp_perturbed_recombination_delta_temp_;
112 int index_tp_perturbed_recombination_delta_chi_;
114 int index_tp_theta_m_;
115 int index_tp_theta_cb_;
116 int index_tp_theta_tot_;
118 int index_tp_phi_;
119 int index_tp_phi_prime_;
120 int index_tp_phi_plus_psi_;
121 int index_tp_psi_;
122 int index_tp_h_;
123 int index_tp_h_prime_;
124 int index_tp_eta_;
125 int index_tp_eta_prime_;
126 int index_tp_H_T_Nb_prime_;
127 int index_tp_k2gamma_Nb_;
129 int index_tp_delta_m_;
130 int index_tp_delta_cb_;
131 std::vector<int>
132 tp_size_;
134 // Resolved-once views into the frozen all_species_ collection (ResolvedSpecies
135 // is defined at file scope above). Resolved by ResolveSpecies() in the ctor.
136 ResolvedSpecies resolved_;
137
138 void ResolveSpecies();
147 std::vector<char> species_emits_source_;
148
149 bool has_source_t_;
150 bool has_source_p_;
151 bool has_source_delta_m_;
152 bool has_source_delta_cb_;
153 bool has_source_delta_tot_;
154 bool has_source_theta_m_;
155 bool has_source_theta_cb_;
156 bool has_source_theta_tot_;
157 bool has_source_phi_;
158 bool has_source_phi_prime_;
159 bool has_source_phi_plus_psi_;
160 bool has_source_psi_;
161 bool has_source_h_;
162 bool has_source_h_prime_;
163 bool has_source_eta_;
164 bool has_source_eta_prime_;
165 bool has_source_H_T_Nb_prime_;
166 bool
167 has_source_k2gamma_Nb_;
171 std::vector<int>
172 index_k_output_values_;
175 std::string
176 scalar_titles_;
177 std::string
178 vector_titles_;
179 std::string
180 tensor_titles_;
182 std::vector<double> scalar_perturbations_data_
184 std::vector<double> vector_perturbations_data_
186 std::vector<double> tensor_perturbations_data_
189 int size_scalar_perturbation_data_
191 int size_vector_perturbation_data_
193 int size_tensor_perturbation_data_
196
200
201 std::vector<std::vector<std::vector<double>>> sources_;
209
210 std::vector<double>
211 ln_tau_;
213 int ln_tau_size_;
216
217 std::vector<double> tau_sampling_;
218 int tau_size_;
220 std::vector<int> k_size_cl_;
223 std::vector<int> k_size_;
226 std::vector<std::vector<double>> k_;
227 double k_min_;
228 double k_max_;
230 private:
231 void perturb_sources_at_tau(
232 int index_md, int index_ic, int index_tp, double tau, double* pvecsources) const;
233 void perturb_init();
234 void perturb_indices_of_perturbs();
235 void perturb_timesampling_for_sources();
236 void perturb_get_k_list();
237 void perturb_workspace_init(int index_md, perturb_workspace* ppw);
238 void perturb_solve(int index_md, int index_ic, int index_k, perturb_workspace* ppw);
239 void perturb_prepare_k_output();
240 void perturb_find_approximation_number(int index_md,
241 double k,
243 double tau_ini,
244 double tau_end,
245 int* interval_number,
246 int* interval_number_of);
247 void perturb_find_approximation_switches(int index_md,
248 double k,
250 double tau_ini,
251 double tau_end,
252 double precision,
253 int interval_number,
254 int* interval_number_of,
255 double* interval_limit,
256 int** interval_approx);
257 void perturb_vector_init(
258 int index_md, int index_ic, double k, double tau, perturb_workspace* ppw, int* pa_old);
259 void perturb_initial_conditions(
260 int index_md, int index_ic, double k, double tau, perturb_workspace* ppw);
261 void perturb_approximations(int index_md, double k, double tau, perturb_workspace* ppw);
262 void perturb_einstein(int index_md, double k, double tau, double* y, perturb_workspace* ppw);
263 void perturb_total_stress_energy(int index_md, double k, double* y, perturb_workspace* ppw);
264 void perturb_timescale_member(double tau, void* parameters_and_workspace, double* timescale);
265 static void perturb_timescale(double tau, void* parameters_and_workspace, double* timescale);
266 void perturb_sources_member(double tau,
267 double* pvecperturbations,
268 double* pvecderivs,
269 int index_tau,
270 void* parameters_and_workspace);
271 static void perturb_sources(double tau,
272 double* pvecperturbations,
273 double* pvecderivs,
274 int index_tau,
275 void* parameters_and_workspace);
276 void perturb_print_variables_member(double tau,
277 double* y,
278 double* dy,
279 void* parameters_and_workspace);
280 static void perturb_print_variables(double tau,
281 double* y,
282 double* dy,
283 void* parameters_and_workspace);
284 void perturb_derivs_member(double tau, double* y, double* dy, void* parameters_and_workspace);
285 static void perturb_derivs(double tau, double* y, double* dy, void* parameters_and_workspace);
286 void perturb_tca_slip_and_shear(double* y, void* parameters_and_workspace);
287 void perturb_rsa_delta_and_theta(
288 double k, double* y, double a_prime_over_a, double* pvecthermo, perturb_workspace* ppw);
289 void perturb_rsa_idr_delta_and_theta(
290 double k, double* y, double a_prime_over_a, double* pvecthermo, perturb_workspace* ppw);
291
292 BackgroundModulePtr background_module_;
293 ThermodynamicsModulePtr thermodynamics_module_;
294 short
295 evolve_tensor_ur_;
296 short
297 evolve_tensor_ncdm_;
302
303 bool has_cmb_;
304 bool has_lss_;
307
308 std::vector<std::vector<double*>> late_sources_;
313 std::vector<std::vector<std::vector<double>>>
314 ddlate_sources_;
320 int number_of_scalar_titles_;
321 int number_of_vector_titles_;
322 int number_of_tensor_titles_;
327
328 std::vector<int> k_size_cmb_;
333};
334
342 perturb_parameters_and_workspace(PerturbationsModule* p_m) : perturbations_module(p_m) {}
343 PerturbationsModule* const perturbations_module;
347 double k;
349};
350
351#endif //PERTURBATIONS_MODULE_H
Definition base_species.h:76
Definition idm_dr_idr_species.h:16
Definition ppf_fluid.h:11
#define _MAX_NUMBER_OF_K_FILES_
Definition perturbations.h:89
Definition perturbations.h:344
Definition perturbations.h:100
file_format
Definition precision.h:40
Definition perturbations_module.h:341
int index_k
Definition perturbations_module.h:346
perturb_workspace * ppw
Definition perturbations_module.h:348
int index_ic
Definition perturbations_module.h:345
double k
Definition perturbations_module.h:347
int index_md
Definition perturbations_module.h:344
Definition precision.h:63