From 0a73d840de38aea671665c414a6bfcf72cfc7819 Mon Sep 17 00:00:00 2001 From: SeverinDiederichs Date: Sat, 25 Jul 2026 11:10:43 +0200 Subject: [PATCH] initialize safety in InitTracks --- include/AdePT/transport/AdePTTransport.cuh | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/include/AdePT/transport/AdePTTransport.cuh b/include/AdePT/transport/AdePTTransport.cuh index 04e4d6d4..f070b6fa 100644 --- a/include/AdePT/transport/AdePTTransport.cuh +++ b/include/AdePT/transport/AdePTTransport.cuh @@ -33,7 +33,7 @@ #include -#include +#include #include using SelectedSteppingAction = adept::SteppingAction::Action; @@ -173,7 +173,7 @@ __device__ inline uint64_t GenerateSeedFromTrackInfo(const adeptint::TrackData & return fnv1a_hash64(input, 12); } -template +template __device__ inline void InitTrackToQueue(SpeciesManagerT &speciesTM, const adeptint::TrackData &trackInfo, short queueIndex, adept::MParrayT *toBeEnqueued, uint64_t initialSeed) @@ -183,10 +183,18 @@ __device__ inline void InitTrackToQueue(SpeciesManagerT &speciesTM, const adepti // Scramble the initial seed with track data so a particle returning from the // device and being injected again does not collide with its old RNG stream. auto seed = GenerateSeedFromTrackInfo(trackInfo, initialSeed); - speciesTM.InitTrack(slot, seed, trackInfo.eKin, trackInfo.globalTime, static_cast(trackInfo.localTime), - static_cast(trackInfo.properTime), trackInfo.weight, trackInfo.position, - trackInfo.direction, trackInfo.navState, trackInfo.eventId, trackInfo.trackId, trackInfo.parentId, - trackInfo.threadId, trackInfo.stepCounter, trackInfo.hasHostData); + auto &track = + speciesTM.InitTrack(slot, seed, trackInfo.eKin, trackInfo.globalTime, static_cast(trackInfo.localTime), + static_cast(trackInfo.properTime), trackInfo.weight, trackInfo.position, + trackInfo.direction, trackInfo.navState, trackInfo.eventId, trackInfo.trackId, + trackInfo.parentId, trackInfo.threadId, trackInfo.stepCounter, trackInfo.hasHostData); + if constexpr (InitializeSafety) { + double safety = 0.; + if (!track.navState.IsOnBoundary()) { + safety = AdePTNavigator::ComputeSafety(track.pos, track.navState); + } + track.SetSafety(track.pos, safety); + } toBeEnqueued->push_back(QueueIndexPair{slot, queueIndex}); } @@ -200,10 +208,10 @@ __global__ void InitTracks(adeptint::TrackData *trackinfo, int ntracks, Particle switch (trackInfo.pdg) { case 11: - InitTrackToQueue(particleManager.electrons, trackInfo, GPUQueueIndex::Electron, toBeEnqueued, initialSeed); + InitTrackToQueue(particleManager.electrons, trackInfo, GPUQueueIndex::Electron, toBeEnqueued, initialSeed); break; case -11: - InitTrackToQueue(particleManager.positrons, trackInfo, GPUQueueIndex::Positron, toBeEnqueued, initialSeed); + InitTrackToQueue(particleManager.positrons, trackInfo, GPUQueueIndex::Positron, toBeEnqueued, initialSeed); break; case 22: // check for Woodcock tracking