-
Notifications
You must be signed in to change notification settings - Fork 106
Extend initial conditions from 1D to 2D and 2D to 3D #844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bcaaa35
4833d7b
c8e7f9f
652d0fa
e63683a
cc20ee9
b720ecc
1182c2c
24a324c
b02547e
308d919
b58a29f
1ba9082
415598a
8a04716
de149bd
7739f59
7e61509
d55b19e
ec14e77
d14900c
0342538
31822b8
f7d279b
fe78533
651ddf9
f5dad3c
bf9ea7d
5b30ddf
fd4aca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,11 @@ and use `patch_icpp(i)%%geometry = 7` and `patch_icpp(i)%%hcid = 200` in the inp | |
Additional variables can be declared in `Hardcoded1[2,3]DVariables` and used in `hardcoded1[2,3]D`. | ||
As a convention, any hard coded patches that are part of the MFC master branch should be identified as 1[2,3]xx where the first digit indicates the number of dimensions. | ||
|
||
Also Several custom hard-coded patches are already defined to support common workflows. These include: | ||
|
||
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. | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be |
||
live in `src/pre_process/include/ExtrusionHardcodedIC.fpp`, and no manual grid‐size settings are required. | ||
#### Parameter Descriptions | ||
|
||
- `num_patches` defines the total number of patches defined in the domain. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this works with other hardcoded ICs? ask @wilfonba There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still a question |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,75 @@ | ||
#:def Hardcoded1DVariables() | ||
! Place any declaration of intermediate variables here | ||
|
||
#:enddef | ||
|
||
#:def Hardcoded1D() | ||
|
||
select case (patch_icpp(patch_id)%hcid) | ||
case (100) | ||
! Put your variable assignments here | ||
case (170) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put a comment about what this case does here? |
||
! Generate file names in a loop | ||
do f = 1, sys_size | ||
! Convert file number to string with proper formatting | ||
if (f < 10) then | ||
write (file_num_str, '(I1)') f ! Single digit | ||
else | ||
write (file_num_str, '(I2)') f ! Double digit | ||
end if | ||
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat" | ||
! Create the filename with the pattern "prim.X.00.000000.dat" | ||
end do | ||
|
||
if (.not. files_loaded) then | ||
!Reading the first file to calculate the number of grid points in the x direction | ||
line_count = 0 | ||
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) | ||
if (ios2 /= 0) then | ||
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1)) | ||
call s_mpi_abort(trim(errmsg)) | ||
end if | ||
do | ||
read (unit2, *, iostat=ios2) dummy_x, dummy_y | ||
if (ios2 /= 0) exit ! Exit since the file has been read | ||
line_count = line_count + 1 | ||
end do | ||
close (unit2) | ||
|
||
xRows = line_count | ||
allocate (x_coords(xRows)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @:ALLOCATE ... |
||
allocate (stored_values(xRows, 1, sys_size)) | ||
do f = 1, sys_size | ||
! Open the file for reading | ||
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios) | ||
if (ios /= 0) then | ||
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f)) | ||
call s_mpi_abort(trim(errmsg)) | ||
end if | ||
! Read all rows at once into memory | ||
do iter = 1, xRows | ||
read (unit, *, iostat=ios) x_coords(iter), stored_values(iter, 1, f) | ||
if (ios /= 0) then | ||
write (errmsg, '(A,A,A,I0,A)') ' Error reading "', trim(fileNames(f)), & | ||
'" at index (', iter, ')' | ||
call s_mpi_abort(trim(errmsg)) ! Exit loop on error | ||
end if | ||
end do | ||
close (unit) | ||
end do | ||
! Calculate domain information for mapping | ||
domain_xstart = x_coords(1) | ||
domain_xend = x_coords(xRows) | ||
x_step = x_cc(1) - x_cc(0) | ||
|
||
delta_x = x_cc(0) - domain_xstart - x_step/2.0 | ||
global_offset_x = nint(abs(delta_x)/x_step) | ||
files_loaded = .true. | ||
end if | ||
! Simple mapping - find the closest index | ||
idx = i + 1 + global_offset_x | ||
do f = 1, sys_size | ||
q_prim_vf(f)%sf(i, 0, 0) = stored_values(idx, 1, f) | ||
end do | ||
|
||
case default | ||
call s_int_to_str(patch_id, iStr) | ||
call s_mpi_abort("Invalid hcid specified for patch "//trim(iStr)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#:def Hardcoded2DVariables() | ||
|
||
! Place any declaration of intermediate variables here | ||
real(wp) :: eps | ||
real(wp) :: r, rmax, gam, umax, p0 | ||
real(wp) :: rhoH, rhoL, pRef, pInt, h, lam, wl, amp, intH, intL, alph | ||
real(wp) :: factor | ||
|
||
eps = 1e-9_wp | ||
|
||
#:enddef | ||
|
||
#:def Hardcoded2D() | ||
|
@@ -158,6 +157,77 @@ | |
q_prim_vf(E_idx)%sf(i, j, 0) = 3.e-5_wp | ||
end if | ||
|
||
case (270) | ||
|
||
do f = 1, sys_size - 1 | ||
! Convert file number to string with proper formatting | ||
if (f < 10) then | ||
write (file_num_str, '(I1)') f ! Single digit | ||
else | ||
write (file_num_str, '(I2)') f ! Double digit | ||
! For more than 99 files, you might need to adjust this format | ||
end if | ||
fileNames(f) = trim(init_dir)//"prim."//trim(file_num_str)//".00."//zeros_default//".dat" | ||
end do | ||
|
||
if (.not. files_loaded) then | ||
! Calculating the number of grid points in the x direction in the file. | ||
line_count = 0 | ||
open (newunit=unit2, file=trim(fileNames(1)), status='old', action='read', iostat=ios2) | ||
if (ios2 /= 0) then | ||
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(1)) | ||
call s_mpi_abort(trim(errmsg)) | ||
end if | ||
do | ||
read (unit2, *, iostat=ios2) dummy_x, dummy_y | ||
if (ios2 /= 0) exit ! Exit since files has been read | ||
line_count = line_count + 1 | ||
end do | ||
close (unit2) | ||
|
||
index_x = i | ||
xRows = line_count | ||
allocate (x_coords(xRows)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @:ALLOCATE? |
||
allocate (stored_values(xRows, 1, sys_size)) | ||
do f = 1, sys_size - 1 | ||
! Open the file for reading | ||
open (newunit=unit, file=trim(fileNames(f)), status='old', action='read', iostat=ios) | ||
if (ios /= 0 .and. proc_rank == 0) then | ||
write (errmsg, '(A,A)') "Error opening file: ", trim(fileNames(f)) | ||
call s_mpi_abort(trim(errmsg)) | ||
end if | ||
! Read all rows at once into memory | ||
do iter = 1, xRows | ||
read (unit, *, iostat=ios) x_coords(iter), stored_values(iter, 1, f) | ||
if (ios /= 0) then | ||
write (errmsg, '(A,A,A,I0,A)') 'Error reading "', trim(fileNames(f)), & | ||
'" at index (', iter, ')' | ||
call s_mpi_abort(trim(errmsg)) ! Exit loop on error | ||
end if | ||
end do | ||
close (unit) | ||
end do | ||
! Calculate domain information for mapping | ||
domain_xstart = x_coords(1) | ||
domain_xend = x_coords(xRows) | ||
x_step = x_cc(1) - x_cc(0) | ||
delta_x = x_cc(index_x) - domain_xstart + x_step/2 | ||
global_offset_x = nint(abs(delta_x)/x_step) | ||
files_loaded = .true. | ||
end if | ||
! Calculate the index in the file data array corresponding to x_cc(i) | ||
idx = i + 1 + global_offset_x - index_x | ||
do f = 1, sys_size - 1 | ||
if (f >= momxe) then | ||
jump = 1 | ||
else | ||
jump = 0 | ||
end if | ||
q_prim_vf(f + jump)%sf(i, j, 0) = stored_values(idx, 1, f) | ||
end do | ||
! Set element the velocity paraller to y explicitly to zero | ||
q_prim_vf(momxe)%sf(i, j, 0) = 0.0_wp | ||
|
||
case default | ||
if (proc_rank == 0) then | ||
call s_int_to_str(patch_id, iStr) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
!> @brief Deallocate and reset variables used for IC extrusion. | ||
!> | ||
!> @details | ||
!> Deallocates: | ||
!> - stored_values(:,:,:). | ||
!> - x_coords(:). | ||
!> - y_coords(:). | ||
!> | ||
!> Resets: | ||
!> - files_loaded => .false. | ||
!> - index_x, index_y, global_offset_x => 0. | ||
!> | ||
!> (Note: The corresponding loader macro reads | ||
!> `prim.<variable>.00.<timestep>.dat` files—pattern controlled by `zeros_default`— | ||
!> from `examples/Case_File/D`.) | ||
|
||
#:def HardcodedDimensionsExtrusion() | ||
integer :: xRows, yRows, nRows, iix, iiy | ||
integer :: f, iter, ios, ios2, unit, unit2, idx, idy, index_x, index_y, jump, line_count, ycount | ||
real(wp) :: x_len, x_step, y_len, y_step | ||
real(wp) :: dummy_x, dummy_y, dummy_z, x0, y0 | ||
integer :: global_offset_x, global_offset_y ! MPI subdomain offset | ||
real(wp) :: delta_x, delta_y | ||
character(len=100), dimension(sys_size) :: fileNames ! Arrays to store all data from files | ||
character(len=200) :: errmsg | ||
real(wp), allocatable :: stored_values(:, :, :) | ||
real(wp), allocatable :: x_coords(:), y_coords(:) | ||
logical :: files_loaded = .false. | ||
real(wp) :: domain_xstart, domain_xend, domain_ystart, domain_yend | ||
character(len=*), parameter :: init_dir = "/home/YourDirectory" ! For example /home/MFC/examples/1D_Shock/D/ | ||
character(len=20) :: file_num_str ! For storing the file number as a string | ||
character(len=20) :: zeros_part ! For the trailing zeros part | ||
character(len=6), parameter :: zeros_default = "00000" ! Default zeros (can be changed) | ||
#:enddef | ||
|
||
#:def HardcodedDellacation() | ||
if (allocated(stored_values)) then | ||
deallocate (stored_values) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @:DEALLOCATE |
||
deallocate (x_coords) | ||
end if | ||
|
||
if (allocated(y_coords)) then | ||
deallocate (y_coords) | ||
end if | ||
#:enddef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's going on here. These include:
but then there are no lines below it with a list....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also capitalization error