Skip to content

Commit ad8e6d7

Browse files
committed
fix: condition midpoint residual at electric-field zero crossings
The restored assurance workflow exposed a pre-existing Linux failure at plasma-mode step 589. Use the documented maximum midpoint/half endpoint-jump norm so a resolved field zero crossing does not amplify roundoff. Preserve nonlinear tolerance, independent conservation gates, and fail-closed commit logic; restore the stricter documented 24-iteration cap. Track included C/test fragments in Make dependencies. Validation: baseline mode failure reproduced. Full assurance suite passes with conditioned update; UBSan passes including final 24-iteration shape. Native root suite passes 4070 checks.
1 parent f6d4f66 commit ad8e6d7

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎assurance/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ $(BUILD) $(OUTPUT):
3939
$(BUILD)/%.o: src/%.c | $(BUILD)
4040
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
4141

42+
# Included implementation/test fragments must invalidate their owning targets.
43+
$(BUILD)/em_pic3d.o: $(wildcard src/em_pic3d*.inc)
44+
$(BUILD)/test_em_pic3d_plasma_modes: $(wildcard tests/em_pic3d_plasma_modes_parts/*.inc)
45+
4246
$(BUILD)/test_%: tests/test_%.c $(LIBOBJ) | $(BUILD)
4347
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LIBOBJ) $(LDLIBS) -o $@
4448

‎assurance/include/spacewind/em_pic3d.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ typedef struct {
8686
double maximum_particle_displacement_cells;
8787
size_t maximum_path_segments;
8888
size_t nonlinear_iterations;
89+
/* Midpoint fixed-point L2 defect divided by the maximum of the old/new
90+
midpoint field norms, half the endpoint field jump norm, and DBL_MIN. */
8991
double nonlinear_relative_residual;
9092

9193
double initial_charge_C;

‎assurance/src/em_pic3d_step.inc‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,35 @@ int swa_em_pic3d_step(
535535
ez_mid_new[index] =
536536
0.5 * (state->ez_V_m[index] + ez_final[index]);
537537
}
538-
out->nonlinear_relative_residual =
539-
pic3d_vector_arrays_relative_difference(
540-
ex_mid, ey_mid, ez_mid,
541-
ex_mid_new, ey_mid_new, ez_mid_new, count
538+
{
539+
/* The midpoint electric field can pass through zero while the
540+
endpoint jump remains physically resolved. Normalize the
541+
fixed-point defect by the larger of the midpoint fields and
542+
half of that endpoint jump, avoiding a cancellation-driven
543+
relative residual without relaxing the requested tolerance. */
544+
const double endpoint_change_scale =
545+
0.5 * pic3d_vector_arrays_difference_l2(
546+
state->ex_V_m, state->ey_V_m, state->ez_V_m,
547+
ex_final, ey_final, ez_final, count
548+
);
549+
const double midpoint_difference =
550+
pic3d_vector_arrays_difference_l2(
551+
ex_mid, ey_mid, ez_mid,
552+
ex_mid_new, ey_mid_new, ez_mid_new, count
553+
);
554+
const double midpoint_scale = pic3d_max4(
555+
pic3d_vector_arrays_l2(
556+
ex_mid, ey_mid, ez_mid, count
557+
),
558+
pic3d_vector_arrays_l2(
559+
ex_mid_new, ey_mid_new, ez_mid_new, count
560+
),
561+
endpoint_change_scale,
562+
DBL_MIN
542563
);
564+
out->nonlinear_relative_residual =
565+
midpoint_difference / midpoint_scale;
566+
}
543567
out->nonlinear_iterations = iteration + 1U;
544568
if (state->particle_count == 0U) {
545569
out->nonlinear_relative_residual = 0.0;

‎assurance/tests/em_pic3d_plasma_modes_parts/part_00.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define MODE_MAX_CROSSINGS 16U
1616
#define MODE_FIELD_AMPLITUDE_V_M 1000.0
1717
#define MODE_PERIODS 4.5
18-
#define MODE_MAX_NONLINEAR_ITERATIONS 32U
18+
#define MODE_MAX_NONLINEAR_ITERATIONS 24U
1919
/* Instantaneous current normalization is weakest at mode zero crossings. */
2020
#define MODE_SPECTRAL_ORACLE_ENVELOPE 1.0e-7
2121

0 commit comments

Comments
 (0)