test_error_path.c (1527B)
1 /* 2 * In-process check that a non-converging configuration makes 3 * coupled_shear_solver() return a non-zero error code instead of terminating 4 * the calling process. A host embedder (e.g. PISM) relies on this so a single 5 * failing column cannot kill the MPI process. 6 */ 7 #include <math.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 11 #include "../simulation.h" 12 13 int 14 main(void) 15 { 16 int i, ret; 17 double mu_wall_orig; 18 struct simulation sim; 19 20 init_sim(&sim); 21 sim.nz = 10; 22 sim.origo_z = 0.03; 23 sim.L_z = 0.64; 24 sim.P_wall = 40e3; 25 sim.v_x_fix = 1e-3; /* velocity-driven mode */ 26 27 if (prepare_arrays(&sim)) { 28 fprintf(stderr, "error: prepare_arrays failed\n"); 29 return 2; 30 } 31 for (i = 0; i < sim.nz; ++i) 32 sim.phi[i] = 0.25; 33 34 lithostatic_pressure_distribution(&sim); 35 compute_effective_stress(&sim); 36 37 /* max_iter = 0 forces the stress solver to exceed its iteration budget 38 * and return a non-zero code rather than aborting the process */ 39 mu_wall_orig = sim.mu_wall; 40 ret = coupled_shear_solver(&sim, 0, 1e-5); 41 42 free_arrays(&sim); 43 44 if (ret == 0) { 45 fprintf(stderr, "error: solver unexpectedly converged (ret = 0)\n"); 46 return 1; 47 } 48 49 /* a failed solve must not leak the perturbed wall friction back to the 50 * caller; an embedder reuses the struct for the next column */ 51 if (sim.mu_wall != mu_wall_orig) { 52 fprintf(stderr, "error: mu_wall not restored on failure: %g != %g\n", 53 sim.mu_wall, mu_wall_orig); 54 return 1; 55 } 56 57 printf("ok: coupled_shear_solver returned %d without terminating\n", ret); 58 return 0; 59 }