Skip to content

Commit 77c7c28

Browse files
committed
fix
1 parent bf64aa5 commit 77c7c28

File tree

1 file changed

+93
-71
lines changed

1 file changed

+93
-71
lines changed

src/simulation/m_riemann_solvers.fpp

Lines changed: 93 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,20 +4101,33 @@ contains
41014101
41024102
end subroutine s_compute_cylindrical_viscous_source_flux
41034103
4104-
!> @brief Computes Cartesian viscous source flux contributions.
4105-
!! Calls helpers for shear/bulk stress after averaging gradients.
4106-
!! @param[in] velL_vf,velR_vf Left/Right boundary velocities.
4107-
!! @param[in] dvelL_dx_vf,dvelR_dx_vf Left/Right boundary $\partial v_i/\partial x$.
4108-
!! @param[in] dvelL_dy_vf,dvelR_dy_vf Left/Right boundary $\partial v_i/\partial y$.
4109-
!! @param[in] dvelL_dz_vf,dvelR_dz_vf Left/Right boundary $\partial v_i/\partial z$.
4110-
!! @param[inout] flux_src_vf Intercell source flux array to update.
4104+
!> @brief Computes Cartesian viscous source flux contributions for momentum and energy.
4105+
!! Calculates averaged velocity gradients, gets Re and interface velocities,
4106+
!! calls helpers for shear/bulk stress, then updates `flux_src_vf`.
4107+
!! @param[in] velL_vf Left boundary velocity (num_dims scalar_field).
4108+
!! @param[in] dvelL_dx_vf Left boundary d(vel)/dx (num_dims scalar_field).
4109+
!! @param[in] dvelL_dy_vf Left boundary d(vel)/dy (num_dims scalar_field).
4110+
!! @param[in] dvelL_dz_vf Left boundary d(vel)/dz (num_dims scalar_field).
4111+
!! @param[in] velR_vf Right boundary velocity (num_dims scalar_field).
4112+
!! @param[in] dvelR_dx_vf Right boundary d(vel)/dx (num_dims scalar_field).
4113+
!! @param[in] dvelR_dy_vf Right boundary d(vel)/dy (num_dims scalar_field).
4114+
!! @param[in] dvelR_dz_vf Right boundary d(vel)/dz (num_dims scalar_field).
4115+
!! @param[inout] flux_src_vf Intercell source flux array to update (sys_size scalar_field).
41114116
!! @param[in] norm_dir Interface normal direction (1=x, 2=y, 3=z).
4112-
!! @param[in] ix,iy,iz Global X,Y,Z-direction loop bounds.
4117+
!! @param[in] ix X-direction loop bounds (int_bounds_info).
4118+
!! @param[in] iy Y-direction loop bounds (int_bounds_info).
4119+
!! @param[in] iz Z-direction loop bounds (int_bounds_info).
41134120
subroutine s_compute_cartesian_viscous_source_flux(velL_vf, &
4114-
dvelL_dx_vf, dvelL_dy_vf, dvelL_dz_vf, &
4121+
dvelL_dx_vf, &
4122+
dvelL_dy_vf, &
4123+
dvelL_dz_vf, &
41154124
velR_vf, &
4116-
dvelR_dx_vf, dvelR_dy_vf, dvelR_dz_vf, &
4117-
flux_src_vf, norm_dir, ix, iy, iz)
4125+
dvelR_dx_vf, &
4126+
dvelR_dy_vf, &
4127+
dvelR_dz_vf, &
4128+
flux_src_vf, &
4129+
norm_dir, &
4130+
ix, iy, iz)
41184131
41194132
! Arguments
41204133
type(scalar_field), dimension(num_dims), intent(in) :: velL_vf, velR_vf
@@ -4126,28 +4139,30 @@ contains
41264139
type(int_bounds_info), intent(in) :: ix, iy, iz
41274140
41284141
! Local variables
4129-
real(wp), dimension(num_dims, num_dims) :: vel_grad_avg !!< Averaged velocity gradient tensor $L_{ij} = \partial v_i/\partial x_j$.
4130-
real(wp), dimension(num_dims, num_dims) :: current_tau_shear !!< Current shear stress tensor $\tau_{ij}^{(s)}$.
4131-
real(wp), dimension(num_dims, num_dims) :: current_tau_bulk !!< Current bulk stress tensor $\tau_{ij}^{(b)}$ (diagonal).
4132-
real(wp), dimension(num_dims) :: vel_src_at_interface !!< Interface velocities $(v_x,v_y,v_z)$ for viscous work.
4133-
integer, dimension(3) :: idx_right_phys !!< Physical $(j,k,l)$ indices for 'right' state.
4134-
4135-
real(wp) :: Re_shear_int !!< Interface shear Reynolds number.
4136-
real(wp) :: Re_bulk_int !!< Interface bulk Reynolds number.
4137-
4138-
integer :: j_loop !!< Physical x-index loop iterator.
4139-
integer :: k_loop !!< Physical y-index loop iterator.
4140-
integer :: l_loop !!< Physical z-index loop iterator.
4141-
integer :: i_dim !!< Generic dimension iterator for flux updates.
4142-
integer :: vel_comp_idx !!< Iterator for velocity components.
4143-
real(wp) :: divergence_v !!< Velocity divergence $\nabla \cdot \mathbf{v}$ at interface.
4142+
real(wp), dimension(num_dims, num_dims) :: vel_grad_avg !< Averaged velocity gradient tensor `d(vel_i)/d(coord_j)`.
4143+
real(wp), dimension(num_dims, num_dims) :: current_tau_shear !< Current shear stress tensor.
4144+
real(wp), dimension(num_dims, num_dims) :: current_tau_bulk !< Current bulk stress tensor.
4145+
real(wp), dimension(num_dims) :: vel_src_at_interface !< Interface velocities (u,v,w) for viscous work.
4146+
integer, dimension(3) :: idx_right_phys !< Physical (j,k,l) indices for right state.
4147+
4148+
real(wp) :: Re_shear !< Interface shear Reynolds number.
4149+
real(wp) :: Re_bulk !< Interface bulk Reynolds number.
4150+
4151+
integer :: j_loop !< Physical x-index loop iterator.
4152+
integer :: k_loop !< Physical y-index loop iterator.
4153+
integer :: l_loop !< Physical z-index loop iterator.
4154+
integer :: i_dim !< Generic dimension/component iterator.
4155+
integer :: vel_comp_idx !< Velocity component iterator (1=u, 2=v, 3=w).
4156+
4157+
real(wp) :: divergence_v !< Velocity divergence at interface.
41444158
41454159
!$acc parallel loop collapse(3) gang vector default(present) &
4146-
!$acc private(idx_right_phys, vel_grad_avg, current_tau_shear, current_tau_bulk, &
4147-
!$acc vel_src_at_interface, Re_shear_int, Re_bulk_int, divergence_v)
4148-
do l_loop = iz%beg, iz%end
4149-
do k_loop = iy%beg, iy%end
4150-
do j_loop = ix%beg, ix%end
4160+
!$acc private(idx_right_phys, vel_grad_avg, &
4161+
!$acc current_tau_shear, current_tau_bulk, vel_src_at_interface, &
4162+
!$acc Re_shear, Re_bulk, divergence_v, i_dim, vel_comp_idx)
4163+
do l_loop = isz%beg, isz%end
4164+
do k_loop = isy%beg, isy%end
4165+
do j_loop = isx%beg, isx%end
41514166
41524167
idx_right_phys(1) = j_loop
41534168
idx_right_phys(2) = k_loop
@@ -4173,28 +4188,31 @@ contains
41734188
divergence_v = divergence_v + vel_grad_avg(i_dim, i_dim)
41744189
end do
41754190
4176-
select case (norm_dir)
4177-
case (1)
4178-
Re_shear_int = Re_avg_rsx_vf(j_loop, k_loop, l_loop, 1)
4179-
Re_bulk_int = Re_avg_rsx_vf(j_loop, k_loop, l_loop, 2)
4180-
vel_src_at_interface(1:num_dims) = vel_src_rsx_vf(j_loop, k_loop, l_loop, 1:num_dims)
4181-
case (2)
4182-
Re_shear_int = Re_avg_rsy_vf(k_loop, j_loop, l_loop, 1)
4183-
Re_bulk_int = Re_avg_rsy_vf(k_loop, j_loop, l_loop, 2)
4184-
vel_src_at_interface(1:num_dims) = vel_src_rsy_vf(k_loop, j_loop, l_loop, 1:num_dims)
4185-
case (3)
4186-
Re_shear_int = Re_avg_rsz_vf(l_loop, k_loop, j_loop, 1)
4187-
Re_bulk_int = Re_avg_rsz_vf(l_loop, k_loop, j_loop, 2)
4188-
vel_src_at_interface(1:num_dims) = vel_src_rsz_vf(l_loop, k_loop, j_loop, 1:num_dims)
4189-
case default
4190-
cycle
4191-
end select
4192-
4193-
current_tau_shear = 0.0_wp
4194-
current_tau_bulk = 0.0_wp
4191+
vel_src_at_interface = 0.0_wp
4192+
if (norm_dir == 1) then
4193+
Re_shear = Re_avg_rsx_vf(j_loop, k_loop, l_loop, 1)
4194+
Re_bulk = Re_avg_rsx_vf(j_loop, k_loop, l_loop, 2)
4195+
do i_dim = 1, num_dims
4196+
vel_src_at_interface(i_dim) = vel_src_rsx_vf(j_loop, k_loop, l_loop, i_dim)
4197+
end do
4198+
else if (norm_dir == 2) then
4199+
Re_shear = Re_avg_rsy_vf(k_loop, j_loop, l_loop, 1)
4200+
Re_bulk = Re_avg_rsy_vf(k_loop, j_loop, l_loop, 2)
4201+
do i_dim = 1, num_dims
4202+
vel_src_at_interface(i_dim) = vel_src_rsy_vf(k_loop, j_loop, l_loop, i_dim)
4203+
end do
4204+
else
4205+
Re_shear = Re_avg_rsz_vf(l_loop, k_loop, j_loop, 1)
4206+
Re_bulk = Re_avg_rsz_vf(l_loop, k_loop, j_loop, 2)
4207+
do i_dim = 1, num_dims
4208+
vel_src_at_interface(i_dim) = vel_src_rsz_vf(l_loop, k_loop, j_loop, i_dim)
4209+
end do
4210+
end if
41954211
41964212
if (shear_stress) then
4197-
call s_calculate_shear_stress_tensor(vel_grad_avg, Re_shear_int, divergence_v, current_tau_shear)
4213+
current_tau_shear = 0.0_wp
4214+
call s_calculate_shear_stress_tensor(vel_grad_avg, Re_shear, divergence_v, current_tau_shear)
4215+
41984216
do i_dim = 1, num_dims
41994217
flux_src_vf(momxb + i_dim - 1)%sf(j_loop, k_loop, l_loop) = &
42004218
flux_src_vf(momxb + i_dim - 1)%sf(j_loop, k_loop, l_loop) - current_tau_shear(norm_dir, i_dim)
@@ -4206,7 +4224,9 @@ contains
42064224
end if
42074225
42084226
if (bulk_stress) then
4209-
call s_calculate_bulk_stress_tensor(Re_bulk_int, divergence_v, current_tau_bulk)
4227+
current_tau_bulk = 0.0_wp
4228+
call s_calculate_bulk_stress_tensor(Re_bulk, divergence_v, current_tau_bulk)
4229+
42104230
do i_dim = 1, num_dims
42114231
flux_src_vf(momxb + i_dim - 1)%sf(j_loop, k_loop, l_loop) = &
42124232
flux_src_vf(momxb + i_dim - 1)%sf(j_loop, k_loop, l_loop) - current_tau_bulk(norm_dir, i_dim)
@@ -4224,46 +4244,48 @@ contains
42244244
42254245
end subroutine s_compute_cartesian_viscous_source_flux
42264246
4227-
!> @brief Calculates Cartesian shear stress tensor components.
4228-
!! @param[in] vel_grad_avg Averaged velocity gradient tensor $L_{ij} = \partial v_i/\partial x_j$.
4247+
!> @brief Calculates shear stress tensor components.
4248+
!! tau_ij_shear = ( (dui/dxj + duj/dxi) - (2/3)*(div_v)*delta_ij ) / Re_shear
4249+
!! @param[in] vel_grad_avg Averaged velocity gradient tensor (d(vel_i)/d(coord_j)).
42294250
!! @param[in] Re_shear Shear Reynolds number.
4230-
!! @param[in] divergence_v Velocity divergence $\nabla \cdot \mathbf{v}$.
4231-
!! @param[out] tau_shear_out Calculated shear stress tensor $\tau_{ij}$.
4251+
!! @param[in] divergence_v Velocity divergence (du/dx + dv/dy + dw/dz).
4252+
!! @param[out] tau_shear_out Calculated shear stress tensor (stress on i-face, j-direction).
42324253
subroutine s_calculate_shear_stress_tensor(vel_grad_avg, Re_shear, divergence_v, tau_shear_out)
4233-
!$acc routine seq
4254+
!$acc routine seq
42344255
42354256
implicit none
4257+
42364258
! Arguments
42374259
real(wp), dimension(num_dims, num_dims), intent(in) :: vel_grad_avg
42384260
real(wp), intent(in) :: Re_shear
42394261
real(wp), intent(in) :: divergence_v
42404262
real(wp), dimension(num_dims, num_dims), intent(out) :: tau_shear_out
42414263
42424264
! Local variables
4243-
integer :: i_face_norm !!< Tensor row index $i$ (face normal).
4244-
integer :: j_force_dir !!< Tensor col index $j$ (force component direction).
4265+
integer :: i_dim !< Loop iterator for face normal.
4266+
integer :: j_dim !< Loop iterator for force component direction.
42454267
42464268
tau_shear_out = 0.0_wp
42474269
4248-
do i_face_norm = 1, num_dims
4249-
do j_force_dir = 1, num_dims
4250-
tau_shear_out(i_face_norm, j_force_dir) = (vel_grad_avg(j_force_dir, i_face_norm) + &
4251-
vel_grad_avg(i_face_norm, j_force_dir))/Re_shear
4252-
if (i_face_norm == j_force_dir) then
4253-
tau_shear_out(i_face_norm, j_force_dir) = tau_shear_out(i_face_norm, j_force_dir) - &
4254-
(2.0_wp/3.0_wp)*divergence_v/Re_shear
4270+
do i_dim = 1, num_dims
4271+
do j_dim = 1, num_dims
4272+
tau_shear_out(i_dim, j_dim) = (vel_grad_avg(j_dim, i_dim) + vel_grad_avg(i_dim, j_dim))/Re_shear
4273+
if (i_dim == j_dim) then
4274+
tau_shear_out(i_dim, j_dim) = tau_shear_out(i_dim, j_dim) - &
4275+
(2.0_wp/3.0_wp)*divergence_v/Re_shear
42554276
end if
42564277
end do
42574278
end do
42584279
42594280
end subroutine s_calculate_shear_stress_tensor
42604281
4261-
!> @brief Calculates Cartesian bulk stress tensor components (diagonal only).
4282+
!> @brief Calculates bulk stress tensor components (diagonal only).
4283+
!! tau_ii_bulk = (div_v) / Re_bulk. Off-diagonals are zero.
42624284
!! @param[in] Re_bulk Bulk Reynolds number.
4263-
!! @param[in] divergence_v Velocity divergence $\nabla \cdot \mathbf{v}$.
4264-
!! @param[out] tau_bulk_out Calculated bulk stress tensor $\tau_{ii}$.
4285+
!! @param[in] divergence_v Velocity divergence (du/dx + dv/dy + dw/dz).
4286+
!! @param[out] tau_bulk_out Calculated bulk stress tensor (stress on i-face, i-direction).
42654287
subroutine s_calculate_bulk_stress_tensor(Re_bulk, divergence_v, tau_bulk_out)
4266-
!$acc routine seq
4288+
!$acc routine seq
42674289
42684290
implicit none
42694291
@@ -4273,7 +4295,7 @@ contains
42734295
real(wp), dimension(num_dims, num_dims), intent(out) :: tau_bulk_out
42744296
42754297
! Local variables
4276-
integer :: i_dim !!< Loop iterator for diagonal components.
4298+
integer :: i_dim !< Loop iterator for diagonal components.
42774299
42784300
tau_bulk_out = 0.0_wp
42794301

0 commit comments

Comments
 (0)