Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2021-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/phys/CutoffView.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "CutoffData.hh"
0011 #include "Secondary.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Access invariant material- and particle-dependent cutoff values.
0018  *
0019  * \c CutoffParamsData is defined in \c CutoffData.hh and constructed by
0020  * \c CutoffParams .
0021  *
0022  * \code
0023  * CutoffParams cutoffs(input);
0024  * CutoffView cutoff_view(cutoffs.host_ref(), material_id);
0025  * cutoff_view.energy(particle_id);
0026  * cutoff_view.range(particle_id);
0027  * \endcode
0028  */
0029 class CutoffView
0030 {
0031   public:
0032     //!@{
0033     //! \name Type aliases
0034     using CutoffId = OpaqueId<ParticleCutoff>;
0035     using CutoffData = NativeCRef<CutoffParamsData>;
0036     using Energy = units::MevEnergy;
0037     //!@}
0038 
0039   public:
0040     // Construct for the given particle and material ids
0041     inline CELER_FUNCTION
0042     CutoffView(CutoffData const& params, MaterialId material);
0043 
0044     // Return energy cutoff value
0045     inline CELER_FUNCTION Energy energy(ParticleId particle) const;
0046 
0047     // Return range cutoff value
0048     inline CELER_FUNCTION real_type range(ParticleId particle) const;
0049 
0050     // Whether to kill secondaries below the production cut post-interaction
0051     inline CELER_FUNCTION bool apply_post_interaction() const;
0052 
0053     // Whether the post-interaction cutoff should be applied to the secondary
0054     inline CELER_FUNCTION bool apply(Secondary const&) const;
0055 
0056   private:
0057     CutoffData const& params_;
0058     MaterialId material_;
0059 
0060     //// HELPER FUNCTIONS ////
0061 
0062     // Get the cutoff for the given particle and material
0063     CELER_FORCEINLINE_FUNCTION ParticleCutoff get(ParticleId particle) const;
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 // INLINE DEFINITIONS
0068 //---------------------------------------------------------------------------//
0069 /*!
0070  * Construct view from host/device for the given material id.
0071  */
0072 CELER_FUNCTION
0073 CutoffView::CutoffView(CutoffData const& params, MaterialId material)
0074     : params_(params), material_(material)
0075 {
0076     CELER_EXPECT(params_);
0077     CELER_EXPECT(material_ < params_.num_materials);
0078 }
0079 
0080 //---------------------------------------------------------------------------//
0081 /*!
0082  * Return energy cutoff value.
0083  */
0084 CELER_FUNCTION auto CutoffView::energy(ParticleId particle) const -> Energy
0085 {
0086     return this->get(particle).energy;
0087 }
0088 
0089 //---------------------------------------------------------------------------//
0090 /*!
0091  * Return range cutoff value.
0092  */
0093 CELER_FUNCTION real_type CutoffView::range(ParticleId particle) const
0094 {
0095     return this->get(particle).range;
0096 }
0097 
0098 //---------------------------------------------------------------------------//
0099 /*!
0100  * Whether to kill secondaries below the production cut post-interaction.
0101  */
0102 CELER_FUNCTION bool CutoffView::apply_post_interaction() const
0103 {
0104     return params_.apply_post_interaction;
0105 }
0106 
0107 //---------------------------------------------------------------------------//
0108 /*!
0109  * Whether the post-interaction cutoff should be applied to the secondary.
0110  *
0111  * This will be true if the \c apply_post_interaction option is enabled and the
0112  * seccondary is an electron, positron, or gamma with energy below the
0113  * production cut.
0114  */
0115 CELER_FUNCTION bool CutoffView::apply(Secondary const& secondary) const
0116 {
0117     return (secondary.particle_id == params_.ids.gamma
0118             || secondary.particle_id == params_.ids.electron
0119             || secondary.particle_id == params_.ids.positron)
0120            && secondary.energy < this->energy(secondary.particle_id);
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 /*!
0125  * Get the cutoff for the given particle and material.
0126  */
0127 CELER_FUNCTION ParticleCutoff CutoffView::get(ParticleId particle) const
0128 {
0129     CELER_EXPECT(particle < params_.id_to_index.size());
0130     CELER_EXPECT(params_.id_to_index[particle] < params_.num_particles);
0131     CutoffId id{params_.num_materials * params_.id_to_index[particle]
0132                 + material_.get()};
0133     CELER_ENSURE(id < params_.cutoffs.size());
0134     return params_.cutoffs[id];
0135 }
0136 
0137 //---------------------------------------------------------------------------//
0138 }  // namespace celeritas