Skip to content

Commit d6e976f

Browse files
committed
fix data paths in tests for new structure
to run tests from build directory: > ctest -C Release -L regression
1 parent d870f37 commit d6e976f

11 files changed

Lines changed: 140 additions & 83 deletions

src/helper.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ static path DATADIR{};
3030
int hydroc::SetInitialEnvironment(int argc, char* argv[]) noexcept {
3131
const char* env_p = std::getenv("HYDROCHRONO_DATA_DIR");
3232

33-
if (env_p == nullptr) {
34-
if (argc < 2) {
35-
hydroc::cli::LogWarning("Usage: .exe [<datadir>] or set HYDROCHRONO_DATA_DIR environment variable");
36-
37-
DATADIR = absolute(path(HC_DATA_DIR));
38-
hydroc::cli::LogInfo(std::string("Set default demos path to '") + getDataDir() + "'");
39-
} else {
33+
if (env_p) {
34+
// Highest priority: explicit environment override
35+
DATADIR = absolute(path(env_p));
36+
hydroc::cli::LogInfo(std::string("HYDROCHRONO_DATA_DIR set, using '") + getDataDir() + "'");
37+
} else {
38+
// If first positional argument looks like a path (does not start with '-'),
39+
// treat it as the data directory. Otherwise, fall back to the compiled-in
40+
// default HC_DATA_DIR (build/install data tree).
41+
if (argc >= 2 && argv[1] && argv[1][0] != '-') {
4042
DATADIR = absolute(path(argv[1]));
43+
hydroc::cli::LogInfo(std::string("Using data directory from CLI: '") + getDataDir() + "'");
44+
} else {
45+
DATADIR = absolute(path(HC_DATA_DIR));
46+
hydroc::cli::LogInfo(std::string("Using default data directory HC_DATA_DIR='") + getDataDir() + "'");
4147
}
42-
} else {
43-
DATADIR = absolute(path(env_p));
4448
}
4549

4650
// Set Chrono data directory

tests/regression/f3of/compare_f3of_dt1.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ def main():
2121
executable_patterns = ["f3of_dt1_test", "f3of_dt1_test.exe"]
2222

2323
# Find the result file
24+
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
2425
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")
26-
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt1", "hc_ref_f3of_dt1_surge.txt")
26+
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt1.txt")
27+
# Reference data lives under: <project_root>/data/reference_data/f3of/
28+
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
29+
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt1_surge.txt")
2730

2831
# Check if files exist
2932
if not os.path.exists(hc_data_file):

tests/regression/f3of/compare_f3of_dt2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ def main():
2121
executable_patterns = ["f3of_dt2_test", "f3of_dt2_test.exe"]
2222

2323
# Find the result file
24+
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
2425
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")
26-
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt2", "hc_ref_f3of_dt2_pitch.txt")
26+
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt2.txt")
27+
# Reference data lives under: <project_root>/data/reference_data/f3of/
28+
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
29+
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt2_pitch.txt")
2730

2831
# Check if files exist
2932
if not os.path.exists(hc_data_file):

tests/regression/f3of/compare_f3of_dt3.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ def main():
2121
executable_patterns = ["f3of_dt3_test", "f3of_dt3_test.exe"]
2222

2323
# Find the result file
24+
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
2425
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+
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt3.txt")
2627

27-
ref_data_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt3", "hc_ref_f3of_dt3_flap_pitch.txt")
28+
# Reference data lives under: <project_root>/data/reference_data/f3of/
29+
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
30+
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt3_flap_pitch.txt")
2831

2932
# Check if files exist
3033
if not os.path.exists(hc_data_file):

tests/regression/oswec/test_oswec_decay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ int main(int argc, char* argv[]) {
7171
visualizationOn = false;
7272
}
7373

74-
// Get model file names - use regression test data directory
75-
std::filesystem::path DATADIR = std::filesystem::current_path();
74+
// Get model file names - use HydroChrono data directory
75+
std::filesystem::path DATADIR(hydroc::getDataDir());
7676

77-
auto body1_meshfame = (DATADIR / "demos" / "geometry" / "flap.obj").lexically_normal().generic_string();
78-
auto body2_meshfame = (DATADIR / "demos" / "geometry" / "base.obj").lexically_normal().generic_string();
79-
auto h5fname = (DATADIR / "demos" / "hydroData" / "oswec.h5").lexically_normal().generic_string();
77+
auto body1_meshfame = (DATADIR / "demos" / "oswec" / "geometry" / "flap.obj").lexically_normal().generic_string();
78+
auto body2_meshfame = (DATADIR / "demos" / "oswec" / "geometry" / "base.obj").lexically_normal().generic_string();
79+
auto h5fname = (DATADIR / "demos" / "oswec" / "hydroData" / "oswec.h5").lexically_normal().generic_string();
8080

8181
// system/solver settings
8282
ChSystemNSC system;

tests/regression/oswec/test_oswec_reg_waves.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ int main(int argc, char* argv[]) {
7676
visualizationOn = false;
7777
}
7878

79-
// Get model file names - use regression test data directory
80-
std::filesystem::path DATADIR = std::filesystem::current_path();
79+
// Get model file names - use HydroChrono data directory
80+
std::filesystem::path DATADIR(hydroc::getDataDir());
8181

82-
auto body1_meshfname = (DATADIR / "demos" / "geometry" / "flap.obj").lexically_normal().generic_string();
83-
auto body2_meshfname = (DATADIR / "demos" / "geometry" / "base.obj").lexically_normal().generic_string();
84-
auto h5fname = (DATADIR / "demos" / "hydroData" / "oswec.h5").lexically_normal().generic_string();
82+
auto body1_meshfname = (DATADIR / "demos" / "oswec" / "geometry" / "flap.obj").lexically_normal().generic_string();
83+
auto body2_meshfname = (DATADIR / "demos" / "oswec" / "geometry" / "base.obj").lexically_normal().generic_string();
84+
auto h5fname = (DATADIR / "demos" / "oswec" / "hydroData" / "oswec.h5").lexically_normal().generic_string();
8585

8686
// system/solver settings
8787
ChSystemNSC system;

tests/regression/rm3/test_rm3_decay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ int main(int argc, char* argv[]) {
2929
visualizationOn = false;
3030
}
3131

32-
// Get model file names - use regression test data directory
33-
std::filesystem::path DATADIR = std::filesystem::current_path();
32+
// Get model file names - use HydroChrono data directory
33+
std::filesystem::path DATADIR(hydroc::getDataDir());
3434

35-
auto body1_meshfame = (DATADIR / "demos" / "geometry" / "float_cog.obj").lexically_normal().generic_string();
36-
auto body2_meshfame = (DATADIR / "demos" / "geometry" / "plate_cog.obj").lexically_normal().generic_string();
37-
auto h5fname = (DATADIR / "demos" / "hydroData" / "rm3.h5").lexically_normal().generic_string();
35+
auto body1_meshfame = (DATADIR / "demos" / "rm3" / "geometry" / "float_cog.obj").lexically_normal().generic_string();
36+
auto body2_meshfame = (DATADIR / "demos" / "rm3" / "geometry" / "plate_cog.obj").lexically_normal().generic_string();
37+
auto h5fname = (DATADIR / "demos" / "rm3" / "hydroData" / "rm3.h5").lexically_normal().generic_string();
3838

3939
// system/solver settings
4040
ChSystemNSC system;

tests/regression/rm3/test_rm3_reg_waves.cpp

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,30 @@ int main(int argc, char* argv[]) {
3636
}
3737
}
3838

39-
// Get model file names - use regression test data directory
40-
std::filesystem::path DATADIR = std::filesystem::current_path();
39+
// Get model file names - use HydroChrono data directory
40+
std::filesystem::path DATADIR(hydroc::getDataDir());
4141

42-
auto body1_meshfame = (DATADIR / "demos" / "geometry" / "float_cog.obj").lexically_normal().generic_string();
43-
auto body2_meshfame = (DATADIR / "demos" / "geometry" / "plate_cog.obj").lexically_normal().generic_string();
44-
auto h5fname = (DATADIR / "demos" / "hydroData" / "rm3.h5").lexically_normal().generic_string();
42+
std::filesystem::path body1_path = DATADIR / "demos" / "rm3" / "geometry" / "float_cog.obj";
43+
std::filesystem::path body2_path = DATADIR / "demos" / "rm3" / "geometry" / "plate_cog.obj";
44+
std::filesystem::path h5_path = DATADIR / "demos" / "rm3" / "hydroData" / "rm3.h5";
45+
46+
// Early sanity check so we fail with a clear message if assets are missing
47+
if (!std::filesystem::exists(body1_path)) {
48+
std::cerr << "ERROR: RM3 regular-waves test: float_cog mesh not found at " << body1_path << std::endl;
49+
return 1;
50+
}
51+
if (!std::filesystem::exists(body2_path)) {
52+
std::cerr << "ERROR: RM3 regular-waves test: plate_cog mesh not found at " << body2_path << std::endl;
53+
return 1;
54+
}
55+
if (!std::filesystem::exists(h5_path)) {
56+
std::cerr << "ERROR: RM3 regular-waves test: rm3.h5 not found at " << h5_path << std::endl;
57+
return 1;
58+
}
59+
60+
auto body1_meshfame = body1_path.lexically_normal().generic_string();
61+
auto body2_meshfame = body2_path.lexically_normal().generic_string();
62+
auto h5fname = h5_path.lexically_normal().generic_string();
4563

4664
std::cout << "Looking for mesh files in:" << std::endl;
4765
std::cout << " body1: " << body1_meshfame << std::endl;
@@ -60,11 +78,6 @@ int main(int argc, char* argv[]) {
6078
ChRealtimeStepTimer realtime_timer;
6179
double simulationDuration = 40.0;
6280

63-
// Create user interface
64-
std::shared_ptr<hydroc::gui::UI> pui = hydroc::gui::CreateUI(visualizationOn);
65-
66-
hydroc::gui::UI& ui = *pui.get();
67-
6881
// some io/viz options
6982
bool profilingOn = true;
7083
bool saveDataOn = true;
@@ -82,6 +95,7 @@ int main(int argc, char* argv[]) {
8295
true, // create visualization asset
8396
false // collisions
8497
);
98+
std::cout << "Created float_body1 from mesh." << std::endl;
8599

86100
// define the float's initial conditions
87101
system.Add(float_body1);
@@ -104,6 +118,7 @@ int main(int argc, char* argv[]) {
104118
true, // create visualization asset
105119
false // collisions
106120
);
121+
std::cout << "Created plate_body2 from mesh." << std::endl;
107122

108123
// Create a visualization material
109124
auto blue = chrono_types::make_shared<ChVisualMaterial>();
@@ -128,6 +143,7 @@ int main(int argc, char* argv[]) {
128143
prismatic_pto->Initialize(float_body1, plate_body2, false, ChVector3d(0, 0, -0.72), ChVector3d(0, 0, -21.29));
129144
prismatic_pto->SetDampingCoefficient(0.0);
130145
system.AddLink(prismatic_pto);
146+
std::cout << "Added prismatic and PTO links." << std::endl;
131147

132148
// attach hydrodynamic forces to body
133149
std::vector<std::shared_ptr<ChBody>> bodies;
@@ -138,30 +154,41 @@ int main(int argc, char* argv[]) {
138154
auto my_hydro_inputs = std::make_shared<RegularWave>(static_cast<unsigned int>(bodies.size()));
139155
my_hydro_inputs->regular_wave_amplitude_ = 1.0;
140156
my_hydro_inputs->regular_wave_omega_ = 2.10;
157+
std::cout << "Configured RegularWave inputs." << std::endl;
141158

159+
std::cout << "Constructing TestHydro..." << std::endl;
160+
// Use default NoWave; TestHydro will size it correctly for the number of bodies.
142161
TestHydro hydro_forces(bodies, h5fname);
143-
hydro_forces.AddWaves(my_hydro_inputs);
162+
std::cout << "TestHydro constructed, adding waves..." << std::endl;
144163

164+
try {
165+
hydro_forces.AddWaves(my_hydro_inputs);
166+
std::cout << "Waves added to TestHydro." << std::endl;
167+
} catch (const std::exception& e) {
168+
std::cerr << "Exception in TestHydro::AddWaves: " << e.what() << std::endl;
169+
return 1;
170+
}
145171
// for profiling
146172
auto start = std::chrono::high_resolution_clock::now();
147173

148-
// main simulation loop
149-
ui.Init(&system, "RM3 - Regular Wave Test");
150-
ui.SetCamera(0, -50, -10, 0, 0, -10);
151-
174+
std::cout << "Entering simulation loop..." << std::endl;
175+
// main simulation loop (headless, no GUI)
176+
int step = 0;
152177
while (system.GetChTime() <= simulationDuration) {
153-
if (ui.IsRunning(timestep) == false) break;
178+
if (step % 100 == 0) {
179+
std::cout << "Step " << step << ", t = " << system.GetChTime() << std::endl;
180+
}
154181

155-
if (ui.simulationStarted) {
156-
system.DoStepDynamics(timestep);
182+
system.DoStepDynamics(timestep);
183+
++step;
157184

158-
// append data to output vector
159-
time_vector.push_back(system.GetChTime());
160-
float_heave_position.push_back(float_body1->GetPos().z());
161-
float_drift_position.push_back(float_body1->GetPos().x());
162-
plate_heave_position.push_back(plate_body2->GetPos().z());
163-
}
185+
// append data to output vector
186+
time_vector.push_back(system.GetChTime());
187+
float_heave_position.push_back(float_body1->GetPos().z());
188+
float_drift_position.push_back(float_body1->GetPos().x());
189+
plate_heave_position.push_back(plate_body2->GetPos().z());
164190
}
191+
std::cout << "Exited simulation loop at t = " << system.GetChTime() << std::endl;
165192

166193
// for profiling
167194
auto end = std::chrono::high_resolution_clock::now();

tests/regression/sphere/compare_sphere_irreg_waves.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,45 @@
66
"""
77

88
import sys
9-
import os
109
from pathlib import Path
1110

1211
# Add the utilities directory to the path to import the comparison template
13-
sys.path.append(str(Path(__file__).parent.parent.parent / "utilities"))
12+
sys.path.append(str(Path(__file__).parent.parent / "utilities"))
1413
from compare_template import run_comparison
1514

15+
1616
def main():
17-
"""Main comparison function for sphere irregular waves test."""
18-
19-
# Get the reference data file
20-
ref_file = Path(__file__).parent.parent.parent / "reference_data" / "sphere" / "irreg_waves" / "hc_ref_sphere_irreg_waves.txt"
21-
22-
# Get the result file from the build directory
23-
# Look for it in the build directory structure
24-
script_dir = Path(__file__).parent
25-
project_root = script_dir.parent.parent.parent.parent # Go up to project root
26-
build_dir = project_root / "build"
27-
28-
# Find the result file
29-
result_file = build_dir / "bin" / "tests" / "regression" / "sphere" / "results" / "CHRONO_SPHERE_IRREGULAR_WAVES.txt"
30-
17+
"""Main comparison function for sphere irregular waves test.
18+
19+
When invoked from CTest, the reference and result file paths are passed as
20+
command-line arguments:
21+
compare_sphere_irreg_waves.py <ref_file> <result_file>
22+
23+
If no arguments are provided (e.g., ad‑hoc runs), we fall back to a sane
24+
default based on the source and build tree layout.
25+
"""
26+
27+
# Prefer explicit paths from CTest if provided
28+
if len(sys.argv) == 3:
29+
ref_file = Path(sys.argv[1])
30+
result_file = Path(sys.argv[2])
31+
else:
32+
# Fallback: infer from repo layout (useful for manual runs)
33+
project_root = Path(__file__).resolve().parents[3]
34+
ref_file = project_root / "data" / "reference_data" / "sphere" / "hc_ref_sphere_irreg_waves.txt"
35+
result_file = (
36+
project_root / "build" / "bin" / "Release" / "results" / "tests" / "sphere" /
37+
"results_sphere_irreg_waves.txt"
38+
)
39+
3140
if not result_file.exists():
3241
print(f"Error: Result file not found: {result_file}")
3342
sys.exit(1)
34-
35-
print(f"Comparing sphere irregular waves test...")
43+
44+
print("Comparing sphere irregular waves test...")
3645
print(f" Reference: {ref_file}")
3746
print(f" Result: {result_file}")
38-
47+
3948
# Run comparison using the template
4049
try:
4150
n1, n2, passed = run_comparison(
@@ -44,19 +53,20 @@ def main():
4453
test_name="Sphere Irregular Waves",
4554
y_label="Heave (m)",
4655
executable_patterns=["sphere_irreg_waves_test"],
47-
pass_criteria=(1e-4, 0.02)
56+
pass_criteria=(1e-4, 0.02),
4857
)
49-
58+
5059
if passed:
5160
print("Sphere irregular waves comparison PASSED")
5261
sys.exit(0)
5362
else:
5463
print("Sphere irregular waves comparison FAILED")
5564
sys.exit(1)
56-
65+
5766
except Exception as e:
5867
print(f"ERROR during comparison: {e}")
5968
sys.exit(1)
6069

70+
6171
if __name__ == "__main__":
62-
main()
72+
main()

tests/regression/sphere/compare_sphere_reg_waves.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pathlib import Path
1313

1414
# Add the utilities directory to the path to import the comparison template
15-
sys.path.append(str(Path(__file__).parent.parent.parent / "utilities"))
15+
sys.path.append(str(Path(__file__).parent.parent / "utilities"))
1616
from compare_template import run_comparison, run_multi_column_comparison
1717

1818
def main():
@@ -23,18 +23,22 @@ def main():
2323

2424
# Get the results directory from the build directory
2525
script_dir = Path(__file__).parent
26-
project_root = script_dir.parent.parent.parent.parent # Go up to project root
26+
# Repo layout: <root>/tests/regression/sphere/compare_sphere_reg_waves.py
27+
# Go up 3 levels to reach project root.
28+
project_root = script_dir.parent.parent.parent
2729
build_dir = project_root / "build"
2830

29-
# Find the results directory
30-
results_dir = build_dir / "bin" / "tests" / "regression" / "sphere" / "results"
31+
# C++ regression tests write results under:
32+
# <build>/bin/Release/results/tests/sphere/
33+
results_dir = build_dir / "bin" / "Release" / "results" / "tests" / "sphere"
3134

3235
if not results_dir.exists():
3336
print(f"Error: Results directory not found: {results_dir}")
3437
sys.exit(1)
3538

36-
# Find all result files
37-
result_files = list(results_dir.glob("CHRONO_SPHERE_REG_WAVES_*.txt"))
39+
# Find all result files produced by the C++ test
40+
# C++ writes files named: results_sphere_reg_waves_<N>.txt
41+
result_files = list(results_dir.glob("results_sphere_reg_waves_*.txt"))
3842
result_files.sort()
3943

4044
if not result_files:

0 commit comments

Comments
 (0)