Triumvirate C++ API 0.5.0.post1.dev301+g026f21751
Three-point clustering measurements in large-scale structure analyses.
Loading...
Searching...
No Matches
maths.hpp
Go to the documentation of this file.
1// Triumvirate: Three-Point Clustering Measurements in LSS
2//
3// Copyright (C) 2023 Mike S Wang & Naonori S Sugiyama [GPL-3.0-or-later]
4//
5// This file is part of the Triumvirate program. See the COPYRIGHT
6// and LICENCE files at the top-level directory of this distribution
7// for details of copyright and licensing.
8//
9// This program is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17// See the GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program. If not, see <https://www.gnu.org/licenses/>.
21
35
36#ifndef TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
37#define TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
38
39#include <gsl/gsl_interp.h>
40#include <gsl/gsl_sf_bessel.h>
41#include <gsl/gsl_sf_coupling.h>
42#include <gsl/gsl_sf_gamma.h>
43#include <gsl/gsl_sf_legendre.h>
44#include <gsl/gsl_sf_result.h>
45#include <gsl/gsl_spline.h>
46
47#include <cmath>
48#include <complex>
49#include <vector>
50
51#include "monitor.hpp"
52
54#ifdef __GNUC__
55#define PURE __attribute__((pure))
56#else
57#define PURE
58#endif
60
61namespace trv {
62namespace maths {
63
64// ***********************************************************************
65// Complex numbers
66// ***********************************************************************
67
68extern const std::complex<double> M_I;
69
78std::complex<double> eval_complex_in_polar(double r, double theta);
79
80
81// ***********************************************************************
82// Vectors
83// ***********************************************************************
84
91double get_vec3d_magnitude(std::vector<double> vec);
92
101PURE double get_vec3d_magnitude(double* vec);
102
103
104// ***********************************************************************
105// Gamma function
106// ***********************************************************************
107
108// -----------------------------------------------------------------------
109// Lanzcos approximation
110// -----------------------------------------------------------------------
111
129std::complex<double> eval_lanczos_approx_series(std::complex<double> z);
130
143std::complex<double> eval_gamma_lanczos(std::complex<double> z);
144
145
146// -----------------------------------------------------------------------
147// Component evaluation
148// -----------------------------------------------------------------------
149
162void get_lngamma_parts(double x, double y, double& lnr, double& theta);
163
180std::complex<double> eval_gamma_lnratio(double mu, std::complex<double> nu);
181
182
183// ***********************************************************************
184// Spherical harmonics
185// ***********************************************************************
186
188extern const double eps_coupling;
189
196double wigner_3j(int j1, int j2, int j3, int m1, int m2, int m3);
197
209 public:
218 static std::complex<double> calc_reduced_spherical_harmonic(
219 const int ell, const int m, double pos[3]
220 );
221
234 const int ell, const int m,
235 const double boxsize[3], const int ngrid[3],
236 std::vector< std::complex<double> >& ylm_out
237 );
238
252 const int ell, const int m,
253 const double boxsize[3], const int ngrid[3],
254 std::vector< std::complex<double> >& ylm_out
255 );
256};
257
258
259// ***********************************************************************
260// Spherical Bessel function
261// ***********************************************************************
262
269 public:
270 int order;
271
277 explicit SphericalBesselCalculator(const int ell);
278
285
290
297 double eval(double x);
298
299 private:
300 // CAVEAT: This calculator is designed for the range of @f$ x = kr @f$
301 // such that max(kr) > 2048Ï€. For @f$ x <= \max\{1000, \ell^2\} @f$,
302 // cubic spline interpolation is used with Δ(kr) = 0.05;
303 // for @f$ x > \max\{1000, \ell^2\} @f$, direct evaluation via
304 // asymptotic expansion is used.
305 double split = 1000.;
306 double step = 0.05;
307
308 gsl_interp_accel* accel;
309 gsl_spline* spline;
310};
311
312} // namespace trv::maths
313} // namespace trv
314
315#endif // !TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
double eval(double x)
Evaluate the interpolated function.
Definition maths.cpp:368
SphericalBesselCalculator(const int ell)
Construct the interpolated function calculator.
Definition maths.cpp:309
~SphericalBesselCalculator()
Destruct the interpolated function.
Definition maths.cpp:358
Reduced spherical harmonics.
Definition maths.hpp:208
static void store_reduced_spherical_harmonic_in_config_space(const int ell, const int m, const double boxsize[3], const int ngrid[3], std::vector< std::complex< double > > &ylm_out)
Store reduced spherical harmonics computed in configuration space.
Definition maths.cpp:263
static void store_reduced_spherical_harmonic_in_fourier_space(const int ell, const int m, const double boxsize[3], const int ngrid[3], std::vector< std::complex< double > > &ylm_out)
Store reduced spherical harmonics computed in Fourier space.
Definition maths.cpp:223
static std::complex< double > calc_reduced_spherical_harmonic(const int ell, const int m, double pos[3])
Calculate the reduced spherical harmonic.
Definition maths.cpp:172
Provide tracking of program resources and exceptions.
std::complex< double > eval_complex_in_polar(double r, double theta)
Evaluate a complex number in the polar form.
Definition maths.cpp:44
double get_vec3d_magnitude(std::vector< double > vec)
Return the magnitude of a 3-d vector.
Definition maths.cpp:53
std::complex< double > eval_gamma_lanczos(std::complex< double > z)
Evaluate the gamma function on the complex plane using the Lanczos approximation.
Definition maths.cpp:98
void get_lngamma_parts(double x, double y, double &lnr, double &theta)
Get the real and imaginary parts of the log-gamma function .
Definition maths.cpp:122
std::complex< double > eval_gamma_lnratio(double mu, std::complex< double > nu)
Evaluate the logarithm of the ratio of two gamma functions.
Definition maths.cpp:130
std::complex< double > eval_lanczos_approx_series(std::complex< double > z)
Evaluate the Lanczos approximation series for the gamma function.
Definition maths.cpp:73
const std::complex< double > M_I
imaginary unit
const double eps_coupling
zero-tolerance for Wigner 3-j coupling coefficients
Definition maths.cpp:165
double wigner_3j(int j1, int j2, int j3, int m1, int m2, int m3)
Calculate Wigner 3-j symbol.
Definition maths.cpp:167