Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-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 
0014 #include "ElementView.hh"
0015 #include "MaterialData.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Access material properties.
0022  *
0023  * A material is a combination of nuclides/elements at a particular state (e.g.
0024  * density, temperature). The proportions and identities of a material's
0025  * constitutents are encoded in the \c elements accessor, where each index of
0026  * the returned span corresponds to an \c ElementComponentId for this material.
0027  * The \c get_element_density and \c element_view helper functions can be used
0028  * to calculate elemental densities and properties.
0029  */
0030 class MaterialView
0031 {
0032   public:
0033     //!@{
0034     //! \name Type aliases
0035     using MaterialParamsRef = NativeCRef<MaterialParamsData>;
0036     //!@}
0037 
0038   public:
0039     // Construct from params and material ID
0040     inline CELER_FUNCTION
0041     MaterialView(MaterialParamsRef const& params, MaterialId id);
0042 
0043     //// MATERIAL DATA ////
0044 
0045     // ID of this Material
0046     CELER_FORCEINLINE_FUNCTION MaterialId material_id() const;
0047 
0048     // Number density [1/len^3]
0049     CELER_FORCEINLINE_FUNCTION real_type number_density() const;
0050 
0051     // Material temperature [K]
0052     CELER_FORCEINLINE_FUNCTION real_type temperature() const;
0053 
0054     // Material state
0055     CELER_FORCEINLINE_FUNCTION MatterState matter_state() const;
0056 
0057     // ID of the optical properties for this material, if any
0058     CELER_FORCEINLINE_FUNCTION OpticalMaterialId optical_material_id() const;
0059 
0060     //// ELEMENT ACCESS ////
0061 
0062     // Number of elemental components
0063     inline CELER_FUNCTION ElementComponentId::size_type num_elements() const;
0064 
0065     // Element properties for a material-specific index
0066     inline CELER_FUNCTION ElementView
0067     make_element_view(ElementComponentId id) const;
0068 
0069     // ID of a component element in this material
0070     inline CELER_FUNCTION ElementId element_id(ElementComponentId id) const;
0071 
0072     // Total number density of an element in this material [1/len^3]
0073     inline CELER_FUNCTION real_type
0074     get_element_density(ElementComponentId id) const;
0075 
0076     // Advanced access to the elemental components (id/fraction)
0077     inline CELER_FUNCTION Span<MatElementComponent const> elements() const;
0078 
0079     //// DERIVATIVE DATA ////
0080 
0081     // Weighted atomic number
0082     inline CELER_FUNCTION real_type zeff() const;
0083 
0084     // Material density [mass/len^3]
0085     inline CELER_FUNCTION real_type density() const;
0086 
0087     // Electrons per unit volume [1/len^3]
0088     inline CELER_FUNCTION real_type electron_density() const;
0089 
0090     // Radiation length for high-energy electron Bremsstrahlung [len]
0091     inline CELER_FUNCTION real_type radiation_length() const;
0092 
0093     // Mean excitation energy [MeV]
0094     inline CELER_FUNCTION units::MevEnergy mean_excitation_energy() const;
0095 
0096     // Log mean excitation energy
0097     inline CELER_FUNCTION units::LogMevEnergy
0098     log_mean_excitation_energy() const;
0099 
0100   private:
0101     MaterialParamsRef const& params_;
0102     MaterialId material_;
0103 
0104     // HELPER FUNCTIONS
0105 
0106     CELER_FORCEINLINE_FUNCTION MaterialRecord const& material_def() const;
0107 };
0108 
0109 //---------------------------------------------------------------------------//
0110 // INLINE DEFINITIONS
0111 //---------------------------------------------------------------------------//
0112 /*!
0113  * Construct from dynamic and static particle properties.
0114  */
0115 CELER_FUNCTION
0116 MaterialView::MaterialView(MaterialParamsRef const& params, MaterialId id)
0117     : params_(params), material_(id)
0118 {
0119     CELER_EXPECT(id < params.materials.size());
0120 }
0121 
0122 //---------------------------------------------------------------------------//
0123 /*!
0124  * Get the material id being viewed.
0125  */
0126 CELER_FUNCTION MaterialId MaterialView::material_id() const
0127 {
0128     return material_;
0129 }
0130 
0131 //---------------------------------------------------------------------------//
0132 /*!
0133  * Get atomic number density [1/len^3].
0134  */
0135 CELER_FUNCTION real_type MaterialView::number_density() const
0136 {
0137     return this->material_def().number_density;
0138 }
0139 
0140 //---------------------------------------------------------------------------//
0141 /*!
0142  * Get material temperature [K].
0143  */
0144 CELER_FUNCTION real_type MaterialView::temperature() const
0145 {
0146     return this->material_def().temperature;
0147 }
0148 
0149 //---------------------------------------------------------------------------//
0150 /*!
0151  * Get material's state of matter (gas, liquid, solid).
0152  */
0153 CELER_FUNCTION MatterState MaterialView::matter_state() const
0154 {
0155     return this->material_def().matter_state;
0156 }
0157 
0158 //---------------------------------------------------------------------------//
0159 /*!
0160  * Get the index in the optical properties for this material.
0161  *
0162  * This will return an invalid ID if the material has no optical properties
0163  * attached.
0164  */
0165 CELER_FUNCTION OpticalMaterialId MaterialView::optical_material_id() const
0166 {
0167     if (params_.optical_id.empty())
0168     {
0169         return {};
0170     }
0171     CELER_ASSERT(material_ < params_.optical_id.size());
0172     return params_.optical_id[material_];
0173 }
0174 
0175 //---------------------------------------------------------------------------//
0176 /*!
0177  * Number of elements present in this material.
0178  */
0179 CELER_FUNCTION ElementComponentId::size_type MaterialView::num_elements() const
0180 {
0181     return this->material_def().elements.size();
0182 }
0183 
0184 //---------------------------------------------------------------------------//
0185 /*!
0186  * Get element properties from a material-specific index.
0187  */
0188 CELER_FUNCTION ElementView
0189 MaterialView::make_element_view(ElementComponentId id) const
0190 {
0191     CELER_EXPECT(id < this->material_def().elements.size());
0192     return ElementView(params_, this->element_id(id));
0193 }
0194 
0195 //---------------------------------------------------------------------------//
0196 /*!
0197  * ID of a component element in this material.
0198  */
0199 CELER_FUNCTION ElementId MaterialView::element_id(ElementComponentId id) const
0200 {
0201     CELER_EXPECT(id < this->material_def().elements.size());
0202     return this->elements()[id.get()].element;
0203 }
0204 
0205 //---------------------------------------------------------------------------//
0206 /*!
0207  * Number density of an element in this material [1/len^3]
0208  */
0209 CELER_FUNCTION real_type
0210 MaterialView::get_element_density(ElementComponentId id) const
0211 {
0212     CELER_EXPECT(id < this->material_def().elements.size());
0213     return this->number_density() * this->elements()[id.get()].fraction;
0214 }
0215 
0216 //---------------------------------------------------------------------------//
0217 /*!
0218  * View the elemental components (id/fraction) of this material.
0219  */
0220 CELER_FUNCTION Span<MatElementComponent const> MaterialView::elements() const
0221 {
0222     return params_.elcomponents[this->material_def().elements];
0223 }
0224 
0225 //---------------------------------------------------------------------------//
0226 /*!
0227  * Weighted atomic number.
0228  *
0229  * This is Z weighted by the atomic fraction of each element in the material.
0230  */
0231 CELER_FUNCTION real_type MaterialView::zeff() const
0232 {
0233     return this->material_def().zeff;
0234 }
0235 
0236 //---------------------------------------------------------------------------//
0237 /*!
0238  * Material's density [mass/len^3].
0239  */
0240 CELER_FUNCTION real_type MaterialView::density() const
0241 {
0242     return this->material_def().density;
0243 }
0244 
0245 //---------------------------------------------------------------------------//
0246 /*!
0247  * Electrons per unit volume [1/len^3].
0248  */
0249 CELER_FUNCTION real_type MaterialView::electron_density() const
0250 {
0251     return this->material_def().electron_density;
0252 }
0253 
0254 //---------------------------------------------------------------------------//
0255 /*!
0256  * Radiation length for high-energy electron Bremsstrahlung [len].
0257  */
0258 CELER_FUNCTION real_type MaterialView::radiation_length() const
0259 {
0260     return this->material_def().rad_length;
0261 }
0262 
0263 //---------------------------------------------------------------------------//
0264 /*!
0265  * Mean excitation energy [MeV].
0266  */
0267 CELER_FUNCTION units::MevEnergy MaterialView::mean_excitation_energy() const
0268 {
0269     return this->material_def().mean_exc_energy;
0270 }
0271 
0272 //---------------------------------------------------------------------------//
0273 /*!
0274  * Log mean excitation energy.
0275  */
0276 CELER_FUNCTION units::LogMevEnergy
0277 MaterialView::log_mean_excitation_energy() const
0278 {
0279     return this->material_def().log_mean_exc_energy;
0280 }
0281 
0282 //---------------------------------------------------------------------------//
0283 // PRIVATE METHODS
0284 //---------------------------------------------------------------------------//
0285 /*!
0286  * Static material defs for the current state.
0287  */
0288 CELER_FUNCTION MaterialRecord const& MaterialView::material_def() const
0289 {
0290     return params_.materials[material_];
0291 }
0292 
0293 //---------------------------------------------------------------------------//
0294 }  // namespace celeritas