Skip to content

Commit d14900c

Browse files
committed
Formatting
1 parent ec14e77 commit d14900c

File tree

4 files changed

+139
-148
lines changed

4 files changed

+139
-148
lines changed

examples/2D_Detonation/case.py

Lines changed: 85 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,121 @@
11
import json, argparse
22
import cantera as ct
33

4-
parser = argparse.ArgumentParser(
5-
prog="2D_Detonation",
6-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4+
parser = argparse.ArgumentParser(prog="2D_Detonation", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
75

8-
parser.add_argument("--mfc", type=json.loads, default='{}', metavar="DICT",
9-
help="MFC's toolchain's internal state.")
10-
parser.add_argument("--no-chem", dest='chemistry', default=True, action="store_false",
11-
help="Disable chemistry.")
12-
parser.add_argument("--scale", type=float, default=1, help="Scale.")
6+
parser.add_argument("--mfc", type=json.loads, default="{}", metavar="DICT", help="MFC's toolchain's internal state.")
7+
parser.add_argument("--no-chem", dest="chemistry", default=True, action="store_false", help="Disable chemistry.")
8+
parser.add_argument("--scale", type=float, default=1, help="Scale.")
139

1410
args = parser.parse_args()
1511

16-
ctfile = 'h2o2.yaml'
17-
sol_L = ct.Solution(ctfile)
18-
sol_L.DPX = 0.072, 7173, 'H2:2,O2:1,AR:7'
12+
ctfile = "h2o2.yaml"
13+
sol_L = ct.Solution(ctfile)
14+
sol_L.DPX = 0.072, 7173, "H2:2,O2:1,AR:7"
1915

20-
sol_R = ct.Solution(ctfile)
21-
sol_R.DPX = 0.18075, 35594, 'H2:2,O2:1,AR:7'
16+
sol_R = ct.Solution(ctfile)
17+
sol_R.DPX = 0.18075, 35594, "H2:2,O2:1,AR:7"
2218

2319
u_l = 0
2420
u_r = -487.34
2521

26-
L = 0.12
22+
L = 0.12
2723
Nx = 800
2824
Ny = 200
29-
dx = L/Nx
30-
dy = (L/4)/Ny
31-
dt = min(dx,dy)/abs(u_r)*0.05*0.1*0.2
32-
Tend=830e-6
25+
dx = L / Nx
26+
dy = (L / 4) / Ny
27+
dt = min(dx, dy) / abs(u_r) * 0.05 * 0.1 * 0.2
28+
Tend = 830e-6
3329

34-
NT=int(Tend/dt)
35-
SAVE_COUNT=100
36-
NS=NT//SAVE_COUNT
30+
NT = int(Tend / dt)
31+
SAVE_COUNT = 100
32+
NS = NT // SAVE_COUNT
3733

3834
case = {
3935
# Logistics ================================================================
40-
'run_time_info' : 'T',
36+
"run_time_info": "T",
4137
# ==========================================================================
42-
4338
# Computational Domain Parameters ==========================================
44-
'x_domain%beg' : 0,
45-
'x_domain%end' : L,
46-
'y_domain%beg' : 0,
47-
'y_domain%end' : L/4,
48-
'm' : Nx,
49-
'n' : Ny,
50-
'p' : 0,
51-
'dt' : float(dt),
52-
't_step_start' : 0,
53-
't_step_stop' : 1,
54-
't_step_save' : 1,
55-
't_step_print' : 1,
56-
'parallel_io' : 'F', #if args.mfc.get("mpi", True) else 'F',
57-
39+
"x_domain%beg": 0,
40+
"x_domain%end": L,
41+
"y_domain%beg": 0,
42+
"y_domain%end": L / 4,
43+
"m": Nx,
44+
"n": Ny,
45+
"p": 0,
46+
"dt": float(dt),
47+
"t_step_start": 0,
48+
"t_step_stop": 1,
49+
"t_step_save": 1,
50+
"t_step_print": 1,
51+
"parallel_io": "F", # if args.mfc.get("mpi", True) else 'F',
5852
# Simulation Algorithm Parameters ==========================================
59-
'model_eqns' : 2,
60-
'num_fluids' : 1,
61-
'num_patches' : 2,
62-
'mpp_lim' : 'F',
63-
'mixture_err' : 'F',
64-
'time_stepper' : 3,
65-
'weno_order' : 5,
66-
'weno_eps' : 1E-16,
67-
'weno_avg' : 'F',
68-
'mapped_weno' : 'T',
69-
'mp_weno' : 'T',
70-
'riemann_solver' : 2,
71-
'wave_speeds' : 1,
72-
'avg_state' : 2,
73-
'bc_x%beg' :-3,
74-
'bc_x%end' :-3,
75-
'bc_y%beg' :-1,
76-
'bc_y%end' :-1,
77-
53+
"model_eqns": 2,
54+
"num_fluids": 1,
55+
"num_patches": 2,
56+
"mpp_lim": "F",
57+
"mixture_err": "F",
58+
"time_stepper": 3,
59+
"weno_order": 5,
60+
"weno_eps": 1e-16,
61+
"weno_avg": "F",
62+
"mapped_weno": "T",
63+
"mp_weno": "T",
64+
"riemann_solver": 2,
65+
"wave_speeds": 1,
66+
"avg_state": 2,
67+
"bc_x%beg": -3,
68+
"bc_x%end": -3,
69+
"bc_y%beg": -1,
70+
"bc_y%end": -1,
7871
# Chemistry ================================================================
79-
'chemistry' : 'T' if not args.chemistry else 'T',
80-
'chem_params%diffusion' : 'F',
81-
'chem_params%reactions' : 'F',
82-
'cantera_file' : ctfile,
72+
"chemistry": "T" if not args.chemistry else "T",
73+
"chem_params%diffusion": "F",
74+
"chem_params%reactions": "F",
75+
"cantera_file": ctfile,
8376
# ==========================================================================
84-
8577
# Formatted Database Files Structure Parameters ============================
86-
'format' : 1,
87-
'precision' : 2,
88-
'prim_vars_wrt' : 'T',
89-
'chem_wrt_T' : 'T',
78+
"format": 1,
79+
"precision": 2,
80+
"prim_vars_wrt": "T",
81+
"chem_wrt_T": "T",
9082
# ==========================================================================
91-
'patch_icpp(1)%geometry' : 3,
92-
'patch_icpp(1)%x_centroid' : L/2,
93-
'patch_icpp(1)%y_centroid' : L/8,
94-
'patch_icpp(1)%length_x' : L,
95-
'patch_icpp(1)%length_y' : L/4,
96-
'patch_icpp(1)%vel(1)' : -487.34,
97-
'patch_icpp(1)%vel(2)' : 0.0,
98-
'patch_icpp(1)%pres' : sol_R.P,
99-
'patch_icpp(1)%alpha(1)' : 1,
100-
'patch_icpp(1)%alpha_rho(1)' : sol_R.density,
83+
"patch_icpp(1)%geometry": 3,
84+
"patch_icpp(1)%x_centroid": L / 2,
85+
"patch_icpp(1)%y_centroid": L / 8,
86+
"patch_icpp(1)%length_x": L,
87+
"patch_icpp(1)%length_y": L / 4,
88+
"patch_icpp(1)%vel(1)": -487.34,
89+
"patch_icpp(1)%vel(2)": 0.0,
90+
"patch_icpp(1)%pres": sol_R.P,
91+
"patch_icpp(1)%alpha(1)": 1,
92+
"patch_icpp(1)%alpha_rho(1)": sol_R.density,
10193
# ==========================================================================
10294
# ==========================================================================
10395
# ==========================================================================
104-
'patch_icpp(2)%geometry' : 7,
105-
'patch_icpp(2)%x_centroid' : L/4,
106-
'patch_icpp(2)%y_centroid' : L/8,
107-
'patch_icpp(2)%length_x' : L/2,
108-
'patch_icpp(2)%length_y' : L/4,
109-
'patch_icpp(2)%hcid' : 270,
110-
'patch_icpp(2)%vel(1)' : 0,
111-
'patch_icpp(2)%vel(2)' : 0,
112-
'patch_icpp(2)%pres' : sol_R.P,
113-
'patch_icpp(2)%alpha(1)' : 1,
114-
'patch_icpp(2)%alpha_rho(1)' : sol_R.density,
115-
# 'patch_icpp(1)%alter_patch(1)' : 'F',
116-
'patch_icpp(2)%alter_patch(1)' : 'T',
96+
"patch_icpp(2)%geometry": 7,
97+
"patch_icpp(2)%x_centroid": L / 4,
98+
"patch_icpp(2)%y_centroid": L / 8,
99+
"patch_icpp(2)%length_x": L / 2,
100+
"patch_icpp(2)%length_y": L / 4,
101+
"patch_icpp(2)%hcid": 270,
102+
"patch_icpp(2)%vel(1)": 0,
103+
"patch_icpp(2)%vel(2)": 0,
104+
"patch_icpp(2)%pres": sol_R.P,
105+
"patch_icpp(2)%alpha(1)": 1,
106+
"patch_icpp(2)%alpha_rho(1)": sol_R.density,
107+
# 'patch_icpp(1)%alter_patch(1)' : 'F',
108+
"patch_icpp(2)%alter_patch(1)": "T",
117109
# ==========================================================================
118110
# Fluids Physical Parameters ===============================================
119-
'fluid_pp(1)%gamma' : 1.0E+00/(4.4E+00-1.0E+00),
120-
'fluid_pp(1)%pi_inf' : 0,
111+
"fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00),
112+
"fluid_pp(1)%pi_inf": 0,
121113
# ==========================================================================
122114
}
123115

124116
if args.chemistry:
125-
for i in range(len(sol_L.Y)):
126-
case[f'chem_wrt_Y({1})'] = 'T'
117+
for i in range(len(sol_L.Y)):
118+
case[f"chem_wrt_Y({1})"] = "T"
127119

128-
if __name__ == '__main__':
120+
if __name__ == "__main__":
129121
print(json.dumps(case))

src/pre_process/include/1dHardcodedIC.fpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
!> initial conditions for your simulation based on those 1D results.
99
!>
1010
!> It provides:
11-
!> - Import of files named
12-
!> `prim.<variable>.00.<timestep>.dat`
11+
!> - Import of files named
12+
!> `prim.<variable>.00.<timestep>.dat`
1313
!> (produced when parallel I/O is disabled in `case.py`).
1414
!> - Configurable parameters:
1515
!> - @c nFiles: total number of primitive‐variable files.
@@ -25,7 +25,7 @@
2525
integer :: f, iter, ios, unit, idx
2626
real(wp) :: x_len, x_step
2727
integer :: global_offset ! MPI subdomain offset
28-
real(wp) :: delta
28+
real(wp) :: delta
2929
character(len=100), dimension(nFiles) :: fileNames ! Arrays to store all data from files
3030
character(len=200) :: errmsg
3131
real(wp), dimension(nRows, nFiles) :: stored_values ! Imported Data
@@ -67,8 +67,8 @@
6767
do iter = 1, nRows
6868
read (unit, *, iostat=ios) x_coords(iter), stored_values(iter, f)
6969
if (ios /= 0) then
70-
write(errmsg, '(A,A,A,I0,A)') ' Error reading "', trim(fileNames(f)), &
71-
'" at index (', iter, ')'
70+
write (errmsg, '(A,A,A,I0,A)') ' Error reading "', trim(fileNames(f)), &
71+
'" at index (', iter, ')'
7272
call s_mpi_abort(trim(errmsg)) ! Exit loop on error
7373
end if
7474
end do

src/pre_process/include/2dHardcodedIC.fpp

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
q_prim_vf(advxe)%sf(i, j, 0) = patch_icpp(1)%alpha(2)
170170
end if
171171

172-
case (250) ! MHD Orszag-Tang vortex
172+
case (250) ! MHD Orszag-Tang vortex
173173
! gamma = 5/3
174174
! rho = 25/(36*pi)
175175
! p = 5/(12*pi)
@@ -197,48 +197,47 @@
197197
q_prim_vf(E_idx)%sf(i, j, 0) = 3.e-5_wp
198198
end if
199199

200-
case (270)
201-
if (.not. files_loaded) then
202-
! Print status message
203-
index_1 = i
204-
do f = 1, nFiles
205-
! Open the file for reading
206-
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
207-
if (ios /= 0) then
208-
cycle ! Skip this file on error
209-
end if
210-
! Read all rows at once into memory
211-
do iter = 1, nRows
212-
read (unit, *, iostat=ios) x_coords(iter), stored_values(iter, f)
213-
if (ios /= 0) then
214-
write(errmsg, '(A,A,A,I0,A)') 'Error reading "', trim(fileNames(f)), &
215-
'" at index (', iter,')'
216-
call s_mpi_abort(trim(errmsg)) ! Exit loop on error
217-
end if
218-
end do
219-
close (unit)
220-
end do
221-
! Calculate domain information for mapping
222-
domain_start = x_coords(1)
223-
domain_end = x_coords(nRows)
224-
x_step = x_cc(1) - x_cc(0)
225-
delta_x = x_cc(index_1) - domain_start + x_step/2
226-
global_offset = nint(abs(delta_x)/x_step)
227-
files_loaded = .true.
228-
end if
229-
! Calculate the index in the file data array corresponding to x_cc(i)
230-
idx = i + 1 + global_offset - index_1
231-
do f = 1, nFiles
232-
if (f .ge. momxe) then
233-
jump = 1
234-
else
235-
jump = 0
236-
end if
237-
q_prim_vf(f + jump)%sf(i, j, 0) = stored_values(idx, f)
238-
end do
239-
! Set element the velocity paraller to y explicitly to zero
240-
q_prim_vf(momxe)%sf(i, j, 0) = 0.0_wp
241-
200+
case (270)
201+
if (.not. files_loaded) then
202+
! Print status message
203+
index_1 = i
204+
do f = 1, nFiles
205+
! Open the file for reading
206+
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
207+
if (ios /= 0) then
208+
cycle ! Skip this file on error
209+
end if
210+
! Read all rows at once into memory
211+
do iter = 1, nRows
212+
read (unit, *, iostat=ios) x_coords(iter), stored_values(iter, f)
213+
if (ios /= 0) then
214+
write (errmsg, '(A,A,A,I0,A)') 'Error reading "', trim(fileNames(f)), &
215+
'" at index (', iter, ')'
216+
call s_mpi_abort(trim(errmsg)) ! Exit loop on error
217+
end if
218+
end do
219+
close (unit)
220+
end do
221+
! Calculate domain information for mapping
222+
domain_start = x_coords(1)
223+
domain_end = x_coords(nRows)
224+
x_step = x_cc(1) - x_cc(0)
225+
delta_x = x_cc(index_1) - domain_start + x_step/2
226+
global_offset = nint(abs(delta_x)/x_step)
227+
files_loaded = .true.
228+
end if
229+
! Calculate the index in the file data array corresponding to x_cc(i)
230+
idx = i + 1 + global_offset - index_1
231+
do f = 1, nFiles
232+
if (f >= momxe) then
233+
jump = 1
234+
else
235+
jump = 0
236+
end if
237+
q_prim_vf(f + jump)%sf(i, j, 0) = stored_values(idx, f)
238+
end do
239+
! Set element the velocity paraller to y explicitly to zero
240+
q_prim_vf(momxe)%sf(i, j, 0) = 0.0_wp
242241

243242
case default
244243
if (proc_rank == 0) then

src/pre_process/include/3dHardcodedIC.fpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
!> @param xRows Number of grid points in the x-direction
1111
!> @param yRows Number of grid points in the y-direction
1212
!> @param init_dir Directory containing the `prim.*.dat` files
13-
13+
1414
! Place any declaration of intermediate variables here
1515
real(wp) :: rhoH, rhoL, pRef, pInt, h, lam, wl, amp, intH, alph
1616

@@ -19,7 +19,7 @@
1919
integer, parameter :: nFiles = 15 ! Number of files (variables)
2020
integer, parameter :: xRows = 401 ! Number of points in x
2121
integer, parameter :: yRows = 403 ! Number of points in y
22-
integer, parameter :: nRows = xRows*yRows
22+
integer, parameter :: nRows = xRows*yRows
2323
integer :: f, iter, ios, unit, idx, idy, jump, index_x, index_y
2424
real(wp) :: x_len, x_step, y_len, y_step
2525
integer :: global_offset_x, global_offset_y ! MPI subdomain offsets
@@ -118,8 +118,8 @@
118118
iter = iter + 1
119119
read (unit, *, iostat=ios) x_coords(iter), y_coords(iter), stored_values(iix, iiy, 1)
120120
if (ios /= 0) then
121-
write(errmsg, '(A,A,A,I0,A)') 'Error reading "', trim(fileNames(1)), &
122-
'" at indices (', iix, ',', iiy, ')'
121+
write (errmsg, '(A,A,A,I0,A)') 'Error reading "', trim(fileNames(1)), &
122+
'" at indices (', iix, ',', iiy, ')'
123123
call s_mpi_abort(trim(errmsg))
124124
end if
125125
end do
@@ -136,8 +136,8 @@
136136
! Read and discard x,y, then read the value
137137
read (unit, *, iostat=ios) dummy_x, dummy_y, stored_values(iix, iiy, f)
138138
if (ios /= 0) then
139-
write(errmsg, '(A,A,I0,A,I0,A)') 'Error reading "', trim(fileNames(f)), &
140-
'" at indices (', iix, ',', iiy, ')'
139+
write (errmsg, '(A,A,I0,A,I0,A)') 'Error reading "', trim(fileNames(f)), &
140+
'" at indices (', iix, ',', iiy, ')'
141141
call s_mpi_abort(trim(errmsg))
142142
end if
143143
end do
@@ -169,7 +169,7 @@
169169
data_j = j + 1 + global_offset_y - index_y ! y-direction index in data grid
170170

171171
do f = 1, nFiles
172-
if (f .ge. momxe) then
172+
if (f >= momxe) then
173173
jump = 1
174174
else
175175
jump = 0

0 commit comments

Comments
 (0)