boundary_conditions Module

Provides apply_bcs(state), which must be called at the start of every residual evaluation. It reads the current solution array and the BC type strings from @p state, then writes the appropriate ghost values directly into the halo cells of state%ub.

Phase B rank-awareness: apply_bcs is a no-op on inner ranks. Only rank 0 writes the left-boundary halo, and only rank N-1 writes the right-boundary halo. Halo exchange (called from compute_resid) fills the interior halo cells of inner ranks with neighbour data. At -np 1 a single rank is both my_rank == 0 and my_rank == n_ranks - 1, so both edges are written and behaviour matches the serial code.

Supported BC types (set via bc_left / bc_right in the &initial_condition namelist group):

'dirichlet' — fixed prescribed state (halo cells preset by the driver, no update here) 'inflow' — same as Dirichlet; use for a driven supersonic inlet 'outflow' — linear extrapolation: ghost = 2boundary - penultimate cell (applied to every halo cell with the same formula) 'reflecting' — solid wall: density and energy mirrored, momentum negated 'periodic' — at -np > 1 handled by halo_exchange (left/right neighbours wrap around for periodic decomp); at -np 1 apply_bcs performs the in-process periodic copy directly 'nonreflecting' — characteristic (LODI/Thompson) non-reflecting outflow. Two algorithm variants are selected by nrbc_mode: 'pressure' (default) — isentropic pressure-relaxation; zeroes the incoming acoustic wave by constructing the ghost via isentropic relation and dp = rhocdu. 'characteristic' — full LODI characteristic targeting (Poinsot & Lele 1992, Sec. 3); decomposes the boundary state into f1/f2/f3 characteristic amplitudes and relaxes each independently. 'supersonic_inlet' — fully prescribed supersonic inflow (Ma > 1). Halo cells preset by the driver and never updated. 'supersonic_outlet' — all characteristics exit; zero-gradient ghost. 'subsonic_inlet' — characteristic-based subsonic inflow (0 < Ma < 1). 'subsonic_outlet' — characteristic-based subsonic outflow (0 < Ma < 1). 'neumann' — homogeneous Neumann BC: ghost = boundary cell. 'neumann_gradient' — prescribed-gradient Neumann: ghost = q_wall + (dq/dn)dx*k.

For the multi-cell halo (halo_width > 1), the "constant ghost" BCs (dirichlet, inflow, supersonic_inlet, supersonic_outlet, neumann, the nonreflecting and subsonic variants) fill every halo cell with the same ghost vector — equivalent to zero-gradient extrapolation past the first halo cell. 'outflow' applies the linear extrapolation to every halo cell using the same penultimate-cell baseline. 'reflecting' mirrors halo cell k about the boundary onto interior cell k (so halo cell 1-k = mirror of interior cell k).

'outflow' uses first-order linear extrapolation (LeVeque 2002, Sec. 7.3). A positivity guard falls back to zero-gradient if extrapolation produces a non-physical ghost state (negative density or pressure).

'nonreflecting' follows Thompson (1987) / Poinsot & Lele (1992). At supersonic outflow all waves leave and the ghost degenerates to zero-gradient. sigma_nrbc in [0,1] blends between fully non-reflecting (0) and a soft Dirichlet target (1) for both modes.



Subroutines

public subroutine apply_bcs(state)

Method dispatcher for boundary-condition enforcement.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state

Solver instance state.

private subroutine apply_bcs_fdm(state)

Update halo cells of state%ub from the current interior solution and BC types (NODAL / finite-difference path). Rank-aware: only edge ranks act.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state

Solver instance state.

private subroutine apply_bcs_fvm_1d(state)

Update ghost cells of state%ub for the CELL-CENTERED finite-volume path.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state

Solver instance state.

private subroutine apply_left_bc_into_halo(state, h)

Compute the left-boundary ghost state and broadcast it across the h halo cells state%ub(:, 1-h .. 0).

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state
integer, intent(in) :: h

private subroutine apply_right_bc_into_halo(state, h, n_local)

Compute the right-boundary ghost state and broadcast it across the h halo cells state%ub(:, n_local+1 .. n_local+h).

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state
integer, intent(in) :: h
integer, intent(in) :: n_local

private subroutine compute_boundary_ghost(state, bc_type, side, q_wall, q_penult, q_ghost, per_cell_pattern, no_write)

Compute one boundary ghost-state vector from a boundary cell. Caller decides whether to broadcast the value across all halo cells or to use the per-cell mirror pattern (signalled by @p per_cell_pattern).

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(inout) :: state

Solver instance (reads gam, BC config, etc.)

character(len=*), intent(in) :: bc_type

Boundary condition type string.

character(len=1), intent(in) :: side

Which boundary: 'L' (left) or 'R' (right).

real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(in) :: q_penult(3)
real(kind=wp), intent(out) :: q_ghost(3)
logical, intent(out) :: per_cell_pattern

.true. for 'reflecting': caller must mirror

logical, intent(out) :: no_write

.true. for 'reflecting': caller must mirror .true. when the halo should not be touched

private subroutine outflow_ghost(state, q_wall, q_penult, q_ghost)

'outflow' ghost: first-order linear extrapolation with a positivity guard.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state
real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(in) :: q_penult(3)
real(kind=wp), intent(out) :: q_ghost(3)

private subroutine nonreflecting_ghost(state, side, q_wall, q_penult, q_ghost, no_write)

'nonreflecting' ghost: characteristic (LODI/Thompson) non-reflecting BC.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state
character(len=1), intent(in) :: side
real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(in) :: q_penult(3)
real(kind=wp), intent(out) :: q_ghost(3)
logical, intent(out) :: no_write

private subroutine neumann_gradient_ghost(state, side, q_wall, q_ghost)

'neumann_gradient' ghost: prescribed-gradient Neumann BC.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state
character(len=1), intent(in) :: side
real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(out) :: q_ghost(3)

private subroutine subsonic_outlet_ghost(state, side, q_wall, q_ghost)

'subsonic_outlet' ghost: characteristic-based subsonic outflow.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state
character(len=1), intent(in) :: side
real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(out) :: q_ghost(3)

private subroutine subsonic_inlet_ghost(state, side, q_wall, q_ghost)

'subsonic_inlet' ghost: characteristic-based subsonic inflow.

Read more…

Arguments

Type IntentOptional Attributes Name
type(solver_state_t), intent(in) :: state
character(len=1), intent(in) :: side
real(kind=wp), intent(in) :: q_wall(3)
real(kind=wp), intent(out) :: q_ghost(3)