Back to home page

EIC code displayed by LXR

 
 

    


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

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/field/CylMapFieldData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Array.hh"
0012 #include "corecel/cont/EnumArray.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/HyperslabIndexer.hh"
0015 #include "corecel/math/Turn.hh"
0016 #include "celeritas/Types.hh"
0017 
0018 #include "FieldDriverOptions.hh"
0019 
0020 namespace celeritas
0021 {
0022 //! Real type for cylindrical map field data
0023 using cylmap_real_type = float;
0024 
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * MapField (3-dimensional R-Phi-Z map) grid data
0028  */
0029 template<Ownership W, MemSpace M>
0030 struct CylMapGridData
0031 {
0032     using real_type = cylmap_real_type;
0033 
0034     template<class T>
0035     using Items = Collection<T, W, M>;
0036     Items<real_type> storage;  //!< [R, Phi, Z]
0037     EnumArray<CylAxis, ItemRange<real_type>> axes;
0038 
0039     //! Check whether the data is assigned
0040     explicit inline CELER_FUNCTION operator bool() const
0041     {
0042         return !storage.empty()
0043                && storage.size()
0044                       == axes[CylAxis::r].size() + axes[CylAxis::phi].size()
0045                              + axes[CylAxis::z].size();
0046     }
0047 
0048     //! Assign from another set of data
0049     template<Ownership W2, MemSpace M2>
0050     CylMapGridData& operator=(CylMapGridData<W2, M2> const& other)
0051     {
0052         CELER_EXPECT(other);
0053         storage = other.storage;
0054         axes = other.axes;
0055         return *this;
0056     }
0057 };
0058 
0059 //---------------------------------------------------------------------------//
0060 /*!
0061  * Device data for interpolating field values.
0062  */
0063 template<Ownership W, MemSpace M>
0064 struct CylMapFieldParamsData
0065 {
0066     using real_type = cylmap_real_type;
0067 
0068     //! Grids of MapField
0069     CylMapGridData<W, M> grids;
0070 
0071     //! Field propagation and substepping tolerances
0072     FieldDriverOptions options;
0073 
0074     //! Index of MapField Collection
0075     using ElementId = ItemId<size_type>;
0076 
0077     template<class T>
0078     using ElementItems = Collection<T, W, M, ElementId>;
0079 
0080     //! MapField data
0081     ElementItems<EnumArray<CylAxis, real_type>> fieldmap;
0082 
0083     //! Check whether the data is assigned
0084     explicit inline CELER_FUNCTION operator bool() const
0085     {
0086         return !fieldmap.empty();
0087     }
0088 
0089     //! Check if the given position is within the field map bounds
0090     inline CELER_FUNCTION bool
0091     valid(real_type r, Turn_t<real_type> phi, real_type z) const
0092     {
0093         CELER_EXPECT(grids);
0094         return (
0095             r >= grids.storage[grids.axes[CylAxis::r].front()]
0096             && r <= grids.storage[grids.axes[CylAxis::r].back()]
0097             && phi.value() >= grids.storage[grids.axes[CylAxis::phi].front()]
0098             && phi.value() <= grids.storage[grids.axes[CylAxis::phi].back()]
0099             && z >= grids.storage[grids.axes[CylAxis::z].front()]
0100             && z <= grids.storage[grids.axes[CylAxis::z].back()]);
0101     }
0102 
0103     inline CELER_FUNCTION ElementId id(size_type idx_r,
0104                                        size_type idx_phi,
0105                                        size_type idx_z) const
0106     {
0107         CELER_EXPECT(grids);
0108         Array<size_type, static_cast<size_type>(CylAxis::size_)> tmp{
0109             grids.axes[CylAxis::r].size(),
0110             grids.axes[CylAxis::phi].size(),
0111             grids.axes[CylAxis::z].size()};
0112         return ElementId{HyperslabIndexer{tmp}(idx_r, idx_phi, idx_z)};
0113     }
0114 
0115     //! Assign from another set of data
0116     template<Ownership W2, MemSpace M2>
0117     CylMapFieldParamsData& operator=(CylMapFieldParamsData<W2, M2> const& other)
0118     {
0119         CELER_EXPECT(other);
0120         grids = other.grids;
0121         options = other.options;
0122         fieldmap = other.fieldmap;
0123         return *this;
0124     }
0125 };
0126 
0127 //---------------------------------------------------------------------------//
0128 }  // namespace celeritas