Back to home page

EIC code displayed by LXR

 
 

    


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

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