macOS CPU build + toroid phantom-collision fix (#467)#465
Open
treegardel wants to merge 2 commits into
Open
Conversation
CI: - Add testMacOS.yaml workflow for macOS CPU build (no rayx-ui, no CUDA). - Set MACOSX_DEPLOYMENT_TARGET=13.3 and pass it consistently to CMake. - Install required toolchain dependencies (compiler, OpenMP, HDF5, zlib, make). Build: - Add AppleClang to platform detection so RAYX_API exports symbols correctly. - Implement macOS getExecutablePath() (was static_assert(false)) using _NSGetExecutablePath. - Drop spurious baseDir from the macOS resource lookup so Data/PALIK, NFF, CROMER, MOLEC are found next to the executable (matches Linux). - Set CMAKE_OSX_DEPLOYMENT_TARGET only as fallback so it does not override the workflow value. Source / tests: - Fix formatAsVec redefinition on Linux (RandCounter == unsigned long there). - Add CPU-build fallback for the test runner so it works without GPU build. - Reduce noisy tolerances in testSchwingerDipole, testBessel1, PlaneGratingDevAzMisVLS.
The Newton solver in getToroidCollision converges to within
NEW_TOLERANCE = 1e-4 mm. After a hit, the ray is nudged forward by
COLLISION_EPSILON = 1e-6 mm — much less than the Newton residual. The
forward check tested only the sign, so a solution within the residual
on the wrong side of the new origin still passed and each toroid
bounce was counted ~4x in non-sequential tracing.
Reject hits inside Newton's own uncertainty by checking parametric
forward distance, local to the toroid solver:
const double t = dot(rayToHitpoint, rayDirection)
/ dot(rayDirection, rayDirection);
if (t <= NEW_TOLERANCE) return std::nullopt;
COLLISION_EPSILON stays at 1e-6 mm, all other surfaces keep their
precision.
Tests:
- toroid_iteration integration test (grazing toroid vs. RAY-UI
reference, regenerated at proper 1e-4 tolerance — old reference
was at 1e-1 and hid the agreement). Now matches to ~1e-10 mm.
- Three unit tests on getToroidCollision: forward and backward grazing
hits at z ~ +/-600 mm walking a tolerance series from 1e-2 down to
1e-6 mm (1 nm), plus a phantom-rejection regression test. Newton's
quadratic convergence delivers sub-nm precision in practice.
- Re-enable ReflectionZonePlateDefault200Toroid with Sequential::Yes.
Bonus: getCubicCollision had 29 pow(float(expr), N) calls truncating
doubles to single precision on every Newton iteration, capping
cubic-surface accuracy at ~1e-7 relative regardless of tolerance.
Removed; all tests still pass.
Also export getToroidCollision via RAYX_API so the test binary can call
it directly.
340c72d to
6dbb136
Compare
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.
Type of Change
Description
This PR bundles two related sets of fixes that came up while getting the macOS CPU build green.
1. macOS CPU build pipeline
13.3and pass it consistently to CMake.rayx-uiand CUDA only for macOS CI.CMAKE_OSX_DEPLOYMENT_TARGETis only set as fallback (does not override workflow value).AppleClangto platform detection soRAYX_APIexports symbols correctly on macOS.getExecutablePath()/getFullPath()inLocate.cpp(wasstatic_assert(false)).baseDirsegment from the macOS resource lookup soData/PALIK,Data/NFF,Data/CROMER,Data/MOLECare found next to the executable (matches Linux behavior). Without this, all material tables came back empty andgetRefractiveIndexreturned(-1, -1).formatAsVecredefinition on Linux (unsigned long == RandCounter).2. Toroid phantom collisions — closes #467
The Newton solver in
getToroidCollisionconverges to withinNEW_TOLERANCE = 1e-4mm. After a hit, the ray is nudged forward byCOLLISION_EPSILON = 1e-6mm — much less than the Newton residual. The forward check tested only the sign:A solution within the residual on the wrong side of the new origin still passed, so each toroid bounce was counted ~4× in non-sequential tracing.
Fix: reject hits inside Newton's own uncertainty by checking parametric forward distance, local to the toroid solver:
COLLISION_EPSILONstays at1e-6mm, all other surfaces keep their precision.Tests added:
toroid_iteration(grazing toroid vs. RAY-UI reference, regenerated at proper1e-4tolerance — old reference was at1e-1and hid the agreement).getToroidCollision: forward & backward grazing hits atz ≈ ±600 mmwalking a tolerance series from1e-2down to1e-6mm (1 nm), plus a phantom-rejection regression test. Newton's quadratic convergence delivers sub-nm precision in practice.Bonus:
getCubicCollisionhad 29pow(float(expr), N)calls truncating doubles to single precision on every Newton iteration — capping cubic-surface accuracy at ~1e-7 relative regardless of tolerance. Removed; all tests still pass.This is not a breaking change. Linux/Windows workflows are not functionally changed by this PR.
Fixes #467
✅ Pre-Merge Checklist
TODOComments (prefer new issues instead)masterif individual commits don't add valuemaster)