Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:59

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 orange/OrangeParams.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <vector>
0012 
0013 #include "corecel/Types.hh"
0014 #include "corecel/cont/LabelIdMultiMap.hh"
0015 #include "corecel/data/CollectionMirror.hh"
0016 #include "corecel/data/ParamsDataInterface.hh"
0017 #include "corecel/io/Label.hh"
0018 #include "geocel/BoundingBox.hh"
0019 #include "geocel/GeoParamsInterface.hh"
0020 
0021 #include "OrangeData.hh"
0022 #include "OrangeTypes.hh"
0023 
0024 class G4VPhysicalVolume;
0025 
0026 namespace celeritas
0027 {
0028 struct OrangeInput;
0029 
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Persistent model data for an ORANGE geometry.
0033  *
0034  * This class initializes and manages the data used by ORANGE (surfaces,
0035  * volumes) and provides a host-based interface for them.
0036  */
0037 class OrangeParams final : public GeoParamsSurfaceInterface,
0038                            public ParamsDataInterface<OrangeParamsData>
0039 {
0040   public:
0041     // Construct from a JSON or GDML file (if JSON or Geant4 are enabled)
0042     explicit OrangeParams(std::string const& filename);
0043 
0044     // Construct in-memory from Geant4
0045     explicit OrangeParams(G4VPhysicalVolume const*);
0046 
0047     // ADVANCED usage: construct from explicit host data
0048     explicit OrangeParams(OrangeInput&& input);
0049 
0050     //! Whether safety distance calculations are accurate and precise
0051     bool supports_safety() const final { return supports_safety_; }
0052 
0053     //! Outer bounding box of geometry
0054     BBox const& bbox() const final { return bbox_; }
0055 
0056     //! Maximum universe depth
0057     size_type max_depth() const { return this->host_ref().scalars.max_depth; }
0058 
0059     //// VOLUMES ////
0060 
0061     // Number of volumes
0062     inline VolumeId::size_type num_volumes() const final;
0063 
0064     // Get the label for a volume ID
0065     Label const& id_to_label(VolumeId vol_id) const final;
0066 
0067     //! \cond
0068     using GeoParamsSurfaceInterface::find_volume;
0069     //! \endcond
0070 
0071     // Get the volume ID corresponding to a unique name
0072     VolumeId find_volume(std::string const& name) const final;
0073 
0074     // Get the volume ID corresponding to a unique label
0075     VolumeId find_volume(Label const& label) const final;
0076 
0077     // Get the volume ID corresponding to a Geant4 logical volume
0078     inline VolumeId find_volume(G4LogicalVolume const* volume) const final;
0079 
0080     // Get zero or more volume IDs corresponding to a name
0081     SpanConstVolumeId find_volumes(std::string const& name) const final;
0082 
0083     //// SURFACES ////
0084 
0085     // Get the label for a surface ID
0086     Label const& id_to_label(SurfaceId surf_id) const final;
0087 
0088     // Get the surface ID corresponding to a unique label name
0089     SurfaceId find_surface(std::string const& name) const final;
0090 
0091     // Number of distinct surfaces
0092     inline SurfaceId::size_type num_surfaces() const final;
0093 
0094     //// UNIVERSES ////
0095 
0096     // Get the label for a universe ID
0097     Label const& id_to_label(UniverseId surf_id) const;
0098 
0099     // Get the universe ID corresponding to a unique label name
0100     UniverseId find_universe(std::string const& name) const;
0101 
0102     // Number of universes
0103     inline UniverseId::size_type num_universes() const;
0104 
0105     //// DATA ACCESS ////
0106 
0107     //! Reference to CPU geometry data
0108     HostRef const& host_ref() const final { return data_.host_ref(); }
0109 
0110     //! Reference to managed GPU geometry data
0111     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0112 
0113   private:
0114     // Host metadata/access
0115     LabelIdMultiMap<UniverseId> univ_labels_;
0116     LabelIdMultiMap<SurfaceId> surf_labels_;
0117     LabelIdMultiMap<VolumeId> vol_labels_;
0118     BBox bbox_;
0119     bool supports_safety_{};
0120 
0121     // Host/device storage and reference
0122     CollectionMirror<OrangeParamsData> data_;
0123 };
0124 
0125 //---------------------------------------------------------------------------//
0126 // INLINE DEFINITIONS
0127 //---------------------------------------------------------------------------//
0128 /*!
0129  * Locate the volume ID corresponding to a Geant4 volume.
0130  *
0131  * TODO: To be properly implemented, as it requires a future Geant4 converter.
0132  */
0133 VolumeId OrangeParams::find_volume(G4LogicalVolume const*) const
0134 {
0135     return VolumeId{};
0136 }
0137 
0138 //---------------------------------------------------------------------------//
0139 /*!
0140  * Number of volumes.
0141  */
0142 VolumeId::size_type OrangeParams::num_volumes() const
0143 {
0144     return vol_labels_.size();
0145 }
0146 
0147 //---------------------------------------------------------------------------//
0148 /*!
0149  * Number of surfaces.
0150  */
0151 SurfaceId::size_type OrangeParams::num_surfaces() const
0152 {
0153     return surf_labels_.size();
0154 }
0155 
0156 //---------------------------------------------------------------------------//
0157 /*!
0158  * Number of universes.
0159  */
0160 UniverseId::size_type OrangeParams::num_universes() const
0161 {
0162     return univ_labels_.size();
0163 }
0164 
0165 //---------------------------------------------------------------------------//
0166 }  // namespace celeritas