CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
hyperspherical.h
1
5#ifndef __HYPERSPHERICAL__
6#define __HYPERSPHERICAL__
7
8#include <algorithm>
9#include <vector>
10
11#include "common.h"
12#include "function_ref.h"
13
14#define _HYPER_OVERFLOW_ 1e200
15#define _ONE_OVER_HYPER_OVERFLOW_ 1e-200
16#define _HYPER_SAFETY_ 1e-5
17#define _TRIG_PRECISSION_ 1e-7
18#define _HYPER_BLOCK_ 8
19#define _HYPER_CHUNK_ 16
20#define _TWO_OVER_THREE_ 0.666666666666666666666666666667e0
21#define _HIS_BYTE_ALIGNMENT_ 16
22
23struct HypersphericalInterpolationStructure {
24 int K = 0; //Sign of the curvature, (0,-1,1)
25 double beta = 0.0;
26 double delta_x = 0.0; //x-spacing. (xvec is uniformly spaced)
27 int trig_order = 0; //Order of the interpolation formula for SinK and CosK.
28 int l_size = 0; //Number of l values
29 std::vector<int> l; //Vector of l values stored
30 std::vector<double> chi_at_phimin; // vector x_min[index-l] below which neglect Bessels
31 int x_size = 0; //Number of x-values
32 std::vector<double> x; //Pointer to x-values
33 std::vector<double> sinK; //Vector of sin_K(xvec)
34 std::vector<double> cotK; //Vector of cot_K(xvec)
35 std::vector<double> phi; //array of size nl*nx. [y_{l1}(x1) t_{l1}(x2)...]
36 std::vector<double> dphi; //Same as phivec, but containing derivatives.
37 /* Second and third derivatives at the nodes, from the radial equation, in the layout of phi.
38 Filled by OnFixedSpacing only, for hyperspherical_Hermite_evaluate; empty otherwise. */
39 std::vector<double> d2phi;
40 std::vector<double> d3phi;
41
42 HypersphericalInterpolationStructure() = default;
45 HypersphericalInterpolationStructure(int K,
46 double beta,
47 int nl,
48 const int* lvec,
49 double xmin,
50 double xmax,
51 double sampling,
52 int l_WKB,
53 double phiminabs);
54
59 static HypersphericalInterpolationStructure OnFixedSpacing(int K,
60 double beta,
61 int nl,
62 const int* lvec,
63 double xmin,
64 double xmax,
65 double sampling,
66 int l_WKB,
67 double phiminabs);
68
69 private:
70 struct Grid {
71 int nx;
72 double deltax;
73 };
74 HypersphericalInterpolationStructure(int K,
75 double beta,
76 int nl,
77 const int* lvec,
78 double xmin,
79 Grid grid,
80 int l_WKB,
81 double phiminabs);
82};
83using HyperInterpStruct = HypersphericalInterpolationStructure;
84
91 std::vector<int>
92 left; /* left node, or -1 when x is outside the table (the functions are 0 there) */
93 std::vector<double> h_left;
94 std::vector<double> h_right;
95 std::vector<double> g_left; /* the derivative weights include the node spacing */
96 std::vector<double> g_right;
97 void resize(int n) {
98 left.resize(n);
99 h_left.resize(n);
100 h_right.resize(n);
101 g_left.resize(n);
102 g_right.resize(n);
103 }
104};
105
107void hyperspherical_Hermite_locate(const HyperInterpStruct* pHIS,
108 int nxi,
109 const double* xinterp,
110 HermiteLocations& where);
111
115template <bool DoPhi, bool DoDPhi, bool DoD2Phi>
116void hyperspherical_Hermite_evaluate(const HyperInterpStruct* pHIS,
117 int lnum,
118 const HermiteLocations& where,
119 int first,
120 int nxi,
121 double* Phi,
122 double* dPhi,
123 double* d2Phi);
124
125struct WKB_parameters {
126 int K;
127 int l;
128 double beta;
129 double phiminabs;
130};
131
132void hyperspherical_forwards_recurrence(int K,
133 int lmax,
134 double beta,
135 double x,
136 double sinK,
137 double cotK,
138 const double* sqrtK,
139 const double* one_over_sqrtK,
140 double* PhiL);
141void hyperspherical_forwards_recurrence_chunk(int K,
142 int lmax,
143 double beta,
144 double* x,
145 double* sinK,
146 double* cotK,
147 int chunk,
148 const double* sqrtK,
149 const double* one_over_sqrtK,
150 double* PhiL);
151void hyperspherical_backwards_recurrence(int K,
152 int lmax,
153 double beta,
154 double x,
155 double sinK,
156 double cotK,
157 const double* sqrtK,
158 const double* one_over_sqrtK,
159 double* PhiL);
160
161void hyperspherical_backwards_recurrence_chunk(int K,
162 int lmax,
163 double beta,
164 double* x,
165 double* sinK,
166 double* cotK,
167 int chunk,
168 const double* sqrtK,
169 const double* one_over_sqrtK,
170 double* PhiL);
171
172bool hyperspherical_WKB(int K, int l, double beta, double y, double* Phi);
173void hyperspherical_bessel_direct_vector(
174 int K, double beta, int* lvec, int nl, const double* xvec, int nx, double* Phi);
175void ClosedModY(int l, int beta, double* y, int* phisign, int* dphisign);
176bool get_CF1(int K, int l, double beta, double cotK, double* CF, int* isign);
177bool CF1_from_Gegenbauer(int l, int beta, double sinK, double cotK, double* CF);
178double airy_cheb_approx(double z);
179double coef1(double z);
180double coef2(double z);
181double coef3(double z);
182double coef4(double z);
183double cheb(double x, int n, const double A[]);
184
185double PhiWKB_minus_phiminabs(double x, const WKB_parameters& wkbparam);
186
187void hyperspherical_get_xmin_from_Airy(
188 int K, int l, double beta, double xtol, double phiminabs, double* xmin, int* fevals);
189
190bool fzero_ridder(FunctionRef<double(double x)> func,
191 double x1,
192 double x2,
193 double xtol,
194 const double* Fx1,
195 const double* Fx2,
196 double* xzero,
197 int* fevals);
198
199void hyperspherical_get_xmin_from_approx(
200 int K, int l, double nu, double ignore1, double phiminabs, double* xmin, int* ignore2);
201
218template <int Order, bool DoPhi, bool DoDPhi, bool DoD2Phi>
219void hyperspherical_Hermite_interpolation(const HyperInterpStruct* pHIS,
220 int nxi,
221 int lnum,
222 const double* xinterp,
223 double* Phi,
224 double* dPhi,
225 double* d2Phi);
226
227// The definition lives in hyperspherical.cpp (same translation unit as
228// ClosedModY, which must inline into the closed-case loop); these are the
229// combinations the transfer module dispatches to.
230extern template void hyperspherical_Hermite_evaluate<true, false, false>(
231 const HyperInterpStruct*, int, const HermiteLocations&, int, int, double*, double*, double*);
232extern template void hyperspherical_Hermite_evaluate<true, true, true>(
233 const HyperInterpStruct*, int, const HermiteLocations&, int, int, double*, double*, double*);
234extern template void hyperspherical_Hermite_evaluate<true, true, false>(
235 const HyperInterpStruct*, int, const HermiteLocations&, int, int, double*, double*, double*);
236extern template void hyperspherical_Hermite_evaluate<true, false, true>(
237 const HyperInterpStruct*, int, const HermiteLocations&, int, int, double*, double*, double*);
238extern template void hyperspherical_Hermite_evaluate<false, true, false>(
239 const HyperInterpStruct*, int, const HermiteLocations&, int, int, double*, double*, double*);
240extern template void hyperspherical_Hermite_interpolation<4, true, false, false>(
241 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
242extern template void hyperspherical_Hermite_interpolation<4, false, true, false>(
243 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
244extern template void hyperspherical_Hermite_interpolation<4, true, true, false>(
245 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
246extern template void hyperspherical_Hermite_interpolation<4, true, false, true>(
247 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
248extern template void hyperspherical_Hermite_interpolation<4, true, true, true>(
249 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
250extern template void hyperspherical_Hermite_interpolation<6, true, false, false>(
251 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
252extern template void hyperspherical_Hermite_interpolation<6, false, true, false>(
253 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
254extern template void hyperspherical_Hermite_interpolation<6, true, true, false>(
255 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
256extern template void hyperspherical_Hermite_interpolation<6, true, false, true>(
257 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
258extern template void hyperspherical_Hermite_interpolation<6, true, true, true>(
259 const HyperInterpStruct*, int, int, const double*, double*, double*, double*);
260
261#endif
Definition hyperspherical.h:90