Skip to content

Commit 1b81e26

Browse files
committed
Fix default arguments for sphere irregular wave tests
1 parent e86a997 commit 1b81e26

3 files changed

Lines changed: 59 additions & 66 deletions

File tree

tests/regression/sphere/test_sphere_decay.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ int main(int argc, char* argv[]) {
101101
// main simulation loop
102102
ui.Init(&system, "Sphere - Decay Test");
103103
ui.simulationStarted = true;
104-
ui.simulationStarted = true;
105104

106105
while (system.GetChTime() <= simulationDuration) {
107106
if (ui.IsRunning(timestep) == false) break;

tests/regression/sphere/test_sphere_irreg_waves_eta.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <chrono>
22
#include <filesystem>
3+
#include <fstream>
34
#include <iomanip>
4-
#include <vector>
55
#include <iostream>
6-
#include <fstream>
6+
#include <vector>
77

88
#include <chrono/assets/ChColor.h>
99
#include <chrono/core/ChRealtimeStep.h>
10-
#include <chrono/physics/ChSystemNSC.h>
1110
#include <chrono/physics/ChBodyEasy.h>
11+
#include <chrono/physics/ChSystemNSC.h>
1212

1313
#include <hydroc/gui/guihelper.h>
1414
#include <hydroc/helper.h>
@@ -26,7 +26,7 @@ int main(int argc, char* argv[]) {
2626
bool profilingOn = true;
2727
bool saveDataOn = true;
2828
bool plotOn = true;
29-
bool visualizationOn = false;
29+
bool visualizationOn = true;
3030
std::string data_dir;
3131
if (!hydroc::GetCLIArguments(argc, argv, "Sphere irregular waves eta regression test", saveDataOn, profilingOn,
3232
plotOn, visualizationOn, data_dir))
@@ -41,21 +41,20 @@ int main(int argc, char* argv[]) {
4141
auto body1_meshfame =
4242
(DATADIR / "demos" / "sphere" / "geometry" / "oes_task10_sphere.obj").lexically_normal().generic_string();
4343
auto h5fname = (DATADIR / "demos" / "sphere" / "hydroData" / "sphere.h5").lexically_normal().generic_string();
44-
44+
4545
// Try multiple possible paths for the ETA file
4646
std::vector<std::filesystem::path> possible_eta_paths = {
4747
DATADIR / "demos" / "sphere" / "eta" / "eta.txt",
4848
std::filesystem::path("C:/code/HydroChrono/build/tests/regression/Release/data/sphere/eta/eta.txt"),
49-
std::filesystem::path("C:/code/HydroChrono/demos/sphere/eta/eta.txt")
50-
};
49+
std::filesystem::path("C:/code/HydroChrono/demos/sphere/eta/eta.txt")};
5150

5251
std::filesystem::path eta_file_path;
5352
bool found_eta_file = false;
54-
53+
5554
for (const auto& path : possible_eta_paths) {
5655
std::cout << "DEBUG: Checking ETA path: " << path << std::endl;
5756
if (std::filesystem::exists(path)) {
58-
eta_file_path = path;
57+
eta_file_path = path;
5958
found_eta_file = true;
6059
std::cout << "DEBUG: Found ETA file at: " << eta_file_path << std::endl;
6160
break;
@@ -147,7 +146,8 @@ int main(int argc, char* argv[]) {
147146

148147
// add prismatic joint between sphere and ground (limit to heave motion only)
149148
auto prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
150-
prismatic->Initialize(sphereBody, ground, false, ChFramed(ChVector3d(0, 0, -2)), ChFramed(ChVector3d(0, 0, -5)));
149+
prismatic->Initialize(sphereBody, ground, false, ChFramed(ChVector3d(0, 0, -2)),
150+
ChFramed(ChVector3d(0, 0, -5)));
151151
system.AddLink(prismatic);
152152

153153
// create the spring between body_1 and ground. The spring end points are
@@ -171,10 +171,11 @@ int main(int argc, char* argv[]) {
171171
wave_inputs.simulation_dt_ = timestep;
172172
wave_inputs.simulation_duration_ = simulationDuration;
173173
wave_inputs.ramp_duration_ = 0.0; // Changed from 60.0
174-
wave_inputs.eta_file_path_ = (DATADIR / "demos" / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string(); // Added ETA file
175-
wave_inputs.frequency_min_ = 0.001;
176-
wave_inputs.frequency_max_ = 1.0;
177-
wave_inputs.nfrequencies_ = 1000;
174+
wave_inputs.eta_file_path_ =
175+
(DATADIR / "demos" / "sphere" / "eta" / "eta.txt").lexically_normal().generic_string(); // Added ETA file
176+
wave_inputs.frequency_min_ = 0.001;
177+
wave_inputs.frequency_max_ = 1.0;
178+
wave_inputs.nfrequencies_ = 1000;
178179
// Removed wave_height_ and wave_period_ as they're not used with ETA
179180

180181
std::shared_ptr<IrregularWaves> my_hydro_inputs; // declare outside the try-catch block
@@ -202,6 +203,7 @@ int main(int argc, char* argv[]) {
202203
// main simulation loop
203204
ui.Init(&system, "Sphere - Irregular Waves Test");
204205
ui.SetCamera(8, -25, 15, 0, 0, 0);
206+
ui.simulationStarted = true;
205207

206208
while (system.GetChTime() <= simulationDuration) {
207209
if (ui.IsRunning(timestep) == false) break;
@@ -265,4 +267,4 @@ int main(int argc, char* argv[]) {
265267
std::cerr << "FATAL ERROR: Unknown unhandled exception in main" << std::endl;
266268
return 1;
267269
}
268-
}
270+
}

tests/regression/sphere/test_sphere_irreg_waves_eta_consistency.cpp

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
using namespace chrono;
3030

3131
// Shared simulation parameters
32-
const double TIMESTEP = 0.015;
33-
const double DURATION = 60.0; // Short duration for faster testing
34-
const double WAVE_HEIGHT = 2.0;
35-
const double WAVE_PERIOD = 12.0;
32+
const double TIMESTEP = 0.015;
33+
const double DURATION = 60.0; // Short duration for faster testing
34+
const double WAVE_HEIGHT = 2.0;
35+
const double WAVE_PERIOD = 12.0;
3636
const double RAMP_DURATION = 0.0; // No ramp for exact comparison
37-
const int SEED = 42; // Fixed seed for reproducibility
37+
const int SEED = 42; // Fixed seed for reproducibility
3838

3939
int main(int argc, char* argv[]) {
4040
std::cout << "=== IRREGULAR WAVES ETA CONSISTENCY TEST ===" << std::endl;
@@ -44,18 +44,17 @@ int main(int argc, char* argv[]) {
4444
bool profilingOn = true;
4545
bool saveDataOn = true;
4646
bool plotOn = true;
47-
bool visualizationOn = false;
47+
bool visualizationOn = true;
4848
std::string data_dir;
4949
if (!hydroc::GetCLIArguments(argc, argv, "Sphere irregular waves eta consistency test", saveDataOn, profilingOn,
5050
plotOn, visualizationOn, data_dir))
5151
return 1;
5252
if (!hydroc::SetInitialEnvironment(data_dir)) return 1;
5353

5454
std::filesystem::path DATADIR(hydroc::getDataDir());
55-
auto meshfname = (DATADIR / "demos" / "sphere" / "geometry" / "oes_task10_sphere.obj")
56-
.lexically_normal().generic_string();
57-
auto h5fname = (DATADIR / "demos" / "sphere" / "hydroData" / "sphere.h5")
58-
.lexically_normal().generic_string();
55+
auto meshfname =
56+
(DATADIR / "demos" / "sphere" / "geometry" / "oes_task10_sphere.obj").lexically_normal().generic_string();
57+
auto h5fname = (DATADIR / "demos" / "sphere" / "hydroData" / "sphere.h5").lexically_normal().generic_string();
5958

6059
// Output directory setup
6160
std::string out_dir = hydroc::getTestOutDir();
@@ -81,40 +80,37 @@ int main(int argc, char* argv[]) {
8180
ground->EnableCollision(false);
8281

8382
// Sphere body
84-
auto sphereBody = chrono_types::make_shared<ChBodyEasyMesh>(
85-
meshfname, 1000, false, true, false);
83+
auto sphereBody = chrono_types::make_shared<ChBodyEasyMesh>(meshfname, 1000, false, true, false);
8684
system.Add(sphereBody);
8785
sphereBody->SetName("body1");
8886
sphereBody->SetPos(ChVector3d(0, 0, -2));
8987
sphereBody->SetMass(261.8e3);
9088

9189
// Prismatic joint (heave only)
9290
auto prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
93-
prismatic->Initialize(sphereBody, ground, false,
94-
ChFramed(ChVector3d(0, 0, -2)),
91+
prismatic->Initialize(sphereBody, ground, false, ChFramed(ChVector3d(0, 0, -2)),
9592
ChFramed(ChVector3d(0, 0, -5)));
9693
system.AddLink(prismatic);
9794

9895
// Spring (zero stiffness/damping)
9996
auto spring = chrono_types::make_shared<ChLinkTSDA>();
100-
spring->Initialize(sphereBody, ground, false,
101-
ChVector3d(0, 0, -2), ChVector3d(0, 0, -5));
97+
spring->Initialize(sphereBody, ground, false, ChVector3d(0, 0, -2), ChVector3d(0, 0, -5));
10298
spring->SetSpringCoefficient(0.0);
10399
spring->SetDampingCoefficient(0.0);
104100
system.AddLink(spring);
105101

106102
// Create spectrum-based waves
107103
IrregularWaveParams spectrum_params;
108-
spectrum_params.num_bodies_ = 1;
109-
spectrum_params.simulation_dt_ = TIMESTEP;
104+
spectrum_params.num_bodies_ = 1;
105+
spectrum_params.simulation_dt_ = TIMESTEP;
110106
spectrum_params.simulation_duration_ = DURATION;
111-
spectrum_params.ramp_duration_ = RAMP_DURATION;
112-
spectrum_params.wave_height_ = WAVE_HEIGHT;
113-
spectrum_params.wave_period_ = WAVE_PERIOD;
114-
spectrum_params.frequency_min_ = 0.001;
115-
spectrum_params.frequency_max_ = 1.0;
116-
spectrum_params.nfrequencies_ = 1000;
117-
spectrum_params.seed_ = SEED;
107+
spectrum_params.ramp_duration_ = RAMP_DURATION;
108+
spectrum_params.wave_height_ = WAVE_HEIGHT;
109+
spectrum_params.wave_period_ = WAVE_PERIOD;
110+
spectrum_params.frequency_min_ = 0.001;
111+
spectrum_params.frequency_max_ = 1.0;
112+
spectrum_params.nfrequencies_ = 1000;
113+
spectrum_params.seed_ = SEED;
118114

119115
auto spectrum_waves = std::make_shared<IrregularWaves>(spectrum_params);
120116

@@ -124,7 +120,7 @@ int main(int argc, char* argv[]) {
124120
hydro_forces.AddWaves(spectrum_waves);
125121

126122
// NOW we can get the free surface data (after AddWaves initialized it)
127-
auto fse_time = spectrum_waves->GetFreeSurfaceTime();
123+
auto fse_time = spectrum_waves->GetFreeSurfaceTime();
128124
auto fse_elevation = spectrum_waves->GetFreeSurfaceElevation();
129125

130126
std::cout << " Generated " << fse_time.size() << " free surface elevation samples." << std::endl;
@@ -171,38 +167,35 @@ int main(int argc, char* argv[]) {
171167
ground->EnableCollision(false);
172168

173169
// Sphere body
174-
auto sphereBody = chrono_types::make_shared<ChBodyEasyMesh>(
175-
meshfname, 1000, false, true, false);
170+
auto sphereBody = chrono_types::make_shared<ChBodyEasyMesh>(meshfname, 1000, false, true, false);
176171
system.Add(sphereBody);
177172
sphereBody->SetName("body1");
178173
sphereBody->SetPos(ChVector3d(0, 0, -2));
179174
sphereBody->SetMass(261.8e3);
180175

181176
// Prismatic joint (heave only)
182177
auto prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
183-
prismatic->Initialize(sphereBody, ground, false,
184-
ChFramed(ChVector3d(0, 0, -2)),
178+
prismatic->Initialize(sphereBody, ground, false, ChFramed(ChVector3d(0, 0, -2)),
185179
ChFramed(ChVector3d(0, 0, -5)));
186180
system.AddLink(prismatic);
187181

188182
// Spring (zero stiffness/damping)
189183
auto spring = chrono_types::make_shared<ChLinkTSDA>();
190-
spring->Initialize(sphereBody, ground, false,
191-
ChVector3d(0, 0, -2), ChVector3d(0, 0, -5));
184+
spring->Initialize(sphereBody, ground, false, ChVector3d(0, 0, -2), ChVector3d(0, 0, -5));
192185
spring->SetSpringCoefficient(0.0);
193186
spring->SetDampingCoefficient(0.0);
194187
system.AddLink(spring);
195188

196189
// Create eta-import waves
197190
IrregularWaveParams eta_params;
198-
eta_params.num_bodies_ = 1;
199-
eta_params.simulation_dt_ = TIMESTEP;
191+
eta_params.num_bodies_ = 1;
192+
eta_params.simulation_dt_ = TIMESTEP;
200193
eta_params.simulation_duration_ = DURATION;
201-
eta_params.ramp_duration_ = RAMP_DURATION;
202-
eta_params.eta_file_path_ = eta_file;
203-
eta_params.frequency_min_ = 0.001;
204-
eta_params.frequency_max_ = 1.0;
205-
eta_params.nfrequencies_ = 1000;
194+
eta_params.ramp_duration_ = RAMP_DURATION;
195+
eta_params.eta_file_path_ = eta_file;
196+
eta_params.frequency_min_ = 0.001;
197+
eta_params.frequency_max_ = 1.0;
198+
eta_params.nfrequencies_ = 1000;
206199

207200
auto eta_waves = std::make_shared<IrregularWaves>(eta_params);
208201

@@ -223,25 +216,25 @@ int main(int argc, char* argv[]) {
223216
std::cout << "\nPhase 3: Comparing results..." << std::endl;
224217

225218
if (heave_spectrum.size() != heave_eta.size()) {
226-
std::cerr << "ERROR: Different number of timesteps! Spectrum: "
227-
<< heave_spectrum.size() << ", Eta: " << heave_eta.size() << std::endl;
219+
std::cerr << "ERROR: Different number of timesteps! Spectrum: " << heave_spectrum.size()
220+
<< ", Eta: " << heave_eta.size() << std::endl;
228221
return 1;
229222
}
230223

231-
double max_diff = 0.0;
232-
double sum_diff_sq = 0.0;
224+
double max_diff = 0.0;
225+
double sum_diff_sq = 0.0;
233226
size_t max_diff_idx = 0;
234227

235228
for (size_t i = 0; i < heave_spectrum.size(); ++i) {
236229
double diff = std::abs(heave_spectrum[i] - heave_eta[i]);
237230
sum_diff_sq += diff * diff;
238231
if (diff > max_diff) {
239-
max_diff = diff;
232+
max_diff = diff;
240233
max_diff_idx = i;
241234
}
242235
}
243236

244-
double rms_diff = std::sqrt(sum_diff_sq / heave_spectrum.size());
237+
double rms_diff = std::sqrt(sum_diff_sq / heave_spectrum.size());
245238
double time_at_max = max_diff_idx * TIMESTEP;
246239

247240
std::cout << " Max difference: " << max_diff << " m (at t=" << time_at_max << "s)" << std::endl;
@@ -257,10 +250,9 @@ int main(int argc, char* argv[]) {
257250
out << "-------- ------------------ ------------- --------------\n";
258251
for (size_t i = 0; i < heave_spectrum.size(); ++i) {
259252
double t = i * TIMESTEP;
260-
out << std::setw(10) << std::fixed << std::setprecision(3) << t
261-
<< std::setw(20) << std::fixed << std::setprecision(8) << heave_spectrum[i]
262-
<< std::setw(18) << std::fixed << std::setprecision(8) << heave_eta[i]
263-
<< std::setw(18) << std::scientific << std::setprecision(4)
253+
out << std::setw(10) << std::fixed << std::setprecision(3) << t << std::setw(20) << std::fixed
254+
<< std::setprecision(8) << heave_spectrum[i] << std::setw(18) << std::fixed << std::setprecision(8)
255+
<< heave_eta[i] << std::setw(18) << std::scientific << std::setprecision(4)
264256
<< (heave_spectrum[i] - heave_eta[i]) << "\n";
265257
}
266258
out.close();
@@ -270,7 +262,7 @@ int main(int argc, char* argv[]) {
270262

271263
// ========== PASS/FAIL determination ==========
272264
const double tolerance = 1e-6; // 1 micrometer tolerance
273-
bool passed = (max_diff < tolerance);
265+
bool passed = (max_diff < tolerance);
274266

275267
std::cout << "\n=== TEST " << (passed ? "PASSED" : "FAILED") << " ===" << std::endl;
276268
if (!passed) {

0 commit comments

Comments
 (0)