safe_vel Function

public pure elemental function safe_vel(mom, rho) result(v)

FP-trap-safe velocity = momentum / density for output/diagnostics.

Returns 0 for a vacuum/non-physical cell (rho <= 0) WITHOUT performing the division, so it cannot raise a zero/overflow/invalid SIGFPE under -ffpe-trap=invalid,zero,overflow. For valid rho > 0 the result is bit-for-bit identical to a plain mom/rho, so golden-master output is unchanged.

NB: deliberately an if/else, not merge() — merge evaluates BOTH arguments and would still divide by zero in the rho <= 0 branch.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: mom

Momentum component (rho*u).

real(kind=wp), intent(in) :: rho

Momentum component (rho*u). Density.

Return Value real(kind=wp)