Skip to content

Split propagate function into client components #850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 82 additions & 46 deletions core/include/detray/propagator/propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ struct propagator {
#endif
};

/// Propagate method: Coordinates the calls of the stepper, navigator and
/// all registered actors.
/// Propagate method init: Initialize a propagation state
///
/// @param propagation the state of a propagation flow
/// @param actor_state_refs tuple containing refences to the actor states
///
/// @return propagation success.
DETRAY_HOST_DEVICE bool propagate(
/// @return The heartbeat at the end of the initialization.
///
/// @note If the return value of this function is true, a propagation step
/// can be taken afterwards.
DETRAY_HOST_DEVICE bool propagate_init(
state &propagation,
typename actor_chain_t::state actor_state_refs) const {

auto &navigation = propagation._navigation;
auto &stepping = propagation._stepping;
const auto &track = stepping();
Expand All @@ -148,47 +149,91 @@ struct propagator {
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);

// Run while there is a heartbeat
while (propagation._heartbeat) {
return propagation._heartbeat;
}

/// Propagate method step: Perform a single propagation step.
///
/// @param propagation the state of a propagation flow
/// @param actor_state_refs tuple containing refences to the actor states
///
/// @return The heartbeat at the end of the step.
///
/// @note If the return value of this function is true, another step can
/// be taken afterwards.
DETRAY_HOST_DEVICE bool propagate_step(
state &propagation,
typename actor_chain_t::state actor_state_refs) const {
auto &navigation = propagation._navigation;
auto &stepping = propagation._stepping;
const auto &track = stepping();

// Set access to the volume material for the stepper
auto vol = navigation.get_volume();
stepping._mat = vol.has_material()
? vol.material_parameters(track.pos())
: nullptr;
// Set access to the volume material for the stepper
auto vol = navigation.get_volume();
stepping._mat =
vol.has_material() ? vol.material_parameters(track.pos()) : nullptr;

// Break automatic step size scaling by the stepper when a surface
// was reached and whenever the navigation is (re-)initialized
const bool reset_stepsize{navigation.is_on_surface() ||
navigation.is_init()};
// Take the step
propagation._heartbeat &= m_stepper.step(
navigation(), stepping, m_cfg.stepping, reset_stepsize);
// Break automatic step size scaling by the stepper when a surface
// was reached and whenever the navigation is (re-)initialized
const bool reset_stepsize{navigation.is_on_surface() ||
navigation.is_init()};
// Take the step
propagation._heartbeat &= m_stepper.step(
navigation(), stepping, m_cfg.stepping, reset_stepsize);

// Reduce navigation trust level according to stepper update
typename stepper_t::policy_type{}(stepping.policy_state(),
propagation);
// Reduce navigation trust level according to stepper update
typename stepper_t::policy_type{}(stepping.policy_state(), propagation);

// Find next candidate
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);
// Find next candidate
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);

// Run all registered actors/aborters after update
run_actors(actor_state_refs, propagation);
// Run all registered actors/aborters after update
run_actors(actor_state_refs, propagation);

// And check the status
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);
// And check the status
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);

#if defined(__NO_DEVICE__)
if (propagation.do_debug) {
inspect(propagation);
}
if (propagation.do_debug) {
inspect(propagation);
}
#endif

return propagation._heartbeat;
}

/// Propagate method finale: Return whether or not the propagation
/// completed succesfully.
///
/// @param propagation the state of a propagation flow
///
/// @return propagation success.
DETRAY_HOST_DEVICE bool propagate_is_complete(state &propagation) const {
return propagation._navigation.is_complete();
}

/// Propagate method: Coordinates the calls of the stepper, navigator and
/// all registered actors.
///
/// @param propagation the state of a propagation flow
/// @param actor_state_refs tuple containing refences to the actor states
///
/// @return propagation success.
DETRAY_HOST_DEVICE bool propagate(
state &propagation,
typename actor_chain_t::state actor_state_refs) const {

bool status = propagate_init(propagation, actor_state_refs);

// Run while there is a heartbeat
while (status) {
status = propagate_step(propagation, actor_state_refs);
}

// Pass on the whether the propagation was successful
return propagation._navigation.is_complete();
return propagate_is_complete(propagation);
}

/// Overload for emtpy actor chain
Expand All @@ -215,21 +260,12 @@ struct propagator {
state &propagation,
typename actor_chain_t::state actor_state_refs) const {

propagate_init(propagation, actor_state_refs);

auto &navigation = propagation._navigation;
auto &stepping = propagation._stepping;
const auto &track = stepping();

// Initialize the navigation
propagation._heartbeat =
m_navigator.init(track, navigation, m_cfg.navigation);

// Run all registered actors/aborters after init
run_actors(actor_state_refs, propagation);

// Find next candidate
propagation._heartbeat &=
m_navigator.update(track, navigation, m_cfg.navigation);

while (propagation._heartbeat) {

bool skip = true;
Expand Down Expand Up @@ -289,7 +325,7 @@ struct propagator {
}

// Pass on the whether the propagation was successful
return propagation._navigation.is_complete();
return propagate_is_complete(propagation);
}

template <typename state_t>
Expand Down
Loading