Repository navigation
McXtrace: Mirror parabolic fixes - #3191
Conversation
- fix Edge-on tests compare the wrong coordinate. - fix Edge-on tests have no extent check. - fix Mirror limits are tested at the wrong point. - fix Rays starting below the entry plane are misjudged.
- test plane_intersect Ignored return value - fix while (status) Re-hit loop cap, added
- Miss handling "no intersection" -> RESTORE_XRAY - clear Unused/shadowed variables - avoid code duplication (Arc-length helper) -> Mirror_parabolic_s - fix One-sided yheight: edge-on fast paths now absorb only substrate-side rays
- header update - mcdisplay Outline mismatch - mcdisplay: Bisection tolerance tightening to allow small mirrors
|
Thanks Emmanuel, good clean-up. The tests give the same intensities before and after, and the limit check at the hit already helps clearly at grazing incidence. Looking at it I found some issues, the main one mine. I hope it is OK by you that I am adding these fixes directly on this branch:
1-3 belong together: 1 without 2 loses rays, 1 without 3 loses reflections. Note: 1 and 2 change numerical results. No
Left for later
Tested on macOS arm64, CPU, no MPI, with |
- paraboloid_intersect: add missing factor 2 in B (likely cause of #1633) - call paraboloid_intersect with sign=1 again (was 0 since f1c14e0) - check limits before propagating, restore on the first hit only - MCDISPLAY: fix sign of outline at z=-zmax - Mirror_parabolic_s: add acc routine Changes numerical results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @willend , no pb to directly contribute for further fixes. |
|
I read your reply as "good to go" - or do you want to include more here? |
|
Yes, go ahead |
McXtrace optics
Mirror parabolicfixesThis is rather limited code fix for the parabolic mirror optic component. No effect on actual test results.
A. Definite bugs
zz = x²/a², but the code testsfabs(z - zz). The x-axis case does the same withfabs(x - xx). Both should comparey.y - zzandy - xx.zorxis unrelated to the surface height.s ≤ xwidth/2(or zdepth/2) and a "not yet past the mirror" test.sxandszare computed at the ray position on the entry planey = Y0, not at the actual hit point. The first hit is never checked afterwards. Only later reflections in the loop (L170-185) are checked correctly. The comment at L104 ("need a check for mirror limits here") flags this.sx,szat the first intersection afterPROP_DL(ll), and restore the ray on a miss. Move the pre-check or drop it.Y0·tanα, so it matters for deep (short-focus) mirrors and oblique rays. For shallow mirrors it is small.l0 ≤ 0), the limit check uses the ray's raw position, which can be far from the mirror. The ray is then rejected even if it would hit it downstream.B. Minor issues
plane_intersectis ignored (L100), andl0is uninitialised. A ray parallel to the plane (ky = 0) could leavel0unset before theif (l0 > 0)test. Fix: check the return value.while (status)loop (L135) has no iteration cap. It relies on the helper snapping the self-intersection to exactly 0 (the comment at L125 assumes this). A tiny positivel0would re-reflect at the same point. A cap would make it safe.C. Consistency and cleanup
RESTORE_XRAY(L119), but the "no intersection" path (L133) leaves the ray moved to theY0plane. This is physically harmless but inconsistent.firstis set but never read.xxandzzare declared at L81 and shadowed inside the loop (L170, L176).llcould trigger a maybe-uninitialised warning.TRACEandMCDISPLAY. The formula itself is correct, and I rederived it:s = (a²/4)(u√(1+u²) + asinh u)withu = 2x/a². Folding it into one helperMirror_parabolic_sin SHARE.yheightis symmetric: the test is|y − zz| ≤ yheight, but a substrate is one-sided (below the surface, since the paraboloid opens toward +y). Rays above the surface withinyheightnow reflect, not be absorbed.D. Documentation errors
(0, f, 0)withf = a²/4for the x-curve andb²/4for the z-curve. Fora ≠ bthese are two different focal lengths (astigmatic), not one focus.xmaxandzmaxare listed but don't exist outsideMCDISPLAY.radius: it sets the focal length, so the name is misleading. Renaming would break compatibility, so I'd only document it.xwidthandzdepthare measured as arc length along the surface, not as projected extents. The doc says only "Width of mirror".E. MCDISPLAY
y = 0at±xwidth/2and±zdepth/2(L203-206). The polygons are on the curved surface and span±xmax(projected, which is smaller). The outline therefore didn't sit on the mirror.Component test (on test Instruments)
mxtest --comp Mirror_parabolic --mpi auto --noplotsreports SUCCESSDeclaration of use of AI-tools
Co-Authored-Byline naming the tool, see CONTRIBUTING.mdDevelopment OS / boundary conditions
PR Checklist for contributing to McStas/McXtrace
For a coherent and useful contribution to McStas/McXtrace, please fill in relevant parts of the checklist:
My contribution includes patches to an existing component file
mcdocutility and rendered a reasonable documentation page for the component (please attach as screenshot in comments!)mccode-clangformattool to apply the standard McCode component indentation schememcrun --c-lint"linter" and followed advice to remove most / all warnings that are raised