Repository navigation
Expand file tree
/
Copy pathtest.cpp
More file actions
73 lines (63 loc) · 2.19 KB
/
Copy pathtest.cpp
File metadata and controls
73 lines (63 loc) · 2.19 KB
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
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdlib>
using namespace std;
// Function to read Cl column from a file
vector<double> read_Cl_column(const string& filename) {
vector<double> cl_values;
ifstream file(filename);
if (!file.is_open()) {
cerr << "Error opening file: " << filename << endl;
exit(1);
}
double time, cl, cd;
while (file >> time >> cl >> cd) {
cl_values.push_back(cl);
}
return cl_values;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
cerr << "Usage: " << argv[0] << " <input_json> [reference_file]" << endl;
return 1;
}
string input_file = argv[1];
string output_file = "output_files/cl_cd_pitch_plunge_k=1.2_n=101.dat";
string reference_file = (argc >= 3) ? argv[2] : "tests/cl_cd_pitch_plunge_k=1.2_n=101_ref.dat";
// Run the solver
int ret = system(("./PANKH_solver " + input_file).c_str());
if (ret != 0) {
cerr << "Solver execution failed with code " << ret << endl;
return 1;
}
// Read output and reference
vector<double> output_cl = read_Cl_column(output_file);
vector<double> reference_cl = read_Cl_column(reference_file);
if (output_cl.size() != reference_cl.size()) {
cerr << "Mismatch in number of time steps: output = "
<< output_cl.size() << ", reference = " << reference_cl.size() << endl;
return 1;
}
const double tolerance = 1e-2;
bool pass = true;
for (size_t i = 0; i < output_cl.size(); ++i) {
double diff = fabs(output_cl[i] - reference_cl[i]);
if (diff > tolerance) {
cerr << "Mismatch at timestep " << i
<< ": output = " << output_cl[i]
<< ", reference = " << reference_cl[i]
<< ", |diff| = " << diff << endl;
pass = false;
}
}
if (pass) {
cout << "Test Passed: All Cl values within the prescribed tolerance" << endl;
return 0;
} else {
cerr << "Test Failed: Some Cl values exceeded tolerance." << endl;
return 1;
}
}