@@ -336,7 +336,7 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
336336 }
337337 }
338338
339- if (convTrapz_ && time_history_.size () > 1 ) {
339+ if (time_history_.size () > 1 ) {
340340 int idx_history = 0 ;
341341
342342 // iterate over RIRF steps
@@ -352,32 +352,39 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
352352 // iterate over bodies
353353 for (int idx_body = 0 ; idx_body < num_bodies_; idx_body++) {
354354 auto & velocity_history_body = velocity_history_[idx_body];
355+ std::vector<double > vel (kDofPerBody );
355356
356357 // interpolate velocity at t_rirf from recorded velocity history
357358 // time values
358359 auto t1 = time_history_[idx_history + 1 ];
359360 auto t2 = time_history_[idx_history];
360- if (t_rirf < t1 || t_rirf > t2) {
361+ if (t_rirf == t1) {
362+ vel = velocity_history_body[idx_history + 1 ];
363+ } else if (t_rirf == t2) {
364+ vel = velocity_history_body[idx_history];
365+ } else if (t_rirf > t1 && t_rirf < t2) {
366+ // weights
367+ auto w1 = (t2 - t_rirf) / (t2 - t1);
368+ auto w2 = 1.0 - w1;
369+ // velocity values
370+ auto vel1 = velocity_history_body[idx_history + 1 ];
371+ auto vel2 = velocity_history_body[idx_history];
372+ for (int dof = 0 ; dof < kDofPerBody ; dof++) {
373+ vel[dof] = w1 * vel1[dof] + w2 * vel2[dof];
374+ }
375+ } else {
361376 throw std::runtime_error (" Radiation convolution: wrong interpolation: " + std::to_string (t_rirf) +
362377 " not between " + std::to_string (t1) + " and " + std::to_string (t2) + " ." );
363378 }
364- // weights
365- auto w1 = (t2 - t_rirf) / (t2 - t1);
366- auto w2 = 1.0 - w1;
367- // velocity values
368- auto vel1 = velocity_history_body[idx_history + 1 ];
369- auto vel2 = velocity_history_body[idx_history];
370379
371380 for (int dof = 0 ; dof < kDofPerBody ; dof++) {
372381 // get column index
373382 int col = dof + idx_body * kDofPerBody ;
374- // get weighted velocity for DOF
375- auto vel_weighted = w1 * vel1[dof] + w2 * vel2[dof];
376383
377384 // iterate over rows
378385 for (int row = 0 ; row < numRows; row++) {
379386 force_radiation_damping_[row] +=
380- GetRIRFval (row, col, step) * vel_weighted * rirf_width_vector[step];
387+ GetRIRFval (row, col, step) * vel[dof] * rirf_width_vector[step];
381388 }
382389 }
383390 }
@@ -442,8 +449,6 @@ double TestHydro::CoordinateFuncForBody(int b, int dof_index) {
442449 std::fill (force_radiation_damping_.begin (), force_radiation_damping_.end (), 0.0 );
443450 std::fill (force_waves_.begin (), force_waves_.end (), 0.0 );
444451
445- // Compute forces using the trapezoidal rule (or other methods in the future)
446- convTrapz_ = true ;
447452 force_hydrostatic_ = ComputeForceHydrostatics ();
448453 force_radiation_damping_ = ComputeForceRadiationDampingConv ();
449454 force_waves_ = ComputeForceWaves ();
0 commit comments