File indexing completed on 2025-02-22 10:31:25
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <cmath>
0011
0012 #include "corecel/Assert.hh"
0013 #include "corecel/Macros.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016 #include "celeritas/Quantities.hh"
0017 #include "celeritas/Types.hh"
0018
0019 #include "MaterialData.hh"
0020 #include "MaterialView.hh"
0021
0022 namespace celeritas
0023 {
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 class MaterialTrackView
0040 {
0041 public:
0042
0043
0044 using Initializer_t = MaterialTrackState;
0045 using MaterialParamsRef = NativeCRef<MaterialParamsData>;
0046 using MaterialStateRef = NativeRef<MaterialStateData>;
0047
0048
0049 public:
0050
0051 inline CELER_FUNCTION MaterialTrackView(MaterialParamsRef const& params,
0052 MaterialStateRef const& states,
0053 TrackSlotId tid);
0054
0055
0056 inline CELER_FUNCTION MaterialTrackView&
0057 operator=(Initializer_t const& other);
0058
0059
0060
0061
0062 CELER_FORCEINLINE_FUNCTION MaterialId material_id() const;
0063
0064
0065
0066
0067 CELER_FORCEINLINE_FUNCTION MaterialView make_material_view() const;
0068
0069
0070 inline CELER_FUNCTION Span<real_type> element_scratch();
0071
0072 private:
0073 MaterialParamsRef const& params_;
0074 MaterialStateRef const& states_;
0075 TrackSlotId const track_slot_;
0076
0077 CELER_FORCEINLINE_FUNCTION MaterialTrackState& state() const;
0078 };
0079
0080
0081
0082
0083
0084
0085
0086 CELER_FUNCTION
0087 MaterialTrackView::MaterialTrackView(MaterialParamsRef const& params,
0088 MaterialStateRef const& states,
0089 TrackSlotId tid)
0090 : params_(params), states_(states), track_slot_(tid)
0091 {
0092 CELER_EXPECT(tid < states.state.size());
0093 }
0094
0095
0096
0097
0098
0099 CELER_FUNCTION MaterialTrackView&
0100 MaterialTrackView::operator=(Initializer_t const& other)
0101 {
0102 CELER_EXPECT(other.material_id < params_.materials.size());
0103 this->state() = other;
0104 return *this;
0105 }
0106
0107
0108
0109
0110
0111 CELER_FUNCTION MaterialId MaterialTrackView::material_id() const
0112 {
0113 return this->state().material_id;
0114 }
0115
0116
0117
0118
0119
0120 CELER_FUNCTION MaterialView MaterialTrackView::make_material_view() const
0121 {
0122 return MaterialView(params_, this->material_id());
0123 }
0124
0125
0126
0127
0128
0129 CELER_FUNCTION Span<real_type> MaterialTrackView::element_scratch()
0130 {
0131 auto offset = track_slot_.get() * params_.max_element_components;
0132 Span<real_type> all_scratch
0133 = states_.element_scratch[AllItems<real_type, MemSpace::native>{}];
0134 CELER_ENSURE(offset + params_.max_element_components <= all_scratch.size());
0135 return all_scratch.subspan(offset, params_.max_element_components);
0136 }
0137
0138
0139
0140
0141
0142 CELER_FUNCTION MaterialTrackState& MaterialTrackView::state() const
0143 {
0144 return states_.state[track_slot_];
0145 }
0146
0147
0148 }