cngf-pf

continuum model for granular flows with pore-pressure dynamics (renamed from 1d_fd_simple_shear)
git clone git://src.adamsgaard.dk/cngf-pf # fast
git clone https://src.adamsgaard.dk/cngf-pf.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit 8ee190a791f59c6d83108b5f7018217a652f47c8
parent a836eef18c61a0535fe1fbfe1123f3f8530a59de
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri,  3 Jul 2026 11:37:32 +0200

fix(simulation): restore mu_wall on coupled_shear_solver error returns

Diffstat:
Msimulation.c | 10++++++++--
Mtest/test_error_path.c | 10++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/simulation.c b/simulation.c @@ -835,8 +835,10 @@ int coupled_shear_solver(struct simulation *sim, const int max_iter, /* step 5, Eq. 13 */ if (sim->fluid && (sim->t > 0)) - if (darcy_solver_1d(sim)) + if (darcy_solver_1d(sim)) { + sim->mu_wall = mu_wall_orig; return 11; + } /* step 6 */ compute_effective_stress(sim); /* Eq. 9 */ @@ -846,8 +848,10 @@ int coupled_shear_solver(struct simulation *sim, const int max_iter, compute_cooperativity_length(sim); /* Eq. 12 */ /* step 8, Eq. 11 */ - if (implicit_1d_sor_poisson_solver(sim)) + if (implicit_1d_sor_poisson_solver(sim)) { + sim->mu_wall = mu_wall_orig; return 12; + } /* step 9 */ compute_shear_strain_rate_plastic(sim); /* Eq. 8 */ @@ -883,6 +887,7 @@ int coupled_shear_solver(struct simulation *sim, const int max_iter, "after %d iterations\n", coupled_iter); fprintf(stderr, ".. Residual normalized error: %g\n", r_norm_max); + sim->mu_wall = mu_wall_orig; return 1; } } @@ -909,6 +914,7 @@ int coupled_shear_solver(struct simulation *sim, const int max_iter, "vel_res_norm=%g, mu_wall=%g\n", sim->v_x[sim->nz - 1], sim->v_x_fix, sim->v_x_limit, vel_res_norm, sim->mu_wall); + sim->mu_wall = mu_wall_orig; return 10; } } while ((!isnan(sim->v_x_fix) || !isnan(sim->v_x_limit)) && diff --git a/test/test_error_path.c b/test/test_error_path.c @@ -14,6 +14,7 @@ int main(void) { int i, ret; + double mu_wall_orig; struct simulation sim; init_sim(&sim); @@ -35,6 +36,7 @@ main(void) /* max_iter = 0 forces the stress solver to exceed its iteration budget * and return a non-zero code rather than aborting the process */ + mu_wall_orig = sim.mu_wall; ret = coupled_shear_solver(&sim, 0, 1e-5); free_arrays(&sim); @@ -44,6 +46,14 @@ main(void) return 1; } + /* a failed solve must not leak the perturbed wall friction back to the + * caller; an embedder reuses the struct for the next column */ + if (sim.mu_wall != mu_wall_orig) { + fprintf(stderr, "error: mu_wall not restored on failure: %g != %g\n", + sim.mu_wall, mu_wall_orig); + return 1; + } + printf("ok: coupled_shear_solver returned %d without terminating\n", ret); return 0; }