Skip to content

Commit d973f47

Browse files
committed
Precalculate width for radiation convolution
1 parent 88c0d03 commit d973f47

3 files changed

Lines changed: 33 additions & 19 deletions

File tree

include/hydroc/hydro_forces.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ class TestHydro {
244244
// Additional properties related to equilibrium and hydrodynamics
245245
std::vector<double> equilibrium_;
246246
std::vector<double> cb_minus_cg_;
247-
double rirf_timestep_;
248247
Eigen::VectorXd rirf_time_vector; // Assumed consistent for each body
248+
Eigen::VectorXd rirf_width_vector;
249249

250250
// Properties for velocity history management and time tracking
251251
std::vector<std::vector<std::vector<double>>> velocity_history_;

src/h5fileinfo.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
// TODO: this include statement list looks good
88
#include <H5Cpp.h>
99
#include <hydroc/h5fileinfo.h>
10-
#include <filesystem> // std::filesystem::absolute
10+
#include <filesystem> // std::filesystem::absolute
1111

1212
using namespace chrono; // TODO narrow this using namespace to specify what we use from chrono or put chrono:: in front
1313
// of it all?
1414

15-
1615
H5FileInfo::H5FileInfo(std::string file, int num_bod) {
1716
h5_file_name_ = file;
1817
num_bodies_ = num_bod;
@@ -41,7 +40,7 @@ HydroData H5FileInfo::ReadH5Data() {
4140
for (int i = 0; i < num_bodies_; i++) {
4241
// body data
4342
data_to_init.body_data_[i].body_name = "body" + std::to_string(i + 1);
44-
std::string bodyName = data_to_init.body_data_[i].body_name; // shortcut for reading later
43+
std::string bodyName = data_to_init.body_data_[i].body_name; // shortcut for reading later
4544
data_to_init.body_data_[i].body_num = i;
4645

4746
InitScalar(userH5File, bodyName + "/properties/disp_vol", data_to_init.body_data_[i].disp_vol);
@@ -54,7 +53,8 @@ HydroData H5FileInfo::ReadH5Data() {
5453

5554
Init1D(userH5File, bodyName + "/properties/cg", data_to_init.body_data_[i].cg);
5655
Init1D(userH5File, bodyName + "/properties/cb", data_to_init.body_data_[i].cb);
57-
Init2D(userH5File, bodyName + "/hydro_coeffs/linear_restoring_stiffness", data_to_init.body_data_[i].lin_matrix);
56+
Init2D(userH5File, bodyName + "/hydro_coeffs/linear_restoring_stiffness",
57+
data_to_init.body_data_[i].lin_matrix);
5858
Init2D(userH5File, bodyName + "/hydro_coeffs/added_mass/inf_freq", data_to_init.body_data_[i].inf_added_mass);
5959
data_to_init.body_data_[i].inf_added_mass *= rho;
6060
Init3D(userH5File, bodyName + "/hydro_coeffs/radiation_damping/impulse_response_fun/K",
@@ -242,5 +242,17 @@ int HydroData::GetRIRFDims(int i) const {
242242
}
243243

244244
Eigen::VectorXd HydroData::GetRIRFTimeVector() const {
245-
return body_data_[0].rirf_time_vector;
245+
double tol = 1e-10;
246+
// check if all time vectors are the same within tolerance
247+
auto& rirf_time_vector = body_data_[0].rirf_time_vector;
248+
for (size_t ii = 1; ii < body_data_.size(); ii++) {
249+
for (size_t jj = 0; jj < body_data_[ii].rirf_time_vector.size(); jj++) {
250+
if (abs(body_data_[ii].rirf_time_vector[jj] - rirf_time_vector[jj]) > tol) {
251+
throw std::runtime_error(
252+
"RIRF time vectors have to be exactly the same for all bodies. Difference found in body " +
253+
std::to_string(jj) + " at time index " + std::to_string(jj) + ".");
254+
}
255+
}
256+
}
257+
return rirf_time_vector;
246258
}

src/hydro_forces.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
170170

171171
// Set up time vector
172172
rirf_time_vector = file_info_.GetRIRFTimeVector();
173-
rirf_timestep_ = rirf_time_vector[1] - rirf_time_vector[0];
173+
// width array
174+
rirf_width_vector.resize(rirf_time_vector.size());
175+
for (int ii = 0; ii < rirf_width_vector.size(); ii++) {
176+
rirf_width_vector[ii] = 0.0;
177+
if (ii < rirf_time_vector.size() - 1) {
178+
rirf_width_vector[ii] += 0.5 * abs(rirf_time_vector[ii + 1] - rirf_time_vector[ii]);
179+
}
180+
if (ii > 0) {
181+
rirf_width_vector[ii] += 0.5 * abs(rirf_time_vector[ii] - rirf_time_vector[ii - 1]);
182+
}
183+
}
174184

175185
// Total degrees of freedom
176186
int total_dofs = kDofPerBody * num_bodies_;
@@ -303,7 +313,7 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
303313

304314
// time history
305315
auto t_sim = bodies_[0]->GetChTime();
306-
auto t_min = t_sim - rirf_timestep_ * size;
316+
auto t_min = t_sim - rirf_time_vector.tail<1>()[0];
307317
time_history_.insert(time_history_.begin(), t_sim);
308318

309319
// velocity history
@@ -333,7 +343,7 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
333343

334344
// iterate over RIRF steps
335345
for (int step = 0; step < size; step++) {
336-
auto t_rirf = t_sim - rirf_timestep_ * step;
346+
auto t_rirf = t_sim - rirf_time_vector[step];
337347
while (time_history_[idx_history + 1] > t_rirf && idx_history < time_history_.size() - 1) {
338348
idx_history += 1;
339349
}
@@ -368,19 +378,11 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
368378

369379
// iterate over rows
370380
for (int row = 0; row < numRows; row++) {
371-
tmp_s[TmpSIndex(row, step)] += GetRIRFval(row, col, step) * vel_weighted;
381+
force_radiation_damping_[row] +=
382+
GetRIRFval(row, col, step) * vel_weighted * rirf_width_vector[step];
372383
}
373384
}
374385
}
375-
376-
if (step > 0) {
377-
// cummulate values for current step on all rows
378-
for (int row = 0; row < numRows; row++) {
379-
// Integrate tmp_s
380-
force_radiation_damping_[row] += (tmp_s[TmpSIndex(row, step - 1)] + tmp_s[TmpSIndex(row, step)]) /
381-
2.0 * (rirf_time_vector[step] - rirf_time_vector[step - 1]);
382-
}
383-
}
384386
}
385387
}
386388
return force_radiation_damping_;

0 commit comments

Comments
 (0)