Skip to content

Commit 31822b8

Browse files
committed
Changes in Hardcoded implemention
1 parent 0342538 commit 31822b8

File tree

6 files changed

+65
-67
lines changed

6 files changed

+65
-67
lines changed

docs/documentation/case.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ specific timestep to be extended uniformly in the transverse direction and used
245245

246246
case(370) in 3dHardcodedIC.fpp: used to build 3D domains by extruding 2D data along the third dimension.
247247

248+
The variables xRows, yRows, and init_dir must be defined to specify the grid dimensions of the previous simulation and the directory where the input files are located.
248249
#### Parameter Descriptions
249250

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

examples/1D_reactive_shocktube/case.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#!/usr/bin/env python3
2-
# References:
3-
# + https://doi.org/10.1016/j.ijhydene.2023.03.190: Verification of numerical method
4-
# + https://doi.org/10.1016/j.compfluid.2013.10.014: 4.7. Multi-species reactive shock tube
5-
62
import json, argparse
73
import cantera as ct
84

examples/2D_Detonation/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"patch_icpp(2)%alpha(1)": 1,
9999
"patch_icpp(2)%alpha_rho(1)": sol_L.density,
100100
"patch_icpp(2)%alter_patch(1)": "T",
101-
# Fluids Physical Parameters ===============================================
101+
# Fluids Physical Parameters
102102
"fluid_pp(1)%gamma": 1.0e00 / (4.4e00 - 1.0e00),
103103
"fluid_pp(1)%pi_inf": 0,
104104
}

src/pre_process/include/1dHardcodedIC.fpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@
1212
!> `prim.<variable>.00.<timestep>.dat`
1313
!> (produced when parallel I/O is disabled in `case.py`).
1414
!> - Configurable parameters:
15-
!> - @c nFiles: total number of primitive‐variable files.
1615
!> - @c nRows: total number of grid points in the 1D profile.
1716
!> - Default file directory: `examples/Case_File/D`
1817
!>
19-
!> @param nFiles Total number of primitive‐variable files to read.
2018
!> @param nRows Total number of grid points in the imported 1D profile.
2119

2220
! Place any declaration of intermediate variables here
23-
integer, parameter :: nFiles = 14 ! Number of files (variables) that are being read
2421
integer, parameter :: nRows = 512 ! Number of grid points
2522
integer :: f, iter, ios, unit, idx
2623
real(wp) :: x_len, x_step
2724
integer :: global_offset ! MPI subdomain offset
2825
real(wp) :: delta
29-
character(len=100), dimension(nFiles) :: fileNames ! Arrays to store all data from files
26+
character(len=100), dimension(sys_size) :: fileNames ! Arrays to store all data from files
3027
character(len=200) :: errmsg
31-
real(wp), dimension(nRows, nFiles) :: stored_values ! Imported Data
28+
real(wp), dimension(nRows, sys_size) :: stored_values ! Imported Data
3229
real(wp), dimension(nRows) :: x_coords
3330
logical :: files_loaded = .false.
3431
real(wp) :: domain_start, domain_end
@@ -37,31 +34,32 @@
3734
character(len=20) :: zeros_part ! For the trailing zeros part
3835
character(len=6), parameter :: zeros_default = "000000" ! Default zeros (can be changed)
3936

40-
! Generate file names in a loop
41-
do f = 1, nFiles
42-
! Convert file number to string with proper formatting
43-
if (f < 10) then
44-
write (file_num_str, '(I1)') f ! Single digit
45-
else
46-
write (file_num_str, '(I2)') f ! Double digit
47-
end if
48-
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
49-
! Create the filename with the pattern "prim.X.00.000000.dat"
50-
end do
51-
5237
#:enddef
5338

5439
#:def Hardcoded1D()
5540

5641
select case (patch_icpp(patch_id)%hcid)
5742
case (100)
43+
44+
! Generate file names in a loop
45+
do f = 1, sys_size
46+
! Convert file number to string with proper formatting
47+
if (f < 10) then
48+
write (file_num_str, '(I1)') f ! Single digit
49+
else
50+
write (file_num_str, '(I2)') f ! Double digit
51+
end if
52+
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
53+
! Create the filename with the pattern "prim.X.00.000000.dat"
54+
end do
5855
! Put your variable assignments here
5956
if (.not. files_loaded) then
60-
do f = 1, nFiles
57+
do f = 1, sys_size
6158
! Open the file for reading
6259
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
63-
if (ios /= 0) then
64-
cycle ! Skip this file on error
60+
if (ios /= 0 .and. proc_rank == 0) then
61+
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f))
62+
call s_mpi_abort(trim(errmsg))
6563
end if
6664
! Read all rows at once into memory
6765
do iter = 1, nRows
@@ -85,7 +83,7 @@
8583
end if
8684
! Simple mapping - find the closest index
8785
idx = i + 1 + global_offset
88-
do f = 1, nFiles
86+
do f = 1, sys_size
8987
q_prim_vf(f)%sf(i, 0, 0) = stored_values(idx, f)
9088
end do
9189

src/pre_process/include/2dHardcodedIC.fpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@
55
!> @details
66
!> Reads a sequence of 1D primitive-variable files and maps them onto
77
!> a 2D domain along the x-direction. These files are produced when parallel I/O is disabled in `case.py`.
8-
!> Parameters control file counts, grid resolution, and domain offsets.
8+
!> Parameters control grid resolution, and domain offsets.
99
!>
10-
!> @param nFiles Number of primitive-variable files to read
1110
!> @param nRows Number of grid points per row
1211
!> @param init_dir Directory containing the `prim.*.dat` files
1312
real(wp) :: eps
1413
real(wp) :: r, rmax, gam, umax, p0
1514
real(wp) :: rhoH, rhoL, pRef, pInt, h, lam, wl, amp, intH, intL, alph
1615
real(wp) :: factor
1716

18-
integer, parameter :: nFiles = 14 ! Number of files (variables)
19-
integer, parameter :: nRows = 401 ! Number of grid points
17+
!integer :: nFiles ! Number of files (variables)
18+
integer, parameter :: nRows = 401 ! Number of grid points
2019
integer :: f, iter, ios, unit, idx, jump, index_1
2120
real(wp) :: x_len, x_step
2221
integer :: global_offset ! MPI subdomain offset
2322
real(wp) :: delta_x
24-
character(len=100), dimension(nFiles) :: fileNames
23+
character(len=100), dimension(sys_size - 1) :: fileNames
2524
character(len=200) :: errmsg
2625
! Arrays to store all data from files
27-
real(wp), dimension(nRows, nFiles) :: stored_values ! Imported Data
26+
real(wp), dimension(nRows, sys_size - 1) :: stored_values ! Imported Data
2827
real(wp), dimension(nRows) :: x_coords
2928
logical :: files_loaded = .false.
3029
real(wp) :: domain_start, domain_end
@@ -33,16 +32,6 @@
3332
character(len=20) :: zeros_part ! For the trailing zeros part
3433
character(len=6), parameter :: zeros_default = "018681" ! Default zeros (can be changed)
3534
! Generate file names in a loop
36-
do f = 1, nFiles
37-
! Convert file number to string with proper formatting
38-
if (f < 10) then
39-
write (file_num_str, '(I1)') f ! Single digit
40-
else
41-
write (file_num_str, '(I2)') f ! Double digit
42-
! For more than 99 files, you might need to adjust this format
43-
end if
44-
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
45-
end do
4635

4736
eps = 1e-9_wp
4837

@@ -198,14 +187,27 @@
198187
end if
199188

200189
case (270)
190+
191+
do f = 1, sys_size - 1
192+
! Convert file number to string with proper formatting
193+
if (f < 10) then
194+
write (file_num_str, '(I1)') f ! Single digit
195+
else
196+
write (file_num_str, '(I2)') f ! Double digit
197+
! For more than 99 files, you might need to adjust this format
198+
end if
199+
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
200+
end do
201+
201202
if (.not. files_loaded) then
202203
! Print status message
203204
index_1 = i
204-
do f = 1, nFiles
205+
do f = 1, sys_size - 1
205206
! Open the file for reading
206207
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
208+
if (ios /= 0 .and. proc_rank == 0) then
209+
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f))
210+
call s_mpi_abort(trim(errmsg))
209211
end if
210212
! Read all rows at once into memory
211213
do iter = 1, nRows
@@ -228,7 +230,7 @@
228230
end if
229231
! Calculate the index in the file data array corresponding to x_cc(i)
230232
idx = i + 1 + global_offset - index_1
231-
do f = 1, nFiles
233+
do f = 1, sys_size - 1
232234
if (f >= momxe) then
233235
jump = 1
234236
else

src/pre_process/include/3dHardcodedIC.fpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
!> dimension (z), these files are produced when parallel I/O is disabled in `case.py`.
77
!> Parameters control file counts (number of primitive variables) grid resolution, and domain offsets in x, and y.
88
!>
9-
!> @param nFiles Number of primitive-variable files to read
109
!> @param xRows Number of grid points in the x-direction
1110
!> @param yRows Number of grid points in the y-direction
1211
!> @param init_dir Directory containing the `prim.*.dat` files
@@ -16,7 +15,6 @@
1615

1716
real(wp) :: eps
1817

19-
integer, parameter :: nFiles = 15 ! Number of files (variables)
2018
integer, parameter :: xRows = 401 ! Number of points in x
2119
integer, parameter :: yRows = 403 ! Number of points in y
2220
integer, parameter :: nRows = xRows*yRows
@@ -28,10 +26,10 @@
2826
real(wp) :: current_x
2927
real(wp) :: sim_x_step, sim_y_step ! Simulation grid steps
3028
integer :: nx_data, ny_data, data_i, data_j, iix, iiy
31-
character(len=100), dimension(nFiles) :: fileNames
29+
character(len=100), dimension(sys_size - 1) :: fileNames
3230
character(len=200) :: errmsg
3331
! Arrays to store all data from files - read once, use many times
34-
real(wp), dimension(xRows, yRows, nFiles) :: stored_values ! Imported 2D Data
32+
real(wp), dimension(xRows, yRows, sys_size - 1) :: stored_values ! Imported 2D Data
3533
real(wp), dimension(nRows) :: x_coords, y_coords
3634
logical :: files_loaded = .false.
3735
real(wp) :: domain_xstart, domain_xend, domain_ystart, domain_yend
@@ -40,17 +38,6 @@
4038
character(len=20) :: zeros_part ! For the trailing zeros part
4139
character(len=6), parameter :: zeros_default = "000000" ! Default zeros (can be changed)
4240

43-
! Generate file names dynamically in a loop
44-
do f = 1, nFiles
45-
! Convert file number to string with proper formatting
46-
if (f < 10) then
47-
write (file_num_str, '(I1)') f ! Single digit
48-
else
49-
write (file_num_str, '(I2)') f ! Double digit
50-
! For more than 99 files, you might need to adjust this format
51-
end if
52-
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
53-
end do
5441
eps = 1e-9_wp
5542
#:enddef
5643

@@ -103,13 +90,26 @@
10390
end if
10491

10592
case (370)
93+
! Generate file names dynamically in a loop
94+
do f = 1, sys_size - 1
95+
! Convert file number to string with proper formatting
96+
if (f < 10) then
97+
write (file_num_str, '(I1)') f ! Single digit
98+
else
99+
write (file_num_str, '(I2)') f ! Double digit
100+
! For more than 99 files, you might need to adjust this format
101+
end if
102+
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
103+
end do
104+
106105
if (.not. files_loaded) then
107106
! Print status message
108107
index_x = i
109108
index_y = j
110109
open (newunit=unit, file=trim(fileNames(1)), status='old', action='read', iostat=ios)
111-
if (ios /= 0) then
112-
return
110+
if (ios /= 0 .and. proc_rank == 0) then
111+
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f))
112+
call s_mpi_abort(trim(errmsg))
113113
end if
114114

115115
iter = 0
@@ -126,10 +126,11 @@
126126
end do
127127
close (unit)
128128
!Now read only the values from remaining files (skip x,y columns)
129-
do f = 2, nFiles
129+
do f = 2, sys_size - 1
130130
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
131-
if (ios /= 0) then
132-
cycle
131+
if (ios /= 0 .and. proc_rank == 0) then
132+
print *, "Error opening file: ", trim(fileNames(f))
133+
cycle ! Skip this file on error
133134
end if
134135
do iix = 1, xRows
135136
do iiy = 1, yRows
@@ -168,7 +169,7 @@
168169
data_i = i + 1 + global_offset_x - index_x ! x-direction index in data grid
169170
data_j = j + 1 + global_offset_y - index_y ! y-direction index in data grid
170171

171-
do f = 1, nFiles
172+
do f = 1, sys_size - 1
172173
if (f >= momxe) then
173174
jump = 1
174175
else

0 commit comments

Comments
 (0)