Skip to content

Commit df27943

Browse files
committed
Simplify F3OF regression test comparison scripts & fix F3OF regression test filenames for better consistency
1 parent 2007507 commit df27943

7 files changed

Lines changed: 110 additions & 92 deletions

File tree

tests/regression/f3of/compare.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
import numpy as np
1616

1717
# Import the comparison template
18-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
18+
sys.path.append(os.path.join(os.path.dirname(__file__), '../utilities'))
1919
from compare_template import run_multi_column_comparison
2020

2121
def main():
2222
if len(sys.argv) == 1 or (len(sys.argv) == 3 and sys.argv[1] == 'default'):
2323
# Use default reference and result file locations
2424
ref_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt3", "hc_ref_f3of_dt3_flap_pitch.txt")
25-
test_file = os.path.join("results", "f3of_dt3.txt")
25+
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
26+
test_file = os.path.join(build_dir, "bin", "tests", "regression", "f3of", "results", "CHRONO_F3OF_DT3_FLAP_PITCH.txt")
2627
elif len(sys.argv) == 3:
2728
ref_file = sys.argv[1]
2829
test_file = sys.argv[2]
@@ -101,7 +102,7 @@ def main():
101102
print("F3OF DT3 TEST PASSED - All comparisons within tolerance")
102103
print(f"Generated plots:")
103104
for config in test_configs:
104-
plot_name = config['test_name'].replace(' ', '_')
105+
plot_name = config['test_name'].lower().replace(' ', '_').replace('-', '_')
105106
print(f" - {config['test_name']}: {plots_dir}/{plot_name}_comparison.png")
106107
else:
107108
print("F3OF DT3 TEST FAILED - Some comparisons outside tolerance")

tests/regression/f3of/compare_dt1.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
import numpy as np
1313

1414
# Import the comparison template
15-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
15+
sys.path.append(os.path.join(os.path.dirname(__file__), '../utilities'))
1616
from compare_template import create_comparison_plot
1717

1818
def main():
1919
# F3OF DT1 specific configuration
2020
test_name = "F3OF DT1 Surge Decay"
2121
executable_patterns = ["f3of_dt1_test", "f3of_dt1_test.exe"]
2222

23-
# Data files - use absolute paths
24-
hc_data_file = "results/CHRONO_F3OF_DT1_SURGE.txt"
23+
# Find the result file
24+
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
25+
hc_data_file = os.path.join(build_dir, "bin", "tests", "regression", "f3of", "results", "CHRONO_F3OF_DT1_SURGE.txt")
2526
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt1", "hc_ref_f3of_dt1_surge.txt")
2627

2728
# Check if files exist
@@ -104,7 +105,7 @@ def rel_to_root(path):
104105
sys.exit(1)
105106
else:
106107
print(f"F3OF DT1 TEST PASSED - L2 Norm: {n1:.2e}, L-infinity Norm: {n2:.2e}")
107-
print(f"Generated plot: {plots_dir}/{test_name.replace(' ', '_')}_comparison.png")
108+
print(f"Generated plot: {plots_dir}/{test_name.lower().replace(' ', '_').replace('-', '_')}_comparison.png")
108109

109110
except Exception as e:
110111
print(f"Error during comparison: {e}")

tests/regression/f3of/compare_dt2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
import numpy as np
1313

1414
# Import the comparison template
15-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
15+
sys.path.append(os.path.join(os.path.dirname(__file__), '../utilities'))
1616
from compare_template import create_comparison_plot
1717

1818
def main():
1919
# F3OF DT2 specific configuration
2020
test_name = "F3OF DT2 Pitch Decay"
2121
executable_patterns = ["f3of_dt2_test", "f3of_dt2_test.exe"]
2222

23-
# Data files - use absolute paths
24-
hc_data_file = "results/CHRONO_F3OF_DT2_PITCH.txt"
23+
# Find the result file
24+
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
25+
hc_data_file = os.path.join(build_dir, "bin", "tests", "regression", "f3of", "results", "CHRONO_F3OF_DT2_PITCH.txt")
2526
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt2", "hc_ref_f3of_dt2_pitch.txt")
2627

2728
# Check if files exist
@@ -104,7 +105,7 @@ def rel_to_root(path):
104105
sys.exit(1)
105106
else:
106107
print(f"F3OF DT2 TEST PASSED - L2 Norm: {n1:.2e}, L-infinity Norm: {n2:.2e}")
107-
print(f"Generated plot: {plots_dir}/{test_name.replace(' ', '_')}_comparison.png")
108+
print(f"Generated plot: {plots_dir}/{test_name.lower().replace(' ', '_').replace('-', '_')}_comparison.png")
108109

109110
except Exception as e:
110111
print(f"Error during comparison: {e}")

tests/regression/f3of/compare_dt3.py

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env python3
22
"""
3-
F3OF DT3 Regression Test Comparison
3+
F3OF DT3 Regression Test Comparison Script
44
5-
This script compares the F3OF DT3 test results with reference data and generates
6-
comparison plots for flap fore pitch and flap aft pitch using the standardized template.
7-
8-
Usage:
9-
python compare_dt3.py <reference_file> <test_file>
5+
This script compares HydroChrono results for F3OF DT3 (flap pitch decay test)
6+
against reference data from the demos folder.
107
"""
118

129
import sys
@@ -15,105 +12,106 @@
1512
import numpy as np
1613

1714
# Import the comparison template
18-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
15+
sys.path.append(os.path.join(os.path.dirname(__file__), '../utilities'))
1916
from compare_template import run_multi_column_comparison
2017

2118
def main():
22-
if len(sys.argv) == 1 or (len(sys.argv) == 3 and sys.argv[1] == 'default'):
23-
# Use default reference and result file locations
24-
ref_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt3", "hc_ref_f3of_dt3_flap_pitch.txt")
25-
26-
# Look for result file in build directory
27-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', 'C:/code/HydroChrono/build')
28-
test_file = os.path.join(build_dir, "tests", "regression", "Release", "f3of", "results", "f3of_dt3.txt")
29-
30-
# Fallback to local results directory if build file not found
31-
if not os.path.exists(test_file):
32-
test_file = os.path.join("results", "f3of_dt3.txt")
33-
elif len(sys.argv) == 3:
34-
ref_file = sys.argv[1]
35-
test_file = sys.argv[2]
36-
else:
37-
print("Usage: python compare_dt3.py <reference_file> <test_file>")
38-
print(" or: python compare_dt3.py default")
39-
sys.exit(1)
40-
4119
# F3OF DT3 specific configuration
42-
test_name = "F3OF DT3 Decay Test"
20+
test_name = "F3OF DT3 Flap Pitch Decay"
4321
executable_patterns = ["f3of_dt3_test", "f3of_dt3_test.exe"]
44-
45-
# Define the columns to plot and their configurations
46-
test_configs = [
47-
{
48-
'column_index': 3, # Flap Fore Pitch
49-
'test_name': f"{test_name} - Flap Fore Pitch",
50-
'y_label': "Flap Fore Pitch (radians)",
51-
'validation_tolerance': (1e-6, 1e-6) # F3OF-specific tolerance
52-
},
53-
{
54-
'column_index': 4, # Flap Aft Pitch
55-
'test_name': f"{test_name} - Flap Aft Pitch",
56-
'y_label': "Flap Aft Pitch (radians)",
57-
'validation_tolerance': (1e-6, 1e-6) # F3OF-specific tolerance
58-
}
59-
]
60-
22+
23+
# Find the result file
24+
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
25+
hc_data_file = os.path.join(build_dir, "bin", "tests", "regression", "f3of", "results", "CHRONO_F3OF_DT3_FLAP_PITCH.txt")
26+
27+
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt3", "hc_ref_f3of_dt3_flap_pitch.txt")
28+
29+
# Check if files exist
30+
if not os.path.exists(hc_data_file):
31+
print(f"Error: Test data file not found: {hc_data_file}")
32+
sys.exit(1)
33+
34+
if not os.path.exists(ref_data_file):
35+
print(f"Error: Reference data file not found: {ref_data_file}")
36+
sys.exit(1)
37+
6138
try:
62-
# Load data for additional F3OF-specific validations
63-
ref_data = np.loadtxt(ref_file, skiprows=1)
64-
test_data = np.loadtxt(test_file, skiprows=1)
65-
39+
# Load data for validation
40+
ref_data = np.loadtxt(ref_data_file, skiprows=1)
41+
test_data = np.loadtxt(hc_data_file, skiprows=1)
42+
6643
# Show where the plots will be saved
67-
test_file_path = Path(test_file)
44+
test_file_path = Path(hc_data_file)
6845
plots_dir = test_file_path.parent / "plots"
6946
plots_dir.mkdir(parents=True, exist_ok=True)
7047
print(f"Plots will be saved to: {plots_dir}")
7148

49+
# Find the executable path
50+
executable_path = None
51+
if executable_patterns:
52+
from compare_template import find_executable
53+
executable_path = find_executable(test_file_path.parent, executable_patterns)
54+
55+
# Define the columns to plot and their configurations
56+
test_configs = [
57+
{
58+
'column_index': 3, # Flap Fore Pitch
59+
'test_name': f"{test_name} - Flap Fore Pitch",
60+
'y_label': "Flap Fore Pitch (radians)",
61+
'validation_tolerance': (1e-6, 1e-6)
62+
},
63+
{
64+
'column_index': 4, # Flap Aft Pitch
65+
'test_name': f"{test_name} - Flap Aft Pitch",
66+
'y_label': "Flap Aft Pitch (radians)",
67+
'validation_tolerance': (1e-6, 1e-6)
68+
}
69+
]
70+
7271
# Run the multi-column comparison using the template
7372
results = run_multi_column_comparison(
74-
ref_file, test_file, test_configs,
73+
ref_data_file, hc_data_file, test_configs,
7574
executable_patterns=executable_patterns
7675
)
77-
76+
7877
# Additional F3OF-specific validations (from the original script)
79-
8078
# Check base surge (column 1)
8179
diff_base_surge = np.linalg.norm(ref_data[:,1] - test_data[:,1]) / len(ref_data[:,1])
8280
if diff_base_surge > 1e-6:
83-
print(f"F3OF validation failed: Base surge difference {diff_base_surge:.2e} > 1e-6")
81+
print(f"F3OF DT3 validation failed: Base surge difference {diff_base_surge:.2e} > 1e-6")
8482
sys.exit(1)
85-
83+
8684
# Check base pitch (column 2) - more stringent tolerance
8785
diff_base_pitch = np.linalg.norm(ref_data[:,2] - test_data[:,2]) / len(ref_data[:,2])
8886
if diff_base_pitch > 1e-10:
89-
print(f"F3OF validation failed: Base pitch difference {diff_base_pitch:.2e} > 1e-10")
87+
print(f"F3OF DT3 validation failed: Base pitch difference {diff_base_pitch:.2e} > 1e-10")
9088
sys.exit(1)
91-
89+
9290
# Check flap fore pitch (column 3)
9391
diff_flap_fore_pitch = np.linalg.norm(ref_data[:,3] - test_data[:,3]) / len(ref_data[:,3])
9492
if diff_flap_fore_pitch > 1e-6:
95-
print(f"F3OF validation failed: Flap fore pitch difference {diff_flap_fore_pitch:.2e} > 1e-6")
93+
print(f"F3OF DT3 validation failed: Flap fore pitch difference {diff_flap_fore_pitch:.2e} > 1e-6")
9694
sys.exit(1)
97-
95+
9896
# Check flap aft pitch (column 4)
9997
diff_flap_aft_pitch = np.linalg.norm(ref_data[:,4] - test_data[:,4]) / len(ref_data[:,4])
10098
if diff_flap_aft_pitch > 1e-6:
101-
print(f"F3OF validation failed: Flap aft pitch difference {diff_flap_aft_pitch:.2e} > 1e-6")
99+
print(f"F3OF DT3 validation failed: Flap aft pitch difference {diff_flap_aft_pitch:.2e} > 1e-6")
102100
sys.exit(1)
103-
101+
104102
# Check if all template comparisons passed
105103
all_passed = all(result[2] for result in results)
106-
104+
107105
if all_passed:
108106
print("F3OF DT3 TEST PASSED - All comparisons within tolerance")
109107
print(f"Generated plots:")
110108
for config in test_configs:
111-
plot_name = config['test_name'].replace(' ', '_')
112-
print(f" - {config['test_name']}: {plots_dir}/{plot_name}_comparison.png")
109+
plot_name = config['test_name'].lower().replace(' ', '_').replace('-', '_')
110+
print(f" - {plots_dir}/{plot_name}_comparison.png")
113111
else:
114112
print("F3OF DT3 TEST FAILED - Some comparisons outside tolerance")
115113
sys.exit(1)
116-
114+
117115
except Exception as e:
118116
print(f"Error during comparison: {e}")
119117
sys.exit(1)

tests/regression/f3of/f3of_dt1_test.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ int main(int argc, char* argv[]) {
4444
std::vector<double> base_pitch;
4545
std::vector<double> fore_pitch;
4646
std::vector<double> aft_pitch;
47+
48+
// Output file names
49+
std::string filename = "CHRONO_F3OF_DT1_SURGE.txt";
50+
std::string filename_duration = "CHRONO_F3OF_DT1_SURGE_DURATION.txt";
4751

4852
// set up body from a mesh
4953
std::cout << "Attempting to open mesh file: " << body1_meshfame << std::endl;
@@ -171,13 +175,17 @@ int main(int argc, char* argv[]) {
171175

172176
if (profilingOn) {
173177
std::ofstream profilingFile;
174-
profilingFile.open("./results/F3OF_DT1_duration.txt");
178+
profilingFile.open("./results/" + filename_duration);
175179
if (!profilingFile.is_open()) {
176180
if (!std::filesystem::exists("./results")) {
177181
std::cout << "Path " << std::filesystem::absolute("./results") << " does not exist, creating it now..."
178182
<< std::endl;
179183
std::filesystem::create_directories("./results");
180-
profilingFile.open("./results/F3OF_DT1_duration.txt");
184+
profilingFile.open("./results/" + filename_duration);
185+
if (!profilingFile.is_open()) {
186+
std::cout << "Still cannot open file, ending program" << std::endl;
187+
return 0;
188+
}
181189
}
182190
}
183191
profilingFile << duration << std::endl;
@@ -186,13 +194,17 @@ int main(int argc, char* argv[]) {
186194

187195
if (saveDataOn) {
188196
std::ofstream outputFile;
189-
outputFile.open("./results/CHRONO_F3OF_DT1_SURGE.txt");
197+
outputFile.open("./results/" + filename);
190198
if (!outputFile.is_open()) {
191199
if (!std::filesystem::exists("./results")) {
192200
std::cout << "Path " << std::filesystem::absolute("./results") << " does not exist, creating it now..."
193201
<< std::endl;
194202
std::filesystem::create_directories("./results");
195-
outputFile.open("./results/CHRONO_F3OF_DT1_SURGE.txt");
203+
outputFile.open("./results/" + filename);
204+
if (!outputFile.is_open()) {
205+
std::cout << "Still cannot open file, ending program" << std::endl;
206+
return 0;
207+
}
196208
}
197209
}
198210
outputFile << "Time (s) Base Surge (m)Base Pitch (radians)Flap Fore Pitch (radians)Flap Aft Pitch (radians)" << std::endl;

tests/regression/f3of/f3of_dt2_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ int main(int argc, char* argv[]) {
4444
std::vector<double> base_pitch;
4545
std::vector<double> fore_pitch;
4646
std::vector<double> aft_pitch;
47+
48+
// Output file names
49+
std::string filename = "CHRONO_F3OF_DT2_PITCH.txt";
50+
std::string filename_duration = "CHRONO_F3OF_DT2_PITCH_DURATION.txt";
4751

4852
// set up body from a mesh
4953
std::cout << "Attempting to open mesh file: " << body1_meshfame << std::endl;
@@ -177,13 +181,13 @@ int main(int argc, char* argv[]) {
177181

178182
if (profilingOn) {
179183
std::ofstream profilingFile;
180-
profilingFile.open("./results/F3OF_DT2_duration.txt");
184+
profilingFile.open("./results/" + filename_duration);
181185
if (!profilingFile.is_open()) {
182186
if (!std::filesystem::exists("./results")) {
183187
std::cout << "Path " << std::filesystem::absolute("./results") << " does not exist, creating it now..."
184188
<< std::endl;
185189
std::filesystem::create_directories("./results");
186-
profilingFile.open("./results/F3OF_DT2_duration.txt");
190+
profilingFile.open("./results/" + filename_duration);
187191
}
188192
}
189193
profilingFile << duration << std::endl;
@@ -192,13 +196,13 @@ int main(int argc, char* argv[]) {
192196

193197
if (saveDataOn) {
194198
std::ofstream outputFile;
195-
outputFile.open("./results/CHRONO_F3OF_DT2_PITCH.txt");
199+
outputFile.open("./results/" + filename);
196200
if (!outputFile.is_open()) {
197201
if (!std::filesystem::exists("./results")) {
198202
std::cout << "Path " << std::filesystem::absolute("./results") << " does not exist, creating it now..."
199203
<< std::endl;
200204
std::filesystem::create_directories("./results");
201-
outputFile.open("./results/CHRONO_F3OF_DT2_PITCH.txt");
205+
outputFile.open("./results/" + filename);
202206
}
203207
}
204208
outputFile << "Time (s) Base Surge (m)Base Pitch (radians)Flap Fore Pitch (radians)Flap Aft Pitch (radians)" << std::endl;

0 commit comments

Comments
 (0)