OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
FixedFFTLowPass.cpp
Go to the documentation of this file.
2#include "Physics/Physics.h"
3#include "gsl/gsl_fft_real.h"
4#include "gsl/gsl_fft_halfcomplex.h"
5
6
8 number_frequencies_m(N)
9{ }
10
11void FixedFFTLowPassFilter::apply(std::vector<double> &LineDensity) {
12 const int M = LineDensity.size();
13 gsl_fft_halfcomplex_wavetable *hc;
14 gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
15 gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
16 double *LD = new double[M];
17 for (int i = 0; i < M; ++ i) {
18 LD[i] = LineDensity[i];
19 }
20 gsl_fft_real_transform(LD, 1, M, real, work);
21
22 for (int i = 2 * number_frequencies_m + 1; i < M; ++ i) {
23 LD[i] = 0.0;
24 }
25
26 gsl_fft_real_wavetable_free(real);
27 hc = gsl_fft_halfcomplex_wavetable_alloc(M);
28
29 gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
30
31 gsl_fft_halfcomplex_wavetable_free(hc);
32 gsl_fft_real_workspace_free(work);
33
34 for (int i = 0; i < M; ++ i) {
35 LineDensity[i] = LD[i];
36 }
37 delete[] LD;
38}
39
40void FixedFFTLowPassFilter::calc_derivative(std::vector<double> &LineDensity, const double &h) {
41 const int M = LineDensity.size();
42 const double gff = 2. * Physics::pi / (h * (M - 1));
43
44 gsl_fft_halfcomplex_wavetable *hc;
45 gsl_fft_real_wavetable *real = gsl_fft_real_wavetable_alloc(M);
46 gsl_fft_real_workspace *work = gsl_fft_real_workspace_alloc(M);
47 double *LD = new double[M];
48
49 for (int i = 0; i < M; ++ i) {
50 LD[i] = LineDensity[i];
51 }
52 gsl_fft_real_transform(LD, 1, M, real, work);
53
54 gsl_fft_real_wavetable_free(real);
55
56 LD[0] = 0.0;
57 for (int i = 1; i < 2 * number_frequencies_m + 1; i += 2) {
58 double temp = LD[i];
59 LD[i] = -LD[i+1] * gff * (i + 1) / 2;
60 LD[i+1] = temp * gff * (i + 1) / 2;
61 }
62
63 for (int i = 2 * number_frequencies_m + 1; i < M; ++ i) {
64 LD[i] = 0.0;
65 }
66
67 hc = gsl_fft_halfcomplex_wavetable_alloc(M);
68
69 gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
70
71 gsl_fft_halfcomplex_wavetable_free(hc);
72 gsl_fft_real_workspace_free(work);
73
74 for (int i = 0; i < M; ++ i) {
75 LineDensity[i] = LD[i];
76 }
77
78 delete[] LD;
79}
80
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
constexpr double pi
The value of.
Definition: Physics.h:30
void apply(std::vector< double > &LineDensity)
FixedFFTLowPassFilter(const int &N)
void calc_derivative(std::vector< double > &histogram, const double &h)