// CelerisLab – boundary/inlet/regularized.cuh
// West velocity inlet with local macro state and donor-damped incoming NEQ.
//
// This method keeps the target macro state from local west-boundary closure but
// avoids a full local algebraic source state by injecting only damped donor NEQ
// on incoming directions.
//
// COMPATIBILITY NOTE (ddf_shifting):
//   Formula: f[1] = feq_tar[1] + beta * (f_neb[1] - feq_neb[1])
//   f_neb comes from load_ddf / load_f_esopull (shifted when USE_DDF_SHIFTING=1).
//   feq_tar / feq_neb come from compute_feq (also shifted when USE_DDF_SHIFTING=1).
//   The NEQ term (f_neb - feq_neb) cancels weights pairwise --> self-consistent.
//
//   CURRENT STATUS: Verified self-consistent for SRT/TRT.  MRT + shifting +
//   regularized inlet shows suppressed vortex shedding -- root cause not yet
//   fully isolated (may involve inlet NEQ interaction with unshifted MRT interior).
//   Use zou_he_local inlet when combining MRT + ddf_shifting.
// ============================================================================

#ifndef CELERIS_BOUNDARY_INLET_REGULARIZED_CUH
#define CELERIS_BOUNDARY_INLET_REGULARIZED_CUH

#if LATTICE_MODEL == LATTICE_D2Q9
__device__ inline void apply_regularized_left_velocity_inlet_d2q9(
    float* __restrict__ f,
    const float* __restrict__ f_neb,
    float ux_target,
    float uy_target)
{
    const float rho = west_velocity_rho_closure_d2q9(f, ux_target);
    float rho_neb, u_neb, v_neb;
    compute_rho_u(f_neb, rho_neb, u_neb, v_neb);

    float feq_tar[9], feq_neb[9];
    compute_feq(rho, ux_target, uy_target, feq_tar);
    compute_feq(rho_neb, u_neb, v_neb, feq_neb);

    const float beta = INLET_REGULARIZED_NEQ_DAMP;
    f[1] = feq_tar[1] + beta * (f_neb[1] - feq_neb[1]);
    f[5] = feq_tar[5] + beta * (f_neb[5] - feq_neb[5]);
    f[7] = feq_tar[7] + beta * (f_neb[7] - feq_neb[7]);
}
#endif

#if LATTICE_MODEL == LATTICE_D3Q19
__device__ inline void apply_regularized_left_velocity_inlet_d3q19(
    float* __restrict__ f,
    const float* __restrict__ f_neb,
    float ux_target,
    float uy_target,
    float uz_target)
{
    const float rho = west_velocity_rho_closure_d3q19(f, ux_target);
    float rho_neb, u_neb, v_neb, w_neb;
    compute_rho_u(f_neb, rho_neb, u_neb, v_neb, w_neb);

    float feq_tar[19], feq_neb[19];
    compute_feq(rho, ux_target, uy_target, uz_target, feq_tar);
    compute_feq(rho_neb, u_neb, v_neb, w_neb, feq_neb);

    const float beta = INLET_REGULARIZED_NEQ_DAMP;
    f[1]  = feq_tar[1]  + beta * (f_neb[1]  - feq_neb[1]);
    f[7]  = feq_tar[7]  + beta * (f_neb[7]  - feq_neb[7]);
    f[9]  = feq_tar[9]  + beta * (f_neb[9]  - feq_neb[9]);
    f[13] = feq_tar[13] + beta * (f_neb[13] - feq_neb[13]);
    f[15] = feq_tar[15] + beta * (f_neb[15] - feq_neb[15]);
}
#endif

#endif // CELERIS_BOUNDARY_INLET_REGULARIZED_CUH
