Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:39

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/optical/surface/model/TrivialInteractor.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/math/Algorithms.hh"
0010 #include "corecel/math/ArrayOperators.hh"
0011 #include "celeritas/optical/CoreTrackView.hh"
0012 
0013 #include "SurfaceInteraction.hh"
0014 #include "TrivialInteractionData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace optical
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Return a trivial interaction based on the \c TrivialInteractionMode.
0023  *
0024  * Each surface in the trivial model has one interaction mode, which is applied
0025  * to all incident tracks. None of the modes depend on any of the previous
0026  * surface physics state or models.
0027  *
0028  *  1. All photons are absorbed on the surface.
0029  *  2. All photons are transmitted with no change to direction or polarization.
0030  *  3. All photons are reflected (back-scattered) with opposite direction and
0031  * polarization.
0032  */
0033 class TrivialInteractor
0034 {
0035   public:
0036     // Construct interactor for a specific mode
0037     inline CELER_FUNCTION TrivialInteractor(
0038         TrivialInteractionMode mode, Real3 const& dir, Real3 const& pol);
0039 
0040     // Calculate surface interaction
0041     inline CELER_FUNCTION SurfaceInteraction operator()() const;
0042 
0043   private:
0044     TrivialInteractionMode mode_;
0045     Real3 const& dir_;
0046     Real3 const& pol_;
0047 };
0048 
0049 //---------------------------------------------------------------------------//
0050 /*!
0051  * Return a trivial interaction for the track based on the surface.
0052  */
0053 struct TrivialInteractionExecutor
0054 {
0055     NativeCRef<TrivialInteractionData> data;
0056 
0057     CELER_FUNCTION SurfaceInteraction operator()(
0058         CoreTrackView const& track) const
0059     {
0060         auto sub_model_id = track.surface_physics()
0061                                 .interface(SurfacePhysicsOrder::interaction)
0062                                 .internal_surface_id();
0063 
0064         CELER_ASSERT(sub_model_id < data.modes.size());
0065 
0066         return TrivialInteractor{data.modes[sub_model_id],
0067                                  track.geometry().dir(),
0068                                  track.particle().polarization()}();
0069     }
0070 };
0071 
0072 //---------------------------------------------------------------------------//
0073 // INLINE DEFINITIONS
0074 //---------------------------------------------------------------------------//
0075 /*!
0076  * Construct the interactor for the given mode, incident direction, and
0077  * incident polarization.
0078  */
0079 CELER_FUNCTION TrivialInteractor::TrivialInteractor(
0080     TrivialInteractionMode mode, Real3 const& dir, Real3 const& pol)
0081     : mode_(mode), dir_(dir), pol_(pol)
0082 {
0083 }
0084 
0085 //---------------------------------------------------------------------------//
0086 /*!
0087  * Calculate surface interaction based on the interaction mode.
0088  */
0089 CELER_FUNCTION SurfaceInteraction TrivialInteractor::operator()() const
0090 {
0091     SurfaceInteraction result;
0092 
0093     switch (mode_)
0094     {
0095         case TrivialInteractionMode::absorb:
0096             result = SurfaceInteraction::from_absorption();
0097             break;
0098         case TrivialInteractionMode::transmit:
0099             result = SurfaceInteraction::from_transmission();
0100             break;
0101         case TrivialInteractionMode::backscatter:
0102             result = {SurfaceInteraction::Action::reflected,
0103                       negate(dir_),
0104                       negate(pol_)};
0105             break;
0106         default:
0107             CELER_ASSERT_UNREACHABLE();
0108     }
0109 
0110     return result;
0111 }
0112 
0113 //---------------------------------------------------------------------------//
0114 }  // namespace optical
0115 }  // namespace celeritas