Skip to content

Commit 5b30ddf

Browse files
committed
Hardcoded Extrusion
1 parent bf9ea7d commit 5b30ddf

File tree

6 files changed

+99
-108
lines changed

6 files changed

+99
-108
lines changed

docs/documentation/case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Also Several custom hard-coded patches are already defined to support common wor
240240

241241
By convention, patch ID `case(170)` load a 1D profile, ID `case(270)` extrude that 1D data into 2D, and ID `case(370)` extrude 2D data into 3D.
242242
You only need to supply `init_dir` (and the filename‐pattern via `zeros_default`). All related variables (including init_dir, zeros_default, and the “files_loaded” flag)
243-
live in `src/pre_process/include/HardcodedExtrusion.fpp`, and no manual grid‐size settings are required.
243+
live in `src/pre_process/include/ExtrusionHardcodedIC.fpp`, and no manual grid‐size settings are required.
244244
#### Parameter Descriptions
245245

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

src/pre_process/include/1dHardcodedIC.fpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
1919
! Create the filename with the pattern "prim.X.00.000000.dat"
2020
end do
21-
21+
2222
if (.not. files_loaded) then
2323
!Reading the first file to calculate the number of grid points in the x direction
2424
line_count = 0
25-
open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
26-
if (ios2 /= 0) then
27-
write(errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1))
28-
call s_mpi_abort(trim(errmsg))
29-
end if
30-
do
31-
read(unit2, *, iostat=ios2) dummy_x, dummy_y
32-
if (ios2 /= 0) exit ! Exit since the file has been read
33-
line_count = line_count + 1
34-
end do
35-
close(unit2)
36-
25+
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
26+
if (ios2 /= 0) then
27+
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1))
28+
call s_mpi_abort(trim(errmsg))
29+
end if
30+
do
31+
read (unit2, *, iostat=ios2) dummy_x, dummy_y
32+
if (ios2 /= 0) exit ! Exit since the file has been read
33+
line_count = line_count + 1
34+
end do
35+
close (unit2)
36+
3737
xRows = line_count
38-
allocate(x_coords(xRows))
39-
allocate(stored_values(xRows, 1, sys_size))
38+
allocate (x_coords(xRows))
39+
allocate (stored_values(xRows, 1, sys_size))
4040
do f = 1, sys_size
4141
! Open the file for reading
4242
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
@@ -74,6 +74,5 @@
7474
call s_int_to_str(patch_id, iStr)
7575
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr))
7676
end select
77-
7877

7978
#:enddef

src/pre_process/include/2dHardcodedIC.fpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,28 @@
167167
write (file_num_str, '(I2)') f ! Double digit
168168
! For more than 99 files, you might need to adjust this format
169169
end if
170-
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
170+
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat"
171171
end do
172172

173173
if (.not. files_loaded) then
174174
! Calculating the number of grid points in the x direction in the file.
175175
line_count = 0
176-
open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
177-
if (ios2 /= 0) then
178-
write(errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1))
179-
call s_mpi_abort(trim(errmsg))
180-
end if
181-
do
182-
read(unit2, *, iostat=ios2) dummy_x, dummy_y
183-
if (ios2 /= 0) exit ! Exit since files has been read
184-
line_count = line_count + 1
185-
end do
186-
close(unit2)
187-
176+
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
177+
if (ios2 /= 0) then
178+
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1))
179+
call s_mpi_abort(trim(errmsg))
180+
end if
181+
do
182+
read (unit2, *, iostat=ios2) dummy_x, dummy_y
183+
if (ios2 /= 0) exit ! Exit since files has been read
184+
line_count = line_count + 1
185+
end do
186+
close (unit2)
187+
188188
index_x = i
189189
xRows = line_count
190-
allocate(x_coords(xRows))
191-
allocate(stored_values(xRows, 1, sys_size))
190+
allocate (x_coords(xRows))
191+
allocate (stored_values(xRows, 1, sys_size))
192192
do f = 1, sys_size - 1
193193
! Open the file for reading
194194
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios)
@@ -227,7 +227,7 @@
227227
end do
228228
! Set element the velocity paraller to y explicitly to zero
229229
q_prim_vf(momxe)%sf(i, j, 0) = 0.0_wp
230-
230+
231231
case default
232232
if (proc_rank == 0) then
233233
call s_int_to_str(patch_id, iStr)
@@ -236,7 +236,4 @@
236236

237237
end select
238238

239-
240-
241-
242239
#:enddef

src/pre_process/include/3dHardcodedIC.fpp

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -68,63 +68,63 @@
6868
end do
6969

7070
if (.not. files_loaded) then
71-
! 1) Discover yRows by reading fileNames(1) until x changes from the first line’s x.
72-
open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
73-
if (ios2 /= 0 ) then
74-
write(errmsg, '(A,A)') "Error opening file for yRows detection: ", trim(fileNames(1))
75-
call s_mpi_abort(trim(errmsg))
76-
end if
77-
78-
! Read the very first line to get (x₀, y₀)
79-
read(unit2, *, iostat=ios2) x0, y0, dummy_z
80-
if (ios2 /= 0 ) then
81-
write(errmsg, '(A,A)') "Error reading first line of: ", trim(fileNames(1))
82-
call s_mpi_abort(trim(errmsg))
83-
end if
84-
85-
ycount = 1
86-
do
87-
read(unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z
88-
if (ios2 /= 0) exit ! End of File : stop counting
89-
if (dummy_x == x0 .and. dummy_y /= y0) then
90-
! As soon as x or y changes from the first line’s (x0,y0),
91-
! we know we have counted all the (x0, y1) rows.
92-
ycount = ycount + 1
93-
else
94-
exit
71+
! 1) Discover yRows by reading fileNames(1) until x changes from the first line’s x.
72+
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
73+
if (ios2 /= 0) then
74+
write (errmsg, '(A,A)') "Error opening file for yRows detection: ", trim(fileNames(1))
75+
call s_mpi_abort(trim(errmsg))
76+
end if
77+
78+
! Read the very first line to get (x₀, y₀)
79+
read (unit2, *, iostat=ios2) x0, y0, dummy_z
80+
if (ios2 /= 0) then
81+
write (errmsg, '(A,A)') "Error reading first line of: ", trim(fileNames(1))
82+
call s_mpi_abort(trim(errmsg))
83+
end if
84+
85+
ycount = 1
86+
do
87+
read (unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z
88+
if (ios2 /= 0) exit ! End of File : stop counting
89+
if (dummy_x == x0 .and. dummy_y /= y0) then
90+
! As soon as x or y changes from the first line’s (x0,y0),
91+
! we know we have counted all the (x0, y1) rows.
92+
ycount = ycount + 1
93+
else
94+
exit
95+
end if
96+
end do
97+
yRows = ycount
98+
close (unit2)
99+
! 2) Count total rows (nrows) to get xRows
100+
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
101+
if (ios2 /= 0) then
102+
write (errmsg, '(A,A)') "Error re‐opening file to count rows: ", trim(fileNames(1))
103+
call s_mpi_abort(trim(errmsg))
104+
end if
105+
106+
nrows = 0
107+
do
108+
read (unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z
109+
if (ios2 /= 0) exit
110+
nrows = nrows + 1
111+
end do
112+
close (unit2)
113+
114+
if (mod(nrows, yRows) /= 0) then
115+
write (errmsg, '(A,A,I0,A,I0)') &
116+
"File ’", trim(fileNames(1)), &
117+
"’ has total lines=", nrows, &
118+
" which is not a multiple of yRows=", yRows
119+
call s_mpi_abort(trim(errmsg))
95120
end if
96-
end do
97-
yRows = ycount
98-
close(unit2)
99-
! 2) Count total rows (nrows) to get xRows
100-
open(newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2)
101-
if (ios2 /= 0 ) then
102-
write(errmsg, '(A,A)') "Error re‐opening file to count rows: ", trim(fileNames(1))
103-
call s_mpi_abort(trim(errmsg))
104-
end if
105-
106-
nrows = 0
107-
do
108-
read(unit2, *, iostat=ios2) dummy_x, dummy_y, dummy_z
109-
if (ios2 /= 0) exit
110-
nrows = nrows + 1
111-
end do
112-
close(unit2)
113-
114-
if (mod(nrows, yRows) /= 0) then
115-
write(errmsg, '(A,A,I0,A,I0)') &
116-
"File ’", trim(fileNames(1)), &
117-
"’ has total lines=", nrows, &
118-
" which is not a multiple of yRows=", yRows
119-
call s_mpi_abort(trim(errmsg))
120-
end if
121-
xRows = nrows / yRows
122-
allocate(x_coords(nRows))
123-
allocate(y_coords(nRows))
124-
allocate(stored_values(xRows, yRows, sys_size))
121+
xRows = nrows/yRows
122+
allocate (x_coords(nRows))
123+
allocate (y_coords(nRows))
124+
allocate (stored_values(xRows, yRows, sys_size))
125125
index_x = i
126126
index_y = j
127-
127+
128128
open (newunit=unit, file=trim(fileNames(1)), status='old', action='read', iostat=ios)
129129
if (ios /= 0) then
130130
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f))
@@ -165,7 +165,6 @@
165165
end do
166166
end do
167167
close (unit)
168-
169168

170169
domain_xstart = x_coords(1) ! First x value
171170
domain_ystart = y_coords(1) ! First y value

src/pre_process/include/ExtrusionHardcodedIC.fpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,23 @@
1010
!> - files_loaded => .false.
1111
!> - index_x, index_y, global_offset_x => 0.
1212
!>
13-
!> (Note: The corresponding loader macro reads
14-
!> `prim.<variable>.00.<timestep>.dat` files—pattern controlled by `zeros_default`—
13+
!> (Note: The corresponding loader macro reads
14+
!> `prim.<variable>.00.<timestep>.dat` files—pattern controlled by `zeros_default`—
1515
!> from `examples/Case_File/D`.)
1616

17-
18-
19-
#:def HardcodedDimensionsExtension()
17+
#:def HardcodedDimensionsExtrusion()
2018
integer :: xRows, yRows, nRows, iix, iiy
21-
integer :: f, iter, ios, ios2, unit, unit2, idx,idy,index_x,index_y, jump, line_count, ycount
19+
integer :: f, iter, ios, ios2, unit, unit2, idx, idy, index_x, index_y, jump, line_count, ycount
2220
real(wp) :: x_len, x_step, y_len, y_step
2321
real(wp) :: dummy_x, dummy_y, dummy_z, x0, y0
2422
integer :: global_offset_x, global_offset_y ! MPI subdomain offset
2523
real(wp) :: delta_x, delta_y
2624
character(len=100), dimension(sys_size) :: fileNames ! Arrays to store all data from files
2725
character(len=200) :: errmsg
28-
real(wp), allocatable :: stored_values(:,:,:)
26+
real(wp), allocatable :: stored_values(:, :, :)
2927
real(wp), allocatable :: x_coords(:), y_coords(:)
3028
logical :: files_loaded = .false.
31-
real(wp) :: domain_xstart, domain_xend, domain_ystart, domain_yend
29+
real(wp) :: domain_xstart, domain_xend, domain_ystart, domain_yend
3230
character(len=*), parameter :: init_dir = "/home/YourDirectory" ! For example /home/MFC/examples/1D_Shock/D/
3331
character(len=20) :: file_num_str ! For storing the file number as a string
3432
character(len=20) :: zeros_part ! For the trailing zeros part
@@ -37,11 +35,11 @@
3735

3836
#:def HardcodedDellacation()
3937
if (allocated(stored_values)) then
40-
deallocate(stored_values)
41-
deallocate(x_coords)
38+
deallocate (stored_values)
39+
deallocate (x_coords)
4240
end if
4341

4442
if (allocated(y_coords)) then
45-
deallocate(y_coords)
43+
deallocate (y_coords)
4644
end if
4745
#:enddef

src/pre_process/m_patches.fpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,8 @@ contains
13021302
! Placeholders for the cell boundary values
13031303
real(wp) :: a, b, c, d, pi_inf, gamma, lit_gamma
13041304
real(wp) :: pi_inf, gamma, lit_gamma
1305-
@:HardcodedDimensionsExtension()
1305+
@:HardcodedDimensionsExtrusion()
13061306
@:Hardcoded1DVariables()
1307-
13081307

13091308
pi_inf = fluid_pp(1)%pi_inf
13101309
gamma = fluid_pp(1)%gamma
@@ -1419,10 +1418,9 @@ contains
14191418

14201419
real(wp) :: pi_inf, gamma, lit_gamma !< equation of state parameters
14211420
real(wp) :: l, U0 !< Taylor Green Vortex parameters
1422-
@:HardcodedDimensionsExtension()
1421+
@:HardcodedDimensionsExtrusion()
14231422
@:Hardcoded2DVariables()
14241423

1425-
14261424
pi_inf = fluid_pp(1)%pi_inf
14271425
gamma = fluid_pp(1)%gamma
14281426
lit_gamma = (1._wp + gamma)/gamma
@@ -1489,7 +1487,7 @@ contains
14891487

14901488
integer :: i, j, k !< generic loop iterators
14911489
real(wp) :: pi_inf, gamma, lit_gamma !< equation of state parameters
1492-
@:HardcodedDimensionsExtension()
1490+
@:HardcodedDimensionsExtrusion()
14931491
@:Hardcoded3DVariables()
14941492

14951493
pi_inf = fluid_pp(1)%pi_inf
@@ -1557,7 +1555,7 @@ contains
15571555
end do
15581556
end do
15591557
end do
1560-
1558+
15611559
@:HardcodedDellacation()
15621560
end subroutine s_3D_analytical
15631561

0 commit comments

Comments
 (0)