Back to home page

EIC code displayed by LXR

 
 

    


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

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/grid/NonuniformGridInserter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <utility>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/CollectionBuilder.hh"
0015 #include "corecel/grid/NonuniformGridData.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/inp/Grid.hh"
0018 
0019 #include "NonuniformGridBuilder.hh"
0020 
0021 namespace celeritas
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Construct a nonuniform grid and add it to the specified grid collection.
0026  */
0027 template<class Index>
0028 class NonuniformGridInserter
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using Values = Collection<real_type, Ownership::value, MemSpace::host>;
0034     using GridValues
0035         = Collection<NonuniformGridRecord, Ownership::value, MemSpace::host, Index>;
0036     //!@}
0037 
0038   public:
0039     // Construct with a reference to mutable host data
0040     NonuniformGridInserter(Values* reals, GridValues* grids);
0041 
0042     // Add an imported physics vector as a grid
0043     Index operator()(inp::Grid const&);
0044 
0045     // Add an empty grid (no data present)
0046     Index operator()();
0047 
0048   private:
0049     NonuniformGridBuilder build_;
0050     CollectionBuilder<NonuniformGridRecord, MemSpace::host, Index> grids_;
0051 };
0052 
0053 //---------------------------------------------------------------------------//
0054 /*!
0055  * Construct with a reference to mutable host data.
0056  */
0057 template<class Index>
0058 NonuniformGridInserter<Index>::NonuniformGridInserter(Values* reals,
0059                                                       GridValues* grids)
0060     : build_(reals), grids_(grids)
0061 {
0062     CELER_EXPECT(reals && grids);
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Add a nonuniform grid to the collection.
0068  *
0069  * Returns the ID of the inserted grid, or an empty ID if the vector is empty.
0070  */
0071 template<class Index>
0072 auto NonuniformGridInserter<Index>::operator()(inp::Grid const& grid) -> Index
0073 {
0074     CELER_EXPECT(grid);
0075     return grids_.push_back(build_(grid));
0076 }
0077 
0078 //---------------------------------------------------------------------------//
0079 /*!
0080  * Add an empty grid.
0081  *
0082  * Useful for when there's no imported grid present for a given material.
0083  */
0084 template<class Index>
0085 auto NonuniformGridInserter<Index>::operator()() -> Index
0086 {
0087     return grids_.push_back({});
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 }  // namespace celeritas