Skip to content

Reject ambiguous and unsupported optical surface reflectivity - #2691

Merged
sethrj merged 6 commits into
celeritas-project:developfrom
DanielChahine004:surface-reflectivity-default
Dec 3, 2026
Merged

sethrj merged 6 commits into
celeritas-project:developfrom
DanielChahine004:surface-reflectivity-default

Conversation

@DanielChahine004

@DanielChahine004 DanielChahine004 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

In GeantSurfacePhysicsLoader::insert_reflectivity, if a surface has TRANSMITTANCE or EFFICIENCY but no REFLECTIVITY, the missing reflectivity is set to a constant 0. REALRINDEX and IMAGINARYRINDEX are silently ignored.

Geant4. G4OpBoundaryProcess starts each step with fReflectivity = 1 and only overrides it from REFLECTIVITY or, if that is missing and both REALRINDEX and IMAGINARYRINDEX are given, from CalculateReflectivity. It absorbs if rand > R + T and transmits if rand > R, so TRANSMITTANCE and EFFICIENCY have no effect on these choices when R = 1. DielectricMetal also calls CalculateReflectivity for repeated reflections if both indices are given, even with REFLECTIVITY.

Consequence. In Celeritas, a surface with only EFFICIENCY absorbs every photon (a perfect absorber or detector), and a surface with only TRANSMITTANCE transmits with probability T and absorbs the rest. Geant4 does neither for these surfaces. Results can also differ for surfaces with a complex refractive index.

Fix. Raise an error if:

  • TRANSMITTANCE or EFFICIENCY is given without REFLECTIVITY (ambiguous), or
  • REALRINDEX or IMAGINARYRINDEX is given, with or without REFLECTIVITY (not supported).

Each error names the surface, lists all of its reflectivity problems and recommends fixes. All invalid surfaces are reported in one import: GeantPhysicsLoader already collects the exceptions, but a failed surface left partial data that could cause a spurious "duplicate" assertion in the next one, hiding its actual error. The surface index now advances after a failure. Other surfaces are imported as before.

Test. The new invalid-optical-surfaces.gdml has six invalid surfaces (TRANSMITTANCE and/or EFFICIENCY only, and complex index alone, with REFLECTIVITY, and with TRANSMITTANCE) and two valid ones. The test checks that one import reports exactly the expected errors for all six, and it fails without the surface index change. full-optical-surfaces.gdml has a new valid surface with all three grids, and optical/SurfaceImporter now also compares the transmittance and efficiency grids. The CPU optical/Surface* and GeantImporter tests pass (Debug build, Geant4 11.4.3, no GPU).

Related: #2514 (comparing efficiency/reflectivity handling with Geant4). Downstream, dielectric_metal surfaces still go through the interactor behaviour reported in #2682.

@github-actions label physics

🤖 Generated with Claude Code (Claude Opus 5.5)

G4OpBoundaryProcess uses a reflectivity of 1 when the surface has no
REFLECTIVITY property (and no complex refractive index), so TRANSMITTANCE
and EFFICIENCY have no effect. Celeritas instead built a grid reflectivity
of 0 whenever TRANSMITTANCE or EFFICIENCY was present, turning such surfaces
into absorbers. Use the Fresnel (always-interact) reflectivity in that case,
warn about the ignored properties, and warn about unsupported complex
refractive index properties.

Assisted-by: Claude Code (Claude Opus 5.5)
@github-actions github-actions Bot added physics Particles, processes, and stepping algorithms ai-generated Generated and managed by an agent/bot, not a human. labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Test summary

 8 214 files  13 506 suites   16m 15s ⏱️
 2 557 tests  2 499 ✅  58 💤 0 ❌
48 114 runs  47 807 ✅ 307 💤 0 ❌

Results for commit fa07d93.

♻️ This comment has been updated with latest results.

@sethrj sethrj added the bug Something isn't working label Nov 24, 2026
@DanielChahine004
DanielChahine004 marked this pull request as ready for review November 24, 2026 18:32
@hhollenb

Copy link
Copy Markdown
Contributor

As you state with the Geant4 implementation, this behavior is dependent on surface type and potentially future surface models. If we want to strictly match the Geant4 defaults, we can just set the reflectivity grid to unity, which will most closely reproduce the Geant4 logical flow.

In general we should be careful about the grid reflectivity implementation since it's still unclear whether it's semantically meaningful and if we even want to replicate the Geant4 behavior. We should be more strict in checking input in the meantime.

If only TRANSMITTANCE or EFFICIENCY is given, use the grid model with
reflectivity one and transmittance zero instead of the Fresnel model.
The transmittance must be zero because the grid model samples
transmission before interaction. Also check the transmittance and
efficiency grids in the surface importer test.

Assisted-by: Claude Code (Claude Opus 5.5)
@DanielChahine004

Copy link
Copy Markdown
Contributor Author

🤖 (Claude Code, Claude Opus 5.5)

Thanks, switched to a unit reflectivity grid in 9dd61f8. When only TRANSMITTANCE and/or EFFICIENCY is given, I also set the transmittance to 0: GridReflectivityExecutor samples transmit before interact, so keeping the user's T with R = 1 would still transmit a fraction T (Geant4 transmits none) and would fail the Selector debug assertion since R + T > 1. The efficiency is dropped because nothing is absorbed. SurfaceImporter now checks the transmittance and efficiency grids too.

On stricter input checking: these cases currently log a warning. Would you prefer an error (CELER_VALIDATE) for TRANSMITTANCE/EFFICIENCY without REFLECTIVITY? That would avoid choosing a behavior until the semantics are settled, but would reject inputs that Geant4 accepts.

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.96%. Comparing base (ac9e26d) to head (fa07d93).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
.../celeritas/ext/detail/GeantSurfacePhysicsLoader.cc 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2691      +/-   ##
===========================================
- Coverage    86.09%   85.96%   -0.14%     
===========================================
  Files         1415     1420       +5     
  Lines        45459    45534      +75     
  Branches     11652    11664      +12     
===========================================
+ Hits         39140    39144       +4     
+ Misses        4607     4605       -2     
- Partials      1712     1785      +73     
Files with missing lines Coverage Δ
.../celeritas/ext/detail/GeantSurfacePhysicsLoader.cc 88.00% <88.88%> (+15.84%) ⬆️

... and 126 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sethrj

sethrj commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

On stricter input checking: these cases currently log a warning. Would you prefer an error (CELER_VALIDATE) for TRANSMITTANCE/EFFICIENCY without REFLECTIVITY? That would avoid choosing a behavior until the semantics are settled, but would reject inputs that Geant4 accepts.

It's probably safest for us to VALIDATE if there's an ambiguous input that results in known different behavior for Celeritas and Geant4. If it's possible, we should stack the ambiguous Geant4 inputs from multiple surfaces/materials together, with recommendations for how to fix them. I want to avoid an iterative process where the user has to repeatedly run celeritas, fix one material, hit the next error, fix that, etc. (Warnings/error messages avoid that.) I think it's good to encourage users to be explicit about the behavior of the optical properties.

Replace the warnings and unit reflectivity fallback with an error if
TRANSMITTANCE or EFFICIENCY is given without REFLECTIVITY, or if
REALRINDEX or IMAGINARYRINDEX is given. Geant4 uses the complex index for
repeated reflections from metals even if REFLECTIVITY is given.

Report all the reflectivity errors for a surface together, with
recommended fixes. Advance the surface index after a failure so that
partially inserted data does not cause a spurious duplicate error that
hides the errors in subsequent surfaces.

Assisted-by: Claude Code (Claude Opus 5.5)
@DanielChahine004 DanielChahine004 changed the title Use unit reflectivity for optical surfaces without REFLECTIVITY Reject ambiguous and unsupported optical surface reflectivity Dec 1, 2026
@DanielChahine004

Copy link
Copy Markdown
Contributor Author

🤖 (Claude Code, Claude Opus 5.5)

Done in 15cddb4: TRANSMITTANCE or EFFICIENCY without REFLECTIVITY is now an error, replacing the R = 1, T = 0 fallback. Each surface gets one error that lists all of its reflectivity problems and how to fix them, and a single import reports every invalid surface.

GeantPhysicsLoader already collected the exceptions, but a failed surface left partial data behind, so the next one could hit the duplicate assertion in emplace and hide its real error. I now advance the surface index after a failure. The new test checks that all six invalid surfaces are reported, and it fails without that change.

This combines errors across surfaces only. Other processes, such as scintillation (per material), have separate handlers, so a failure in one of those can still be reported in a separate run. Combining them would need a handler shared across processes, which I'd suggest leaving to a separate PR.

@DanielChahine004

Copy link
Copy Markdown
Contributor Author

🤖 (Claude Code, Claude Opus 5.5) The resolute-gcc-15-c++23 job failed while installing packages (503 from security.ubuntu.com), before compiling. Could someone rerun the failed and cancelled jobs when convenient?

@DanielChahine004

Copy link
Copy Markdown
Contributor Author

🤖 (Claude Code, Claude Opus 5.5) Thanks for rerunning this. resolute-gcc-15 no longer fails, but the two cancelled jobs (noble-gcc-14, resolute-arm-gcc-15) still show their attempt 1 results, so the later jobs haven't run. Could you try "Re-run all jobs" when convenient? noble-gcc-14 hit the same 503 error, and the ARM log shows no compile errors before it was cancelled.

@sethrj

sethrj commented Dec 1, 2026

Copy link
Copy Markdown
Member

@hhollenb I've recommended throwing errors where we think missing data is ambiguous/error-prone. Reasonable?

@sethrj
sethrj requested review from hhollenb and removed request for drbenmorgan December 2, 2026 19:21

@hhollenb hhollenb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some conflation of grid reflectivity and complex refractive index here. Also some over-complication of the import logic and testing.

Move the complex refractive index check into
check_unimplemented_properties, which is now called for every surface.
GROUPVEL is dropped from that list because Geant4 adds it whenever RINDEX
is given (e.g. back-painted surfaces). insert_reflectivity uses Fresnel
when no grid property is given and otherwise requires REFLECTIVITY.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sethrj sethrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Waiting to merge pending these two small changes and @hhollenb 's re-review.

…nter

Per review: keep the original condition and if/else structure in
insert_reflectivity (validate REFLECTIVITY inside the grid branch, Fresnel
in the else branch), which also shrinks the diff against develop. Document
current_surface_ in the class and the postcondition of operator(): the
counter is left at the next unused physics surface ID, including after a
failed surface.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sethrj sethrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@sethrj
sethrj dismissed hhollenb’s stale review December 3, 2026 14:38

Changes were addressed. Thanks again @hholenb!

@sethrj
sethrj added this pull request to the merge queue Dec 3, 2026
Merged via the queue into celeritas-project:develop with commit 016943a Dec 3, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Generated and managed by an agent/bot, not a human. bug Something isn't working physics Particles, processes, and stepping algorithms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants