commit 169a3e9cb29a2010a6d25dba71998e869bf7a446
parent 77c07cecbee823a1a38ccebab52a55d69f3c4d1e
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 14 Jan 2026 09:50:22 +0100
fix(simulation): improve velocity residual normalization stability
Use reference velocity scale based on max of absolute values to prevent error amplification when dividing by small velocities.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/simulation.c b/simulation.c
@@ -885,8 +885,8 @@ coupled_shear_solver(struct simulation *sim,
} while (sim->transient);
if (!isnan(sim->v_x_limit) || !isnan(sim->v_x_fix)) {
if (!isnan(sim->v_x_limit)) {
- vel_res_norm = (sim->v_x_limit - sim->v_x[sim->nz - 1])
- / (sim->v_x[sim->nz - 1] + 1e-12);
+ double v_ref = fmax(fabs(sim->v_x_limit), fabs(sim->v_x[sim->nz - 1])) + 1e-12;
+ vel_res_norm = (sim->v_x_limit - sim->v_x[sim->nz - 1]) / v_ref;
if (vel_res_norm > 0.0)
vel_res_norm = 0.0;
} else {