Skip to content

Hybrid histogram: bin each molecule to a node in its own compartment - #34

Merged
jcschaff merged 1 commit into
mainfrom
fix/hybrid-same-compartment-binning
Oct 8, 2026
Merged

jcschaff merged 1 commit into
mainfrom
fix/hybrid-same-compartment-binning

Conversation

@jcschaff

@jcschaff jcschaff commented Oct 8, 2026

Copy link
Copy Markdown
Member

Fixes #25.

The bug. VCellSmoldynOutput::computeHistogram bins each molecule to its nearest grid node, whatever compartment that node is in. Next to a curved membrane, a molecule inside the cell can be nearest to an exterior node. The PDE does not solve the coupled species there, so that molecule's contribution is lost.

The fix. The nearest same-compartment re-binning written for this in 2011 was commented out for performance (742e6d7), before the spatial hybrid existed. Since then, posincompart has gained the highResVolumeSamples map, which removes most of that cost. This PR:

  • re-enables the re-binning;
  • restores isInSameCompartment from 1edb089;
  • fixes the node centre it compares against, which left out the mesh origin and used dy for z.

The issue has the full history.

Measured. Native runs through libvcell → pyvcell-fvsolver: ball R = 4 µm on a 37³ mesh of [0,9]³, 8 seeds.

stock 0.10.7 #32 + this PR
A binned to nodes outside the cell (conversion) 1.23% 0.003%
conversion A_p → B: A + B mass balance at 2 s −0.57% +0.19%
exchange A_p ⇌ B: A + B mass balance at 5 s −6.8% −2.1%

Not covered. I haven't run the C++ test suite locally; CI covers it. The cases come from viva-pde-particle, Study B2b sphere-cosim-vs-native.

🤖 Generated with Claude Code

computeHistogram binned every molecule to its nearest grid node, whatever
compartment that node belonged to. Next to a curved membrane a molecule just
inside the cell can be nearest to an exterior node, where the coupled
continuous species is not solved, so its PDE contribution was lost
(1.2% of A on a ball, R = 16 cells; 0.6% mass lost in a conversion run).

The nearest same-compartment re-binning written for this in 2011 was
commented out for performance (742e6d7) before the spatial hybrid existed.
posincompart now answers from the highResVolumeSamples map, which removes
most of that cost. Re-enable it, restore isInSameCompartment, and fix the
node centre it compares against (it omitted the mesh origin and used dy for z).

Fixes #25.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jcschaff
jcschaff merged commit 6369264 into main Oct 8, 2026
12 checks passed
@jcschaff jcschaff mentioned this pull request Oct 8, 2026
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.

Hybrid histogram bins particles to nodes outside their compartment (same-compartment correction is commented out)

1 participant