Fix large-model segment/patch collisions and EX source resolution - #21
Merged
maurymarkowitz merged 2 commits intoSep 15, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two correctness issues encountered while testing OpenNEC with a large NEC-2 model containing approximately 10,248 generated wire segments.
PCHCON was set to 10000 and is used to distinguish patch connections from ordinary wire-segment connections. Once the generated segment count exceeds that value, valid segment numbers can collide with the patch-connection encoding.
In testing, this caused the results of an otherwise identical model to depend strongly on the ordering of its GW cards, including implausible impedances, broken geometric symmetry, and incorrect radiation patterns. PCHCON is moved to 1000000000, well above the segment counts encountered in practical testing.
An EX card specifies a segment relative to its tag, but the sequential reporting path queued that relative segment number in a field subsequently interpreted as an absolute/global segment number. The fix resolves the tag-relative segment through segment_number() before queueing the source.
For example, in the model that exposed the problem, EX 0 902 1 ... was intended to excite the first segment of tag 902, whose global segment number was 358, but the queued source instead referred to global segment 1.
With both fixes applied, seven different orderings of the same geometry produced identical impedance and 360-degree radiation patterns. The corrected result also agreed with nec2c: approximately Z = 159.18 - j51.18 ohms, gain 12.21 dBi, and F/B 18.28 dB, with no pattern asymmetry to printed precision.
Both changes have been rebuilt successfully against the current main branch.