Skip to content

Commit 4bbff8d

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 4bbff8d

File tree

84 files changed

+10451
-13775
lines changed

Some content is hidden

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

84 files changed

+10451
-13775
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
q_prim_vf(B_idx%end)%sf(i, 0, 0) = 0.1_wp*cos(2._wp*pi*x_cc(i))
1616

1717
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)
18+
! This hardcoded case can be used to start a simulation with initial conditions given from a known 1D profile (e.g. Cantera,
19+
! SDtoolbox)
1920
@: HardcodedReadValues()
2021

2122
case (180)
@@ -51,16 +52,13 @@
5152

5253
temp = (320.0_wp - 1350.0_wp)*profile_shape + 1350.0_wp
5354

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

5957
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)
6058

6159
case default
6260
call s_int_to_str(patch_id, iStr)
63-
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
61+
call s_mpi_abort("Invalid hcid specified for patch " // trim(iStr))
6462
end select
6563

6664
#:enddef

src/common/include/2dHardcodedIC.fpp

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
end if
110110

111111
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
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
115115

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

@@ -124,13 +124,13 @@
124124
end if
125125

126126
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
127+
h = 0.0_wp ! non dim origin y
128+
lam = 1.0_wp ! non dim lambda
129129
amp = patch_icpp(patch_id)%a(2)
130130

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

133-
if (x_cc(i) > intL) then !this is the liquid
133+
if (x_cc(i) > intL) then ! this is the liquid
134134
q_prim_vf(contxb)%sf(i, j, 0) = patch_icpp(1)%alpha_rho(1)
135135
q_prim_vf(contxe)%sf(i, j, 0) = patch_icpp(1)%alpha_rho(2)
136136
q_prim_vf(E_idx)%sf(i, j, 0) = patch_icpp(1)%pres
@@ -142,8 +142,7 @@
142142
sigma = 0.05_wp/sqrt(2.0_wp)
143143
gauss1 = exp(-(y_cc(j) - 0.75_wp)**2/(2.0_wp*sigma**2))
144144
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)
145+
q_prim_vf(momxb + 1)%sf(i, j, 0) = 0.1_wp*sin(4.0_wp*pi*x_cc(i))*(gauss1 + gauss2)
147146

148147
case (208) ! Richtmeyer Meshkov Instability
149148
lam = 1.0_wp
@@ -178,7 +177,7 @@
178177
if (x_cc(i)**2 + y_cc(j)**2 < 0.08_wp**2) then
179178
q_prim_vf(contxb)%sf(i, j, 0) = 0.01
180179
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
180+
else if (x_cc(i)**2 + y_cc(j)**2 <= 1._wp**2) then
182181
! Linear interpolation between r=0.08 and r=1.0
183182
factor = (1.0_wp - sqrt(x_cc(i)**2 + y_cc(j)**2))/(1.0_wp - 0.08_wp)
184183
q_prim_vf(contxb)%sf(i, j, 0) = 0.01_wp*factor + 1.e-4_wp*(1.0_wp - factor)
@@ -238,13 +237,14 @@
238237
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)
239238

240239
! 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)
240+
q_prim_vf(E_idx)%sf(i, j, &
241+
& 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)
242242

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.
243+
case (260) ! Gaussian Divergence Pulse
244+
! Bx(x) = 1 + C * erf((x-0.5)/\sigma)
245+
! => \partialBx/\partialx = C * (2/\sqrt\pi) * exp[-((x-0.5)/\sigma)**2] * (1/\sigma)
246+
! Choose C = \epsilon * \sigma * \sqrt\pi / 2 => \partialBx/\partialx = \epsilon * exp[-((x-0.5)/\sigma)**2]
247+
! \psi is initialized to zero everywhere.
248248

249249
eps_mhd = patch_icpp(patch_id)%a(2)
250250
sigma = patch_icpp(patch_id)%a(3)
@@ -253,7 +253,7 @@
253253
! B-field
254254
q_prim_vf(B_idx%beg)%sf(i, j, 0) = 1._wp + C_mhd*erf((x_cc(i) - 0.5_wp)/sigma)
255255

256-
case (261) ! Blob
256+
case (261) ! Blob
257257
r0 = 1._wp/sqrt(8._wp)
258258
r2 = x_cc(i)**2 + y_cc(j)**2
259259
r = sqrt(r2)
@@ -265,34 +265,30 @@
265265
! q_prim_vf(E_idx)%sf(i,j,0) = 6._wp - q_prim_vf(B_idx%beg)%sf(i,j,0)**2/2._wp
266266
end if
267267

268-
case (262) ! Tilted 2D MHD shock‐tube at α = arctan2 (≈63.4°)
269-
! rotate by α = atan(2)
268+
case (262) ! Tilted 2D MHD shock‐tube at α = arctan2 (≈63.4°)
269+
! rotate by \alpha = atan(2)
270270
alpha = atan(2._wp)
271271
cosA = cos(alpha)
272272
sinA = sin(alpha)
273273
! projection along shock normal
274274
r = x_cc(i)*cosA + y_cc(j)*sinA
275275

276276
if (r <= 0.5_wp) then
277-
! LEFT state: ρ=1, v=+10, v=0, p=20, B=B⊥=5/√(4π)
277+
! LEFT state: \rho=1, v\parallel=+10, v\perp=0, p=20, B\parallel=B\perp=5/\sqrt(4\pi)
278278
q_prim_vf(contxb)%sf(i, j, 0) = 1._wp
279279
q_prim_vf(momxb)%sf(i, j, 0) = 10._wp*cosA
280280
q_prim_vf(momxb + 1)%sf(i, j, 0) = 10._wp*sinA
281281
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
282+
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA - (5._wp/sqrt(4._wp*pi))*sinA
283+
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
286284
else
287-
! RIGHT state: ρ=1, v=10, v=0, p=1, B=B⊥=5/√(4π)
285+
! RIGHT state: \rho=1, v\parallel=-10, v\perp=0, p=1, B\parallel=B\perp=5/\sqrt(4\pi)
288286
q_prim_vf(contxb)%sf(i, j, 0) = 1._wp
289287
q_prim_vf(momxb)%sf(i, j, 0) = -10._wp*cosA
290288
q_prim_vf(momxb + 1)%sf(i, j, 0) = -10._wp*sinA
291289
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
290+
q_prim_vf(B_idx%beg)%sf(i, j, 0) = (5._wp/sqrt(4._wp*pi))*cosA - (5._wp/sqrt(4._wp*pi))*sinA
291+
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
296292
end if
297293
! v^z and B^z remain zero by default
298294

@@ -305,36 +301,49 @@
305301
! 2D_isentropicvortex case:
306302
! This analytic patch uses geometry 2
307303
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))
304+
q_prim_vf(E_idx)%sf(i, j, &
305+
& 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) &
306+
& - patch_icpp(1)%x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0)))**(1.4 + 1.0)
307+
q_prim_vf(contxb + 0)%sf(i, j, &
308+
& 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) &
309+
& - 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, &
311+
& 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) &
312+
& %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
313+
q_prim_vf(momxb + 1)%sf(i, j, &
314+
& 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) &
315+
& %x_centroid)**2.0 - (y_cc(j) - patch_icpp(1)%y_centroid)**2.0))
312316
end if
313317

314318
case (281)
315319
! This is patch is hard-coded for test suite optimization used in the
316320
! 2D_acoustic_pulse case:
317321
! This analytic patch uses geometry 2
318322
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))
323+
q_prim_vf(E_idx)%sf(i, j, &
324+
& 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))
325+
q_prim_vf(contxb + 0)%sf(i, j, &
326+
& 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))
321327
end if
322328

323329
case (282)
324330
! This is patch is hard-coded for test suite optimization used in the
325331
! 2D_zero_circ_vortex case:
326332
! This analytic patch uses geometry 2
327333
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)))
334+
q_prim_vf(E_idx)%sf(i, j, &
335+
& 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))
336+
q_prim_vf(contxb + 0)%sf(i, j, &
337+
& 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))
338+
q_prim_vf(momxb + 0)%sf(i, j, &
339+
& 0) = 112.99092883944267*(1 - (0.1/0.3))*y_cc(j)*exp(0.5*(1 - sqrt(x_cc(i)**2 + y_cc(j)**2)))
331340
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)))
332341
end if
333342

334343
case default
335344
if (proc_rank == 0) then
336345
call s_int_to_str(patch_id, iStr)
337-
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
346+
call s_mpi_abort("Invalid hcid specified for patch " // trim(iStr))
338347
end if
339348

340349
end select

src/common/include/3dHardcodedIC.fpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
real(wp) :: rcut, xcut ! Intermediate variables for creating smooth initial condition
1212

1313
real(wp), dimension(0:n, 0:p) :: rcut_arr
14-
integer :: l, q, s ! Iterators for reading input files
15-
integer :: start, end ! Ints to keep track of position in file
16-
character(len=1000) :: line ! String to store line in ile
17-
character(len=25) :: value ! String to store value in line
18-
integer :: NJet ! Number of jets
14+
integer :: l, q, s ! Iterators for reading input files
15+
integer :: start, end ! Ints to keep track of position in file
16+
character(len=1000) :: line ! String to store line in ile
17+
character(len=25) :: value ! String to store value in line
18+
integer :: NJet ! Number of jets
1919

2020
eps = 1e-9_wp
2121

@@ -31,20 +31,20 @@
3131

3232
open (unit=10, file="jets.csv", status="old", action="read")
3333
do q = 0, NJet - 1
34-
read (10, '(A)') line ! Read a full line as a string
34+
read (10, '(A)') line ! Read a full line as a string
3535
start = 1
3636

3737
do l = 0, 2
38-
end = index(line(start:), ',') ! Find the next comma
38+
end = index(line(start:), ',') ! Find the next comma
3939
if (end == 0) then
40-
value = trim(adjustl(line(start:))) ! Last value in the line
40+
value = trim(adjustl(line(start:))) ! Last value in the line
4141
else
42-
value = trim(adjustl(line(start:start + end - 2))) ! Extract substring
43-
start = start + end ! Move to next value
42+
value = trim(adjustl(line(start:start + end - 2))) ! Extract substring
43+
start = start + end ! Move to next value
4444
end if
4545
if (l == 0) then
46-
read (value, *) y_th_arr(q) ! Convert string to numeric value
47-
elseif (l == 1) then
46+
read (value, *) y_th_arr(q) ! Convert string to numeric value
47+
else if (l == 1) then
4848
read (value, *) z_th_arr(q)
4949
else
5050
read (value, *) r_th_arr(q)
@@ -184,14 +184,15 @@
184184
! This analytic patch used geometry 9
185185
Mach = 0.1
186186
if (patch_id == 1) then
187-
q_prim_vf(E_idx)%sf(i, j, k) = 101325 + (Mach**2*376.636429464809**2/16)*(cos(2*x_cc(i)/1) + cos(2*y_cc(j)/1))*(cos(2*z_cc(k)/1) + 2)
187+
q_prim_vf(E_idx)%sf(i, j, &
188+
& k) = 101325 + (Mach**2*376.636429464809**2/16)*(cos(2*x_cc(i)/1) + cos(2*y_cc(j)/1))*(cos(2*z_cc(k)/1) + 2)
188189
q_prim_vf(momxb + 0)%sf(i, j, k) = Mach*376.636429464809*sin(x_cc(i)/1)*cos(y_cc(j)/1)*sin(z_cc(k)/1)
189190
q_prim_vf(momxb + 1)%sf(i, j, k) = -Mach*376.636429464809*cos(x_cc(i)/1)*sin(y_cc(j)/1)*sin(z_cc(k)/1)
190191
end if
191192

192193
case default
193194
call s_int_to_str(patch_id, iStr)
194-
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
195+
call s_mpi_abort("Invalid hcid specified for patch " // trim(iStr))
195196
end select
196197

197198
#:enddef

0 commit comments

Comments
 (0)