CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
perturb_source_context.h
1#pragma once
2#include <string>
3#include <vector>
4
5#include "common.h" // for file_format, true, false, class_store_* macros
6
7// Forward declarations
9struct perturb_vector;
10struct precision;
11class PerturbationsModule;
12
13// ── existing PerturbScalarContext (unchanged) ────────────────────────────────
14
21 double k = 0., k2 = 0.;
22 double a = 0., a2 = 0., a_prime_over_a = 0.;
23 double metric_continuity = 0.;
24 double metric_euler = 0.;
25 double metric_shear = 0.;
26 double metric_ufa_class = 0.;
27 double cotKgen = 0., s2_squared = 1.;
29 double delta_g = 0., theta_g = 0.;
31 double delta_b = 0., theta_b = 0.;
33 int b_idx_theta = -1;
35 int idr_nature = 0;
37 double R = 0.;
39 double cb2 = 0.;
41 int gauge = 0;
42};
43
49 bool wants_density; // ppt->has_density_transfers
50 bool wants_velocity; // ppt->has_velocity_transfers
51 int gauge; // possible_gauges; CDM registers theta only when != synchronous
52};
53
54// ── PerturbColumnWriter ──────────────────────────────────────────────────────
64 public:
65 // Title mode (used from perturb_output_titles and perturb_prepare_k_output)
66 explicit PerturbColumnWriter(std::string& titles) : titles_(&titles) {}
67
68 // Data mode for WriteOutputColumns: value = tk[tp_index]
69 PerturbColumnWriter(double* dataptr, const double* tk, int& storeidx)
70 : dataptr_(dataptr), tk_(tk), storeidx_(&storeidx) {}
71
72 // Data mode for PrintVariables: value passed directly
73 PerturbColumnWriter(double* dataptr, int& storeidx) : dataptr_(dataptr), storeidx_(&storeidx) {}
74
75 bool IsTitleMode() const {
76 return titles_ != nullptr;
77 }
78
79 // For WriteOutputColumns: species pass a tp_index; writer looks up tk[tp_index]
80 void Add(const char* title, int tp_index, bool active);
81 void Add(const std::string& title, int tp_index, bool active) {
82 Add(title.c_str(), tp_index, active);
83 }
84
85 // For PrintVariables: species pass the value directly
86 void Add(const char* title, double value, bool active);
87 void Add(const std::string& title, double value, bool active) {
88 Add(title.c_str(), value, active);
89 }
90
91 private:
92 std::string* titles_ = nullptr;
93 double* dataptr_ = nullptr;
94 const double* tk_ = nullptr;
95 int* storeidx_ = nullptr;
96};
97
98// ── PerturbSourceContext ─────────────────────────────────────────────────────
104 PerturbationsModule* p_mod = nullptr;
105 perturb_workspace* ppw = nullptr;
106 int index_md = 0;
107 int index_ic = 0;
108 int index_k = 0;
109 int index_tau = 0;
110 double k = 0.;
111 double a = 0.;
112 double a2 = 0.;
113 double a_prime_over_a = 0.;
114 // Pre-computed N-body gauge corrections (0 when not has_Nbody_gauge_transfers)
115 double theta_over_k2 = 0.;
116 double theta_shift = 0.;
117};
118
119// ── PerturbIcContext ─────────────────────────────────────────────────────────
126 // Density fractions
127 double fracnu = 0., fracg = 0., fracb = 0., fraccdm = 0., fracidm_drmd = 0.;
128 double rho_m_over_rho_r = 0., om = 0.;
129 // (k*tau)^2, (k*tau)^3
130 double ktau_two = 0., ktau_three = 0.;
131 // Curvature factor: 1 - 3K/k^2
132 double s2_squared = 1.;
133 // IC seed values pre-computed by module (photon delta/theta set by module formulas)
134 double delta_g_ic = 0., theta_g_ic = 0.;
135 // Shared relativistic IC (= delta_g_ic for adiabatic, computed by module for isocurvatures)
136 double delta_ur = 0., theta_ur = 0., shear_ur = 0., l3_ur = 0., delta_dr = 0.;
137 // Synchronous metric IC
138 double eta = 0.;
139 // DO NOT read in ApplyInitialConditions() — filled by module AFTER the species loop
140 // for the Newtonian gauge transformation. Zero during the species dispatch.
141 double alpha = 0., alpha_prime = 0.;
142 // Kinematics
143 double k = 0., tau = 0., a = 0., a_prime_over_a = 0.;
144 int index_ic = 0;
145 int gauge = 0;
146 // Pointers
147 perturb_workspace* ppw = nullptr;
148 const precision* ppr = nullptr;
149 const PerturbationsModule* p_mod = nullptr;
150};
151
152// ── PerturbSwitchContext ─────────────────────────────────────────────────────
160 double k = 0.;
161 double a = 0.;
162 const double* pvecback = nullptr;
163};
Definition perturb_source_context.h:63
Definition perturbations.h:250
Definition perturbations.h:344
Definition perturb_source_context.h:125
Definition perturb_source_context.h:20
int gauge
Definition perturb_source_context.h:41
int b_idx_theta
Definition perturb_source_context.h:33
double delta_b
Definition perturb_source_context.h:31
double R
Definition perturb_source_context.h:37
int idr_nature
Definition perturb_source_context.h:35
double cb2
Definition perturb_source_context.h:39
double delta_g
Definition perturb_source_context.h:29
Definition perturb_source_context.h:103
Definition perturb_source_context.h:159
Definition perturb_source_context.h:48
Definition precision.h:63