Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:44

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/optical/MfpBuilder.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "celeritas/grid/NonuniformGridInserter.hh"
0010 
0011 namespace celeritas
0012 {
0013 namespace optical
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Helper class for optical models to build MFP tables.
0018  *
0019  * Tracks individual grid IDs that have been built, and returns them
0020  * as an ItemRange which may be used by model MFP tables.
0021  */
0022 class MfpBuilder
0023 {
0024   public:
0025     //!@{
0026     //! \name Type aliases
0027     using GridId = OpaqueId<NonuniformGridRecord>;
0028     using GridInserter = NonuniformGridInserter<GridId>;
0029     using GridIdRange = Range<GridId>;
0030 
0031     using Values = typename GridInserter::Values;
0032     using GridValues = typename GridInserter::GridValues;
0033     //!@}
0034 
0035   public:
0036     // Construct with given inserter
0037     inline MfpBuilder(Values* real_data, GridValues* grid_data);
0038 
0039     // Build the grid
0040     template<typename... Args>
0041     inline void operator()(Args const&... args);
0042 
0043     // Get the range of grid IDs that have been built
0044     inline GridIdRange grid_ids() const;
0045 
0046   private:
0047     GridInserter insert_grid_;
0048     GridValues* grid_data_;
0049     GridId const grid_id_first_;
0050 };
0051 
0052 //---------------------------------------------------------------------------//
0053 // INLINE DEFINITIONS
0054 //---------------------------------------------------------------------------//
0055 /*!
0056  * Construct with given collections.
0057  */
0058 MfpBuilder::MfpBuilder(Values* real_data, GridValues* grid_data)
0059     : insert_grid_(real_data, grid_data)
0060     , grid_data_(grid_data)
0061     , grid_id_first_(grid_data->size())
0062 {
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Build the grid.
0068  *
0069  * Passes its arguments directly to a \c NonuniformGridInserter.
0070  */
0071 template<typename... Args>
0072 void MfpBuilder::operator()(Args const&... args)
0073 {
0074     insert_grid_(args...);
0075 }
0076 
0077 //---------------------------------------------------------------------------//
0078 /*!
0079  * Get the range of grid IDs that have been built.
0080  */
0081 auto MfpBuilder::grid_ids() const -> GridIdRange
0082 {
0083     return GridIdRange(grid_id_first_, GridId{grid_data_->size()});
0084 }
0085 
0086 //---------------------------------------------------------------------------//
0087 }  // namespace optical
0088 }  // namespace celeritas