Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 68 additions & 27 deletions src/simulation/m_rhs.fpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level Suggestion

Refactor the code to eliminate duplication between the viscous and non-viscous logic paths. Instead of duplicating the reconstruction calls, determine the variable ranges based on viscosity first, then use a single block of code for the reconstruction. [High-level, importance: 8]

Solution Walkthrough:

Before:

if (.not. surface_tension) then
    if (all(Re_size == 0)) then
        ! Reconstruct all variables (1 to sys_size)
        call s_reconstruct_cell_boundary_values(...)
    else
        ! Reconstruct non-velocity variables
        call s_reconstruct_cell_boundary_values(...) ! for 1:contxe
        call s_reconstruct_cell_boundary_values(...) ! for E_idx:sys_size
    end if
else
    if (all(Re_size == 0)) then
        ! Reconstruct in 3 parts, including velocities
        call s_reconstruct_cell_boundary_values(...) ! for 1:E_idx-1
        ...
    else
        ! Reconstruct in 3 parts, excluding velocities
        call s_reconstruct_cell_boundary_values(...) ! for 1:contxe
        ...
    end if
end if

After:

integer :: range1_end
if (all(Re_size == 0)) then
    range1_end = E_idx - 1
else
    range1_end = contxe
end if

if (.not. surface_tension) then
    if (all(Re_size == 0)) then
        call s_reconstruct_cell_boundary_values(...) ! for 1:sys_size
    else
        call s_reconstruct_cell_boundary_values(...) ! for 1:contxe
        call s_reconstruct_cell_boundary_values(...) ! for E_idx:sys_size
    end if
else
    call s_reconstruct_cell_boundary_values(...) ! for 1:range1_end
    call s_reconstruct_cell_boundary_values_first_order(...) ! for E_idx
    call s_reconstruct_cell_boundary_values(...) ! for E_idx+1:sys_size
end if

Original file line number Diff line number Diff line change
Expand Up @@ -762,34 +762,75 @@ contains
call nvtxStartRange("RHS-WENO")

if (.not. surface_tension) then
! Reconstruct densitiess
iv%beg = 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(1:sys_size), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
if (all(Re_size == 0)) then
! Reconstruct densitiess
iv%beg = 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(1:sys_size), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
else
iv%beg = 1; iv%end = contxe
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
end if

else
iv%beg = 1; iv%end = E_idx - 1
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx; iv%end = E_idx
call s_reconstruct_cell_boundary_values_first_order( &
q_prim_qp%vf(E_idx), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx + 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
if (all(Re_size == 0)) then
iv%beg = 1; iv%end = E_idx - 1
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx; iv%end = E_idx
call s_reconstruct_cell_boundary_values_first_order( &
q_prim_qp%vf(E_idx), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx + 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
else
iv%beg = 1; iv%end = contxe
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx; iv%end = E_idx
call s_reconstruct_cell_boundary_values_first_order( &
q_prim_qp%vf(E_idx), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)

iv%beg = E_idx + 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
Comment on lines +826 to +831
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a conditional check to ensure the reconstruction call for variables after the energy index E_idx is only performed if such variables exist, preventing a potentially problematic call with a zero-sized array. [possible issue, importance: 5]

Suggested change
iv%beg = E_idx + 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
if (E_idx < sys_size) then
iv%beg = E_idx + 1; iv%end = sys_size
call s_reconstruct_cell_boundary_values( &
q_prim_qp%vf(iv%beg:iv%end), &
qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, &
id)
end if

end if

end if

! Reconstruct viscous derivatives for viscosity
Expand Down
Loading