Skip to content

Refactor case BC hooks: rename to define_BC/apply_BC and hoist BC fields to base#307

Merged
kaanolgu merged 14 commits into
mainfrom
boundary_precorrect_fix
Jun 15, 2026
Merged

Refactor case BC hooks: rename to define_BC/apply_BC and hoist BC fields to base#307
kaanolgu merged 14 commits into
mainfrom
boundary_precorrect_fix

Conversation

@kaanolgu

Copy link
Copy Markdown
Collaborator
  • Rename boundary_conditions -> define_BC and pre_correction -> apply_BC across base and child cases.
  • Hoist 12 BC field pointers (bc_{start,end}_{u,v,w}_{x,y}) onto base_case_t; cases use only what they need.
  • Add field_set_face_from_field backend hook (CUDA + OMP) for spatially-varying face BCs.
  • Channel: y-wall BCs now use persistent device fields refreshed with noise per substep, applied via the new hook.
  • Cylinder: inflow profile now built field-side using new inlet_noise(3) config (replaces bc_start_u/v/w scalars).
  • Cylinder: compute_outflow_params moved from apply_BC into define_BC; results stored on self%out_vel / self%flow_rate_diff (drops _cached suffix).
  • Behavioural note: outflow params sampled one substep earlier than before.
  • Breaking change: existing cylinder_nml files must replace bc_start_u/v/w with inlet_noise.

@kaanolgu kaanolgu requested a review from ia267 May 14, 2026 09:30
@kaanolgu kaanolgu self-assigned this May 14, 2026
@kaanolgu kaanolgu added the enhancement New feature or request label May 14, 2026
Comment thread src/case/cylinder.f90
Comment thread src/backend/omp/backend.f90
Comment thread src/backend/cuda/backend.f90
Comment thread src/backend/cuda/backend.f90 Outdated
Comment thread src/backend/cuda/kernels/fieldops.f90 Outdated
Comment thread src/backend/cuda/kernels/fieldops.f90
Comment thread src/case/cylinder.f90 Outdated
Comment thread src/config.f90
Comment thread src/backend/omp/backend.f90
Comment thread src/case/base_case.f90 Outdated
Comment thread src/backend/omp/backend.f90 Outdated

!$omp parallel do private(k_end, y_block, i_max)
do k = 1, n_y_blocks*dims(3)
y_block = (k - 1)/dims(3) + 1

@ia267 ia267 Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be:

Suggested change
y_block = (k - 1)/dims(3) + 1
y_block = mod(k - 1, n_y_blocks) + 1

OMP reordering uses get_index_dir (line 54), which maps a Cartesian (y, z) position to the third DIR_X index as:

dir_k = n_y_blocks*(z-1) + y_block

Therefore, y-block is the fast-varying component. For n_y_blocks = 3 and nz = 2, increasing k from 1 to 6 gives y-blocks 1, 2, 3, 1, 2, 3. The current expression, (b - 1)/nz + 1 produces 1, 1, 2, 2, 3, 3 (opposite flattening order). For CUDA it calls reorder_cuda (doesn't call get_index_dir). The current expression assumes CUDA's different layout.

Also, I think in field_set_face_omp (line 848), the Y_FACE block also uses the same incorrect CUDA-style indexing and should be changed to:

case (Y_FACE)
  i_mod = mod(dims(2) - 1, SZ) + 1
  n_y_blocks = (dims(2) - 1)/SZ + 1

  !$omp parallel do private(k_start, k_end)
  do z = 1, dims(3)
    k_start = 1 + (z - 1)*n_y_blocks
    k_end = n_y_blocks + (z - 1)*n_y_blocks

    do j = 1, dims(1)
      f%data(1, j, k_start) = c_start
      f%data(i_mod, j, k_end) = c_end
    end do
  end do
  !$omp end parallel do

This follows the OMP's DIR_X layout.

@ia267 ia267 self-requested a review June 9, 2026 17:57
Comment thread src/backend/omp/backend.f90
Comment thread src/backend/cuda/backend.f90
Comment thread src/backend/omp/backend.f90 Outdated
error stop 'field_set_face_from_field: only supported for DIR_X fields.'
if (f%data_loc == NULL_LOC) &
error stop 'field_set_face_from_field: requires a valid data_loc.'
if (face /= X_FACE) &

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channel case calls this routine with Y_FACE - we will need to implement Y_FACE path using OMP ordering:

n_mod = mod(dims(2) - 1, SZ) + 1
n_y_blocks = (dims(2) - 1)/SZ + 1

!$omp parallel do private(k_start, k_end)
do z = 1, dims(3)
  k_start = 1 + (z - 1)*n_y_blocks
  k_end = n_y_blocks + (z - 1)*n_y_blocks

  do j = 1, dims(1)
    f%data(1, j, k_start) = f_start%data(1, j, k_start)
    f%data(n_mod, j, k_end) = f_start%data(n_mod, j, k_end)
  end do
end do
!$omp end parallel do

@ia267 ia267 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OMP boundary path incorrectly assumes CUDA’s z-fast block ordering. OMP uses y-block-fast ordering through get_index_dir, so the y_block calculation and Y-face indices must be corrected accordingly. Additionally, field_set_face_from_field_omp must support Y_FACE, since the channel case calls that path.

@ia267 ia267 self-requested a review June 15, 2026 10:05

@ia267 ia267 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved - please fix the formatting issues before merging.

@kaanolgu

Copy link
Copy Markdown
Collaborator Author

@x3d2bot fix style

@github-actions

Copy link
Copy Markdown

On it -- running fprettify to fix style issues.

@kaanolgu kaanolgu merged commit 901bc10 into main Jun 15, 2026
2 checks passed
@kaanolgu kaanolgu deleted the boundary_precorrect_fix branch June 15, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants