Skip to content

Commit 9825639

Browse files
committed
Merge remote-tracking branch 'upstream/master' into IGRMergeOne
2 parents 538a180 + f68bce1 commit 9825639

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+981
-551
lines changed

.github/copilot-instructions.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# GitHub Copilot Instructions – Pull-Request Reviews for MFC
2+
3+
These instructions guide **GitHub Copilot Code Review** and **Copilot Chat** when they evaluate pull requests in this repository.
4+
5+
---
6+
7+
## 1 Project Context (always include)
8+
9+
* **Project:** MFC (exascale many-physics solver) written in **modern Fortran 2008+**, generated with **Fypp**.
10+
* **Directory layout:**
11+
* Sources in `src/`, tests in `tests/`, examples in `examples/`.
12+
* Most source files are templated `.fpp`; CMake transpiles them to `.f90`.
13+
* **Fypp macros** are in `src/<subprogram>/include/`, where `<subprogram>` is `simulation`, `common`, `pre_process`, or `post_process`. Review these first.
14+
* Only `simulation` (plus its `common` dependencies) is GPU-accelerated with **OpenACC**.
15+
16+
> **Copilot, when reviewing:**
17+
> * Treat the codebase as free-form Fortran 2008+ with `implicit none`, explicit `intent`, and standard intrinsics.
18+
> * Prefer `module … contains … subroutine foo()` over legacy constructs; flag uses of `COMMON`, file-level `include`, or other global state.
19+
20+
---
21+
22+
## 2 Incremental-Change Workflow
23+
24+
Copilot, when reviewing:
25+
* Encourage small, buildable commits
26+
27+
---
28+
29+
## 3 Style & Naming Conventions (*.fpp / *.f90)
30+
31+
| Element | Rule |
32+
|---------|------|
33+
| Indentation | 2 spaces; continuation lines align beneath &. |
34+
| Case | Lower-case keywords & intrinsics (do, end subroutine, …). |
35+
| Modules | m_<feature> (e.g. m_transport). |
36+
| Public subroutines | s_<verb>_<noun> (s_compute_flux). |
37+
| Public functions | f_<verb>_<noun>. |
38+
| Routine size | subroutine ≤ 500 lines, helper ≤ 150, function ≤ 100, file ≤ 1000. |
39+
| Arguments | ≤ 6; else use a derived-type params struct. |
40+
| Forbidden | goto (except legacy), COMMON, save globals. |
41+
| Variables | Every arg has explicit intent; use dimension/allocatable/pointer as appropriate. |
42+
| Errors | Call s_mpi_abort(<msg>), never stop or error stop. |
43+
44+
Copilot, when reviewing:
45+
* Flag violations of any cell above.
46+
* Suggest refactors when size or argument limits are exceeded.
47+
* Ensure private helpers stay inside their defining module and avoid nested procedures.
48+
49+
---
50+
51+
## 4 OpenACC Guidelines (for GPU kernels)
52+
53+
Wrap tight loops:
54+
55+
```fortran
56+
!$acc parallel loop gang vector default(present) reduction(...)
57+
```
58+
59+
* Add collapse(n) when safe.
60+
* Declare loop-local variables with private(...).
61+
* Allocate large arrays with managed or move them into a persistent !$acc enter data region at start-up.
62+
* Avoid stop/error stop inside device code.
63+
* Code must compile with Cray ftn, NVIDIA nvfortran, GNU gfortran, and Intel ifx/ifort.
64+
65+
---
66+
67+
## 5 Review Checklist (what Copilot should verify)
68+
69+
1. Buildability: PR includes build instructions or CI passes the staged build.
70+
2. Tests: Focused tests are added/updated.
71+
3. Style compliance: All rules in §3 are satisfied.
72+
4. Module hygiene: No new global state; proper namespacing.
73+
5. Performance: GPU code follows §4; no large host/device transfers in hot loops.
74+
6. Documentation: Updated in-code comments and, when needed, README or docs site.
75+
7. Regressions: No changes to outputs of golden tests without clear justification.

.github/workflows/bench.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: 'Benchmark'
22

3-
on: pull_request
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
workflow_dispatch:
47

58
jobs:
69
file-changes:
@@ -20,11 +23,12 @@ jobs:
2023

2124
self:
2225
name: Georgia Tech | Phoenix (NVHPC)
23-
if: github.repository == 'MFlowCode/MFC' && needs.file-changes.outputs.checkall == 'true'
26+
if: github.repository == 'MFlowCode/MFC' && needs.file-changes.outputs.checkall == 'true' && ${{ github.event.review.state == 'approved' }}
2427
needs: file-changes
2528
strategy:
2629
matrix:
2730
device: ['cpu', 'gpu']
31+
fail-fast: false
2832
runs-on:
2933
group: phoenix
3034
labels: gt
@@ -56,6 +60,12 @@ jobs:
5660
(cd pr && . ./mfc.sh load -c p -m g)
5761
(cd pr && ./mfc.sh bench_diff ../master/bench-${{ matrix.device }}.yaml ../pr/bench-${{ matrix.device }}.yaml)
5862
63+
- name: Print Logs
64+
if: always()
65+
run: |
66+
cat pr/bench-${{ matrix.device }}.* 2>/dev/null || true
67+
cat master/bench-${{ matrix.device }}.* 2>/dev/null || true
68+
5969
- name: Archive Logs
6070
uses: actions/upload-artifact@v4
6171
if: always()

.github/workflows/frontier/submit.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ sbatch <<EOT
3333
#SBATCH -A CFD154 # charge account
3434
#SBATCH -N 1 # Number of nodes required
3535
$sbatch_device_opts
36-
#SBATCH -t 01:59:00 # Duration of the job (Ex: 15 mins)
36+
#SBATCH -t 03:59:00 # Duration of the job (Ex: 15 mins)
3737
#SBATCH -o$job_slug.out # Combined output and error messages file
3838
#SBATCH -p extended # Extended partition for shorter queues
39-
#SBATCH -q debug # Use debug QOS - only one job per user allowed in queue!
4039
#SBATCH -W # Do not exit until the submitted job terminates.
4140
4241
set -e

.github/workflows/lint-source.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
run: |
4343
! grep -iR -e '\.\.\.' -e '\-\-\-' -e '===' ./src/*
4444
45+
- name: Looking for false integers
46+
run: |
47+
! grep -onRP '(?<![0-9.eE\-])\b[0-9]*_wp\b' src/
48+
4549
- name: Looking for junk comments in examples
4650
run: |
4751
! grep -R '# ===' ./benchmarks **/*.py

.github/workflows/pmd.yml

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,102 @@ jobs:
3030
unzip -q pmd.zip
3131
PMD_HOME="pmd-bin-${PMD_VERSION}"
3232
33+
SOURCE_DIR="${1:-src}"
34+
total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l)
35+
processed=0
36+
37+
find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) -print0 |
38+
while IFS= read -r -d $'\0' file; do
39+
processed=$((processed + 1))
40+
41+
# Create a temporary file with same permissions as original
42+
TMP_FILE=$(mktemp)
43+
if [ $? -ne 0 ]; then
44+
echo -e "Failed to create temporary file for $file, skipping"
45+
continue
46+
fi
47+
48+
# Copy permissions from original file
49+
chmod --reference="$file" "$TMP_FILE"
50+
51+
# More comprehensive sed command to handle different Fortran comment styles:
52+
# 1. Replace lines that are entirely comments with an empty line:
53+
# - Lines starting with '!' (free form comments)
54+
# - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments)
55+
# 2. Remove end-of-line comments (anything after '!' that isn't in a string)
56+
# 3. Preserve strings containing '!' characters
57+
sed -E '
58+
# First handle & continuation style (modern Fortran)
59+
:ampersand_loop
60+
/&[[:space:]]*$/ {
61+
N
62+
s/&[[:space:]]*\n[[:space:]]*(&)?/ /g
63+
tampersand_loop
64+
}
65+
66+
# Handle fixed-form continuation (column 6 indicator)
67+
:fixed_form_loop
68+
/^[[:space:]]{0,5}[^[:space:]!&]/ {
69+
N
70+
s/\n[[:space:]]{5}[^[:space:]]/ /g
71+
tfixed_form_loop
72+
}
73+
74+
# Remove any remaining continuation markers
75+
s/&//g
76+
77+
# Normalize spacing - replace multiple spaces with single space
78+
s/[[:space:]]{2,}/ /g
79+
80+
# Remove spaces around mathematical operators
81+
s/[[:space:]]*\*[[:space:]]*/*/g
82+
s/[[:space:]]*\+[[:space:]]*/+/g
83+
s/[[:space:]]*-[[:space:]]*/-/g
84+
s/[[:space:]]*\/[[:space:]]*/\//g
85+
s/[[:space:]]*\*\*[[:space:]]*/\*\*/g
86+
87+
# Remove spaces in common Fortran constructs (array indexing, function calls)
88+
s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*,/(\1,/g # First argument
89+
s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*,/,\1,/g # Middle arguments
90+
s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/,\1)/g # Last argument
91+
s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/(\1)/g # Single argument
92+
93+
# Remove spaces around brackets and parentheses
94+
s/\[[[:space:]]*/</g
95+
s/\[[[:space:]]*/>/g
96+
s/\[[[:space:]]*/</g
97+
s/[[:space:]]*\]/]/g
98+
s/\([[:space:]]*/(/g
99+
s/[[:space:]]*\)/)/g
100+
101+
# Remove spaces around comparison operators
102+
s/[[:space:]]*<=[[:space:]]*/</g
103+
s/[[:space:]]*>=[[:space:]]*/>/g
104+
s/[[:space:]]*<[[:space:]]*/</g
105+
s/[[:space:]]*>[[:space:]]*/>/g
106+
s/[[:space:]]*==[[:space:]]*/==/g
107+
108+
# Remove full-line comments
109+
/^\s*!/d
110+
/^[cC*dD]/d
111+
/^[ \t]*[cC*dD]/d
112+
/^[[:space:]]*$/d
113+
114+
# Remove end-of-line comments, preserving quoted strings
115+
s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/
116+
' "$file" > "$TMP_FILE"
117+
118+
if cmp -s "$file" "$TMP_FILE"; then
119+
rm "$TMP_FILE"
120+
else
121+
# Overwrite the original file with the processed content
122+
mv "$TMP_FILE" "$file"
123+
fi
124+
done
125+
33126
"${PMD_HOME}/bin/pmd" cpd \
34127
--dir src \
35128
--language fortran \
36-
--minimum-tokens=40
129+
--minimum-tokens=20 \
130+
--no-fail-on-violation \
131+
--no-fail-on-error

.pr_agent.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# .pr_agent.toml
2+
[github_app]
3+
# Run these tools automatically on every new PR:
4+
pr_commands = ["/describe", "/review", "/improve"]
5+
6+
[pr_reviewer] # (all fields optional)
7+
num_max_findings = 5 # how many items to surface
8+
require_tests_review = true
9+
extra_instructions = """
10+
Focus on duplicate code, the possibility of bugs, and if the PR added appropriate tests if it added a simulation feature.
11+
"""
12+
13+
[pr_code_suggestions]
14+
commitable_code_suggestions = false # purely advisory, no write ops
15+
apply_suggestions_checkbox = false # hides the “Apply/Chat” boxes

docs/documentation/case.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ and use `patch_icpp(i)%%geometry = 7` and `patch_icpp(i)%%hcid = 200` in the inp
236236
Additional variables can be declared in `Hardcoded1[2,3]DVariables` and used in `hardcoded1[2,3]D`.
237237
As a convention, any hard coded patches that are part of the MFC master branch should be identified as 1[2,3]xx where the first digit indicates the number of dimensions.
238238

239+
The code provides three pre-built patches for dimensional extrusion of initial conditions:
240+
241+
- `case(170)`: Load 1D profile from data files
242+
- `case(270)`: Extrude 1D data to 2D domain
243+
- `case(370)`: Extrude 2D data to 3D domain
244+
245+
Setup: Only requires specifying `init_dir` and filename pattern via `zeros_default`. Grid dimensions are automatically detected from the data files.
246+
Implementation: All variables and file handling are managed in `src/pre_process/include/ExtrusionHardcodedIC.fpp` with no manual grid configuration needed.
247+
Usage: Ideal for initializing simulations from lower-dimensional solutions, enabling users to add perturbations or modifications to the base extruded fields for flow instability studies.
248+
239249
#### Parameter Descriptions
240250

241251
- `num_patches` defines the total number of patches defined in the domain.

src/common/m_checker_common.fpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ contains
334334
@:PROHIBIT(surface_tension .and. sigma < 0._wp, &
335335
"sigma must be greater than or equal to zero")
336336

337-
@:PROHIBIT(surface_tension .and. sigma == dflt_real, &
337+
@:PROHIBIT(surface_tension .and. f_approx_equal(sigma, dflt_real), &
338338
"sigma must be set if surface_tension is enabled")
339339

340340
@:PROHIBIT(.not. f_is_default(sigma) .and. .not. surface_tension, &
@@ -359,9 +359,12 @@ contains
359359
!! Called by s_check_inputs_common for all three stages
360360
impure subroutine s_check_inputs_moving_bc
361361
#:for X, VB2, VB3 in [('x', 'vb2', 'vb3'), ('y', 'vb3', 'vb1'), ('z', 'vb1', 'vb2')]
362-
if (any((/bc_${X}$%vb1, bc_${X}$%vb2, bc_${X}$%vb3/) /= 0._wp)) then
362+
if (.not. (f_approx_equal(bc_${X}$%vb1, 0._wp) .and. &
363+
f_approx_equal(bc_${X}$%vb2, 0._wp) .and. &
364+
f_approx_equal(bc_${X}$%vb3, 0._wp))) then
363365
if (bc_${X}$%beg == BC_SLIP_WALL) then
364-
if (any((/bc_${X}$%${VB2}$, bc_${X}$%${VB3}$/) /= 0._wp)) then
366+
if (.not. (f_approx_equal(bc_${X}$%${VB2}$, 0._wp) .and. &
367+
f_approx_equal(bc_${X}$%${VB3}$, 0._wp))) then
365368
call s_mpi_abort("bc_${X}$%beg must be -15 if "// &
366369
"bc_${X}$%${VB2}$ or bc_${X}$%${VB3}$ "// &
367370
"is set. Exiting.", CASE_FILE_ERROR_CODE)
@@ -374,9 +377,12 @@ contains
374377
#:endfor
375378

376379
#:for X, VE2, VE3 in [('x', 've2', 've3'), ('y', 've3', 've1'), ('z', 've1', 've2')]
377-
if (any((/bc_${X}$%ve1, bc_${X}$%ve2, bc_${X}$%ve3/) /= 0._wp)) then
380+
if (.not. (f_approx_equal(bc_${X}$%ve1, 0._wp) .and. &
381+
f_approx_equal(bc_${X}$%ve2, 0._wp) .and. &
382+
f_approx_equal(bc_${X}$%ve3, 0._wp))) then
378383
if (bc_${X}$%end == BC_SLIP_WALL) then
379-
if (any((/bc_${X}$%${VE2}$, bc_${X}$%${VE3}$/) /= 0._wp)) then
384+
if (.not. (f_approx_equal(bc_${X}$%${VE2}$, 0._wp) .and. &
385+
f_approx_equal(bc_${X}$%${VE3}$, 0._wp))) then
380386
call s_mpi_abort("bc_${X}$%end must be -15 if "// &
381387
"bc_${X}$%${VE2}$ or bc_${X}$%${VE3}$ "// &
382388
"is set. Exiting.", CASE_FILE_ERROR_CODE)

src/common/m_constants.fpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module m_constants
88

99
character, parameter :: dflt_char = ' ' !< Default string value
1010

11-
real(wp), parameter :: dflt_real = -1e6_wp !< Default real value
12-
real(wp), parameter :: sgm_eps = 1e-16_wp !< Segmentation tolerance
13-
real(wp), parameter :: small_alf = 1e-11_wp !< Small alf tolerance
11+
real(wp), parameter :: dflt_real = -1.e6_wp !< Default real value
12+
real(wp), parameter :: sgm_eps = 1.e-16_wp !< Segmentation tolerance
13+
real(wp), parameter :: small_alf = 1.e-11_wp !< Small alf tolerance
1414
real(wp), parameter :: pi = 3.141592653589793_wp !< Pi
1515
real(wp), parameter :: verysmall = 1.e-12_wp !< Very small number
1616

@@ -29,7 +29,7 @@ module m_constants
2929
integer, parameter :: dflt_num_igr_warm_start_iters = 50 !< default number of iterations for IGR elliptic solve
3030
real(wp), parameter :: dflt_alf_factor = 10._wp !< scaling factor for IGR alpha
3131
integer, parameter :: gp_layers = 3 !< Number of ghost point layers for IBM
32-
real(wp), parameter :: capillary_cutoff = 1e-6 !< color function gradient magnitude at which to apply the surface tension fluxes
32+
real(wp), parameter :: capillary_cutoff = 1.e-6 !< color function gradient magnitude at which to apply the surface tension fluxes
3333
real(wp), parameter :: acoustic_spatial_support_width = 2.5_wp !< Spatial support width of acoustic source, used in s_source_spatial
3434
real(wp), parameter :: dflt_vcfl_dt = 100._wp !< value of vcfl_dt when viscosity is off for computing adaptive timestep size
3535
real(wp), parameter :: broadband_spectral_level_constant = 20._wp !< The constant to scale the spectral level at the lower frequency bound
@@ -44,25 +44,25 @@ module m_constants
4444
integer, parameter :: Ifactor_bary_3D = 20 !< Multiple factor of the ratio (triangle area to cell face area) for interpolation on triangle facets for 3D models
4545
integer, parameter :: num_ray = 20 !< Default number of rays traced per cell
4646
real(wp), parameter :: ray_tracing_threshold = 0.9_wp !< Threshold above which the cell is marked as the model patch
47-
real(wp), parameter :: threshold_vector_zero = 1e-10 !< Threshold to treat the component of a vector to be zero
48-
real(wp), parameter :: threshold_edge_zero = 1e-10 !< Threshold to treat two edges to be overlapped
49-
real(wp), parameter :: threshold_bary = 1e-1 !< Threshold to interpolate a barycentric facet
50-
real(wp), parameter :: initial_distance_buffer = 1e12_wp !< Initialized levelset distance for the shortest path pair algorithm
47+
real(wp), parameter :: threshold_vector_zero = 1.e-10_wp !< Threshold to treat the component of a vector to be zero
48+
real(wp), parameter :: threshold_edge_zero = 1.e-10_wp !< Threshold to treat two edges to be overlapped
49+
real(wp), parameter :: threshold_bary = 1.e-1_wp !< Threshold to interpolate a barycentric facet
50+
real(wp), parameter :: initial_distance_buffer = 1.e12_wp !< Initialized levelset distance for the shortest path pair algorithm
5151

5252
! Lagrange bubbles constants
5353
integer, parameter :: mapCells = 3 !< Number of cells around the bubble where the smoothening function will have effect
5454
real(wp), parameter :: R_uni = 8314._wp ! Universal gas constant - J/kmol/K
5555

5656
! Strang Splitting constants
57-
real(wp), parameter :: dflt_adap_dt_tol = 1e-4_wp !< Default tolerance for adaptive step size
57+
real(wp), parameter :: dflt_adap_dt_tol = 1.e-4_wp !< Default tolerance for adaptive step size
5858
integer, parameter :: adap_dt_max_iters = 100 !< Maximum number of iterations
5959
! Constants of the algorithm described by Heirer, E. Hairer S.P.Nørsett G. Wanner, Solving Ordinary Differential Equations I, Chapter II.4
6060
! to choose the initial time step size for the adaptive time stepping routine
61-
real(wp), parameter :: threshold_first_guess = 1e-5_wp
62-
real(wp), parameter :: threshold_second_guess = 1e-15_wp
63-
real(wp), parameter :: scale_first_guess = 1e-3_wp
64-
real(wp), parameter :: scale_guess = 1e-2_wp
65-
real(wp), parameter :: small_guess = 1e-6_wp
61+
real(wp), parameter :: threshold_first_guess = 1.e-5_wp
62+
real(wp), parameter :: threshold_second_guess = 1.e-15_wp
63+
real(wp), parameter :: scale_first_guess = 1.e-3_wp
64+
real(wp), parameter :: scale_guess = 1.e-2_wp
65+
real(wp), parameter :: small_guess = 1.e-6_wp
6666

6767
! Relativity
6868
integer, parameter :: relativity_cons_to_prim_max_iter = 100

0 commit comments

Comments
 (0)