Skip to content

Correct rhs index in not_a_knot right boundary condition#30

Open
gistrec wants to merge 1 commit into
ttk592:masterfrom
gistrec:fix-not-a-knot-right-bc-rhs-index
Open

Correct rhs index in not_a_knot right boundary condition#30
gistrec wants to merge 1 commit into
ttk592:masterfrom
gistrec:fix-not-a-knot-right-bc-rhs-index

Conversation

@gistrec
Copy link
Copy Markdown

@gistrec gistrec commented Apr 26, 2026

Bug

When using not_a_knot as the right boundary condition together with
a non-zero left boundary condition (first_deriv or second_deriv),
the left BC value was silently ignored

Root cause: set_points() wrote rhs[0] = 0.0 instead of
rhs[n-1] = 0.0 inside the not_a_knot right-BC branch. This
overwrote whatever the left-BC block had stored in rhs[0] a few
lines earlier

The bug did not affect the symmetric case (not_a_knot on both sides)
because rhs[0] was already 0 there, so the overwrite was a no-op.
That is also why no existing test caught it

Fix

src/spline.h, line 332: change rhs[0] to rhs[n-1]

Test

Added MixedBoundaryNotAKnot to unit_tests.cpp. It verifies that:

  • second_deriv left + not_a_knot right: f''(x[0]) matches the requested value.
  • first_deriv left + not_a_knot right: f'(x[0]) matches the requested value.

Both assertions fail on the unfixed code and pass after the fix

rhs[0] was written instead of rhs[n-1], silently overwriting the left boundary condition value when m_right == not_a_knot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant