File indexing completed on 2026-10-29 09:13:53
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <optional>
0011
0012 #include "corecel/Assert.hh"
0013 #include "corecel/io/Logger.hh"
0014 #include "geocel/GeoTrackInterface.hh"
0015 #include "geocel/Types.hh"
0016 #include "geocel/UnitLength.hh"
0017
0018 namespace celeritas
0019 {
0020
0021 template<class RT>
0022 class GeoTrackInterface;
0023 class GeoParamsInterface;
0024 class VolumeParams;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 class CheckedGeoTrackView final : public GeoTrackInterface<real_type>
0052 {
0053 public:
0054
0055
0056 using Initializer_t = GeoTrackInitializer;
0057 using Real3 = Array<real_type, 3>;
0058 using TrackT = GeoTrackInterface<real_type>;
0059 using UPTrack = std::unique_ptr<TrackT>;
0060 using SPConstGeoI = std::shared_ptr<GeoParamsInterface const>;
0061 using SPConstVolumes = std::shared_ptr<VolumeParams const>;
0062
0063
0064 public:
0065
0066 explicit CheckedGeoTrackView(UPTrack track)
0067 : CheckedGeoTrackView{std::move(track), nullptr, nullptr, UnitLength{}}
0068 {
0069 }
0070
0071
0072 CheckedGeoTrackView(UPTrack track,
0073 SPConstVolumes volumes,
0074 SPConstGeoI geo_interface,
0075 UnitLength unit_length);
0076
0077
0078 CELER_DEFAULT_MOVE_DELETE_COPY(CheckedGeoTrackView);
0079
0080
0081 explicit operator bool() const { return t_ != nullptr; }
0082
0083
0084 TrackT const& track_view() const { return *t_; }
0085
0086 TrackT& track_view() { return *t_; }
0087
0088
0089 Logger const& logger() const { return log_; }
0090
0091 Logger& logger() { return log_; }
0092
0093
0094 real_type safety_tol() const { return 1e-4 * unit_length_.value; }
0095
0096
0097
0098
0099 size_type intersect_count() const { return count_.intersect; }
0100
0101 size_type safety_count() const { return count_.safety; }
0102
0103 void reset_count() { count_ = {}; }
0104
0105
0106 void check_normal(bool value) { check_normal_ = value; }
0107
0108 bool check_normal() const { return check_normal_; }
0109
0110
0111 void check_failure(bool value) { check_failure_ = value; }
0112
0113 bool check_failure() const { return check_failure_; }
0114
0115
0116 void check_zero_distance(bool value) { check_zero_distance_ = value; }
0117
0118 bool check_zero_distance() const { return check_zero_distance_; }
0119
0120
0121 void check_next_safety(bool value) { check_next_safety_ = value; }
0122
0123
0124 SPConstVolumes const& volumes() const { return volumes_; }
0125
0126 SPConstGeoI const& geo_interface() const { return geo_interface_; }
0127
0128 UnitLength unit_length() const { return unit_length_; }
0129
0130
0131
0132
0133 CheckedGeoTrackView& operator=(GeoTrackInitializer const& init) final;
0134
0135
0136 Real3 const& pos() const final { return t_->pos(); }
0137 Real3 const& dir() const final { return t_->dir(); }
0138
0139
0140 VolumeId volume_id() const final { return t_->volume_id(); }
0141 VolumeInstanceId volume_instance_id() const final
0142 {
0143 return t_->volume_instance_id();
0144 }
0145 VolumeLevelId volume_level() const final { return t_->volume_level(); }
0146 void volume_instance_id(Span<VolumeInstanceId> levels) const final
0147 {
0148 t_->volume_instance_id(levels);
0149 }
0150 void foreach_volume_path(VolPathVisitor visit) const final
0151 {
0152 t_->foreach_volume_path(std::move(visit));
0153 }
0154
0155
0156 ImplVolumeId impl_volume_id() const final { return t_->impl_volume_id(); }
0157
0158
0159 bool is_outside() const final { return t_->is_outside(); }
0160 bool failed() const final { return t_->failed(); }
0161
0162
0163 bool is_on_boundary() const final { return t_->is_on_boundary(); }
0164 Real3 normal() const final { return t_->normal(); }
0165
0166
0167 GeoStatus geo_status() const final;
0168
0169
0170 real_type find_safety() final;
0171
0172
0173 real_type find_safety(real_type max_safety) final;
0174
0175
0176 void set_dir(Real3 const&) final;
0177
0178
0179 Propagation find_next_step(real_type max_distance) final;
0180
0181
0182 void move_internal(real_type step) final;
0183
0184
0185 void move_internal(Real3 const& pos) final;
0186
0187
0188 void move_to_boundary() final;
0189
0190
0191 void cross_boundary() final;
0192
0193 private:
0194 UPTrack t_;
0195 Logger log_;
0196
0197
0198 SPConstVolumes volumes_;
0199 SPConstGeoI geo_interface_;
0200 UnitLength unit_length_;
0201
0202
0203 bool check_normal_{true};
0204 bool check_failure_{true};
0205 bool check_next_safety_{true};
0206 bool check_safety_{true};
0207 bool check_zero_distance_{true};
0208
0209
0210 struct
0211 {
0212 size_type intersect{0};
0213 size_type safety{0};
0214 } count_;
0215
0216
0217
0218
0219
0220 bool checked_internal_{false};
0221
0222 std::optional<real_type> next_step_;
0223
0224 bool next_is_boundary_{false};
0225 };
0226
0227
0228
0229 class CheckedGeoError : public RuntimeError
0230 {
0231 public:
0232 CheckedGeoError(RuntimeErrorDetails&& r) : RuntimeError(std::move(r)) {}
0233 };
0234
0235
0236
0237
0238
0239 std::ostream& operator<<(std::ostream&, CheckedGeoTrackView const&);
0240
0241
0242 }