Skip to content

Code tidying #907

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Code tidying #907

wants to merge 6 commits into from

Conversation

XZTian64
Copy link
Collaborator

@XZTian64 XZTian64 commented Jun 29, 2025

User description

Description

This is the latest progress of code tidying.

Fixes #845

Type of change

  • Fixed most of the warnings during ./mfc.sh build --debug

A few issues remaining

  • Several unused functions.
  • A few unused dummy variables. They can be resolved by creating local copies to force usage, but this may reduce runtime efficiency unnecessarily.

For example:

    subroutine s_convert_primitive_to_flux_variables(qK_prim_vf, &
                                                     FK_vf, &
                                                     FK_src_vf, &
                                                     is1, is2, is3, s2b, s3b)

        integer, intent(in) :: s2b, s3b
        real(wp), dimension(0:, s2b:, s3b:, 1:), intent(in) :: qK_prim_vf
        ......
#ifdef MFC_SIMULATION
        !$acc loop seq
        do i = 1, contxe
            alpha_rho_K(i) = qK_prim_vf(j, k, l, i)
        end do

Adding a local variable only to silence a warning:

  real(wp), allocatable :: qK_prim_vf_loc(:,:,:,:)
  qK_prim_vf_loc = qK_prim_vf

which I feel is not necessary.

  • Unused loop variables (i, j, k) in /pre_process/m_patches.fpp. They appear unused but are required by the @:analytical() macro during ./mfc.sh test.
  • Several rank mismatch issues in /post_process/m_data_output.fpp. This relates to silo package, wondering if this required to be fixed.
    An example is attached:
err = DBADDIOPT(optlist, DBOPT_LO_OFFSET, lo_offset)    
      |                                                                 ! rank-1 array
......
err = DBADDIOPT(optlist, DBOPT_EXTENTS_SIZE, 2)            
      |                                                                 ! scalar
Warning: Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)

PR Type

Enhancement


Description

  • Remove unused variables and dummy arguments across modules

  • Fix compiler warnings for uninitialized variables

  • Correct MPI data type declarations for proper addressing

  • Add conditional compilation guards for unused code sections


Changes diagram

flowchart LR
  A["Compiler Warnings"] --> B["Remove Unused Variables"]
  B --> C["Fix MPI Data Types"]
  B --> D["Add Conditional Guards"]
  B --> E["Initialize Variables"]
  C --> F["Clean Code"]
  D --> F
  E --> F
Loading

Changes walkthrough 📝

Relevant files
Bug fix
24 files
m_boundary_common.fpp
Remove unused variables and fix MPI types                               
+7/-13   
m_checker_common.fpp
Add conditional compilation guard for variable                     
+2/-1     
m_finite_differences.fpp
Fix parameter order and optional arguments                             
+10/-3   
m_mpi_common.fpp
Initialize variables and add conditional guards                   
+12/-2   
m_nvtx.f90
Fix variable scope and initialization                                       
+12/-7   
m_variables_conversion.fpp
Remove unused variables and fix declarations                         
+66/-50 
m_start_up.f90
Fix parameter order in function calls                                       
+3/-3     
ExtrusionHardcodedIC.fpp
Remove unused variables and fix comparisons                           
+6/-6     
m_compute_levelset.fpp
Remove unused variable declaration                                             
+0/-2     
m_patches.fpp
Remove unused parameters from subroutines                               
+7/-7     
m_compute_cbc.fpp
Remove unused loop variable                                                           
+0/-1     
m_data_output.fpp
Remove unused stability criterion variables                           
+5/-5     
m_derived_variables.f90
Fix parameter order in function calls                                       
+3/-3     
m_fftw.fpp
Add conditional compilation for variables                               
+4/-1     
m_hyperelastic.fpp
Fix parameter order in function calls                                       
+3/-3     
m_hypoelastic.fpp
Fix parameter order in function calls                                       
+3/-3     
m_ibm.fpp
Remove unused loop variables                                                         
+0/-2     
m_mhd.fpp
Remove unused variables and fix calls                                       
+6/-6     
m_mpi_proxy.fpp
Remove unused variables from subroutine                                   
+2/-2     
m_rhs.fpp
Comment out unused gradient magnitude variables                   
+2/-2     
m_riemann_solvers.fpp
Remove unused field variables                                                       
+1/-3     
m_start_up.fpp
Fix variable initialization and declarations                         
+3/-2     
m_time_steppers.fpp
Comment out unused gradient variables                                       
+2/-2     
m_weno.fpp
Remove duplicate parameter declarations                                   
+4/-7     
Enhancement
1 files
m_helper_basic.f90
Improve precision-specific tolerance handling                       
+12/-4   

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @XZTian64 XZTian64 requested a review from a team as a code owner June 29, 2025 00:36
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    845 - PR Code Verified

    Compliant requirements:

    • Remove unused variables, subroutines, dummy variables, etc. to eliminate compiler warnings
    • Handle warnings that persist due to different compilation units marked by #ifdef
    • Work around issues by enclosing offending variables with corresponding #ifdef and #endif tags

    Requires further human verification:

    • Verification that all compiler warnings are actually eliminated during build
    • Testing that the code still functions correctly after variable removal/reorganization
    • Confirmation that performance is not negatively impacted by the changes

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

    Duplicate Code

    Variable initialization code is duplicated across multiple functions. The same initialization patterns for variables like Re_K, rho_K, gamma_K, etc. appear in several subroutines with slight variations, which could lead to maintenance issues.

    ! Initiate the variables to avoid compiler warnings
    rho_K = 0._wp
    gamma_K = 0._wp
    pi_inf_K = 0._wp
    qv_K = 0._wp
    alpha_K_sum = 0._wp
    if (present(G_K) .and. present(G)) G_K = 0._wp
    Re_K(:) = dflt_real
    Possible Issue

    Local copies of arrays are created (alpha_K_local, alpha_rho_K_local) but the original intent parameters are not used in computations, which may not reflect the intended behavior and could introduce subtle bugs.

            real(wp), dimension(num_fluids) :: alpha_K_local, alpha_rho_K_local !<
            real(wp), dimension(2), intent(out) :: Re_K
    #ifdef MFC_SIMULATION
            integer :: i, j !< Generic loop iterators
    #endif
            ! Initiate the variables to avoid compiler warnings
            rho_K = 0._wp
            gamma_K = 0._wp
            pi_inf_K = 0._wp
            qv_K = 0._wp
            Re_K(:) = dflt_real
            alpha_K_local(:) = alpha_K(:)
            alpha_rho_K_local(:) = alpha_rho_K(:)
    Parameter Order

    The parameter order in the subroutine signature has been changed, which could break existing function calls if they rely on positional arguments rather than named arguments.

    pure subroutine s_compute_finite_difference_coefficients(q, s_cc, fd_coeff_s, buff_size, &
                                                             fd_order_in, fd_number_in, offset_s)

    Copy link

    qodo-merge-pro bot commented Jun 29, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Use correct variable for allocation
    Suggestion Impact:The commit directly implements the suggested fix by replacing fd_number_in with fd_number in the allocate statement, fixing the bug with optional parameter handling

    code diff:

    -        allocate (fd_coeff_s(-fd_number_in:fd_number_in, lb:lE))
    +        allocate (fd_coeff_s(-fd_number:fd_number, lb:lE))

    The variable fd_number_in is used in the allocation but should be replaced with
    the local variable fd_number that handles the optional parameter logic.

    src/common/m_finite_differences.fpp [100-101]

     if (allocated(fd_coeff_s)) deallocate (fd_coeff_s)
    -        allocate (fd_coeff_s(-fd_number_in:fd_number_in, lb:lE))
    +        allocate (fd_coeff_s(-fd_number:fd_number, lb:lE))
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a critical bug. The code uses an optional argument fd_number_in directly in an allocate statement. If fd_number_in is not provided, this will lead to a runtime error. The fix correctly proposes using the local variable fd_number, which is designed to handle the optional logic.

    High
    Fix preprocessor directive syntax
    Suggestion Impact:The suggestion was directly implemented - both #endif directives in the file had their macro names removed to follow standard preprocessor syntax

    code diff:

    -#endif MFC_PRE_PROCESS
    +#endif
     
             @:PROHIBIT(surface_tension .and. sigma < 0._wp, &
                 "sigma must be greater than or equal to zero")
    @@ -340,7 +340,7 @@
                 @:PROHIBIT(surface_tension .and. f_is_default(patch_icpp(i)%cf_val), &
                     "patch_icpp(i)%cf_val must be set if surface_tension is enabled")
             end do
    -#endif MFC_PRE_PROCESS
    +#endif

    The #endif directive should not include the macro name. In Fortran preprocessor
    directives, #endif should stand alone without the condition name.

    src/common/m_checker_common.fpp [319-321]

     #ifdef MFC_PRE_PROCESS
             integer :: i
    -#endif MFC_PRE_PROCESS
    +#endif
    Suggestion importance[1-10]: 4

    __

    Why: The suggestion correctly points out that the standard preprocessor syntax for #endif does not include the macro name. While some compilers might tolerate this, it's non-standard and harms portability. The fix improves code correctness and style.

    Low
    • Update

    Copy link

    codecov bot commented Jun 29, 2025

    Codecov Report

    Attention: Patch coverage is 53.03030% with 31 lines in your changes missing coverage. Please review.

    Project coverage is 45.98%. Comparing base (4864d36) to head (e1a05b4).

    Files with missing lines Patch % Lines
    src/common/m_variables_conversion.fpp 44.44% 11 Missing and 4 partials ⚠️
    src/common/m_nvtx.f90 0.00% 2 Missing and 1 partial ⚠️
    src/simulation/m_hyperelastic.fpp 0.00% 3 Missing ⚠️
    src/common/m_finite_differences.fpp 33.33% 1 Missing and 1 partial ⚠️
    src/common/m_helper_basic.f90 33.33% 2 Missing ⚠️
    src/pre_process/m_patches.fpp 50.00% 2 Missing ⚠️
    src/simulation/m_derived_variables.f90 33.33% 2 Missing ⚠️
    src/common/m_boundary_common.fpp 50.00% 1 Missing ⚠️
    src/simulation/m_mhd.fpp 66.66% 1 Missing ⚠️
    Additional details and impacted files
    @@           Coverage Diff           @@
    ##           master     #907   +/-   ##
    =======================================
      Coverage   45.98%   45.98%           
    =======================================
      Files          68       68           
      Lines       18629    18646   +17     
      Branches     2239     2244    +5     
    =======================================
    + Hits         8566     8574    +8     
    - Misses       8711     8715    +4     
    - Partials     1352     1357    +5     

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

    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.

    Code tidying - Remove unused variables, subroutines, dummy variables, etc.
    2 participants