File indexing completed on 2025-09-17 08:53:38
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <type_traits>
0011
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/data/DeviceVector.hh"
0015 #include "celeritas/Types.hh"
0016 #include "celeritas/field/FieldDriverOptions.hh"
0017
0018 #include "detail/CovfieFieldTraits.hh"
0019
0020 namespace celeritas
0021 {
0022
0023 template<MemSpace M>
0024 struct CartMapFieldParamsDataBase
0025 {
0026 using field_t = detail::CovfieFieldTraits<M>::field_t;
0027 using view_t = field_t::view_t;
0028
0029 FieldDriverOptions options;
0030 };
0031
0032
0033
0034 template<Ownership W, MemSpace M>
0035 struct CartMapFieldParamsData;
0036
0037 template<>
0038 struct CartMapFieldParamsData<Ownership::value, MemSpace::host>
0039 : CartMapFieldParamsDataBase<MemSpace::host>
0040 {
0041 CELER_FUNCTION view_t get_view() const { return view_t(*field); }
0042
0043 CELER_FUNCTION explicit operator bool() const { return field.get(); }
0044
0045 std::unique_ptr<field_t> field;
0046 };
0047 template<>
0048 struct CartMapFieldParamsData<Ownership::const_reference, MemSpace::host>
0049 : CartMapFieldParamsDataBase<MemSpace::host>
0050 {
0051 CELER_FUNCTION view_t const& get_view() const { return field_view; }
0052
0053 CELER_FUNCTION explicit operator bool() const { return true; }
0054
0055 view_t field_view;
0056 };
0057
0058 template<>
0059 struct CartMapFieldParamsData<Ownership::value, MemSpace::device>
0060 : CartMapFieldParamsDataBase<MemSpace::device>
0061 {
0062 CELER_FUNCTION view_t const& get_view() const
0063 {
0064 return field_view.device_ref()[0];
0065 }
0066
0067 CELER_FUNCTION explicit operator bool() const
0068 {
0069 return field.get() && field_view.size() == 1;
0070 }
0071
0072 CartMapFieldParamsData& operator=(
0073 CartMapFieldParamsData<Ownership::value, MemSpace::host> const& other)
0074 {
0075 if constexpr (!std::is_same_v<
0076 field_t,
0077 detail::CovfieFieldTraits<MemSpace::host>::field_t>)
0078 {
0079 field = std::make_unique<field_t>(covfie::make_parameter_pack(
0080 other.field->backend().get_configuration(),
0081 other.field->backend().get_backend().get_backend()));
0082 field_view = DeviceVector<view_t>{1};
0083 field_view.copy_to_device(make_span<view_t const>({{*field}}));
0084 }
0085 else
0086 {
0087 field = std::make_unique<field_t>(*other.field);
0088 }
0089 options = other.options;
0090 return *this;
0091 }
0092
0093 std::unique_ptr<field_t> field;
0094 DeviceVector<view_t> field_view;
0095 };
0096 template<>
0097 struct CartMapFieldParamsData<Ownership::const_reference, MemSpace::device>
0098 : CartMapFieldParamsDataBase<MemSpace::device>
0099 {
0100 CELER_FUNCTION view_t const& get_view() const { return *field_view; }
0101
0102 CELER_FUNCTION explicit operator bool() const { return field_view; }
0103
0104 CartMapFieldParamsData& operator=(
0105 CartMapFieldParamsData<Ownership::value, MemSpace::device> const& other)
0106 {
0107 field_view = &other.field_view.device_ref()[0];
0108 options = other.options;
0109 return *this;
0110 }
0111
0112 view_t const* field_view;
0113 };
0114
0115
0116 }