Skip to content

Commit 99e8b49

Browse files
committed
Extend eta file time range for IRF convolution
When reading wave elevation from an eta file, the IRF convolution needs to access free surface elevation at negative times (time - tau) at the start of the simulation. Previously, only spectrum-generated waves extended the time range backwards; eta file imports did not. This caused a crash at t=0 when the convolution tried to access elevation at negative times that weren't in the data. Fix: Extend eta file data backwards to -t_irf_max with zero-padded elevation, matching the behavior of CreateFreeSurfaceElevation(). Also removes unused FSE mesh visualization code from the irregular waves eta demo and test.
1 parent 4efaa06 commit 99e8b49

3 files changed

Lines changed: 37 additions & 61 deletions

File tree

demos/sphere/demo_sphere_irreg_waves_eta_import.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -130,39 +130,6 @@ int main(int argc, char* argv[]) {
130130
std::cout << "Adding waves to TestHydro object..." << std::endl;
131131
hydro_forces.AddWaves(my_hydro_inputs);
132132

133-
std::cout << "Creating fse mesh..." << std::endl;
134-
// set up free surface from a mesh
135-
auto fse_plane = chrono_types::make_shared<ChBody>();
136-
fse_plane->SetPos(ChVector3d(0, 0, 0));
137-
fse_plane->SetFixed(true);
138-
fse_plane->EnableCollision(false);
139-
system.AddBody(fse_plane);
140-
141-
// std::cout << "SetUpWaveMesh..." << std::endl;
142-
// my_hydro_inputs->SetUpWaveMesh();
143-
// std::shared_ptr<ChBody> fse_mesh = chrono_types::make_shared<ChBodyEasyMesh>( //
144-
// my_hydro_inputs->GetMeshFile(), // file name
145-
// 1000, // density
146-
// false, // do not evaluate mass
147-
// automatically true, // create
148-
// visualization asset false // do not
149-
// collide
150-
//);
151-
// fse_mesh->SetMass(1.0);
152-
// fse_mesh->SetPos_dt(my_hydro_inputs->GetWaveMeshVelocity());
153-
// std::cout << "system.Add(fse_mesh)..." << std::endl;
154-
// system.Add(fse_mesh);
155-
// auto fse_prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
156-
// fse_prismatic->Initialize(fse_plane, fse_mesh, ChFramed(ChVector3d(1.0, 0.0, 0.0), QuatFromAnglY(CH_PI_2)));
157-
// system.AddLink(fse_prismatic);
158-
159-
//// Create a visualization material
160-
// std::cout << "Create a visualization material..." << std::endl;
161-
// auto fse_texture = chrono_types::make_shared<ChVisualMaterial>();
162-
// fse_texture->SetDiffuseColor(ChColor(0.026f, 0.084f, 0.168f));
163-
// fse_texture->SetOpacity(0.1);
164-
// fse_mesh->GetVisualShape(0)->SetMaterial(0, fse_texture);
165-
166133
// for profiling
167134
auto start = std::chrono::high_resolution_clock::now();
168135
// main simulation loop

src/hydro/waves/irregular_wave.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,43 @@ void IrregularWaves::InitializeIRFVectors() {
4040

4141
if (!params_.eta_file_path_.empty()) {
4242
ReadEtaFromFile();
43+
44+
// Populate free_surface_time_sampled_ from time_data_, extending backwards
45+
// to cover negative times needed for IRF convolution (same as CreateFreeSurfaceElevation does)
46+
double t_irf_max = 0.0;
47+
for (size_t b = 0; b < ex_irf_time_sampled_.size(); b++) {
48+
if (ex_irf_time_sampled_[b].size() > 0) {
49+
double t_end = ex_irf_time_sampled_[b][ex_irf_time_sampled_[b].size() - 1];
50+
if (t_end > t_irf_max) t_irf_max = t_end;
51+
}
52+
}
53+
54+
double eta_tmin = time_data_.front();
55+
double required_tmin = -t_irf_max;
56+
57+
if (required_tmin < eta_tmin && time_data_.size() > 1) {
58+
// Extend backwards with zero elevation padding
59+
double dt = time_data_[1] - time_data_[0];
60+
int num_pad = static_cast<int>(std::ceil((eta_tmin - required_tmin) / dt));
61+
62+
std::vector<double> extended_time(num_pad + time_data_.size());
63+
std::vector<double> extended_eta(num_pad + free_surface_elevation_sampled_.size());
64+
65+
for (int i = 0; i < num_pad; ++i) {
66+
extended_time[i] = eta_tmin - (num_pad - i) * dt;
67+
extended_eta[i] = 0.0;
68+
}
69+
for (size_t i = 0; i < time_data_.size(); ++i) {
70+
extended_time[num_pad + i] = time_data_[i];
71+
extended_eta[num_pad + i] = free_surface_elevation_sampled_[i];
72+
}
73+
74+
free_surface_time_sampled_ = std::move(extended_time);
75+
free_surface_elevation_sampled_ = std::move(extended_eta);
76+
} else {
77+
free_surface_time_sampled_ = time_data_;
78+
}
79+
4380
spectrumCreated_ = false;
4481
} else if (params_.wave_height_ != 0.0 && params_.wave_period_ != 0.0) {
4582
CreateSpectrum();

tests/regression/sphere/test_sphere_irreg_waves_eta.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,6 @@ int main(int argc, char* argv[]) {
189189
HydroForces hydro_forces(bodies, h5fname);
190190
hydro_forces.AddWaves(my_hydro_inputs);
191191

192-
// set up free surface from a mesh
193-
auto fse_plane = chrono_types::make_shared<ChBody>();
194-
fse_plane->SetPos(ChVector3d(0, 0, 0));
195-
fse_plane->SetFixed(true);
196-
fse_plane->EnableCollision(false);
197-
system.AddBody(fse_plane);
198-
199-
my_hydro_inputs->SetUpWaveMesh();
200-
std::shared_ptr<ChBody> fse_mesh = chrono_types::make_shared<ChBodyEasyMesh>( //
201-
my_hydro_inputs->GetMeshFile(), // file name
202-
1000, // density
203-
false, // do not evaluate mass automatically
204-
true, // create visualization asset
205-
false // do not collide
206-
);
207-
fse_mesh->SetMass(1.0);
208-
fse_mesh->SetPosDt(my_hydro_inputs->GetWaveMeshVelocity());
209-
system.Add(fse_mesh);
210-
auto fse_prismatic = chrono_types::make_shared<ChLinkLockPrismatic>();
211-
fse_prismatic->Initialize(fse_plane, fse_mesh, ChFramed(ChVector3d(1.0, 0.0, 0.0), QuatFromAngleY(CH_PI_2)));
212-
system.AddLink(fse_prismatic);
213-
214-
// Create a visualization material
215-
auto fse_texture = chrono_types::make_shared<ChVisualMaterial>();
216-
fse_texture->SetDiffuseColor(ChColor(0.026f, 0.084f, 0.168f));
217-
fse_texture->SetOpacity(0.1);
218-
fse_mesh->GetVisualShape(0)->SetMaterial(0, fse_texture);
219-
220192
// for profiling
221193
auto start = std::chrono::high_resolution_clock::now();
222194
// main simulation loop

0 commit comments

Comments
 (0)