Skip to content

fem: a stepped Poisson solve with one source value reads it before filling f - #903

Merged
transfix merged 1 commit into
masterfrom
fix/fem-stepped-constant-source
Oct 30, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/fem-stepped-constant-source

Conversation

@transfix

Copy link
Copy Markdown
Owner

Fem.SteppedPoissonMatchesTheOneShotSolve fails on macOS, in its last case, "a single source value" (fem_test.cpp:612). The stepped solve differs from fem::solve_poisson by a max relative 0.0968, where the test allows under 1e-10. It came with #890, whose macOS jobs were cancelled before it merged. Since then it has turned the macOS Release lane red on every PR built on master. It was first seen on #885 (run 41005671302, job 123899893970).

Cause

stepped_solve::impl::begin() (src/cvc/geometry/fem.cpp) spread a one-value source over every vertex like this:

f.assign(es.nv, f[0]);

assign(n, t) requires that t is not a reference into the container, and here it is one. libstdc++ copies t before it reallocates, so the Linux and Windows lanes were right. libc++ 17 frees first:

// libcxx/include/vector, vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
    else
    {
        __vdeallocate();
        __vallocate(__recommend(static_cast<size_type>(__n)));
        __construct_at_end(__n, __u);
    }

f holds one element, so filling it to nv takes the reallocating branch. Every vertex then got whatever the freed block held instead of -6. The one-shot solve_poisson fills a separate rhs vector, so it was always right. That is why only the stepped solve's single-value case differed. The varying-source cases earlier in the test pass on macOS.

Fix

Copy f[0] before the assign. I found no other assign, resize or insert in src/ or inc/ that takes its value from the same container.

Testing

  • This machine has no libc++, so the macOS lanes on this PR are the proof: recipe / macos-latest / Release and Debug should pass Fem.SteppedPoissonMatchesTheOneShotSolve.
  • Local (Linux, GCC 13): with CVC_ENABLE_LIBIGL defined, fem.cpp compiles warning-free apart from the existing types.h ones. The full libigl test build wasn't run, because libigl isn't installed in this machine's prefix. On libstdc++ the behaviour doesn't change.
  • git clang-format (18.1.3): no changes.

…lling f

stepped_solve's begin() spread a one-value source over every vertex with
f.assign(nv, f[0]), passing a reference into f itself. assign(n, t) requires
that t is not a reference into the vector. libstdc++ copies t before it
reallocates, so Linux and Windows were right. libc++ frees the old buffer
first (__vdeallocate, then __construct_at_end(n, u)), so on macOS every vertex
got whatever freed memory held. Fem.SteppedPoissonMatchesTheOneShotSolve's "a
single source value" case then differed from fem::solve_poisson by 9.7%
(macOS recipe Release, run 41005671302).

The value is now copied first.
@transfix
transfix merged commit 276de39 into master Oct 30, 2026
25 of 26 checks passed
@transfix
transfix deleted the fix/fem-stepped-constant-source branch October 30, 2026 18:14
transfix pushed a commit that referenced this pull request Oct 30, 2026
Takes #903's fix for the stepped Poisson solve in place of the same fix made here.
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