Skip to content

Fix: VCML writer dropped species velocity components equal to "0.0"#54

Merged
jcschaff merged 2 commits into
mainfrom
fix-velocity-zero-component-dropped
Jun 24, 2026
Merged

Fix: VCML writer dropped species velocity components equal to "0.0"#54
jcschaff merged 2 commits into
mainfrom
fix-velocity-zero-component-dropped

Conversation

@jcschaff

Copy link
Copy Markdown
Member

The bug

vcml_writer.py skipped any species advection-velocity component whose string was exactly "0.0":

if str_val_y != "0.0":
    velocity_element.set("Y", str_val_y)

So an axis-aligned advection v = (0.5, 0) emitted <Velocity X="0.5"/> with no Y. The FV reader defaults a missing component to 0, so the data-layer round trip survived and the bug was invisible there — but the Moving Boundary solver reads the VCML directly and requires each needed component, failing at runtime with:

RuntimeError: Expression for VelocityY is null  at .../Solver/src/Variable.cpp:82

This surfaced while setting a species advection velocity (v = v_b) for a moving-boundary cross-validation: any 2D velocity with a zero component was unusable.

The fix

Emit every component that is set, including "0.0". The round trip is unchanged (the reader already defaults missing → 0, so emitting "0.0" is equivalent). Regression test added (test_species_advection_velocity_emits_zero_components), and verified end-to-end against pyvcell-mbsolver: velocity_y="0.0" now solves (previously crashed).

mypy clean; the moving-boundary + velocity tests (incl. the gated end-to-end solve) pass.

🤖 Generated with Claude Code

jcschaff and others added 2 commits June 24, 2026 17:08
The writer skipped any species advection-velocity component whose string was
exactly "0.0", emitting e.g. <Velocity X="0.5"/> for an axis-aligned advection
v = (0.5, 0). The FV reader defaults a missing component to 0, so the data-layer
round trip survived — but the Moving Boundary solver reads the VCML directly and
requires each needed component, failing at runtime with "Expression for VelocityY
is null". Emit every component that is set, including "0.0"; the round trip is
unchanged. Regression test added (verified end-to-end against pyvcell-mbsolver:
velocity_y="0.0" now solves).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The quality job failed because float(reloaded_sm.velocity_x/_y) tripped mypy
(velocity components are typed float | str | None). Narrow out None before
float() so the assertions type-check; behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jcschaff jcschaff merged commit d817b09 into main Jun 24, 2026
5 checks passed
@jcschaff jcschaff deleted the fix-velocity-zero-component-dropped branch June 24, 2026 22:40
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