spatial_discretization_2d Module

R(Q) = -( (Fx_{i+1/2,j}-Fx_{i-1/2,j})/dx + (Gy_{i,j+1/2}-Gy_{i,j-1/2})/dy ). Per-line component-wise reconstruction (reused via state % reconstruct) + 4-component face flux (euler_riemann_2d). Characteristic projection is a later refinement.

Bounds note: state%ub has declared bounds (neq2d, 1-h:nx+h, 1-h:ny+h). Stencil gathers are inlined (not delegated to assumed-shape subroutine dummies) so that Fortran component-access retains those explicit lower bounds and halo indices like -2 map to the correct ghost cells.



Subroutines

private subroutine ensure_resid_scratch_2d(state, nx, ny, sw)

Allocate (or re-allocate on a dimension change) the reconstruction scratch arrays shared by the uniform and curvilinear residual paths. Consistent stat= handling: the two paths previously diverged (one omitted stat=).

Arguments

Type IntentOptional Attributes Name
type(solver_state_2d_t), intent(inout) :: state
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: sw

private pure subroutine limit_pos_2d(qf, qa, gam)

Zhang-Shu positivity limiter for a 2D Euler face state (neq2d=4). Blends the reconstructed face state toward the cell average until density rho >= eps and pressure p >= eps. A no-op in smooth regions.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(inout) :: qf(neq2d)
real(kind=wp), intent(in) :: qa(neq2d)
real(kind=wp), intent(in) :: gam

public subroutine compute_resid_2d(state)

Arguments

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

private subroutine compute_resid_2d_curvilinear(state)

Curvilinear residual: R = -(1/V)[ (Fhat_{i+1}-Fhat_i) + (Ghat_{j+1}-Ghat_j) ] with contravariant face fluxes Fhat = |S_xi| * f_n(qL,qR; n_xi), Ghat = |S_eta| * f_n(qL,qR; n_eta). Reconstruction is identical to the uniform path (uniform computational stencil); geometry enters via s_xi/s_eta/vol.

Arguments

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

private subroutine compute_resid_fdm_curv_2d(state)

Curvilinear-FDM (FDS) residual on NODAL transformation metrics: R = -(1/J)[ (Fhat_{i+1/2}-Fhat_{i-1/2}) + (Ghat_{j+1/2}-Ghat_{j-1/2}) ] with contravariant face fluxes Fhat = |S_xi| * f_n(qL,qR; n_xi), Ghat = |S_eta| * f_n(qL,qR; n_eta) and S_xi=mesh%sx_xi, S_eta=mesh%sx_eta, J=mesh%jac. Structurally identical to compute_resid_2d_curvilinear (the FVM curvilinear residual); only the metric SOURCE differs — FVM face-area vectors (s_xi/s_eta/vol) become the nodal transformation metrics here. Reconstruction and the contravariant flux machinery are reused verbatim. Freestream/GCL preservation (the Phase 1 gate) relies on the consistent metric evaluation in compute_metrics_fdm_2d: a constant flow telescopes the face fluxes to ~0.

Read more…

Arguments

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

private subroutine compute_resid_fdm_curv_fvs_2d(state)

Curvilinear-FDM FLUX-VECTOR-SPLITTING residual on NODAL transformation metrics (the FVS counterpart of compute_resid_fdm_curv_2d): R = -(1/J)[ (Fhat_{i+1/2}-Fhat_{i-1/2}) + (Ghat_{j+1/2}-Ghat_{j-1/2}) ] with the contravariant split-flux reconstruction Fhat_{i+1/2} = recon_L[ Fhat^+ ] + recon_R[ Fhat^- ], mirroring the uniform FVS residual compute_resid_fdm_fvs_2d but with CONTRAVARIANT split fluxes and the 1/J divisor.

Read more…

Arguments

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

private subroutine ensure_fvs_scratch_2d(state, nx, ny, h)

Allocate (or re-allocate on a dimension change) the FVS split-flux scratch fp_all/fm_all, halo-padded like ub (1-h:nx+h, 1-h:ny+h). Allocated lazily from compute_resid_fdm_fvs_2d so non-FVS paths never pay the memory cost.

Arguments

Type IntentOptional Attributes Name
type(solver_state_2d_t), intent(inout) :: state
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: h

private subroutine fvs_vacuum_guard_2d(q, gam, ctx)

Vacuum/positivity guard for the FVS split-flux precompute. The FVS split routines evaluate sqrt(gam*p/rho); a non-positive density or pressure would produce NaN that then propagates silently through the reconstructed face fluxes and the residual. Detect it here and fail clearly instead. Mirrors the 1D FVS guard in spatial_discretization.f90 (block-guarded check + parallel_fatal). Operands are guarded with nested ifs because Fortran .and. does not short-circuit (rho is a divisor in p).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: q(neq2d)
real(kind=wp), intent(in) :: gam
character(len=*), intent(in) :: ctx

private subroutine compute_resid_fdm_fvs_2d(state)

FDM + flux-vector-splitting residual (Shu-style conservative finite difference). Per direction: split the physical flux at every node (interior + halo) into F^+/F^-, reconstruct F^+ with the LEFT-biased stencil and F^- with the RIGHT-biased (mirror) stencil, sum the two reconstructions at each face, then take the conservative difference.

Read more…

Arguments

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