excitation: assign every current-source rhs entry at coincident elements - #128
Merged
Merged
Conversation
…ments etmns_current_source skipped an element when the applied-current source sat exactly on that element's center, leaving its right-hand-side entries at whatever complex_array left uninitialized. The solver factored that undefined row, and the reader printed subnormal or otherwise garbage components for the coincident patch or segment, disagreeing with every other engine on currents and radiation-pattern quantities that had previously matched. - add etmns_patch_base to compute a patch's two tangential slots in the n+2m layout, replacing the inline arithmetic duplicated across the builder - add etmns_zero_element to assign zero to one element's entries, segment or patch, using that shared base arithmetic - call etmns_zero_element before the coincident-source skip in etmns_current_source so every index in [0, n_plus_2m) is assigned, matching the invariant the sibling etmns_* builders already satisfy Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
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.
Description
An
EXtype-4 elementary current source placed exactly on the center of a segment or the centroid of a patch madenec2++print garbage for that element and for the currents coupled to it.etmns_current_sourcewalks the n+m elements, measures the squared distance from the source point to each element center, andcontinues when that distance vanishes,src/nec_context.cpp:3419. The entries owned by the skipped element,e[i]for a segment or the two tangential slots for a patch, are never assigned, so the solver factors whatever the array held. The three sibling builders,etmns_voltage_source,etmns_linear_wave, andetmns_circular_wave, assign every row they own unconditionally.current_vectoris a member of the persistingnec_context,src/nec_context.h:849, sized atsrc/nec_context.cpp:140.safe_array::resize,src/safe_array.h:96-107, grows storage 1.5x and copies onlyhead(_len), and the same vector carries solve results thatc_geometry::cabcexpands in place. The skipped slot therefore reads residue. Zero is the value the geometry calls for: an element centered on the source point receives no field from it.Type of Change
Implementation Details
nec_context::etmns_patch_basereturns a patch's first tangential slot in the n+2m layout, replacing the inlinen + patch_index*2arithmetic in the builder.nec_context::etmns_zero_elementassigns zero to one element's entries, one for a segment and two for a patch, off that same base, so the zeroing and the writing agree by construction on where a patch lives.continue, so every index in[0, n_plus_2m)is assigned on return.Reproduction
Three patches tile a plate in the xy-plane at x = +0.1, 0, -0.1, the source sits on the middle patch centroid at the origin, and a wire off to the side gives n > 0 segments so the patch slots are based at a nonzero
n.Before: patch 2 printed
9.88E-324as its Y-real component, the double whose bit pattern is the integer 2, in a problem whose quantities span 1e-10 to 1e+1. The wire currents were asymmetric about the source plane.After: patch 2 reads zero in every component and the wire currents are antisymmetric about that plane, segments 1 and 3 printing
±6.9547E-05 ∓1.5977E-05with the center segment nulling at2.2E-11, the symmetry a z-directed source imposes.Cross-engine: before this change
nec2++disagreed withnec2c,xnec2c, and the NEC-2 Fortran oncurrents:current,rdpat:gtot,rdpat:sens,rdpat:tilt, andrdpat:axrtfor this deck; after it, those agree.Those three carry the same skip, at
nec2c.c:4579,xnec2c/src/matrix.c:1066, andnec2dxs.f:4347where the guard branches to the loop-terminating24 CONTINUE. Their zero at that slot arrives implicitly, from static storage or a first-touchmalloc, rather than from an explicit assignment; each reuses one right-hand-side buffer across frequency steps, so the skipped slot carries the previous step's solved current on a multi-frequency deck. Matching corrections are going to those engines as well, so every lineage assigns the entry explicitly.Three
rdpat:gtotrows remain atphi=120, theta=110, where the others print-18.53dB andnec2++prints-18.52dB while the underlying E(theta) and E(phi) agree to five figures: one two-decimal print step. The companion deck that offsets the source and never reaches the guard carries the identical three rows.The segment branch of the same guard, a type-4 source on a segment center, is covered by the same change.
Testing