|
| 1 | +#include <iostream> |
| 2 | +#include <fstream> |
| 3 | +#include <vector> |
| 4 | +#include <cmath> |
| 5 | +#include <string> |
| 6 | + |
| 7 | +using namespace std; |
| 8 | + |
| 9 | +// Function to read the second column (Cl) from the given file |
| 10 | +vector<double> read_Cl_column(const string& filename) { |
| 11 | + vector<double> cl_values; |
| 12 | + ifstream file(filename); |
| 13 | + if (!file.is_open()) { |
| 14 | + cerr << "Error opening file: " << filename << endl; |
| 15 | + exit(1); |
| 16 | + } |
| 17 | + |
| 18 | + double time, cl, cd; |
| 19 | + while (file >> time >> cl >> cd) { |
| 20 | + cl_values.push_back(cl); |
| 21 | + } |
| 22 | + return cl_values; |
| 23 | +} |
| 24 | + |
| 25 | +int main() { |
| 26 | + const string input_file = "input.json"; |
| 27 | + const string output_file = "output_files/cl_cd_pitch_plunge_k=1.2_n=101.dat"; |
| 28 | + const string reference_file = "tests/cl_cd_pitch_plunge_k=1.2_n=101_ref.dat"; |
| 29 | + const double tolerance = 1e-2; |
| 30 | + |
| 31 | + // Run the main solver |
| 32 | + int return_code = system(("./PANKH_solver " + input_file).c_str()); |
| 33 | + if (return_code != 0) { |
| 34 | + cerr << "Solver execution failed with code " << return_code << endl; |
| 35 | + return 1; |
| 36 | + } |
| 37 | + |
| 38 | + // Read solver output and reference data |
| 39 | + vector<double> output_cl = read_Cl_column(output_file); |
| 40 | + vector<double> reference_cl = read_Cl_column(reference_file); |
| 41 | + |
| 42 | + // Check for matching size |
| 43 | + if (output_cl.size() != reference_cl.size()) { |
| 44 | + cerr << "Mismatch in number of time steps: " |
| 45 | + << "output has " << output_cl.size() |
| 46 | + << ", reference has " << reference_cl.size() << endl; |
| 47 | + return 1; |
| 48 | + } |
| 49 | + |
| 50 | + // Compare values |
| 51 | + bool pass = true; |
| 52 | + for (size_t i = 0; i < output_cl.size(); ++i) { |
| 53 | + double diff = fabs(output_cl[i] - reference_cl[i]); |
| 54 | + if (diff > tolerance) { |
| 55 | + cerr << "Mismatch at timestep " << i << ": " |
| 56 | + << "output = " << output_cl[i] |
| 57 | + << ", reference = " << reference_cl[i] |
| 58 | + << ", |diff| = " << diff << endl; |
| 59 | + pass = false; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + if (pass) { |
| 64 | + cout << "✅ Test Passed: All Cl values within tolerance of " << tolerance << endl; |
| 65 | + return 0; |
| 66 | + } else { |
| 67 | + cerr << "❌ Test Failed: Some Cl values exceeded tolerance." << endl; |
| 68 | + return 1; |
| 69 | + } |
| 70 | +} |
0 commit comments