Skip to content

Commit d6a4128

Browse files
committed
Integrate ffmt Fortran formatter into MFC
Replace fprettify + indenter.py with ffmt (https://github.com/sbryngelson/ffmt), a fast, configurable Fortran formatter written in Rust. Integration: - toolchain/bootstrap/format.sh: single ffmt call replaces multi-pass fprettify + indenter.py loop - toolchain/pyproject.toml: replace fprettify dependency with ffmt - ffmt.toml: MFC formatting configuration - .gitignore: add .ffmt_cache/ - Remove toolchain/indenter.py Source formatting: - All .fpp/.f90 files reformatted with ffmt v0.2.0 - Unicode symbols replaced with LaTeX (sigma, pi, partial, etc.) - Operator spacing, keyword casing, declaration alignment - Named end statements, comment wrapping at 132 chars - Doxygen comment block re-wrapping Install: pip install ffmt Repo: https://github.com/sbryngelson/ffmt
1 parent febffab commit d6a4128

File tree

87 files changed

+11278
-17617
lines changed

Some content is hidden

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

87 files changed

+11278
-17617
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ benchmarks/*.png
113113
cce_*/
114114
cce_*.log
115115
run_cce_*.sh
116+
.ffmt_cache/

ffmt.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# MFC Fortran formatting configuration
2+
# These are the defaults — this file makes them explicit.
3+
4+
indent-width = 4
5+
keyword-case = "lower"
6+
normalize-keywords = true
7+
indent-fypp = true
8+
9+
[whitespace]
10+
relational = true
11+
logical = true
12+
plusminus = true
13+
multdiv = false
14+
power = false
15+
assignment = true
16+
declaration = true
17+
comma = true

src/common/include/1dHardcodedIC.fpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
! magnetic field
1414
q_prim_vf(B_idx%end - 1)%sf(i, 0, 0) = 0.1_wp*sin(2._wp*pi*x_cc(i))
1515
q_prim_vf(B_idx%end)%sf(i, 0, 0) = 0.1_wp*cos(2._wp*pi*x_cc(i))
16-
1716
case (170)
18-
! This hardcoded case can be used to start a simulation with initial conditions given from a known 1D profile (e.g. Cantera, SDtoolbox)
17+
! This hardcoded case can be used to start a simulation with initial conditions given from a known 1D profile (e.g. Cantera,
18+
! SDtoolbox)
1919
@: HardcodedReadValues()
20-
2120
case (180)
2221
! This is patch is hard-coded for test suite optimization used in the
2322
! 1D_shuoser cases: "patch_icpp(2)%alpha_rho(1)": "1 + 0.2*sin(5*x)"
2423
if (patch_id == 2) then
2524
q_prim_vf(contxb + 0)%sf(i, 0, 0) = 1 + 0.2*sin(5*x_cc(i))
2625
end if
27-
2826
case (181)
2927
! This is patch is hard-coded for test suite optimization used in the
3028
! 1D_titarevtorro cases: "patch_icpp(2)%alpha_rho(1)": "1 + 0.1*sin(20*x*pi)"
3129
q_prim_vf(contxb + 0)%sf(i, 0, 0) = 1 + 0.1*sin(20*x_cc(i)*pi)
32-
3330
case (182)
3431
! This patch is a hard-coded for test suite optimization (multiple component diffusion)
3532
x_mid_diffu = 0.05_wp/2.0_wp
@@ -51,16 +48,11 @@
5148

5249
temp = (320.0_wp - 1350.0_wp)*profile_shape + 1350.0_wp
5350

54-
molar_mass_inv = y1/31.998_wp + &
55-
y2/18.01508_wp + &
56-
y3/16.04256_wp + &
57-
y4/28.0134_wp
51+
molar_mass_inv = y1/31.998_wp + y2/18.01508_wp + y3/16.04256_wp + y4/28.0134_wp
5852

5953
q_prim_vf(contxb)%sf(i, 0, 0) = 1.01325_wp*(10.0_wp)**5/(temp*8.3144626_wp*1000.0_wp*molar_mass_inv)
60-
6154
case default
6255
call s_int_to_str(patch_id, iStr)
63-
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
56+
call s_mpi_abort("Invalid hcid specified for patch " // trim(iStr))
6457
end select
65-
6658
#:enddef

src/common/include/2dHardcodedIC.fpp

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
real(wp) :: factor
77
real(wp) :: r0, alpha, r2
88
real(wp) :: sinA, cosA
9-
109
real(wp) :: r_sq
1110

1211
! # 207
@@ -18,9 +17,7 @@
1817
#:enddef
1918

2019
#:def Hardcoded2D()
21-
2220
select case (patch_icpp(patch_id)%hcid) ! 2D_hardcoded_ic example case
23-
2421
case (200)
2522
if (y_cc(j) <= (-x_cc(i)**3 + 1)**(1._wp/3._wp)) then
2623
! Volume Fractions
@@ -107,11 +104,10 @@
107104
pInt = pref + rhoH*9.81_wp*(1.2_wp - intH)
108105
q_prim_vf(E_idx)%sf(i, j, 0) = pInt + rhoL*9.81_wp*(intH - y_cc(j))
109106
end if
110-
111107
case (205) ! 2D lung wave interaction problem
112-
h = 0.0_wp !non dim origin y
113-
lam = 1.0_wp !non dim lambda
114-
amp = patch_icpp(patch_id)%a(2) !to be changed later! !non dim amplitude
108+
h = 0.0_wp ! non dim origin y
109+
lam = 1.0_wp ! non dim lambda
110+
amp = patch_icpp(patch_id)%a(2) ! to be changed later! !non dim amplitude
115111

116112
intH = amp*sin(2*pi*x_cc(i)/lam - pi/2) + h
117113

@@ -122,29 +118,25 @@
122118
q_prim_vf(advxb)%sf(i, j, 0) = patch_icpp(1)%alpha(1)
123119
q_prim_vf(advxe)%sf(i, j, 0) = patch_icpp(1)%alpha(2)
124120
end if
125-
126121
case (206) ! 2D lung wave interaction problem - horizontal domain
127-
h = 0.0_wp !non dim origin y
128-
lam = 1.0_wp !non dim lambda
122+
h = 0.0_wp ! non dim origin y
123+
lam = 1.0_wp ! non dim lambda
129124
amp = patch_icpp(patch_id)%a(2)
130125

131126
intL = amp*sin(2*pi*y_cc(j)/lam - pi/2) + h
132127

133-
if (x_cc(i) > intL) then !this is the liquid
128+
if (x_cc(i) > intL) then ! this is the liquid
134129
q_prim_vf(contxb)%sf(i, j, 0) = patch_icpp(1)%alpha_rho(1)
135130
q_prim_vf(contxe)%sf(i, j, 0) = patch_icpp(1)%alpha_rho(2)
136131
q_prim_vf(E_idx)%sf(i, j, 0) = patch_icpp(1)%pres
137132
q_prim_vf(advxb)%sf(i, j, 0) = patch_icpp(1)%alpha(1)
138133
q_prim_vf(advxe)%sf(i, j, 0) = patch_icpp(1)%alpha(2)
139134
end if
140-
141135
case (207) ! Kelvin Helmholtz Instability
142136
sigma = 0.05_wp/sqrt(2.0_wp)
143137
gauss1 = exp(-(y_cc(j) - 0.75_wp)**2/(2.0_wp*sigma**2))
144138
gauss2 = exp(-(y_cc(j) - 0.25_wp)**2/(2.0_wp*sigma**2))
145-
q_prim_vf(momxb + 1)%sf(i, j, 0) = &
146-
0.1_wp*sin(4.0_wp*pi*x_cc(i))*(gauss1 + gauss2)
147-
139+
q_prim_vf(momxb + 1)%sf(i, j, 0) = 0.1_wp*sin(4.0_wp*pi*x_cc(i))*(gauss1 + gauss2)
148140
case (208) ! Richtmeyer Meshkov Instability
149141
lam = 1.0_wp
150142
eps = 1.0e-6_wp
@@ -160,7 +152,6 @@
160152
q_prim_vf(advxb)%sf(i, j, 0) = alpha_sf6
161153
q_prim_vf(advxe)%sf(i, j, 0) = alpha_air
162154
end if
163-
164155
case (250) ! MHD Orszag-Tang vortex
165156
! gamma = 5/3
166157
! rho = 25/(36*pi)
@@ -173,12 +164,11 @@
173164

174165
q_prim_vf(B_idx%beg)%sf(i, j, 0) = -sin(2._wp*pi*y_cc(j))/sqrt(4._wp*pi)
175166
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = sin(4._wp*pi*x_cc(i))/sqrt(4._wp*pi)
176-
177167
case (251) ! RMHD Cylindrical Blast Wave [Mignone, 2006: Section 4.3.1]
178168
if (x_cc(i)**2 + y_cc(j)**2 < 0.08_wp**2) then
179169
q_prim_vf(contxb)%sf(i, j, 0) = 0.01
180170
q_prim_vf(E_idx)%sf(i, j, 0) = 1.0
181-
elseif (x_cc(i)**2 + y_cc(j)**2 <= 1._wp**2) then
171+
else if (x_cc(i)**2 + y_cc(j)**2 <= 1._wp**2) then
182172
! Linear interpolation between r=0.08 and r=1.0
183173
factor = (1.0_wp - sqrt(x_cc(i)**2 + y_cc(j)**2))/(1.0_wp - 0.08_wp)
184174
q_prim_vf(contxb)%sf(i, j, 0) = 0.01_wp*factor + 1.e-4_wp*(1.0_wp - factor)
@@ -223,7 +213,6 @@
223213
q_prim_vf(momxb)%sf(i, j, 0) = -(2._wp/sqrt(r_sq))*(y_cc(j) - 0.5_wp)*(0.115_wp - sqrt(r_sq))/(0.015_wp)
224214
q_prim_vf(momxb + 1)%sf(i, j, 0) = (2._wp/sqrt(r_sq))*(x_cc(i) - 0.5_wp)*(0.115_wp - sqrt(r_sq))/(0.015_wp)
225215
end if
226-
227216
case (253) ! MHD Smooth Magnetic Vortex
228217
! Section 5.2 of
229218
! Implicit hybridized discontinuous Galerkin methods for compressible magnetohydrodynamics
@@ -238,22 +227,21 @@
238227
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = x_cc(i)*exp(1 - (x_cc(i)**2 + y_cc(j)**2))/(2.*pi)
239228

240229
! pressure
241-
q_prim_vf(E_idx)%sf(i, j, 0) = 1._wp + (1 - 2._wp*(x_cc(i)**2 + y_cc(j)**2))*exp(1 - (x_cc(i)**2 + y_cc(j)**2))/((2._wp*pi)**3)
242-
243-
case (260) ! Gaussian Divergence Pulse
244-
! Bx(x) = 1 + C * erf((x-0.5)/σ)
245-
! ⇒ ∂Bx/∂x = C * (2/√π) * exp[-((x-0.5)/σ)**2] * (1/σ)
246-
! Choose C = ε * σ * √π / 2 ⇒ ∂Bx/∂x = ε * exp[-((x-0.5)/σ)**2]
247-
! ψ is initialized to zero everywhere.
230+
q_prim_vf(E_idx)%sf(i, j, &
231+
& 0) = 1._wp + (1 - 2._wp*(x_cc(i)**2 + y_cc(j)**2))*exp(1 - (x_cc(i)**2 + y_cc(j)**2))/((2._wp*pi)**3)
232+
case (260) ! Gaussian Divergence Pulse
233+
! Bx(x) = 1 + C * erf((x-0.5)/\sigma)
234+
! => \partialBx/\partialx = C * (2/\sqrt\pi) * exp[-((x-0.5)/\sigma)**2] * (1/\sigma)
235+
! Choose C = \epsilon * \sigma * \sqrt\pi / 2 => \partialBx/\partialx = \epsilon * exp[-((x-0.5)/\sigma)**2]
236+
! \psi is initialized to zero everywhere.
248237

249238
eps_mhd = patch_icpp(patch_id)%a(2)
250239
sigma = patch_icpp(patch_id)%a(3)
251240
C_mhd = eps_mhd*sigma*sqrt(pi)*0.5_wp
252241

253242
! B-field
254243
q_prim_vf(B_idx%beg)%sf(i, j, 0) = 1._wp + C_mhd*erf((x_cc(i) - 0.5_wp)/sigma)
255-
256-
case (261) ! Blob
244+
case (261) ! Blob
257245
r0 = 1._wp/sqrt(8._wp)
258246
r2 = x_cc(i)**2 + y_cc(j)**2
259247
r = sqrt(r2)
@@ -264,79 +252,80 @@
264252
! q_prim_vf(B_idx%beg)%sf(i,j,0) = 1._wp/(4._wp*pi) * (alpha**8 - 2._wp*alpha**4 + 1._wp)
265253
! q_prim_vf(E_idx)%sf(i,j,0) = 6._wp - q_prim_vf(B_idx%beg)%sf(i,j,0)**2/2._wp
266254
end if
267-
268-
case (262) ! Tilted 2D MHD shock‐tube at α = arctan2 (≈63.4°)
269-
! rotate by α = atan(2)
255+
case (262) ! Tilted 2D MHD shock‐tube at α = arctan2 (≈63.4°)
256+
! rotate by \alpha = atan(2)
270257
alpha = atan(2._wp)
271258
cosA = cos(alpha)
272259
sinA = sin(alpha)
273260
! projection along shock normal
274261
r = x_cc(i)*cosA + y_cc(j)*sinA
275262

276263
if (r <= 0.5_wp) then
277-
! LEFT state: ρ=1, v=+10, v=0, p=20, B=B⊥=5/√(4π)
264+
! LEFT state: \rho=1, v\parallel=+10, v\perp=0, p=20, B\parallel=B\perp=5/\sqrt(4\pi)
278265
q_prim_vf(contxb)%sf(i, j, 0) = 1._wp
279266
q_prim_vf(momxb)%sf(i, j, 0) = 10._wp*cosA
280267
q_prim_vf(momxb + 1)%sf(i, j, 0) = 10._wp*sinA
281268
q_prim_vf(E_idx)%sf(i, j, 0) = 20._wp
282-
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA &
283-
- (5._wp/sqrt(4._wp*pi))*sinA
284-
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*sinA &
285-
+ (5._wp/sqrt(4._wp*pi))*cosA
269+
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA - (5._wp/sqrt(4._wp*pi))*sinA
270+
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*sinA + (5._wp/sqrt(4._wp*pi))*cosA
286271
else
287-
! RIGHT state: ρ=1, v=10, v=0, p=1, B=B⊥=5/√(4π)
272+
! RIGHT state: \rho=1, v\parallel=-10, v\perp=0, p=1, B\parallel=B\perp=5/\sqrt(4\pi)
288273
q_prim_vf(contxb)%sf(i, j, 0) = 1._wp
289274
q_prim_vf(momxb)%sf(i, j, 0) = -10._wp*cosA
290275
q_prim_vf(momxb + 1)%sf(i, j, 0) = -10._wp*sinA
291276
q_prim_vf(E_idx)%sf(i, j, 0) = 1._wp
292-
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA &
293-
- (5._wp/sqrt(4._wp*pi))*sinA
294-
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*sinA &
295-
+ (5._wp/sqrt(4._wp*pi))*cosA
277+
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA - (5._wp/sqrt(4._wp*pi))*sinA
278+
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*sinA + (5._wp/sqrt(4._wp*pi))*cosA
296279
end if
297280
! v^z and B^z remain zero by default
298-
299281
case (270)
300282
! This hardcoded case extrudes a 1D profile to initialize a 2D simulation domain
301283
@: HardcodedReadValues()
302-
303284
case (280)
304285
! This is patch is hard-coded for test suite optimization used in the
305286
! 2D_isentropicvortex case:
306287
! This analytic patch uses geometry 2
307288
if (patch_id == 1) then
308-
q_prim_vf(E_idx)%sf(i, j, 0) = 1.0*(1.0 - (1.0/1.0)*(5.0/(2.0*pi))*(5.0/(8.0*1.0*(1.4 + 1.0)*pi))*exp(2.0*1.0*(1.0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**(1.4 + 1.0)
309-
q_prim_vf(contxb + 0)%sf(i, j, 0) = 1.0*(1.0 - (1.0/1.0)*(5.0/(2.0*pi))*(5.0/(8.0*1.0*(1.4 + 1.0)*pi))*exp(2.0*1.0*(1.0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**1.4
310-
q_prim_vf(momxb + 0)%sf(i, j, 0) = 0.0 + (y_cc(j) - patch_icpp(1)%y_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
311-
q_prim_vf(momxb + 1)%sf(i, j, 0) = 0.0 - (x_cc(i) - patch_icpp(1)%x_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
289+
q_prim_vf(E_idx)%sf(i, j, &
290+
& 0) = 1.0*(1.0 - (1.0/1.0)*(5.0/(2.0*pi))*(5.0/(8.0*1.0*(1.4 + 1.0)*pi))*exp(2.0*1.0*(1.0 - (x_cc(i) &
291+
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**(1.4 + 1.0)
292+
q_prim_vf(contxb + 0)%sf(i, j, &
293+
& 0) = 1.0*(1.0 - (1.0/1.0)*(5.0/(2.0*pi))*(5.0/(8.0*1.0*(1.4 + 1.0)*pi))*exp(2.0*1.0*(1.0 - (x_cc(i) &
294+
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**1.4
295+
q_prim_vf(momxb + 0)%sf(i, j, &
296+
& 0) = 0.0 + (y_cc(j) - patch_icpp(1)%y_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) - patch_icpp(1) &
297+
& %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
298+
q_prim_vf(momxb + 1)%sf(i, j, &
299+
& 0) = 0.0 - (x_cc(i) - patch_icpp(1)%x_centroid)*(5.0/(2.0*pi))*exp(1.0*(1.0 - (x_cc(i) - patch_icpp(1) &
300+
& %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
312301
end if
313-
314302
case (281)
315303
! This is patch is hard-coded for test suite optimization used in the
316304
! 2D_acoustic_pulse case:
317305
! This analytic patch uses geometry 2
318306
if (patch_id == 2) then
319-
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))
320-
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))
307+
q_prim_vf(E_idx)%sf(i, j, &
308+
& 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))
309+
q_prim_vf(contxb + 0)%sf(i, j, &
310+
& 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))
321311
end if
322-
323312
case (282)
324313
! This is patch is hard-coded for test suite optimization used in the
325314
! 2D_zero_circ_vortex case:
326315
! This analytic patch uses geometry 2
327316
if (patch_id == 2) then
328-
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))
329-
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))
330-
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)))
317+
q_prim_vf(E_idx)%sf(i, j, &
318+
& 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))
319+
q_prim_vf(contxb + 0)%sf(i, j, &
320+
& 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))
321+
q_prim_vf(momxb + 0)%sf(i, j, &
322+
& 0) = 112.99092883944267*(1 - (0.1/0.3))*y_cc(j)*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2)))
331323
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)))
332324
end if
333-
334325
case default
335326
if (proc_rank == 0) then
336327
call s_int_to_str(patch_id, iStr)
337-
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
328+
call s_mpi_abort("Invalid hcid specified for patch " // trim(iStr))
338329
end if
339-
340330
end select
341-
342331
#:enddef

0 commit comments

Comments
 (0)