Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:11:48

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 geocel/detail/SurfaceParamsBuilder.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <map>
0010 #include <utility>
0011 #include <vector>
0012 
0013 #include "corecel/Assert.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/data/Collection.hh"
0016 #include "corecel/data/CollectionBuilder.hh"
0017 #include "corecel/data/DedupeCollectionBuilder.hh"
0018 #include "corecel/io/Label.hh"
0019 #include "geocel/SurfaceData.hh"
0020 #include "geocel/Types.hh"
0021 #include "geocel/VolumeParams.hh"
0022 #include "geocel/inp/Model.hh"
0023 
0024 namespace celeritas
0025 {
0026 namespace detail
0027 {
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Temporary data structure to hold surface information for a volume.
0031  *
0032  * This is an intermediate representation of VolumeSurfaceRecord that uses
0033  * STL containers for easier construction before being converted to the
0034  * device-compatible format.
0035  */
0036 struct VolumeSurfaceData
0037 {
0038     //! Type for interface key (pre/post volume instance ID)
0039     using Interface = std::pair<VolumeInstanceId, VolumeInstanceId>;
0040 
0041     //! Surface identifier for the volume boundary (if any)
0042     SurfaceId boundary;
0043 
0044     //! Map of pre/post volume instance pairs to surface IDs
0045     std::map<Interface, SurfaceId> interfaces;
0046 
0047     //! True if any data is present
0048     explicit operator bool() const { return boundary || !interfaces.empty(); }
0049 };
0050 
0051 //---------------------------------------------------------------------------//
0052 /*!
0053  * Process input surfaces and build VolumeSurfaceData structures.
0054  *
0055  * This class processes inp::Surface data and constructs the necessary
0056  * VolumeSurfaceData objects that map surfaces to volumes and their interfaces.
0057  * It performs error checking against duplicate surface assignments.
0058  */
0059 class SurfaceInputInserter
0060 {
0061   public:
0062     // Construct with pointers to target data and volume params
0063     SurfaceInputInserter(VolumeParams const& volumes,
0064                          std::vector<Label>& labels,
0065                          std::vector<VolumeSurfaceData>& volume_surfaces);
0066 
0067     // Process an input surface and return its ID
0068     SurfaceId operator()(inp::Surface const& surf);
0069 
0070     // Process a boundary surface
0071     SurfaceId operator()(inp::Surface::Boundary const& boundary);
0072 
0073     // Process an interface surface
0074     SurfaceId operator()(inp::Surface::Interface const& interface);
0075 
0076   private:
0077     VolumeParams const& volumes_;
0078     std::vector<Label>& labels_;
0079     std::vector<VolumeSurfaceData>& volume_surfaces_;
0080 
0081     //// HELPER FUNCTIONS ////
0082 
0083     // Get the next surface ID to be added
0084     SurfaceId next_surface_id() const;
0085     // Get the label for a volume ID
0086     Label const& label(VolumeId vol_id) const;
0087     // Get the label for a volume instance ID
0088     Label const& label(VolumeInstanceId vol_inst_id) const;
0089     // Get the label for a surface ID
0090     Label const& label(SurfaceId surface_id) const;
0091 };
0092 
0093 //---------------------------------------------------------------------------//
0094 /*!
0095  * Convert VolumeSurfaceData to VolumeSurfaceRecord for device storage.
0096  *
0097  * This class takes the temporary VolumeSurfaceData structure and converts it
0098  * to the device-compatible VolumeSurfaceRecord format, flattening the maps
0099  * into sorted arrays.
0100  */
0101 class VolumeSurfaceRecordBuilder
0102 {
0103   public:
0104     //!@{
0105     //! \name Type aliases
0106     template<class T>
0107     using Items = Collection<T, Ownership::value, MemSpace::host>;
0108     template<class T>
0109     using VolumeItems
0110         = Collection<T, Ownership::value, MemSpace::host, VolumeId>;
0111     //!@}
0112 
0113     // Construct with pointers to target collections
0114     VolumeSurfaceRecordBuilder(VolumeItems<VolumeSurfaceRecord>* volume_surfaces,
0115                                Items<VolumeInstanceId>* volume_instance_ids,
0116                                Items<SurfaceId>* surface_ids);
0117 
0118     // Convert VolumeSurfaceData to VolumeSurfaceRecord
0119     VolumeId operator()(VolumeSurfaceData const& data);
0120 
0121   private:
0122     CollectionBuilder<VolumeSurfaceRecord, MemSpace::host, VolumeId>
0123         volume_surfaces_;
0124     DedupeCollectionBuilder<VolumeInstanceId> volume_instance_ids_;
0125     DedupeCollectionBuilder<SurfaceId> surface_ids_;
0126 };
0127 
0128 //---------------------------------------------------------------------------//
0129 }  // namespace detail
0130 }  // namespace celeritas