File indexing completed on 2026-11-27 10:40:37
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/OpaqueId.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Range.hh"
0014 #include "corecel/data/Collection.hh"
0015 #include "corecel/data/CollectionBuilder.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017 #include "geocel/BoundingBox.hh" // IWYU pragma: keep
0018
0019 #include "OrangeTypes.hh"
0020
0021 #include "detail/BvhData.hh"
0022
0023 namespace celeritas
0024 {
0025 class OrangeParams;
0026 class VolumeParams;
0027
0028
0029
0030
0031
0032 inline constexpr LocalVolumeId orange_exterior_volume{0};
0033
0034
0035 inline constexpr UnivId orange_global_univ{0};
0036
0037
0038 inline constexpr UnivLevelId orange_global_univ_level{0};
0039
0040
0041 inline constexpr auto orange_tracking_logic{LogicNotation::infix};
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 struct OrangeParamsScalars
0054 {
0055 size_type num_univ_levels{};
0056 size_type max_faces{};
0057 size_type max_intersections{};
0058 size_type max_csg_levels{};
0059
0060
0061 vol_level_uint num_vol_levels{};
0062
0063
0064 Tolerance<> tol;
0065
0066
0067 OrangeParams const* host_geo_params{nullptr};
0068 VolumeParams const* host_volume_params{nullptr};
0069
0070
0071 explicit CELER_FUNCTION operator bool() const
0072 {
0073 return num_univ_levels > 0 && max_faces > 0 && max_intersections > 0
0074 && tol;
0075 }
0076 };
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 struct LocalVolumeRecord
0090 {
0091 ItemRange<LocalSurfaceId> faces;
0092 ItemRange<logic_int> logic;
0093
0094 logic_int max_intersections{0};
0095 logic_int flags{0};
0096 DaughterId daughter_id;
0097 OrientedBoundingZoneId obz_id;
0098
0099
0100
0101
0102 enum Flags : logic_int
0103 {
0104 internal_surfaces = 0x1,
0105 implicit_vol = 0x2,
0106 simple_safety = 0x4,
0107 embedded_universe = 0x8
0108 };
0109 };
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 struct SurfacesRecord
0128 {
0129 using SurfaceTypeId = ItemId<SurfaceType>;
0130 using RealId = ItemId<real_type>;
0131 using RealIdId = ItemId<RealId>;
0132
0133 ItemMap<LocalSurfaceId, SurfaceTypeId> types;
0134 ItemMap<LocalSurfaceId, RealIdId> data_offsets;
0135
0136
0137 CELER_FUNCTION size_type size() const { return types.size(); }
0138
0139
0140 explicit CELER_FUNCTION operator bool() const
0141 {
0142 return data_offsets.size() == types.size();
0143 }
0144 };
0145
0146
0147
0148
0149
0150
0151
0152
0153 struct ConnectivityRecord
0154 {
0155 ItemRange<LocalVolumeId> neighbors;
0156 };
0157
0158
0159
0160
0161
0162 struct OrientedBoundingZoneRecord
0163 {
0164 using Real3 = Array<fast_real_type, 3>;
0165
0166
0167 Array<Real3, 2> half_widths;
0168
0169
0170
0171 Array<TransformId, 2> offset_ids;
0172
0173
0174
0175 TransformId trans_id;
0176
0177
0178 explicit CELER_FUNCTION operator bool() const
0179 {
0180 return offset_ids[0] && offset_ids[1] && trans_id;
0181 }
0182 };
0183
0184
0185
0186
0187
0188 template<std::size_t N>
0189 struct RaggedRightIndexerData
0190 {
0191 using Sizes = Array<size_type, N>;
0192 using Offsets = Array<size_type, N + 1>;
0193
0194 Offsets offsets;
0195
0196
0197 static RaggedRightIndexerData from_sizes(Sizes sizes)
0198 {
0199 CELER_EXPECT(sizes.size() > 0);
0200
0201 Offsets offs;
0202 offs[0] = 0;
0203 for (auto i : range(N))
0204 {
0205 CELER_EXPECT(sizes[i] > 0);
0206 offs[i + 1] = sizes[i] + offs[i];
0207 }
0208 return RaggedRightIndexerData{offs};
0209 }
0210 };
0211
0212
0213
0214
0215
0216 struct TransformRecord
0217 {
0218 using RealId = OpaqueId<real_type>;
0219 TransformType type{TransformType::size_};
0220 RealId data_offset;
0221
0222
0223 explicit CELER_FUNCTION operator bool() const
0224 {
0225 return type != TransformType::size_ && data_offset;
0226 }
0227 };
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250 struct SimpleUnitRecord
0251 {
0252 using LocalVolumeRecordId = ItemId<LocalVolumeRecord>;
0253 using ConnectivityRecordId = ItemId<ConnectivityRecord>;
0254 using LocalVolumeIdId = ItemId<LocalVolumeId>;
0255 using VolDepthUint = ItemId<vol_level_uint>;
0256
0257
0258 SurfacesRecord surfaces;
0259 ItemMap<LocalSurfaceId, ConnectivityRecordId> connectivity;
0260
0261
0262 ItemMap<LocalVolumeId, LocalVolumeRecordId> volumes;
0263
0264 ItemMap<LocalVolumeId, LocalVolumeIdId> local_parent;
0265 ItemMap<LocalVolumeId, VolDepthUint> local_vol_level;
0266
0267
0268 detail::BvhTreeRecord bvh_tree;
0269
0270 LocalVolumeId background{};
0271 bool simple_safety{};
0272
0273
0274 explicit CELER_FUNCTION operator bool() const
0275 {
0276 return surfaces && connectivity.size() == surfaces.types.size()
0277 && !volumes.empty();
0278 }
0279 };
0280
0281
0282
0283
0284
0285 struct RectArrayRecord
0286 {
0287 using Dims = Array<size_type, 3>;
0288 using Grid = Array<ItemRange<real_type>, 3>;
0289 using SurfaceIndexerData = RaggedRightIndexerData<3>;
0290
0291
0292 ItemMap<LocalVolumeId, DaughterId> daughters;
0293
0294
0295 Dims dims;
0296 Grid grid;
0297 SurfaceIndexerData surface_indexer_data;
0298
0299
0300 explicit CELER_FUNCTION operator bool() const
0301 {
0302 return !daughters.empty() && !grid[to_int(Axis::x)].empty()
0303 && !grid[to_int(Axis::y)].empty()
0304 && !grid[to_int(Axis::z)].empty();
0305 }
0306 };
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 template<Ownership W, MemSpace M>
0320 struct UniverseIndexerData
0321 {
0322 Collection<size_type, W, M> surfaces;
0323 Collection<size_type, W, M> volumes;
0324
0325 template<Ownership W2, MemSpace M2>
0326 UniverseIndexerData& operator=(UniverseIndexerData<W2, M2> const& other)
0327 {
0328 CELER_EXPECT(other);
0329
0330 surfaces = other.surfaces;
0331 volumes = other.volumes;
0332
0333 CELER_ENSURE(*this);
0334 return *this;
0335 }
0336
0337 explicit CELER_FUNCTION operator bool() const
0338 {
0339 return !surfaces.empty() && volumes.size() == surfaces.size();
0340 }
0341 };
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355 template<Ownership W, MemSpace M>
0356 struct OrangeParamsData
0357 {
0358 template<class T>
0359 using Items = Collection<T, W, M>;
0360 template<class T>
0361 using ImplVolumeItems = Collection<T, W, M, ImplVolumeId>;
0362 template<class T>
0363 using UnivItems = Collection<T, W, M, UnivId>;
0364
0365 using RealId = SurfacesRecord::RealId;
0366
0367
0368
0369
0370 OrangeParamsScalars scalars;
0371
0372
0373 UnivItems<UnivType> univ_types;
0374 UnivItems<size_type> univ_indices;
0375 Items<SimpleUnitRecord> simple_units;
0376 Items<RectArrayRecord> rect_arrays;
0377 Items<TransformRecord> transforms;
0378
0379
0380 ImplVolumeItems<VolumeId> volume_ids;
0381 ImplVolumeItems<VolumeInstanceId> volume_instance_ids;
0382
0383
0384 detail::BvhTreeData<W, M> bvh_tree_data;
0385
0386
0387 Items<LocalSurfaceId> local_surface_ids;
0388 Items<LocalVolumeId> local_volume_ids;
0389 Items<RealId> real_ids;
0390 Items<vol_level_uint> vl_uints;
0391 Items<logic_int> logic_ints;
0392 Items<real_type> reals;
0393 Items<SurfaceType> surface_types;
0394 Items<ConnectivityRecord> connectivity_records;
0395 Items<LocalVolumeRecord> volume_records;
0396 Items<Daughter> daughters;
0397 Items<OrientedBoundingZoneRecord> obz_records;
0398
0399 UniverseIndexerData<W, M> univ_indexer_data;
0400
0401
0402
0403
0404 explicit CELER_FUNCTION operator bool() const
0405 {
0406 return scalars && !univ_types.empty()
0407 && univ_indices.size() == univ_types.size()
0408 && !volume_ids.empty()
0409 && volume_ids.size() == volume_instance_ids.size()
0410 && (bvh_tree_data || !simple_units.empty())
0411 && ((!local_volume_ids.empty() && !logic_ints.empty()
0412 && !reals.empty())
0413 || surface_types.empty())
0414 && !volume_records.empty() && univ_indexer_data;
0415 }
0416
0417
0418 template<Ownership W2, MemSpace M2>
0419 OrangeParamsData& operator=(OrangeParamsData<W2, M2> const& other)
0420 {
0421 scalars = other.scalars;
0422
0423 univ_types = other.univ_types;
0424 univ_indices = other.univ_indices;
0425 simple_units = other.simple_units;
0426 rect_arrays = other.rect_arrays;
0427 transforms = other.transforms;
0428
0429 volume_ids = other.volume_ids;
0430 volume_instance_ids = other.volume_instance_ids;
0431
0432 bvh_tree_data = other.bvh_tree_data;
0433
0434 local_surface_ids = other.local_surface_ids;
0435 local_volume_ids = other.local_volume_ids;
0436 real_ids = other.real_ids;
0437 vl_uints = other.vl_uints;
0438 logic_ints = other.logic_ints;
0439 reals = other.reals;
0440 surface_types = other.surface_types;
0441 connectivity_records = other.connectivity_records;
0442 volume_records = other.volume_records;
0443 obz_records = other.obz_records;
0444 daughters = other.daughters;
0445 univ_indexer_data = other.univ_indexer_data;
0446
0447 CELER_ENSURE(static_cast<bool>(*this) == static_cast<bool>(other));
0448 return *this;
0449 }
0450 };
0451
0452
0453
0454
0455
0456
0457
0458 template<Ownership W, MemSpace M>
0459 struct OrangeStateData
0460 {
0461
0462
0463 template<class T>
0464 using StateItems = StateCollection<T, W, M>;
0465 template<class T>
0466 using Items = Collection<T, W, M>;
0467
0468
0469
0470
0471 StateItems<UnivLevelId> univ_level;
0472 StateItems<UnivLevelId> surface_univ_level;
0473 StateItems<LocalSurfaceId> surf;
0474 StateItems<Sense> sense;
0475 StateItems<GeoStatus> status;
0476
0477
0478 StateItems<real_type> next_step;
0479 StateItems<UnivLevelId> next_univ_level;
0480 StateItems<LocalSurfaceId> next_surf;
0481 StateItems<Sense> next_sense;
0482
0483
0484 Items<Real3> pos;
0485 Items<Real3> dir;
0486 Items<LocalVolumeId> vol;
0487 Items<UnivId> univ;
0488
0489
0490 Items<FaceId> temp_face;
0491 Items<real_type> temp_distance;
0492 Items<size_type> temp_isect;
0493
0494
0495
0496
0497 explicit CELER_FUNCTION operator bool() const
0498 {
0499
0500 return !univ_level.empty()
0501 && surface_univ_level.size() == this->size()
0502 && surf.size() == this->size()
0503 && sense.size() == this->size()
0504 && status.size() == this->size()
0505 && next_step.size() == this->size()
0506 && next_univ_level.size() == this->size()
0507 && next_surf.size() == this->size()
0508 && next_sense.size() == this->size()
0509 && pos.size() >= this->size()
0510 && dir.size() == pos.size()
0511 && vol.size() == pos.size()
0512 && univ.size() == pos.size()
0513 && !temp_face.empty()
0514 && temp_distance.size() == temp_face.size()
0515 && temp_isect.size() == temp_face.size();
0516
0517 }
0518
0519
0520 CELER_FUNCTION TrackSlotId::size_type size() const
0521 {
0522 return univ_level.size();
0523 }
0524
0525
0526 template<Ownership W2, MemSpace M2>
0527 OrangeStateData& operator=(OrangeStateData<W2, M2>& other)
0528 {
0529 CELER_EXPECT(other);
0530
0531 univ_level = other.univ_level;
0532 surface_univ_level = other.surface_univ_level;
0533 surf = other.surf;
0534 sense = other.sense;
0535 status = other.status;
0536
0537 next_step = other.next_step;
0538 next_univ_level = other.next_univ_level;
0539 next_surf = other.next_surf;
0540 next_sense = other.next_sense;
0541
0542 pos = other.pos;
0543 dir = other.dir;
0544 vol = other.vol;
0545 univ = other.univ;
0546
0547 temp_face = other.temp_face;
0548 temp_distance = other.temp_distance;
0549 temp_isect = other.temp_isect;
0550
0551 CELER_ENSURE(*this);
0552 return *this;
0553 }
0554 };
0555
0556
0557
0558
0559
0560 template<MemSpace M>
0561 inline void resize(OrangeStateData<Ownership::value, M>* data,
0562 HostCRef<OrangeParamsData> const& params,
0563 size_type num_tracks)
0564 {
0565 CELER_EXPECT(data);
0566 CELER_EXPECT(num_tracks > 0);
0567
0568 resize(&data->univ_level, num_tracks);
0569 resize(&data->surface_univ_level, num_tracks);
0570 resize(&data->surf, num_tracks);
0571 resize(&data->sense, num_tracks);
0572 resize(&data->status, num_tracks);
0573
0574 resize(&data->next_step, num_tracks);
0575 resize(&data->next_univ_level, num_tracks);
0576 resize(&data->next_surf, num_tracks);
0577 resize(&data->next_sense, num_tracks);
0578
0579 size_type num_track_univ = params.scalars.num_univ_levels * num_tracks;
0580 resize(&data->pos, num_track_univ);
0581 resize(&data->dir, num_track_univ);
0582 resize(&data->vol, num_track_univ);
0583 resize(&data->univ, num_track_univ);
0584
0585 size_type num_track_isect = params.scalars.max_intersections * num_tracks;
0586 resize(&data->temp_face, num_track_isect);
0587 resize(&data->temp_distance, num_track_isect);
0588 resize(&data->temp_isect, num_track_isect);
0589
0590 CELER_ENSURE(*data);
0591 }
0592
0593
0594 }