| Bsoft 2.0.5 Bernard's software package

FSI_Kernel.h
Go to the documentation of this file.
1
9 #include "Vector3.h"
10 #include "Complex.h"
11 #include "utilities.h"
12
13 #ifndef _FSI_Kernel_
14 class FSI_Kernel {
15 private:
16 long wd; // Width of kernel
17 long power; // Interpolation power
18 long ndiv; // Number of divisions in sampling
19 long size; // Total number of elements in kernel
20 vector<double> data; // Kernel values
21 public:
22 FSI_Kernel() { wd = power = ndiv = size = 0; }
29 FSI_Kernel(long kernel_width, long kernel_power) {
30 long i, j, ik, wd_2;
31 double s1, s2, c, arg, arg1, arg2, iwd, piwd, incr;
32
33 power = kernel_power;
34
35 if ( power < 0 ) wd = 1;
36 else wd = kernel_width;
37
38 wd_2 = (wd - 1) / 2;
39 ndiv = 512;
40 size = (ndiv + 1) * wd;
41 data.resize(size);
42
43 for ( i = 0; i < size; i++ ) data[i] = 0;
44
45 if ( power < 0 ) {
46 for ( i = 0; i < size; i++ ) data[i] = 1;
47 } else {
48 iwd = 1.0L / wd;
49 piwd = M_PI * iwd;
50 incr = 1.0L / ndiv;
51 arg = incr;
52 data[wd_2] = 1;
53 for ( i = 1, ik = wd; i < ndiv; i++ ) {
54 arg1 = M_PI * (arg + wd_2);
55 s1 = iwd * sin (arg1);
56 arg2 = arg1 * iwd;
57 for ( j = 0; j < wd; j++, ik++ ) {
58 s2 = sin (arg2);
59 c = cos (arg2);
60 data[ik] = (s1 / s2) * pow (c, power);
61 arg2 -= piwd;
62 s1 = -s1;
63 }
64 arg += incr;
65 }
66 ik += wd_2 + 1;
67 data[ik] = 1;
68 }
69 }
70 long width() { return wd; }
71 long half_width() { return (wd - 1)/2; }
72 long divisions() { return ndiv; }
73 double operator[](long i) const { return data[i]; }
74 void show() {
75 long i, j, ik;
76
77 cout << "Kernel parameters:" << endl;
78 cout << "Width: " << wd << endl;
79 cout << "Half width: " << half_width() << endl;
80 cout << "Power: " << power << endl;
81 cout << "Divisions: " << ndiv << endl;
82 cout << "Data size: " << size << endl << endl;
83
84 cout << "Kernel content:" << endl;
85 for ( i=ik=0; i<=ndiv; i++ ) {
86 cout << i;
87 for ( j=0; j<wd; j++, ik++ ) {
88 cout << tab << data[ik];
89 }
90 cout << endl;
91 }
92 cout << endl;
93 }
94 } ;
95
96 #define _FSI_Kernel_
97 #endif
98
99
FSI_Kernel::divisions
long divisions()
Definition: FSI_Kernel.h:72
FSI_Kernel::FSI_Kernel
FSI_Kernel(long kernel_width, long kernel_power)
Calculates a reciprocal space interpolation lookup table.
Definition: FSI_Kernel.h:29
utilities.h
Header file for general utilities.
FSI_Kernel::width
long width()
Definition: FSI_Kernel.h:70
Complex.h
Class for complex numbers.
FSI_Kernel
Definition: FSI_Kernel.h:14
M_PI
#define M_PI
Definition: utilities.h:59
FSI_Kernel::FSI_Kernel
FSI_Kernel()
Definition: FSI_Kernel.h:22
Vector3.h
Class for 3-value vectors.
FSI_Kernel::operator[]
double operator[](long i) const
Definition: FSI_Kernel.h:73
FSI_Kernel::show
void show()
Definition: FSI_Kernel.h:74
FSI_Kernel::half_width
long half_width()
Definition: FSI_Kernel.h:71
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21