Peano
Loading...
Searching...
No Matches
harmonics.h
Go to the documentation of this file.
1#ifndef APPARENT_HORIZON_FINDER_HARMONICS_H_
2#define APPARENT_HORIZON_FINDER_HARMONICS_H_
3
4#include <cstddef>
5#include <utility>
6#include <vector>
7
8// Real spherical-harmonic basis and spectral collocation grid for the apparent
9// horizon finder. Rdepends Depends on the C++ standard library only (no BLAS).
10//
11// The horizon shape h(rho, sigma) is expanded in real spherical harmonics as
12//
13// h(rho, sigma) = sum_{l=0}^{lmax} sum_{m=-l}^{l} a_lm Y_lm(rho, sigma).
14//
15// Note: because the notes use sigma as an *elevation* angle, the harmonics are
16// evaluated at colatitude theta = pi/2 - sigma and azimuth phi = rho, so that
17// cos(theta) = sin(sigma) = mu.
18// The collocation grid uses Gauss-Legendre nodes in
19// mu = sin(sigma) and a uniform grid in rho; with nSigma >= lmax+1 and
20// nRho >= 2 lmax+1 so that the discrete transform is exact for the band l, m <= lmax,
21// and #coefficients == #equations.
22
23namespace exahype2::ccz4::ahf {
24
28std::vector<std::pair<int, int>> EnumerateModes(int lmax);
29
34std::pair<std::vector<double>, std::vector<double>> GaussLegendre(int n);
35
39struct ModeValues {
40 double Y = 0.0;
41 double Yrho = 0.0;
42 double Ysigma = 0.0;
43 double Yrhorho = 0.0;
44 double Yrhosigma = 0.0;
45 double Ysigmasigma = 0.0;
46};
47
60ModeValues EvalMode(int l, int m, double rho, double sigma);
61
91double EvalModeValue(int l, int m, double rho, double sigma);
92
101 int lmax = 0;
102 int nSigma = 0;
103 int nRho = 0;
104 std::size_t nModes = 0;
105 std::size_t nPoints = 0;
106 std::vector<std::pair<int, int>> modes;
107
108 std::vector<double> rho; // (nPoints,)
109 std::vector<double> sigma; // (nPoints,)
110 std::vector<double> weight; // (nPoints,) quadrature weight, integrates f dmu drho
111
112 std::vector<double> Y; // (nPoints x nModes) design matrices
113 std::vector<double> Yrho;
114 std::vector<double> Ysigma;
115 std::vector<double> Yrhorho;
116 std::vector<double> Yrhosigma;
117 std::vector<double> Ysigmasigma;
118
119 double designMatrixValue(const std::vector<double>& matrix,
120 std::size_t point, std::size_t mode) const {
121 return matrix[point * nModes + mode];
122 }
123};
124
130SpectralBasis BuildSpectralBasis(int lmax, int nSigma = -1, int nRho = -1);
131
136 std::vector<double> h;
137 std::vector<double> hRho;
138 std::vector<double> hSigma;
139 std::vector<double> hRhoRho;
140 std::vector<double> hRhoSigma;
141 std::vector<double> hSigmaSigma;
142};
143
149 const std::vector<double>& coefficients);
150
156std::vector<double> Project(const SpectralBasis& basis,
157 const std::vector<double>& field);
158
163std::vector<double> SphereCoefficients(const SpectralBasis& basis, double radius);
164
165} // namespace exahype2::ccz4::ahf
166
167#endif // APPARENT_HORIZON_FINDER_HARMONICS_H_
SpectralBasis BuildSpectralBasis(int lmax, int nSigma=-1, int nRho=-1)
Construct a SpectralBasis for the given lmax.
std::vector< double > SphereCoefficients(const SpectralBasis &basis, double radius)
Coefficient vector for a coordinate sphere h = radius (only a_00 != 0, since Y_00 = 1/sqrt(4 pi) so a...
std::vector< std::pair< int, int > > EnumerateModes(int lmax)
Ordered list of (l, m) modes, l = 0..lmax, m = -l..l.
SynthesizedField Synthesize(const SpectralBasis &basis, const std::vector< double > &coefficients)
Synthesis (coefficients -> point values): h = Y a, hRho = Yrho a, etc.
std::pair< std::vector< double >, std::vector< double > > GaussLegendre(int n)
Gauss-Legendre nodes and weights on [-1, 1] (integrates d mu).
ModeValues EvalMode(int l, int m, double rho, double sigma)
Evaluate the real Y_lm and its rho/sigma derivatives at (rho, sigma).
std::vector< double > Project(const SpectralBasis &basis, const std::vector< double > &field)
Analysis (point values -> coefficients): a = Y^T (weight .
double EvalModeValue(int l, int m, double rho, double sigma)
The real Y_lm at (rho, sigma), without any derivatives.
-source
Y_lm and its first/second rho- and sigma-derivatives at one (rho, sigma).
Definition harmonics.h:39
Spectral basis plus collocation grid and precomputed design matrices.
Definition harmonics.h:100
std::vector< double > Ysigma
Definition harmonics.h:114
std::vector< double > weight
Definition harmonics.h:110
std::vector< double > Yrhorho
Definition harmonics.h:115
std::vector< double > Yrho
Definition harmonics.h:113
std::vector< double > Yrhosigma
Definition harmonics.h:116
double designMatrixValue(const std::vector< double > &matrix, std::size_t point, std::size_t mode) const
Definition harmonics.h:119
std::vector< std::pair< int, int > > modes
Definition harmonics.h:106
std::vector< double > rho
Definition harmonics.h:108
std::vector< double > sigma
Definition harmonics.h:109
std::vector< double > Ysigmasigma
Definition harmonics.h:117
h and its angular derivatives at every collocation point (each (nPoints,)).
Definition harmonics.h:135
std::vector< double > hRhoSigma
Definition harmonics.h:140
std::vector< double > hSigmaSigma
Definition harmonics.h:141