Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:44

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/MaterialView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "celeritas/Types.hh"
0012 #include "celeritas/grid/NonuniformGridCalculator.hh"
0013 
0014 #include "MaterialData.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace optical
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Access optical material properties.
0023  */
0024 class MaterialView
0025 {
0026   public:
0027     //!@{
0028     //! \name Type aliases
0029     using ParamsRef = NativeCRef<MaterialParamsData>;
0030     using MatId = OptMatId;
0031     //!@}
0032 
0033   public:
0034     // Construct from params and material ID
0035     inline CELER_FUNCTION MaterialView(ParamsRef const& params, MatId id);
0036 
0037     // Construct from params and volume ID
0038     inline CELER_FUNCTION MaterialView(ParamsRef const& params, VolumeId vol);
0039 
0040     // Whether the view is into an optical material
0041     inline CELER_FUNCTION operator bool() const;
0042 
0043     //// MATERIAL DATA ////
0044 
0045     // ID of this optical material
0046     CELER_FORCEINLINE_FUNCTION MatId material_id() const;
0047 
0048     // ID of the associated core physics material
0049     CELER_FORCEINLINE_FUNCTION PhysMatId core_material_id() const;
0050 
0051     //// PARAMETER DATA ////
0052 
0053     // Access energy-dependent refractive index
0054     inline CELER_FUNCTION NonuniformGridCalculator
0055     make_refractive_index_calculator() const;
0056 
0057   private:
0058     //// DATA ////
0059 
0060     ParamsRef const& params_;
0061     MatId mat_id_;
0062 };
0063 
0064 //---------------------------------------------------------------------------//
0065 // INLINE DEFINITIONS
0066 //---------------------------------------------------------------------------//
0067 /*!
0068  * Construct from an optical material.
0069  */
0070 CELER_FUNCTION
0071 MaterialView::MaterialView(ParamsRef const& params, MatId id)
0072     : params_(params), mat_id_(id)
0073 {
0074     CELER_EXPECT(id < params_.refractive_index.size());
0075 }
0076 
0077 //---------------------------------------------------------------------------//
0078 /*!
0079  * Construct from the current geometry volume.
0080  */
0081 CELER_FUNCTION
0082 MaterialView::MaterialView(ParamsRef const& params, VolumeId id)
0083     : params_{params}
0084 {
0085     CELER_EXPECT(id < params_.optical_id.size());
0086     mat_id_ = params_.optical_id[id];
0087 }
0088 
0089 //---------------------------------------------------------------------------//
0090 /*!
0091  * Whether the view is into an optical material.
0092  *
0093  * This accessor is so that tracks can enter a non-optical region and be killed
0094  * without crashing the code.
0095  */
0096 CELER_FORCEINLINE_FUNCTION MaterialView::operator bool() const
0097 {
0098     return static_cast<bool>(mat_id_);
0099 }
0100 
0101 //---------------------------------------------------------------------------//
0102 /*!
0103  * Get the optical material id.
0104  */
0105 CELER_FUNCTION auto MaterialView::material_id() const -> MatId
0106 {
0107     return mat_id_;
0108 }
0109 
0110 //---------------------------------------------------------------------------//
0111 /*!
0112  * Get the id of the core material associated with this optical material.
0113  */
0114 CELER_FUNCTION PhysMatId MaterialView::core_material_id() const
0115 {
0116     return params_.core_material_id[mat_id_];
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 /*!
0121  * Access energy-dependent refractive index.
0122  */
0123 CELER_FUNCTION NonuniformGridCalculator
0124 MaterialView::make_refractive_index_calculator() const
0125 {
0126     CELER_EXPECT(*this);
0127     return NonuniformGridCalculator(params_.refractive_index[mat_id_],
0128                                     params_.reals);
0129 }
0130 
0131 //---------------------------------------------------------------------------//
0132 }  // namespace optical
0133 }  // namespace celeritas