File indexing completed on 2025-09-17 08:53:38
0001
0002
0003
0004
0005
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
0023 using cylmap_real_type = float;
0024
0025
0026
0027
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;
0037 EnumArray<CylAxis, ItemRange<real_type>> axes;
0038
0039
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
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
0062
0063 template<Ownership W, MemSpace M>
0064 struct CylMapFieldParamsData
0065 {
0066 using real_type = cylmap_real_type;
0067
0068
0069 CylMapGridData<W, M> grids;
0070
0071
0072 FieldDriverOptions options;
0073
0074
0075 using ElementId = ItemId<size_type>;
0076
0077 template<class T>
0078 using ElementItems = Collection<T, W, M, ElementId>;
0079
0080
0081 ElementItems<EnumArray<CylAxis, real_type>> fieldmap;
0082
0083
0084 explicit inline CELER_FUNCTION operator bool() const
0085 {
0086 return !fieldmap.empty();
0087 }
0088
0089
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
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 }