CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
type3_species.h
1#pragma once
2#include <string_view>
3#include <vector>
4
5#include "background.h"
6#include "cdm.h"
7#include "composite_species.h"
8#include "scalar_field.h"
9#include "species_build_context.h"
10
11// ── Type-3 momentum-transfer coupling, as pure free functions (arXiv:1604.04222,
12// synchronous gauge). Factored out of AddCouplingDerivs / StressEnergy so the
13// physics is unit-testable without a perturb_parameters_and_workspace, and so the
14// same closed form feeds both the derivs and the stress-energy paths. Conventions:
15// Zbar = -phi_prime_bg/a; D = 3*rho_cdm*a2 - 2*beta*Zbar^2. Every term carries an
16// explicit `beta` factor, so both return exactly 0 at beta = 0.
17
18// phi-KG momentum source (added to dy[scf.idx_phi_prime]).
19double Type3CouplingDeltaPhiPrime(double beta, double phi_prime_bg, double theta_cdm);
20
21// CDM-Euler momentum-transfer source (added to dy[cdm.idx_theta]).
22double Type3CouplingDeltaThetaCdm(double beta,
23 double k2,
24 double a_prime_over_a,
25 double rho_cdm,
26 double a2,
27 double Zbar,
28 double dV,
29 double phi,
30 double phi_prime,
31 double phi_prime_bg,
32 double theta_cdm);
33
42 public:
43 static constexpr std::string_view kTypeName = "cdm_scf_momentum";
44
46 bool SupportsNewtonianGauge() const override {
47 return false;
48 }
49
50 enum ChildIndex { kCdm = 0, kScf = 1 }; // children_ order, set in the ctor
51 static const CDMSpecies::PerturbLayout& cdm_layout(const CompositeSpecies::PerturbLayout& my) {
52 return static_cast<const CDMSpecies::PerturbLayout&>(*my.child_layouts[kCdm]);
53 }
54 static const ScalarFieldSpecies::PerturbLayout& scf_layout(
56 return static_cast<const ScalarFieldSpecies::PerturbLayout&>(*my.child_layouts[kScf]);
57 }
58
59 Type3Species(const background& pba, double omega0_cdm, std::unique_ptr<ScalarFieldSpecies> scf);
60
61 CDMSpecies& cdm() {
62 return *cdm_;
63 }
64 ScalarFieldSpecies& scf() {
65 return *scf_;
66 }
67 const CDMSpecies& cdm() const {
68 return *cdm_;
69 }
70 const ScalarFieldSpecies& scf() const {
71 return *scf_;
72 }
73 double beta() const {
74 return scf_->beta();
75 }
76
78 void WriteBackgroundData(const double* pvecback, BackgroundColumnWriter& w) const override;
79
80 std::vector<ShootingTarget> GetShootingTargets() const override {
81 return scf_->GetShootingTargets();
82 }
83 void ComputeShootingGuess(const SpeciesBuildContext& ctx,
84 std::vector<double>& guess,
85 std::vector<double>& dxdy) const override {
86 scf_->ComputeShootingGuess(ctx, guess, dxdy);
87 }
88 double ComputeShootingResidual(const ShootingResidualContext& ctx,
89 const ShootingTarget& target) const override {
90 return scf_->ComputeShootingResidual(ctx, target);
91 }
92
93 static std::vector<Named> CreateAll(const SpeciesBuildContext& ctx);
94
95 // Generic child sum (CompositeSpecies::StressEnergy) PLUS the coupling's
96 // -(2 beta/3) Zbar^2 theta_cdm contribution to the total (rho+p)theta. Used
97 // un-tallied at the IC delta_tot loop; the hot-path total goes through
98 // DelegateTally below, which adds the same cross-term.
99 StressEnergyContribution StressEnergy(const BaseSpecies::PerturbLayout& base,
100 const perturb_vector* pv,
101 const double* y,
102 const double* pvecback,
103 const perturb_workspace* ppw) const override;
104
105 // Hot-path total stress-energy for composites bypasses StressEnergy (it sums
106 // each child's StressEnergy via TallyStressEnergy). Override so the coupling
107 // cross-term reaches ppw->rho_plus_p_theta during the ODE, not only at ICs.
108 void DelegateTally(const BaseSpecies::PerturbLayout& base,
109 const perturb_vector* pv,
110 const double* y,
111 const double* pvecback,
112 const perturb_workspace* ppw,
113 StressEnergyContribution& total,
114 StressEnergyContribution& total_cold,
115 StressEnergyContribution& total_warm) const override;
116
117 protected:
118 void AddCouplingDerivs(double tau,
119 const double* y,
120 double* dy,
121 const perturb_parameters_and_workspace& ppaw) const override;
122
123 private:
124 // The -(2 beta/3) Zbar^2 theta_cdm coupling contribution to (rho+p)theta, shared
125 // by StressEnergy (ICs) and DelegateTally (hot path). Returns 0 at beta = 0.
126 double CrossTermRhoPlusPTheta(const BaseSpecies::PerturbLayout& base,
127 const double* y,
128 const double* pvecback,
129 const perturb_workspace* ppw) const;
130
131 CDMSpecies* cdm_ = nullptr;
132 ScalarFieldSpecies* scf_ = nullptr;
133};
Definition base_species.h:33
Definition cdm.h:18
Definition composite_species.h:27
Definition scalar_field.h:19
Definition type3_species.h:41
bool SupportsNewtonianGauge() const override
Definition type3_species.h:46
StressEnergyContribution StressEnergy(const BaseSpecies::PerturbLayout &base, const perturb_vector *pv, const double *y, const double *pvecback, const perturb_workspace *ppw) const override
Definition type3_species.cpp:128
void WriteBackgroundData(const double *pvecback, BackgroundColumnWriter &w) const override
Definition type3_species.cpp:26
void AddCouplingDerivs(double tau, const double *y, double *dy, const perturb_parameters_and_workspace &ppaw) const override
Definition type3_species.cpp:65
void WriteBackgroundColumnTitles(BackgroundColumnWriter &w) const override
Definition type3_species.cpp:21
Definition perturbations.h:253
Definition perturbations.h:347
Definition base_species.h:106
Definition composite_species.h:37
Definition shooting_target.h:7
Definition shooting_target.h:14
Definition species_build_context.h:58
Definition perturbations_module.h:380