Skip to content

Remove a dead element-code check in MeshFile, and record why node Z is float64 - #53

Open
ecomodeller wants to merge 1 commit into
masterfrom
fix/meshfile-dead-element-code-check
Open

Remove a dead element-code check in MeshFile, and record why node Z is float64#53
ecomodeller wants to merge 1 commit into
masterfrom
fix/meshfile-dead-element-code-check

Conversation

@ecomodeller

Copy link
Copy Markdown
Member

Two behaviour-preserving edits in mikecore/MeshFile.py, both replacing a TODO with the answer it was asking for.

1. Remove a dead element-code check. The block was

if (elmtCode!=21) or (elmtCode!=25):
pass# TODO?? Do we care?

The condition is a tautology — true for every value, including 21 and 25; it needs and. It is harmless only because the body is pass, so removing it is a runtime no-op. Removing rather than fixing the operator is deliberate: the TODO invites someone to fill the body in, and with the current condition that would reject every valid mesh. Whether an unexpected element code should raise, warn, or keep being ignored is a separate policy question, filed as #46.

2. Record why node Z is float64.# TODO or np.float32 ? is replaced by the reasoning for keeping float64: a .mesh stores coordinates as text, so the file imposes no width and can carry more precision than float32 holds. MeshBuilder.SetNodes narrows Z to float32 because that is the path towards a dfsu, where node Z occupies four bytes — reading a file is not that path. Narrowing here would drop digits the file contains, and downstream consumers that stack the coordinates would upcast back to float64, hiding the loss.

No expression, assignment or control-flow change; the suite counts are unchanged (tests/test_eum.py::TestEUM::test_wrapper fails identically before and after — see #52).

…at64
The element-code check could never do anything:
if (elmtCode != 21) or (elmtCode != 25):
pass
The condition is true for every value — 21 fails the second test, 25 fails the
first — so it needs `and`. That was harmless only because the body is `pass`,
but the TODO beside it invited filling the body in, at which point the check
would have rejected every valid mesh. ElementType is already derived per element
from the corner count a few lines below, so the header's code needs no separate
handling; the comment now says what elmtCode is and that nothing acts on it.
Whether an unexpected element code should raise, warn, or continue to be ignored
is a policy question, filed as an issue rather than decided here.
The `# TODO or np.float32 ?` beside the Z array is also answerable: float64 is
correct. A .mesh stores coordinates as text, so the file can carry more precision
than float32 holds, and MeshBuilder.SetNodes narrows Z only because that path
leads to a dfsu, where node Z occupies four bytes. Narrowing on read would drop
digits the file actually contains, and mikeio reads MeshFile.Z straight into its
mesh geometry, so the loss would be silent there.
No behaviour change: both hunks are comments plus the removal of an if/pass.
Sign up for freeto 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

@ecomodeller