OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Stencil.cpp
Go to the documentation of this file.
1 #include "Filters/Stencil.h"
2 
3 
4 void StencilFilter::apply(std::vector<double> &LineDensity) {
5  int size = LineDensity.size();
6  std::vector<double> temp1(size + 8, 0.0);
7  std::vector<double> temp2(5, 0.0);
8 
9  for(int i = 0; i < size; ++i)
10  temp1[i+4] = LineDensity[i];
11 
12  for(int i = 0; i < 4; ++ i) {
13  temp1[3-i] = temp1[5+i];
14  temp1[size+5+i] = temp1[size+3-i];
15  }
16 
17  for(int i = 0; i < size; ++i) {
18  temp2[i%5] = (7. * (temp1[i] + temp1[i+8]) + 24. * (temp1[i+2] + temp1[i+6]) + 34.*temp1[i+4]) / 96.;
19  temp1[i] = temp2[(i+1)%5];
20  }
21 
22  temp1[2] = temp1[6];
23  temp1[3] = temp1[5];
24  temp1[size+5] = temp1[size+1];
25  temp1[size+4] = temp1[size+2];
26 
27  for(int i = 0; i < size; ++i)
28  LineDensity[i] = (7. * (temp1[i+2] + temp1[i+6]) + 24. * (temp1[i+3] + temp1[i+5]) + 34.*temp1[i+4]) / 96.;
29 }
30 
31 void StencilFilter::calc_derivative(std::vector<double> &LineDensity, const double &h) {
32  std::vector<double> temp(LineDensity.begin(), LineDensity.end());
33  const double N = LineDensity.size();
34  LineDensity[0] = (-25.*temp[0] + 48.*temp[1] - 36.*temp[2] + 16.*temp[3] + temp[4]) / (12.*h);
35  LineDensity[1] = (-3.*temp[0] - 10.*temp[1] + 18.*temp[2] - 6.*temp[3] + temp[4]) / (12.*h);
36  for(int i = 2; i < N - 2; ++ i) {
37  LineDensity[i] = (temp[i-2] - 8.*temp[i-1] + 8.*temp[i+1] - temp[i+2]) / (12.*h);
38  }
39  LineDensity[N-2] = (-temp[N-5] + 6.*temp[N-4] - 18.*temp[N-3] + 10.*temp[N-2] + 3.*temp[N-1]) / (12.*h);
40  LineDensity[N-1] = (3.*temp[N-5] - 16.*temp[N-4] + 36.*temp[N-3] - 48.*temp[N-2] + 25.*temp[N-1]) / (12.*h);
42 }
void apply(std::vector< double > &histogram)
Definition: Stencil.cpp:4
void calc_derivative(std::vector< double > &histogram, const double &h)
Definition: Stencil.cpp:31