Skip to content

Commit 3ef5e1e

Browse files
Fixed RK convergence (#2040)
* Fixed RK convergence * Regenerating golden files for two failing tests
1 parent d9fa909 commit 3ef5e1e

5 files changed

Lines changed: 185 additions & 197 deletions

File tree

‎src/simulation/m_time_steppers.fpp‎

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,11 @@ contains
862862
!> Update immersed boundary positions and velocities at the current Runge-Kutta stage
863863
subroutine s_propagate_immersed_boundaries(s, t_step)
864864

865-
integer, intent(in) :: s, t_step
866-
integer :: i
867-
integer :: gbl_id ! used for analytic ib patch motion
868-
real(wp) :: t_stage ! time of the state produced by RK stage s (used by prescribed kinematics)
865+
integer, intent(in) :: s, t_step
866+
integer :: i
867+
integer :: gbl_id ! used for analytic ib patch motion
868+
real(wp) :: t_stage ! time of the state produced by RK stage s (used by prescribed kinematics)
869+
real(wp), dimension(3) :: vel_new, angular_new
869870

870871
call nvtxStartRange("PROPAGATE-IMMERSED-BOUNDARIES")
871872

@@ -880,7 +881,7 @@ contains
880881
if (time_stepper == time_stepper_rk3 .and. s == 2) t_stage = (t_step + 0.5_wp)*dt
881882
end if
882883

883-
$:GPU_PARALLEL_LOOP(private='[i, gbl_id]', copyin='[s, t_stage]')
884+
$:GPU_PARALLEL_LOOP(private='[i, gbl_id, vel_new, angular_new]', copyin='[s, t_stage]')
884885
do i = 1, num_ibs
885886
if (s == 1) then
886887
patch_ib(i)%step_vel = patch_ib(i)%vel
@@ -893,39 +894,42 @@ contains
893894

894895
! Compute forces BEFORE the RK velocity blend so the device copy of patch_ib%vel matches the host (pre-blend) when
895896
! velocity-dependent collision damping forces are evaluated on the GPU.
896-
if (patch_ib(i)%moving_ibm > 0 .and. patch_ib(i)%kin_model > 0) then
897-
call s_prescribed_kinematics(i, t_stage)
898-
else if (patch_ib(i)%moving_ibm > 0) then
899-
patch_ib(i)%vel = (rk_coef(s, 1)*patch_ib(i)%step_vel + rk_coef(s, 2)*patch_ib(i)%vel)/rk_coef(s, 4)
900-
patch_ib(i)%angular_vel = (rk_coef(s, 1)*patch_ib(i)%step_angular_vel + rk_coef(s, &
901-
& 2)*patch_ib(i)%angular_vel)/rk_coef(s, 4)
902-
903-
if (patch_ib(i)%moving_ibm == 1) then
897+
if (patch_ib(i)%moving_ibm > 0) then
898+
if (patch_ib(i)%kin_model > 0) then
899+
call s_prescribed_kinematics(i, t_stage)
900+
else
901+
vel_new = (rk_coef(s, 1)*patch_ib(i)%vel + rk_coef(s, 2)*patch_ib(i)%step_vel)/rk_coef(s, 4)
902+
angular_new = (rk_coef(s, 1)*patch_ib(i)%angular_vel + rk_coef(s, 2)*patch_ib(i)%step_angular_vel)/rk_coef(s, 4)
903+
904+
if (patch_ib(i)%moving_ibm >= 2) then ! if we are using two-way coupling, apply force and torque
905+
! update the velocity from the force value
906+
vel_new = vel_new + rk_coef(s, 3)*dt*(patch_ib(i)%force/patch_ib(i)%mass)/rk_coef(s, 4)
907+
908+
! update the angular velocity with the torque value add the torque to the angular momentum
909+
angular_new = (angular_new*patch_ib(i)%moment) + (rk_coef(s, 3)*dt*patch_ib(i)%torque/rk_coef(s, 4))
910+
! update the moment of inertia to be based on the direction of the angular momentum
911+
if (num_dims == 3) call s_compute_moment_of_inertia(patch_ib(i), angular_new, patch_ib(i)%moment)
912+
angular_new = angular_new/patch_ib(i)%moment
913+
end if
914+
915+
! Update the angle and position from the current-stage velocities, before they are overwritten
916+
patch_ib(i)%angles = (rk_coef(s, 1)*patch_ib(i)%angles + rk_coef(s, 2)*patch_ib(i)%step_angles + rk_coef(s, &
917+
& 3)*patch_ib(i)%angular_vel*dt)/rk_coef(s, 4)
918+
patch_ib(i)%x_centroid = (rk_coef(s, 1)*patch_ib(i)%x_centroid + rk_coef(s, &
919+
& 2)*patch_ib(i)%step_x_centroid + rk_coef(s, 3)*patch_ib(i)%vel(1)*dt)/rk_coef(s, 4)
920+
patch_ib(i)%y_centroid = (rk_coef(s, 1)*patch_ib(i)%y_centroid + rk_coef(s, &
921+
& 2)*patch_ib(i)%step_y_centroid + rk_coef(s, 3)*patch_ib(i)%vel(2)*dt)/rk_coef(s, 4)
922+
patch_ib(i)%z_centroid = (rk_coef(s, 1)*patch_ib(i)%z_centroid + rk_coef(s, &
923+
& 2)*patch_ib(i)%step_z_centroid + rk_coef(s, 3)*patch_ib(i)%vel(3)*dt)/rk_coef(s, 4)
924+
925+
patch_ib(i)%vel = vel_new
926+
patch_ib(i)%angular_vel = angular_new
927+
904928
! plug in analytic velocities for 1-way coupling, if it exists
905-
@:mib_analytical()
906-
else if (patch_ib(i)%moving_ibm == 2) then ! if we are using two-way coupling, apply force and torque
907-
! update the velocity from the force value
908-
patch_ib(i)%vel = patch_ib(i)%vel + rk_coef(s, 3)*dt*(patch_ib(i)%force/patch_ib(i)%mass)/rk_coef(s, 4)
909-
910-
! update the angular velocity with the torque value
911-
patch_ib(i)%angular_vel = (patch_ib(i)%angular_vel*patch_ib(i)%moment) + (rk_coef(s, &
912-
& 3)*dt*patch_ib(i)%torque/rk_coef(s, 4)) ! add the torque to the angular momentum
913-
if (num_dims == 3) call s_compute_moment_of_inertia(patch_ib(i), patch_ib(i)%angular_vel, patch_ib(i)%moment)
914-
! update the moment of inertia to be based on the direction of the angular momentum
915-
patch_ib(i)%angular_vel = patch_ib(i)%angular_vel/patch_ib(i)%moment
929+
if (patch_ib(i)%moving_ibm == 1) then
930+
@:mib_analytical()
931+
end if
916932
end if
917-
918-
! Update the angle of the IB
919-
patch_ib(i)%angles = (rk_coef(s, 1)*patch_ib(i)%step_angles + rk_coef(s, 2)*patch_ib(i)%angles + rk_coef(s, &
920-
& 3)*patch_ib(i)%angular_vel*dt)/rk_coef(s, 4)
921-
922-
! Update the position of the IB
923-
patch_ib(i)%x_centroid = (rk_coef(s, 1)*patch_ib(i)%step_x_centroid + rk_coef(s, &
924-
& 2)*patch_ib(i)%x_centroid + rk_coef(s, 3)*patch_ib(i)%vel(1)*dt)/rk_coef(s, 4)
925-
patch_ib(i)%y_centroid = (rk_coef(s, 1)*patch_ib(i)%step_y_centroid + rk_coef(s, &
926-
& 2)*patch_ib(i)%y_centroid + rk_coef(s, 3)*patch_ib(i)%vel(2)*dt)/rk_coef(s, 4)
927-
patch_ib(i)%z_centroid = (rk_coef(s, 1)*patch_ib(i)%step_z_centroid + rk_coef(s, &
928-
& 2)*patch_ib(i)%z_centroid + rk_coef(s, 3)*patch_ib(i)%vel(3)*dt)/rk_coef(s, 4)
929933
end if
930934
end do
931935
$:END_GPU_PARALLEL_LOOP()

‎tests/09FDDC81/golden-metadata.txt‎

Lines changed: 67 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)