From 1d87192ac2cc6c016f0b56af0d4bd705a54dfadd Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Sun, 29 Dec 2024 14:19:40 -0500 Subject: [PATCH] Finalizes some source code lint checks and automates them (#780) --- .fortitude.toml | 5 +++++ .github/workflows/lint-source.yml | 17 +++++++---------- src/common/m_helper.fpp | 2 +- src/common/m_variables_conversion.fpp | 4 +++- src/post_process/m_data_output.fpp | 17 +---------------- src/pre_process/m_data_output.fpp | 2 +- src/pre_process/m_patches.fpp | 2 +- src/pre_process/m_perturbation.fpp | 4 ++-- src/simulation/m_bubbles_EL.fpp | 16 +++++++++------- src/simulation/m_data_output.fpp | 2 +- src/simulation/m_hyperelastic.fpp | 4 ++-- src/simulation/m_qbmm.fpp | 2 +- src/simulation/m_start_up.fpp | 2 +- src/simulation/m_surface_tension.fpp | 2 +- toolchain/pyproject.toml | 2 ++ 15 files changed, 38 insertions(+), 45 deletions(-) create mode 100644 .fortitude.toml diff --git a/.fortitude.toml b/.fortitude.toml new file mode 100644 index 000000000..0d3dbcc7b --- /dev/null +++ b/.fortitude.toml @@ -0,0 +1,5 @@ +[check] +# Ignored Rules and justification: +ignore = ["E001","S001","S101","M011","F001","S041","T001","S101","S102","T002","T011","T042","M001"] +file-extensions = ["f90","fpp","fypp"] +output-format = "pylint" diff --git a/.github/workflows/lint-source.yml b/.github/workflows/lint-source.yml index 0b8a2bca8..eeb400b78 100644 --- a/.github/workflows/lint-source.yml +++ b/.github/workflows/lint-source.yml @@ -25,17 +25,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install Fortitude - run: pip install fortitude-lint ansi2txt + - name: Initialize MFC + run: ./mfc.sh init - - name: Lint the source code - run: fortitude check --file-extensions=f90,fpp,fypp --ignore=E001,S001,S101,M011,F001,S041,T001,S101,S102,T002,T011 ./src/** || true - - - name: Ensure kind is specified - run: fortitude check --file-extensions=f90,fpp,fypp --select=P001 ./src/** - - - name: Ensure subroutines are named - run: fortitude check --file-extensions=f90,fpp,fypp --select=S061 ./src/** + - name: Lint the full source + run: | + source build/venv/bin/activate + find ./src -type f -not -name '*nvtx*' -exec fortitude check {} \; + find ./src -type f -not -name '*nvtx*' -exec fortitude check {} \; | wc -l | xargs -I{} sh -c '[ {} -gt 0 ] && exit 1 || exit 0' - name: No double precision intrinsics run: | diff --git a/src/common/m_helper.fpp b/src/common/m_helper.fpp index d00439a9b..0d849dbf6 100644 --- a/src/common/m_helper.fpp +++ b/src/common/m_helper.fpp @@ -244,7 +244,7 @@ contains subroutine s_int_to_str(i, res) integer, intent(in) :: i - character(len=*), intent(out) :: res + character(len=*), intent(inout) :: res write (res, '(I0)') i res = trim(res) diff --git a/src/common/m_variables_conversion.fpp b/src/common/m_variables_conversion.fpp index de910fc5f..17d644259 100644 --- a/src/common/m_variables_conversion.fpp +++ b/src/common/m_variables_conversion.fpp @@ -1081,7 +1081,7 @@ contains real(wp) :: dyn_pres real(wp) :: nbub, R3, vftmp, R3tmp real(wp), dimension(nb) :: Rtmp - real(wp) :: G = 0._wp + real(wp) :: G real(wp), dimension(2) :: Re_K integer :: i, j, k, l, q !< Generic loop iterators @@ -1090,6 +1090,8 @@ contains real(wp), dimension(num_species) :: Ys real(wp) :: e_mix, mix_mol_weight, T + G = 0._wp + #ifndef MFC_SIMULATION ! Converting the primitive variables to the conservative variables do l = 0, p diff --git a/src/post_process/m_data_output.fpp b/src/post_process/m_data_output.fpp index fbe6c051b..5faf15f59 100644 --- a/src/post_process/m_data_output.fpp +++ b/src/post_process/m_data_output.fpp @@ -50,6 +50,7 @@ module m_data_output real(wp), allocatable, dimension(:, :, :), public :: q_sf real(wp), allocatable, dimension(:, :, :) :: q_root_sf real(wp), allocatable, dimension(:, :, :) :: cyl_q_sf + ! Single precision storage for flow variables real(sp), allocatable, dimension(:, :, :), public :: q_sf_s real(sp), allocatable, dimension(:, :, :) :: q_root_sf_s @@ -219,10 +220,6 @@ contains file_loc = trim(proc_rank_dir)//'/.' - !INQUIRE( DIRECTORY = TRIM(file_loc), & ! Intel compiler - !EXIST = dir_check ) - ! INQUIRE( FILE = TRIM(file_loc), & ! NAG/PGI/GCC compiler - ! EXIST = dir_check ) call my_inquire(file_loc, dir_check) if (dir_check .neqv. .true.) then call s_create_directory(trim(proc_rank_dir)) @@ -235,10 +232,6 @@ contains file_loc = trim(rootdir)//'/.' - !INQUIRE( DIRECTORY = TRIM(file_loc), & ! Intel compiler - ! EXIST = dir_check ) - ! INQUIRE( FILE = TRIM(file_loc), & ! NAG/PGI/GCC compiler - ! EXIST = dir_check ) call my_inquire(file_loc, dir_check) if (dir_check .neqv. .true.) then call s_create_directory(trim(rootdir)) @@ -259,10 +252,6 @@ contains file_loc = trim(proc_rank_dir)//'/.' - !INQUIRE( DIRECTORY = TRIM(file_loc), & ! Intel compiler - ! EXIST = dir_check ) - ! INQUIRE( FILE = TRIM(file_loc), & ! NAG/PGI/GCC compiler - ! EXIST = dir_check ) call my_inquire(file_loc, dir_check) if (dir_check .neqv. .true.) then @@ -276,10 +265,6 @@ contains file_loc = trim(rootdir)//'/.' - !INQUIRE( DIRECTORY = TRIM(file_loc), & ! Intel compiler - ! EXIST = dir_check ) - ! INQUIRE( FILE = TRIM(file_loc), & ! NAG/PGI/GCC compiler - ! EXIST = dir_check ) call my_inquire(file_loc, dir_check) if (dir_check .neqv. .true.) then diff --git a/src/pre_process/m_data_output.fpp b/src/pre_process/m_data_output.fpp index 4d194c5bf..32b51e648 100644 --- a/src/pre_process/m_data_output.fpp +++ b/src/pre_process/m_data_output.fpp @@ -831,7 +831,7 @@ contains ! Generic string used to store the address of a particular file character(LEN=len_trim(case_dir) + 2*name_len) :: file_loc character(len=15) :: temp - character(LEN=1), dimension(3) :: coord = (/'x', 'y', 'z'/) + character(LEN=1), dimension(3), parameter :: coord = (/'x', 'y', 'z'/) ! Generic logical used to check the existence of directories logical :: dir_check diff --git a/src/pre_process/m_patches.fpp b/src/pre_process/m_patches.fpp index 39e354cb9..2a2ef1797 100644 --- a/src/pre_process/m_patches.fpp +++ b/src/pre_process/m_patches.fpp @@ -1416,7 +1416,7 @@ contains integer :: i, j, k !< generic loop iterators real(wp) :: epsilon, beta - complex(wp) :: cmplx_i = (0._wp, 1._wp) + complex(wp), parameter :: cmplx_i = (0._wp, 1._wp) complex(wp) :: H ! Transferring the patch's centroid and radius information diff --git a/src/pre_process/m_perturbation.fpp b/src/pre_process/m_perturbation.fpp index ccb1b6175..10c5b0f14 100644 --- a/src/pre_process/m_perturbation.fpp +++ b/src/pre_process/m_perturbation.fpp @@ -497,8 +497,8 @@ contains real(wp) :: ang, norm real(wp) :: tr, ti, cr, ci !< temporary memory real(wp) :: xratio - integer idx - integer i, j, k + integer :: idx + integer :: i, j, k xratio = mixlayer_vel_coef diff --git a/src/simulation/m_bubbles_EL.fpp b/src/simulation/m_bubbles_EL.fpp index 170bfe765..b48f941a3 100644 --- a/src/simulation/m_bubbles_EL.fpp +++ b/src/simulation/m_bubbles_EL.fpp @@ -401,7 +401,7 @@ contains !! @param save_count File identifier subroutine s_restart_bubbles(bub_id, save_count) - integer :: bub_id, save_count + integer, intent(inout) :: bub_id, save_count character(LEN=path_len + 2*name_len) :: file_loc @@ -1460,7 +1460,7 @@ contains function particle_in_domain(pos_part) logical :: particle_in_domain - real(wp), dimension(3) :: pos_part + real(wp), dimension(3), intent(in) :: pos_part ! 2D if (p == 0 .and. cyl_coord .neqv. .true.) then @@ -1513,7 +1513,7 @@ contains function particle_in_domain_physical(pos_part) logical :: particle_in_domain_physical - real(wp), dimension(3) :: pos_part + real(wp), dimension(3), intent(in) :: pos_part particle_in_domain_physical = ((pos_part(1) < x_cb(m)) .and. (pos_part(1) >= x_cb(-1)) .and. & (pos_part(2) < y_cb(n)) .and. (pos_part(2) >= y_cb(-1))) @@ -1589,7 +1589,7 @@ contains !! @param q_time Current time subroutine s_write_lag_particles(qtime) - real(wp) :: qtime + real(wp), intent(in) :: qtime integer :: k character(LEN=path_len + 2*name_len) :: file_loc @@ -1631,7 +1631,8 @@ contains !! @param q_time Current time subroutine s_write_void_evol(qtime) - real(wp) :: qtime, volcell, voltot + real(wp), intent(in) :: qtime + real(wp) :: volcell, voltot real(wp) :: lag_void_max, lag_void_avg, lag_vol real(wp) :: void_max_glb, void_avg_glb, vol_glb @@ -1704,11 +1705,12 @@ contains subroutine s_write_restart_lag_bubbles(t_step) ! Generic string used to store the address of a particular file + integer, intent(in) :: t_step + character(LEN=path_len + 2*name_len) :: file_loc logical :: file_exist - - integer :: i, k, t_step integer :: bub_id, tot_part, tot_part_wrtn, npart_wrtn + integer :: i, k #ifdef MFC_MPI ! For Parallel I/O diff --git a/src/simulation/m_data_output.fpp b/src/simulation/m_data_output.fpp index 6417dc797..c2e6ddba2 100644 --- a/src/simulation/m_data_output.fpp +++ b/src/simulation/m_data_output.fpp @@ -110,7 +110,7 @@ contains !! time-step. subroutine s_open_run_time_information_file - character(LEN=name_len) :: file_name = 'run_time.inf' !< + character(LEN=name_len), parameter :: file_name = 'run_time.inf' !< !! Name of the run-time information file character(LEN=path_len + name_len) :: file_path !< diff --git a/src/simulation/m_hyperelastic.fpp b/src/simulation/m_hyperelastic.fpp index 5af5508c9..46addb768 100644 --- a/src/simulation/m_hyperelastic.fpp +++ b/src/simulation/m_hyperelastic.fpp @@ -227,7 +227,7 @@ contains integer, intent(in) :: j, k, l real(wp) :: trace - real(wp) :: f13 = 1_wp/3_wp + real(wp), parameter :: f13 = 1._wp/3._wp integer :: i !< Generic loop iterators ! tensor is the symmetric tensor & calculate the trace of the tensor @@ -266,7 +266,7 @@ contains integer, intent(in) :: j, k, l real(wp) :: trace - real(wp) :: f13 = 1_wp/3_wp + real(wp), parameter :: f13 = 1._wp/3._wp integer :: i !< Generic loop iterators !TODO Make this 1D and 2D capable diff --git a/src/simulation/m_qbmm.fpp b/src/simulation/m_qbmm.fpp index 4a23839af..11298e4f7 100644 --- a/src/simulation/m_qbmm.fpp +++ b/src/simulation/m_qbmm.fpp @@ -823,7 +823,7 @@ contains real(wp), dimension(startx:, starty:, startz:, 1:, 1:), intent(inout) :: pb, rhs_pb real(wp), dimension(startx:, starty:, startz:, 1:, 1:), intent(inout) :: mv, rhs_mv type(int_bounds_info), intent(in) :: ix, iy, iz - real(wp), dimension(startx:, starty:, startz:) :: nbub_sc !> Unused Variable not sure what to put as intent + real(wp), dimension(startx:, starty:, startz:), intent(inout) :: nbub_sc real(wp), dimension(nmom) :: moms, msum real(wp), dimension(nnode, nb) :: wght, abscX, abscY, wght_pb, wght_mv, wght_ht, ht diff --git a/src/simulation/m_start_up.fpp b/src/simulation/m_start_up.fpp index 6be30adc6..547502ff6 100644 --- a/src/simulation/m_start_up.fpp +++ b/src/simulation/m_start_up.fpp @@ -125,7 +125,7 @@ contains subroutine s_read_input_file ! Relative path to the input file provided by the user - character(LEN=name_len) :: file_path = './simulation.inp' + character(LEN=name_len), parameter :: file_path = './simulation.inp' logical :: file_exist !< !! Logical used to check the existence of the input file diff --git a/src/simulation/m_surface_tension.fpp b/src/simulation/m_surface_tension.fpp index 0f9a24a51..06b230c60 100644 --- a/src/simulation/m_surface_tension.fpp +++ b/src/simulation/m_surface_tension.fpp @@ -70,7 +70,7 @@ contains flux_src_vf, & id, isx, isy, isz) - type(scalar_field), dimension(sys_size) :: q_prim_vf !> unused so unsure what intent to give it + type(scalar_field), dimension(sys_size), intent(in) :: q_prim_vf real(wp), dimension(-1:, 0:, 0:, 1:), intent(in) :: vSrc_rsx_vf real(wp), dimension(-1:, 0:, 0:, 1:), intent(in) :: vSrc_rsy_vf real(wp), dimension(-1:, 0:, 0:, 1:), intent(in) :: vSrc_rsz_vf diff --git a/toolchain/pyproject.toml b/toolchain/pyproject.toml index 0ede6a15c..4af041224 100644 --- a/toolchain/pyproject.toml +++ b/toolchain/pyproject.toml @@ -26,6 +26,8 @@ dependencies = [ "pylint", "fprettify", "black", + "fortitude-lint", + "ansi2txt", # Profiling "numpy",