-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.h
117 lines (98 loc) · 3.67 KB
/
tests.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "gridInterp.h"
void test2D(){
std::cout << "2D Interpolation using evenly spaced data" << std::endl;
GRID_INTERP::interp<2> peaks;
peaks.getDataFromFile("Rgridinterp/peak_data_cnst.tmp");
std::vector<double> vv;
std::vector<std::vector<double> > xx;
for(double y = -29.42; y < 30.54; y = y+0.5047){
for(double x = -29.52; x < 30.64; x = x+0.4856){
xx.push_back(std::vector<double> {x,y});
vv.push_back(peaks.interpolate(x, y));
}
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_cnst_peak_l.tmp", xx, vv);
peaks.setMethod(GRID_INTERP::METHOD::NEAREST);
vv.clear();
xx.clear();
for(double y = -29.4; y < 30.3; y = y+0.5047){
for(double x = -29.5; x < 30.5; x = x+0.4856){
xx.push_back(std::vector<double> {x,y});
vv.push_back(peaks.interpolate(x, y));
}
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_cnst_peak_n.tmp", xx, vv);
std::cout << "2D Interpolation using variably spaced data" << std::endl;
double fromX = -21.0;
double toX = 21.0;
double dx = 0.2;
double fromY = -10.0;
double toY = 9.5;
double dy = 0.2;
// Read the data for the POINT mode and LINEAR method
GRID_INTERP::interp<2> testD;
testD.getDataFromFile("Rgridinterp/test2D_data_var.tmp");
vv.clear();
xx.clear();
for(double y = fromY; y < toY; y = y+dy){
for(double x = fromX; x < toX; x = x+dx){
xx.push_back(std::vector<double> {x,y});
vv.push_back(testD.interpolate(x, y));
}
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_var_test2D_l.tmp", xx, vv);
testD.setMethod(GRID_INTERP::METHOD::NEAREST);
vv.clear();
xx.clear();
for(double y = fromY; y < toY; y = y+dy){
for(double x = fromX; x < toX; x = x+dx){
xx.push_back(std::vector<double> {x,y});
vv.push_back(testD.interpolate(x, y));
}
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_var_test2D_n.tmp", xx, vv);
}
void test1D(){
std::cout << "1D Interpolation using evenly spaced data" << std::endl;
// Read the data for LINEAR method
GRID_INTERP::interp<1> oneD;
oneD.getDataFromFile("Rgridinterp/test1_cnst_data.tmp");
std::vector<double> vv;
std::vector<std::vector<double> > xx;
for(double x = 39.0; x < 66.5; x = x+0.1){
xx.push_back(std::vector<double> {x});
vv.push_back(oneD.interpolate(x));
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_cnst_test1_l.tmp", xx, vv);
// Set the method to NEAREST and repeat the interpolation
oneD.setMethod(GRID_INTERP::METHOD::NEAREST);
vv.clear();
xx.clear();
for(double x = 39.0; x < 66.5; x = x+0.1){
xx.push_back(std::vector<double> {x});
vv.push_back(oneD.interpolate(x));
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_cnst_test1_n.tmp", xx, vv);
std::cout << "1D Interpolation using variably spaced data" << std::endl;
oneD.reset();
oneD.getDataFromFile("Rgridinterp/test1_var_data.tmp");
vv.clear();
xx.clear();
for(double x = 38.0; x < 82.2; x = x+0.1){
xx.push_back(std::vector<double> {x});
vv.push_back(oneD.interpolate(x));
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_var_test1_l.tmp", xx, vv);
oneD.setMethod(GRID_INTERP::METHOD::NEAREST);
vv.clear();
xx.clear();
for(double x = 38.0; x < 82.2; x = x+0.1){
xx.push_back(std::vector<double> {x});
vv.push_back(oneD.interpolate(x));
}
GRID_INTERP::writeCoordsValues("Rgridinterp/res_var_test1_n.tmp", xx, vv);
}