Skip to content

Conversation

@DimAdam-01
Copy link
Contributor

@DimAdam-01 DimAdam-01 commented Sep 26, 2025

User description

Description

Please include a summary of the changes and the related issue(s) if they exist.
Please also include relevant motivation and context.

Fixes #(issue) [optional]

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Something else

Scope

  • This PR comprises a set of related changes with a common goal

If viscosity is enabled then in the rhs module (m_rhs.fpp) the s_get_viscous subroutine is called (line 709). Inside s_get_viscous (in the m_viscous.fpp module) the s_reconstruct_cell_boundary_values_visc (line 557) is called, and this subroutine implements weno interpolation for the velocities. Afterwards in the m_rhs module the Weno reconstruction is being implemented for i=1,sys_size. This was removed now and the weno interpolation is implemented only one time for the velocity field. This bug somehow introduced in the past for example in MFC 4.0, it did not exist https://github.com/MFlowCode/MFC/blob/v4.0.0/src/simulation_code/m_rhs.f90 (line 1137)

If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.
Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Configuration:

  • What computers and compilers did you use to test this:
    My Laptop

Checklist

  • I have added comments for the new code
  • I added Doxygen docstrings to the new code
  • I have made corresponding changes to the documentation (docs/)
  • I have added regression tests to the test suite so that people can verify in the future that the feature is behaving as expected
  • I have added example cases in examples/ that demonstrate my new feature performing as expected.
    They run to completion and demonstrate "interesting physics"
  • I ran ./mfc.sh format before committing my code
  • New and existing tests pass locally with my changes, including with GPU capability enabled (both NVIDIA hardware with NVHPC compilers and AMD hardware with CRAY compilers) and disabled
  • This PR does not introduce any repeated code (it follows the DRY principle)
  • I cannot think of a way to condense this code and reduce any introduced additional line count

If your code changes any code source files (anything in src/simulation)

To make sure the code is performing as expected on GPU devices, I have:

  • Checked that the code compiles using NVHPC compilers
  • Checked that the code compiles using CRAY compilers
  • Ran the code on either V100, A100, or H100 GPUs and ensured the new feature performed as expected (the GPU results match the CPU results)
  • Ran the code on MI200+ GPUs and ensure the new features performed as expected (the GPU results match the CPU results)
  • Enclosed the new feature via nvtx ranges so that they can be identified in profiles
  • Ran a Nsight Systems profile using ./mfc.sh run XXXX --gpu -t simulation --nsys, and have attached the output file (.nsys-rep) and plain text results to this PR
  • Ran a Rocprof Systems profile using ./mfc.sh run XXXX --gpu -t simulation --rsys --hip-trace, and have attached the output file and plain text results to this PR.
  • Ran my code using various numbers of different GPUs (1, 2, and 8, for example) in parallel and made sure that the results scale similarly to what happens if you run without the new code/feature

PR Type

Bug fix


Description

  • Eliminate duplicate WENO interpolation for velocity fields when viscosity is enabled

  • Add conditional logic to skip velocity reconstruction when already done in viscous module

  • Restructure reconstruction calls based on Reynolds number configuration


Diagram Walkthrough

flowchart LR
  A["Viscous Flow Check"] --> B["Reynolds Number Check"]
  B --> C["Skip Velocity WENO"]
  B --> D["Perform Full WENO"]
  C --> E["Reconstruct Non-Velocity Fields Only"]
  D --> F["Reconstruct All Fields"]
Loading

File Walkthrough

Relevant files
Bug fix
m_rhs.fpp
Conditional WENO reconstruction to eliminate velocity duplication

src/simulation/m_rhs.fpp

  • Add conditional checks for Reynolds number (Re_size) to prevent
    duplicate WENO reconstruction
  • Split reconstruction logic into velocity and non-velocity components
  • Restructure both surface tension and non-surface tension code paths
  • Maintain separate reconstruction calls for continuity, energy, and
    other field variables
+68/-27 

@DimAdam-01 DimAdam-01 requested a review from a team as a code owner September 26, 2025 23:20
@qodo-merge-pro
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The new conditional uses all(Re_size == 0) to decide whether to reconstruct the full system vs. skipping velocity components; if Re_size is an array or can be partially zero, this logic may mis-handle mixed/variable viscosity cases. Confirm Re_size semantics and whether any partial-zero scenarios exist.

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
Indexing Risk

The ranges using contxe, E_idx, and sys_size assume non-overlapping, correct ordering; off-by-one or mis-ordered indices could skip or double-process variables. Validate that contxe excludes velocity indices and that E_idx blocks are consistent in both surface_tension branches.

        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
    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)
    end if
Consistency with Viscous Path

Since velocity WENO is now handled in s_get_viscous, ensure weno_Re_flux and subsequent viscous derivative reconstruction do not implicitly assume velocity reconstruction was also done here, to avoid missing or stale interfaces.

! Reconstruct viscous derivatives for viscosity
if (weno_Re_flux) then

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

Comment on lines +826 to +831
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)
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

@codecov
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

❌ Patch coverage is 42.85714% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.89%. Comparing base (eb61616) to head (bfe68c6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_rhs.fpp 42.85% 15 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1005      +/-   ##
==========================================
- Coverage   41.91%   41.89%   -0.03%     
==========================================
  Files          69       69              
  Lines       19783    19800      +17     
  Branches     2473     2475       +2     
==========================================
+ Hits         8293     8296       +3     
- Misses       9952     9964      +12     
- Partials     1538     1540       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson sbryngelson merged commit e8a47a9 into MFlowCode:master Sep 28, 2025
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants