Skip to content

Add hard coded patched for tests #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

danieljvickers
Copy link
Collaborator

@danieljvickers danieljvickers commented Jul 14, 2025

User description

Description

The primary intent of this PR is to remove hardcoded patches from the test suite, preventing the need to recompile them and saving time during testing. In doing so, I also refactored the geometries because we had no existing support for creating hard-coded patches on any geometries other than line segments, rectangles, and cuboids. Now we can generate hard-coded patches on almost any geometries except for the airfoil geometries (I left a TODO about this) and the model (STL) geometry (this will require it's own dedicated refactor). I also changed every test that used analytic patches to use new hard coded patches, added comments to some code in the toolchain, and updated the docs to note that the old analytic geometry patches are deprecated. I left a print statement warning that those geometries are deprecated, and we should delete them after some time. For now, I had then call subroutines that recreated their original functionality.

TODO :: After this PR, we should go back and add the analytic patches as examples that will be skipped so that they are present for external reference.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Something else

Scope

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

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

  • This was tested on the full test suite. (./mfc.sh test -j $(nproc))

Test Configuration:

All of my testing was done locally on Ubuntu with the intel and non-intel compilers.

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

Enhancement, Tests


Description

  • Replace analytical patches with hardcoded patches for test optimization

  • Add hardcoded patch support to all geometry types

  • Deprecate old analytical patch geometries (7, 13, 15)

  • Update test cases to use new hardcoded patch system


Changes diagram

flowchart LR
  A["Analytical Patches"] --> B["Hardcoded Patches"]
  B --> C["Test Cases Updated"]
  B --> D["Geometry Support Added"]
  E["Old Geometries"] --> F["Deprecated"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
4 files
1dHardcodedIC.fpp
Add 1D hardcoded patch cases 180-181                                         
+12/-1   
2dHardcodedIC.fpp
Add 2D hardcoded patch cases 280-282                                         
+32/-1   
3dHardcodedIC.fpp
Add 3D hardcoded patch case 380                                                   
+10/-0   
m_patches.fpp
Integrate hardcoded patches into geometry functions           
+115/-183
Tests
11 files
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 180                           
+2/-1     
case.py
Replace analytical with hardcoded patch 181                           
+2/-1     
case.py
Replace analytical with hardcoded patch 281                           
+3/-2     
case.py
Replace analytical with hardcoded patch 280                           
+5/-4     
case.py
Replace analytical with hardcoded patch 282                           
+5/-4     
case.py
Replace analytical with hardcoded patch 380                           
+4/-3     
Documentation
2 files
case.py
Add comments to analytical patch generation                           
+13/-1   
case.md
Update patch documentation and deprecation notes                 
+7/-6     
Configuration changes
1 files
intel.yml
Add Intel compiler CI workflow                                                     
+32/-0   

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • …ote the 80s of each case to test values, following the suite of 70s be inheretived value. No particular reason for this other than to keep it away from interesting cases.
    … how these patches are added. Will do that soon.
    … geometry. There is no way to handle that in the code currently, so I will be adding it in a future commit to resolve the final two examples
    …erences to hard coded patches in the case documentaiton
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Debug Statement

    A debug print statement was left in the code that will output to console during execution. This should be removed before merging to production.

    print *, "DEBUG: patch_id=", patch_id, " hcid=", patch_icpp(patch_id)%hcid
    
    Code Duplication

    The hardcoded patch implementations contain very similar mathematical expressions with hardcoded constants. Consider extracting common patterns or using parameterized functions to reduce duplication and improve maintainability.

    case (280)
        ! This is patch is hard-coded for test suite optimization used in the
        ! 2D_isentropicvortex case:
        ! This analytic patch uses geometry 2
        if (patch_id == 1) then
            q_prim_vf(E_idx)%sf(i, j, 0) = 1d0*(1d0 - (1d0/1d0)*(5d0/(2d0*3.141592653589793))*(5d0/(8d0*1d0*(1.4 + 1d0)*3.141592653589793))*exp(2d0*1d0*(1d0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2d0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2d0)))**(1.4 + 1d0)
            q_prim_vf(contxb + 0)%sf(i, j, 0) = 1d0*(1d0 - (1d0/1d0)*(5d0/(2d0*3.141592653589793))*(5d0/(8d0*1d0*(1.4 + 1d0)*3.141592653589793))*exp(2d0*1d0*(1d0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2d0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2d0)))**1.4
            q_prim_vf(momxb + 0)%sf(i, j, 0) = 0d0 + (y_cc(j) - patch_icpp(1)%y_centroid)*(5d0/(2d0*3.141592653589793))*exp(1d0*(1d0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2d0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2d0))
            q_prim_vf(momxb + 1)%sf(i, j, 0) = 0d0 - (x_cc(i) - patch_icpp(1)%x_centroid)*(5d0/(2d0*3.141592653589793))*exp(1d0*(1d0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2d0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2d0))
        end if
    
    case (281)
        ! This is patch is hard-coded for test suite optimization used in the
        ! 2D_acoustic_pulse case:
        ! This analytic patch uses geometry 2
        if (patch_id == 2) then
            q_prim_vf(E_idx)%sf(i, j, 0) = 101325*(1 - 0.5*(1.4 - 1)*(0.4)**2*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2))))**(1.4/(1.4 - 1))
            q_prim_vf(contxb + 0)%sf(i, j, 0) = 1*(1 - 0.5*(1.4 - 1)*(0.4)**2*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2))))**(1/(1.4 - 1))
        end if
    
    case (282)
        ! This is patch is hard-coded for test suite optimization used in the
        ! 2D_zero_circ_vortex case:
        ! This analytic patch uses geometry 2
        if (patch_id == 2) then
            q_prim_vf(E_idx)%sf(i, j, 0) = 101325*(1 - 0.5*(1.4 - 1)*(0.1/0.3)**2*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2))))**(1.4/(1.4 - 1))
            q_prim_vf(contxb + 0)%sf(i, j, 0) = 1*(1 - 0.5*(1.4 - 1)*(0.1/0.3)**2*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2))))**(1/(1.4 - 1))
            q_prim_vf(momxb + 0)%sf(i, j, 0) = 112.99092883944267*(1 - (0.1/0.3))*y_cc(j)*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2)))
            q_prim_vf(momxb + 1)%sf(i, j, 0) = 112.99092883944267*((0.1/0.3))*x_cc(i)*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2)))
        end if
    Possible Issue

    Variable assignments like j = 0.0_wp and k = 0.0_wp are assigning floating point values to integer variables, which may cause compilation errors or unexpected behavior.

    j = 0.0_wp
    k = 0.0_wp

    Copy link

    qodo-merge-pro bot commented Jul 14, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove debug print statement
    Suggestion Impact:The debug print statement was removed from line 5 of the diff, exactly as suggested

    code diff:

    -    print *, "DEBUG: patch_id=", patch_id, " hcid=", patch_icpp(patch_id)%hcid

    Remove debug print statement from production code. Debug output should not be
    included in the final codebase as it can clutter logs and impact performance.

    src/pre_process/include/2dHardcodedIC.fpp [12]

    -print *, "DEBUG: patch_id=", patch_id, " hcid=", patch_icpp(patch_id)%hcid
    +! Debug print removed
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion correctly identifies a debug print statement that should be removed from the final code to avoid cluttering logs and potential performance impacts.

    Low
    • Update

    Copy link

    codecov bot commented Jul 14, 2025

    Codecov Report

    Attention: Patch coverage is 11.11111% with 64 lines in your changes missing coverage. Please review.

    Project coverage is 44.07%. Comparing base (293557c) to head (03622a1).

    Files with missing lines Patch % Lines
    src/pre_process/m_patches.fpp 11.59% 47 Missing and 14 partials ⚠️
    src/pre_process/m_check_patches.fpp 0.00% 3 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##           master     #942      +/-   ##
    ==========================================
    + Coverage   43.76%   44.07%   +0.30%     
    ==========================================
      Files          68       68              
      Lines       18378    18227     -151     
      Branches     2292     2289       -3     
    ==========================================
    - Hits         8044     8033      -11     
    + Misses       8945     8829     -116     
    + Partials     1389     1365      -24     

    ☔ 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.

    Copy link
    Member

    @sbryngelson sbryngelson left a comment

    Choose a reason for hiding this comment

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

    added several comments. also, some of these hardcoded examples are important. it would be useful to somehow check that you didn't break the case when you switched from analytical to hardcoded.

    also probably won't merge this until analytical examples are added (but skipped in the test suite). Presumably, we only need a few of these.

    @sbryngelson sbryngelson marked this pull request as draft July 14, 2025 06:48
    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.

    4 participants