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