Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:26

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/optical/detail/CerenkovOffloadExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "celeritas/global/CoreTrackView.hh"
0013 #include "celeritas/optical/CerenkovOffload.hh"
0014 #include "celeritas/optical/OffloadData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 // LAUNCHER
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Generate optical distribution data.
0025  */
0026 struct CerenkovOffloadExecutor
0027 {
0028     inline CELER_FUNCTION void
0029     operator()(celeritas::CoreTrackView const& track);
0030 
0031     NativeCRef<celeritas::optical::MaterialParamsData> const material;
0032     NativeCRef<celeritas::optical::CerenkovData> const cerenkov;
0033     NativeRef<OffloadStateData> const state;
0034     OffloadBufferSize size;
0035 };
0036 
0037 //---------------------------------------------------------------------------//
0038 // INLINE DEFINITIONS
0039 //---------------------------------------------------------------------------//
0040 /*!
0041  * Generate optical distribution data.
0042  */
0043 CELER_FUNCTION void
0044 CerenkovOffloadExecutor::operator()(CoreTrackView const& track)
0045 {
0046     CELER_EXPECT(state);
0047     CELER_EXPECT(cerenkov);
0048     CELER_EXPECT(material);
0049 
0050     using DistId = ItemId<celeritas::optical::GeneratorDistributionData>;
0051 
0052     auto tsid = track.track_slot_id();
0053     CELER_ASSERT(size.cerenkov + tsid.get() < state.cerenkov.size());
0054     auto& cerenkov_dist = state.cerenkov[DistId(size.cerenkov + tsid.get())];
0055 
0056     // Clear distribution data
0057     cerenkov_dist = {};
0058 
0059     auto sim = track.make_sim_view();
0060     auto const& step = state.step[tsid];
0061 
0062     if (!step || sim.status() == TrackStatus::inactive)
0063     {
0064         // Inactive tracks, materials with no optical properties, or particles
0065         // that started the step with zero energy (e.g. a stopped positron)
0066         return;
0067     }
0068 
0069     auto particle = track.make_particle_view();
0070 
0071     // Get the distribution data used to generate Cerenkov optical photons
0072     if (particle.charge() != zero_quantity())
0073     {
0074         Real3 const& pos = track.make_geo_view().pos();
0075         optical::MaterialView opt_mat{material, step.material};
0076         auto rng = track.make_rng_engine();
0077 
0078         CerenkovOffload generate(particle, sim, opt_mat, pos, cerenkov, step);
0079         cerenkov_dist = generate(rng);
0080     }
0081 }
0082 
0083 //---------------------------------------------------------------------------//
0084 }  // namespace detail
0085 }  // namespace celeritas