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

Merged

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

  • Remove deprecated geometry types 7, 13, and 15

  • Add hardcoded patch support across all geometry types

  • Update test cases to use new hardcoded patch system


Changes diagram

flowchart LR
  A["Analytical Patches"] --> B["Hardcoded Patches"]
  C["Geometry Types 7,13,15"] --> D["Deprecated/Removed"]
  E["Test Cases"] --> F["Updated with HCID"]
  G["Patch Processing"] --> H["Enhanced Support"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
5 files
m_patches.fpp
Remove analytical patches and add hardcoded support           
+115/-247
2dHardcodedIC.fpp
Add 2D hardcoded patch cases 280-282                                         
+31/-1   
m_check_patches.fpp
Remove deprecated geometry type checks                                     
+9/-51   
3dHardcodedIC.fpp
Add 3D hardcoded patch case 380                                                   
+10/-0   
1dHardcodedIC.fpp
Add 1D hardcoded patch cases 180-181                                         
+12/-1   
Bug fix
1 files
m_checker.fpp
Add variable declaration for loop iterator                             
+1/-0     
Documentation
1 files
case.py
Add comments to analytical function generation                     
+13/-1   
Tests
13 files
case.py
Create analytical version of zero circulation vortex         
+109/-0 
case.py
Create analytical version of isentropic vortex                     
+115/-0 
case.py
Create analytical version of acoustic pulse                           
+102/-0 
case.py
Create analytical version of Taylor-Green vortex                 
+100/-0 
case.py
Create analytical version of Shu-Osher test                           
+74/-0   
case.py
Create analytical version of Titarev-Torro test                   
+72/-0   
cases.py
Skip analytical test cases during testing                               
+20/-3   
case.py
Update to use hardcoded patch HCID 282                                     
+3/-4     
case.py
Update to use hardcoded patch HCID 380                                     
+4/-3     
case.py
Update to use hardcoded patch HCID 281                                     
+3/-2     
case.py
Update to use hardcoded patch HCID 280                                     
+5/-4     
case.py
Update to use hardcoded patch HCID 180                                     
+2/-1     
case.py
Update to use hardcoded patch HCID 181                                     
+2/-1     
Additional files
14 files
case.md +7/-6     
case.py +2/-1     
case.py +2/-1     
case.py +2/-1     
case.py +2/-1     
case.py +2/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     
case.py +1/-1     

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

    qodo-merge-pro bot commented Jul 14, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit 03622a1)

    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

    Duplicate Code

    The hardcoded patch integration logic is duplicated across multiple geometry functions. Each function has nearly identical code blocks for checking hcid and calling hardcoded macros, which could be refactored into a common helper function.

    if (patch_icpp(patch_id)%hcid /= dflt_int) then
        @:Hardcoded1D()
    end if
    Magic Number

    The hardcoded epsilon value sgm_eps is used throughout for patch boundary comparisons, replacing the previous hardcoded 1.e-16_wp. This should be verified to ensure it's properly defined and has the correct value for all use cases.

    if (1._wp - eta < sgm_eps) patch_id_fp(i, 0, 0) = patch_id
    
    Test Coverage

    The analytical example cases are being skipped in the test suite, which means the new hardcoded patches may not have equivalent test coverage. This could lead to regressions going undetected.

                   "1D_shuosher_analytical",
                   "1D_titarevtorro_analytical", 
                   "2D_acoustic_pulse_analytical",
                   "2D_isentropicvortex_analytical",
                   "2D_zero_circ_vortex_analytical",
                   "3D_TaylorGreenVortex_analytical"]
    if path in casesToSkip:

    Copy link

    qodo-merge-pro bot commented Jul 14, 2025

    PR Code Suggestions ✨

    Latest suggestions up to 03622a1
    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Verify patch geometry type selection

    The geometry value 3 corresponds to a Rectangle patch type according to the
    documentation table. Verify that this is the intended patch type for the
    hardcoded initial condition example, as the original value 7 was specifically
    for hardcoded patches.

    examples/2D_hardcodied_ic/case.py [58]

    -"patch_icpp(1)%geometry": 3,
    +"patch_icpp(1)%geometry": 3,  # Rectangle patch - verify this is correct for hardcoded IC
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion correctly identifies that the patch geometry has changed from a specific hardcoded type to a standard rectangle, but it only asks for verification of a change that seems intentional given the context of the entire PR.

    Low
    • Update

    Previous suggestions

    ✅ Suggestions up to commit 45d40e8
    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

    @danieljvickers danieljvickers requested a review from wilfonba July 15, 2025 19:41
    @sbryngelson sbryngelson marked this pull request as ready for review July 15, 2025 20:08
    @sbryngelson
    Copy link
    Member

    This seems fine to me, pending removing some comments / extra junk. Also, if @wilfonba approves, since he uses a lot of these features and added some of them to the code to begin with.

    @wilfonba
    Copy link
    Contributor

    wilfonba commented Jul 15, 2025

    I added some minor comments. I don't see any other issues with these changes

    @sbryngelson
    Copy link
    Member

    @danieljvickers would you consider this ready to merge?

    @sbryngelson sbryngelson merged commit febf131 into MFlowCode:master Jul 17, 2025
    29 checks passed
    @danieljvickers danieljvickers deleted the add-hard-coded-patched-for-tests branch July 17, 2025 00:58
    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