Back to home page

EIC code displayed by LXR

 
 

    


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

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