Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:07

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