Repository navigation
McXtrace Lenses fix - #3049
McXtrace Lenses fix#3049farhi wants to merge 10 commits into
Conversation
…placed the formula with an exact closed form, and the slow path’s y_n now uses the correct amplitude and phase. In fast=0 mode the x-position was propagated from an already-modified x. yheight was ignored, so I now use it as the full aperture height. Photons outside the aperture passed straight through. They are now absorbed. The display box used the half-height as the full height.
Energy was K2E*k*1e-3, so a unit error. It read mu and f from the wrong table columns and double-counted Z. Its table lookup could read out of bounds. kx, ky, kz weren’t updated before the second PROP_DL, so the photon moved along the wrong direction. Absorption used d*N instead of the real path through the material. Several return; statements in a non-void function are fixed. acos(alpha) came out as NaN, because of a wrong normalisation. Table_ParseHeader was missing its NULL terminator. The generic names intersection, incom and lens could clash with other components and are renamed.
A missed aperture returned the original k vector, so the “miss” test never fired. Rays outside the lens passed through unabsorbed. I added a hit flag and these rays are now absorbed. The aperture in Lens_parab was square rather than circular. With k exactly along z, the linear-equation branch skipped the aperture check. The code could pick an intersection behind the photon.
A missed aperture returned the original k vector, so the “miss” test never fired. Rays outside the lens passed through unabsorbed. I added a hit flag and these rays are now absorbed. Lens_parab_Cyl treated the surface tangent as the normal, which gives wrong refraction when kx ≠ 0.
The default radius=1e-3 silently overrode xwidth/yheight, so the documented example didn’t work. The default is now 0. The phase term multiplied by F instead of dividing by it. Removed the dead rotation-matrix code and added a guard against calling Table_Free on an unread table.
Circular and linear logic could mix when both were specified. The linear plate had no display. The docs said the slits were along x; they are along y. There was no input validation. Things to check Behaviour change: photons that miss any lens aperture are now absorbed instead of passing through. ZonePlate weighting: it doesn’t apply the pdir weight, so intensity is not solid-angle weighted.
|
Thanks for the work on these lenses. Several of them had real problems, and the sign and geometry fixes look right. I checked the vector Snell update, the surface normals and the elliptical rim drawing by hand, and they hold up. This PR is large, though, and it combines bug fixes, API changes and some behaviour changes in one go. That makes it hard to review and hard to bisect if something regresses. For future PRs, could we keep bug fixes and new features or API changes separate? That would also make it easier for a reviewer to confirm each change. Some things to address before merge, following AGENTS.md:
Smaller items (AGENTS.md §4, §5):
I haven't compiled or run |
|
I fully agree with all these remarks, thanks Peter. The component updates were initiated before the AGENTS.md is created on the repo. Clear rules are now better to harness the AI contributions. I'll try to find time to process the requested clarifications... |
|
Perhaps it would be better to split this PR into separate PR's, one per comp. And I can take into account the new AGENTS.md rules to reduce the amount of changes and keep control over AI's ? |
|
@farhi feel free to take whatever route you prefer. Also, I don't mind multiple comps edited pr PR, it's more the mix of bugfixes with other stuff. |
McXtrace Lenses fix
The lens components are not much used, but there are known issues in some of them that do not properly focus. For this reason, an AI check was performed and dig out some significant improvements. Still, only one test value had to be changed.
Fixes for:
New components are more compact.
Mostly:
Updated MaxIV/FemtoMAX test value after Lens_parab_Cyl fix
All mxtest --comp pass
All mxtest --lint --comp pass
All mxdoc pass
Declaration of use of AI-tools
Development OS / boundary conditions
Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
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!)mctestutility to test one or more instruments making use of the component (please attachmcviewtestreport 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 raisedMy contribution includes patches to an existing instrument file
mcdocutility and rendered a reasonable documentation page for the instrument (please attach as screenshot in comments!)mctestutility to test the instrument (please attachmcviewtestreport as screenshot in comments)mcrun --c-lint"linter" and followed advice to remove most / all warnings that are raisedMy contribution includes a new 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 schemecontribcomponent categoryMy contribution includes a new instrument file
mcdocutility and rendered a reasonable documentation page for the instrument (please attach as screenshot in comments!)%Test:line (or a%TestScan:line for a parameter scan) to describe expected behaviourmcrun --c-lint"linter" and followed advice to remove most / all warnings that are raisedexampleshierarchy in a folder in the style ofexamples/ESS/New_stuff/New_stuff.instrexamplefolder, but if general use I have placed it in the globaldatafolder.My work touches the code-generator in mccode/src
My work touches / adds to the runtime lib code (.c,.h etc in multiple locations
My PR is meant to fix a specific, existing issue
My contribution contains something else