OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
RelativeFFTLowPass.cpp
Go to the documentation of this file.
2#include "Physics/Physics.h"
3#include "Utilities/GSLFFT.h"
4
5#include <cmath>
6
8 : threshold_m(threshold) {}
9
10void RelativeFFTLowPassFilter::apply(std::vector<double>& LineDensity) {
11 const int M = LineDensity.size();
12 double max_four_coef = 0.0;
13
16 double* LD = new double[M];
17
18 for (int i = 0; i < M; ++i) {
19 LD[i] = LineDensity[i];
20 }
21 gsl_fft_real_transform(LD, 1, M, real, work);
22
24
25 for (int i = 0; i < M; ++i) {
26 if (std::abs(LD[i]) > max_four_coef) {
27 max_four_coef = std::abs(LD[i]);
28 }
29 }
30 max_four_coef *= threshold_m;
31
32 for (int i = 0; i < M; ++i) {
33 if (std::abs(LD[i]) < max_four_coef) {
34 LD[i] = 0.0;
35 }
36 }
37
39
40 gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
41
44
45 for (int i = 0; i < M; ++i) {
46 LineDensity[i] = LD[i];
47 }
48
49 delete[] LD;
50}
51
52void RelativeFFTLowPassFilter::calc_derivative(std::vector<double>& LineDensity, const double& h) {
53 const int M = LineDensity.size();
54 const double gff = 2. * Physics::pi / (h * (M - 1));
55 double max_four_coef = 0.0;
56
59 double* LD = new double[M];
60
61 for (int i = 0; i < M; ++i) {
62 LD[i] = LineDensity[i];
63 }
64 gsl_fft_real_transform(LD, 1, M, real, work);
65
67
68 for (int i = 1; i < M; ++i) {
69 if (std::abs(LD[i]) > max_four_coef) {
70 max_four_coef = std::abs(LD[i]);
71 }
72 }
73 max_four_coef *= threshold_m;
74
75 LD[0] = 0.0;
76 for (int i = 1; i < M; i += 2) {
77 double temp = LD[i];
78 if (std::abs(LD[i + 1]) > max_four_coef) {
79 temp = LD[i];
80 LD[i] = -LD[i + 1] * gff * (i + 1) / 2;
81 } else {
82 LD[i] = 0.0;
83 }
84 if (std::abs(temp) > max_four_coef) {
85 LD[i + 1] = temp * gff * (i + 1) / 2;
86 } else {
87 LD[i + 1] = 0.0;
88 }
89 }
90
92
93 gsl_fft_halfcomplex_inverse(LD, 1, M, hc, work);
94
97
98 for (int i = 0; i < M; ++i) {
99 LineDensity[i] = LD[i];
100 }
101
102 delete[] LD;
103}
gsl_fft_halfcomplex_wavetable * gsl_fft_halfcomplex_wavetable_alloc(size_t n)
Allocate a halfcomplex FFT wavetable of size .
Definition GSLFFT.h:181
void gsl_fft_real_wavetable_free(gsl_fft_real_wavetable *w)
Free a real FFT wavetable.
Definition GSLFFT.h:159
gsl_fft_real_workspace * gsl_fft_real_workspace_alloc(size_t n)
Allocate a real FFT workspace of size .
Definition GSLFFT.h:138
void gsl_fft_halfcomplex_inverse(double *data, size_t stride, size_t n, gsl_fft_halfcomplex_wavetable *wavetable, gsl_fft_halfcomplex_workspace *workspace)
Alias for halfcomplex inverse transform.
Definition GSLFFT.h:245
void gsl_fft_real_workspace_free(gsl_fft_real_workspace *w)
Free a real FFT workspace.
Definition GSLFFT.h:163
void gsl_fft_real_transform(double *data, size_t stride, size_t n, gsl_fft_real_wavetable *, gsl_fft_real_workspace *)
Forward real FFT with GSL-compatible packed output.
Definition GSLFFT.h:151
gsl_fft_real_wavetable * gsl_fft_real_wavetable_alloc(size_t n)
Allocate a real FFT wavetable of size .
Definition GSLFFT.h:129
void gsl_fft_halfcomplex_wavetable_free(gsl_fft_halfcomplex_wavetable *w)
Free a halfcomplex FFT wavetable.
Definition GSLFFT.h:233
Halfcomplex FFT types for inverse transforms.
Definition GSLFFT.h:167
GSL-compatible interface for FFT routines.
Definition GSLFFT.h:115
Workspace for real FFT routines.
Definition GSLFFT.h:121
RelativeFFTLowPassFilter(const double &threshold)
void calc_derivative(std::vector< double > &histogram, const double &h)
void apply(std::vector< double > &LineDensity)
constexpr double pi
The value of.
Definition Physics.h:36