Triumvirate C++ API 0.5.0
Three-point clustering measurements in large-scale structure analyses.
Loading...
Searching...
No Matches
maths.hpp
Go to the documentation of this file.
1// Copyright (C) [GPLv3 Licence]
2//
3// This file is part of the Triumvirate program. See the COPYRIGHT
4// and LICENCE files at the top-level directory of this distribution
5// for details of copyright and licensing.
6//
7// This program is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15// See the GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <https://www.gnu.org/licenses/>.
19
34#ifndef TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
35#define TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
36
37#include <gsl/gsl_interp.h>
38#include <gsl/gsl_sf_bessel.h>
39#include <gsl/gsl_sf_coupling.h>
40#include <gsl/gsl_sf_gamma.h>
41#include <gsl/gsl_sf_legendre.h>
42#include <gsl/gsl_sf_result.h>
43#include <gsl/gsl_spline.h>
44
45#include <cmath>
46#include <complex>
47#include <vector>
48
49#include "monitor.hpp"
50
51namespace trv {
52namespace maths {
53
54// ***********************************************************************
55// Complex numbers
56// ***********************************************************************
57
58extern const std::complex<double> M_I;
59
68std::complex<double> eval_complex_in_polar(double r, double theta);
69
70
71// ***********************************************************************
72// Vectors
73// ***********************************************************************
74
81double get_vec3d_magnitude(std::vector<double> vec);
82
91double get_vec3d_magnitude(double* vec);
92
93
94// ***********************************************************************
95// Gamma function
96// ***********************************************************************
97
98// -----------------------------------------------------------------------
99// Lanzcos approximation
100// -----------------------------------------------------------------------
101
119std::complex<double> eval_lanczos_approx_series(std::complex<double> z);
120
133std::complex<double> eval_gamma_lanczos(std::complex<double> z);
134
135
136// -----------------------------------------------------------------------
137// Component evaluation
138// -----------------------------------------------------------------------
139
152void get_lngamma_parts(double x, double y, double& lnr, double& theta);
153
170std::complex<double> eval_gamma_lnratio(double mu, std::complex<double> nu);
171
172
173// ***********************************************************************
174// Spherical harmonics
175// ***********************************************************************
176
178extern const double eps_coupling;
179
186double wigner_3j(int j1, int j2, int j3, int m1, int m2, int m3);
187
199 public:
208 static std::complex<double> calc_reduced_spherical_harmonic(
209 const int ell, const int m, double pos[3]
210 );
211
224 const int ell, const int m,
225 const double boxsize[3], const int ngrid[3],
226 std::vector< std::complex<double> >& ylm_out
227 );
228
242 const int ell, const int m,
243 const double boxsize[3], const int ngrid[3],
244 std::vector< std::complex<double> >& ylm_out
245 );
246};
247
248
249// ***********************************************************************
250// Spherical Bessel function
251// ***********************************************************************
252
259 public:
260 int order;
261
267 explicit SphericalBesselCalculator(const int ell);
268
275
280
287 double eval(double x);
288
289 private:
290 // CAVEAT: This calculator is designed for the range of @f$ x = kr @f$
291 // such that max(kr) > 2048Ï€. For @f$ x <= \max\{1000, \ell^2\} @f$,
292 // cubic spline interpolation is used with Δ(kr) = 0.05;
293 // for @f$ x > \max\{1000, \ell^2\} @f$, direct evaluation via
294 // asymptotic expansion is used.
295 double split = 1000.;
296 double step = 0.05;
297
298 gsl_interp_accel* accel;
299 gsl_spline* spline;
300};
301
302} // namespace trv::maths
303} // namespace trv
304
305#endif // !TRIUMVIRATE_INCLUDE_MATHS_HPP_INCLUDED_
Interpolated spherical Bessel function of the first kind.
Definition maths.hpp:258
double eval(double x)
Evaluate the interpolated function.
Definition maths.cpp:366
SphericalBesselCalculator(const int ell)
Construct the interpolated function calculator.
Definition maths.cpp:307
~SphericalBesselCalculator()
Destruct the interpolated function.
Definition maths.cpp:356
Reduced spherical harmonics.
Definition maths.hpp:198
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:261
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:221
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:170
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:42
double get_vec3d_magnitude(std::vector< double > vec)
Return the magnitude of a 3-d vector.
Definition maths.cpp:51
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:96
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:120
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:128
std::complex< double > eval_lanczos_approx_series(std::complex< double > z)
Evaluate the Lanczos approximation series for the gamma function.
Definition maths.cpp:71
const std::complex< double > M_I
imaginary unit
const double eps_coupling
zero-tolerance for Wigner 3-j coupling coefficients
Definition maths.cpp:163
double wigner_3j(int j1, int j2, int j3, int m1, int m2, int m3)
Calculate Wigner 3-j symbol.
Definition maths.cpp:165