Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:10:55

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/geo/GeoMaterialParams.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/CollectionMirror.hh"
0014 #include "corecel/data/ParamsDataInterface.hh"
0015 #include "corecel/io/Label.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/mat/MaterialParams.hh"
0018 
0019 #include "GeoFwd.hh"
0020 #include "GeoMaterialData.hh"
0021 
0022 namespace celeritas
0023 {
0024 struct ImportData;
0025 
0026 //---------------------------------------------------------------------------//
0027 /*!
0028  * Map a track's geometry state to a material ID.
0029  *
0030  * For the forseeable future this class should just be a vector of
0031  * PhysicsMaterialIds, one per volume.
0032  *
0033  * The constructor takes an array of material IDs for every volume. Missing
0034  * material IDs may be allowed if they correspond to unreachable volume IDs. If
0035  * the list of `volume_names` strings is provided, it must be the same size as
0036  * `volume_to_mat` and indicate a mapping for the geometry's volume IDs.
0037  * Otherwise, the array is required to have exactly one entry per volume ID.
0038  *
0039  * Warnings are emitted if materials are unavailable for any volumes, *unless*
0040  * the corresponding volume name is empty (corresponding perhaps to a "parallel
0041  * world" or otherwise unused volume) or is enclosed with braces (used for
0042  * virtual volumes such as `[EXTERIOR]` or temporary boolean/reflected volumes.
0043  */
0044 class GeoMaterialParams final
0045     : public ParamsDataInterface<GeoMaterialParamsData>
0046 {
0047   public:
0048     //!@{
0049     //! \name Type aliases
0050     using SPConstGeo = std::shared_ptr<GeoParams const>;
0051     using SPConstMaterial = std::shared_ptr<MaterialParams const>;
0052     //!@}
0053 
0054     //! Input parameters
0055     struct Input
0056     {
0057         SPConstGeo geometry;
0058         SPConstMaterial materials;
0059         std::vector<PhysMatId> volume_to_mat;
0060         std::vector<Label> volume_labels;  // Optional
0061     };
0062 
0063   public:
0064     // Construct with imported data
0065     static std::shared_ptr<GeoMaterialParams>
0066     from_import(ImportData const& data,
0067                 SPConstGeo geo_params,
0068                 SPConstMaterial material_params);
0069 
0070     // Construct from geometry and material params
0071     explicit GeoMaterialParams(Input);
0072 
0073     //! Access material properties on the host
0074     HostRef const& host_ref() const final { return data_.host_ref(); }
0075 
0076     //! Access material properties on the device
0077     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0078 
0079     // Get the total number of volumes
0080     inline VolumeId::size_type num_volumes() const;
0081 
0082     // Get the material ID corresponding to a volume ID
0083     inline PhysMatId material_id(VolumeId v) const;
0084 
0085   private:
0086     CollectionMirror<GeoMaterialParamsData> data_;
0087 
0088     using HostValue = HostVal<GeoMaterialParamsData>;
0089 };
0090 
0091 //---------------------------------------------------------------------------//
0092 // INLINE DEFINITIONS
0093 //---------------------------------------------------------------------------//
0094 /*!
0095  * Get the total number of volumes.
0096  */
0097 VolumeId::size_type GeoMaterialParams::num_volumes() const
0098 {
0099     return this->host_ref().materials.size();
0100 }
0101 
0102 //---------------------------------------------------------------------------//
0103 /*!
0104  * Get the material ID corresponding to a volume ID.
0105  *
0106  * Some "virtual" volumes may have a null ID.
0107  */
0108 PhysMatId GeoMaterialParams::material_id(VolumeId v) const
0109 {
0110     CELER_EXPECT(v < this->num_volumes());
0111 
0112     return this->host_ref().materials[v];
0113 }
0114 
0115 //---------------------------------------------------------------------------//
0116 }  // namespace celeritas