1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include "fourier.hpp"
inline Real fP(unsigned p, Real q) {
return 0.5 * pow(q, p);
}
inline Real dfP(unsigned p, Real q) {
return 0.5 * p * pow(q, p - 1);
}
inline Real ddfP(unsigned p, Real q) {
return 0.5 * p * (p - 1) * pow(q, p - 2);
}
Real f(Real λ, unsigned p, unsigned s, Real q) {
return (1 - λ) * fP(p, q) + λ * fP(s, q);
}
Real df(Real λ, unsigned p, unsigned s, Real q) {
return (1 - λ) * dfP(p, q) + λ * dfP(s, q);
}
Real ddf(Real λ, unsigned p, unsigned s, Real q) {
return (1 - λ) * ddfP(p, q) + λ * ddfP(s, q);
}
FourierTransform::FourierTransform(unsigned n, Real Δω, Real Δτ, unsigned flags) : a(2 * n), â(n + 1), Δω(Δω), Δτ(Δτ) {
plan_r2c = fftw_plan_dft_r2c_1d(2 * n, a.data(), reinterpret_cast<fftw_complex*>(â.data()), flags);
plan_c2r = fftw_plan_dft_c2r_1d(2 * n, reinterpret_cast<fftw_complex*>(â.data()), a.data(), flags);
}
FourierTransform::~FourierTransform() {
fftw_destroy_plan(plan_r2c);
fftw_destroy_plan(plan_c2r);
fftw_cleanup();
}
std::vector<Complex> FourierTransform::fourier(const std::vector<Real>& c) {
a = c;
fftw_execute(plan_r2c);
std::vector<Complex> ĉ(â.size());
for (unsigned i = 0; i < â.size(); i++) {
ĉ[i] = â[i] * (Δτ * M_PI);
}
return ĉ;
}
std::vector<Real> FourierTransform::inverse(const std::vector<Complex>& ĉ) {
â = ĉ;
fftw_execute(plan_c2r);
std::vector<Real> c(a.size());
for (unsigned i = 0; i < a.size(); i++) {
c[i] = a[i] * (Δω / (2 * M_PI));
}
return c;
}
std::string fourierFile(std::string prefix, unsigned p, unsigned s, Real λ, Real τ₀, Real y, unsigned log2n, Real τₘₐₓ) {
return prefix + "_" + std::to_string(p) + "_" + std::to_string(s) + "_" + std::to_string(λ) + "_" + std::to_string(τ₀) + "_" + std::to_string(y) + "_" + std::to_string(log2n) + "_" + std::to_string(τₘₐₓ) + ".dat";
}
Real energy(const std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ, Real y, Real Δτ) {
Real e = 0;
for (unsigned i = 0; i < C.size() / 2; i++) {
e += y * R[i] * df(λ, p, s, C[i]) * M_PI * Δτ;
}
return e;
}
std::tuple<std::vector<Complex>, std::vector<Complex>> RddfCtdfCt(FourierTransform& fft, const std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ) {
std::vector<Real> RddfC(C.size());
for (unsigned i = 0; i < C.size(); i++) {
RddfC[i] = R[i] * ddf(λ, p, s, C[i]);
}
std::vector<Complex> RddfCt = fft.fourier(RddfC);
std::vector<Real> dfC(C.size());
for (unsigned i = 0; i < C.size(); i++) {
dfC[i] = df(λ, p, s, C[i]);
}
std::vector<Complex> dfCt = fft.fourier(dfC);
return {RddfCt, dfCt};
}
|