ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
constrained_step.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// detray definitions
12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/definitions/math.hpp"
16
17// System include(s).
18#include <limits>
19#include <type_traits>
20
21namespace detray {
22
23// Add constraints for steppers
24namespace step {
25
27enum class direction : int {
28 e_forward = 1,
29 e_unknown = std::numeric_limits<int>::max(),
30 e_backward = -1,
31};
32
38enum constraint : std::size_t {
39 e_accuracy = 0u,
40 e_actor = 1u,
41 e_aborter = 2u,
42 e_user = 3u,
43 e_all = 4u
44};
45
46} // namespace step
47
49template <concepts::scalar scalar_t>
52 template <step::constraint type>
53 DETRAY_HOST_DEVICE constexpr void set(const scalar_t /*step_size*/) const {
54 /*Do nothing*/
55 }
56
58 template <step::constraint type = step::constraint::e_all>
59 DETRAY_HOST_DEVICE constexpr scalar_t size(
60 const step::direction /*dir*/ = step::direction::e_forward) const {
61 return std::numeric_limits<scalar_t>::max();
62 }
63
65 template <step::constraint type = step::constraint::e_actor>
66 DETRAY_HOST_DEVICE constexpr void release() const {
67 /*Do nothing*/
68 }
69};
70
73template <concepts::scalar scalar_t>
76 template <step::constraint type>
77 requires(type != step::constraint::e_all)
78 DETRAY_HOST_DEVICE void set(const scalar_t step_size) {
79 _constraints[type] = math::min(_constraints[type], math::fabs(step_size));
80 }
81
85 template <step::constraint type = step::constraint::e_all>
86 DETRAY_HOST_DEVICE scalar_t
87 size(const step::direction dir = step::direction::e_forward) const {
88 if constexpr (type == step::constraint::e_all) {
89 return static_cast<scalar_t>(dir) * min();
90 } else {
91 return static_cast<scalar_t>(dir) * _constraints[type];
92 }
93 }
94
96 template <step::constraint type = step::constraint::e_actor>
97 DETRAY_HOST_DEVICE void release() {
98 if constexpr (type == step::constraint::e_all) {
99 _constraints = {std::numeric_limits<scalar_t>::max(),
100 std::numeric_limits<scalar_t>::max(),
101 std::numeric_limits<scalar_t>::max(),
102 std::numeric_limits<scalar_t>::max()};
103 } else {
104 _constraints[type] = std::numeric_limits<scalar_t>::max();
105 }
106 }
107
109 DETRAY_HOST_DEVICE scalar_t min() const {
110 scalar_t min_constr = std::numeric_limits<scalar_t>::max();
111 min_constr =
112 math::min(min_constr, _constraints[step::constraint::e_accuracy]);
113 min_constr = math::min(min_constr, _constraints[step::constraint::e_actor]);
114 min_constr =
115 math::min(min_constr, _constraints[step::constraint::e_aborter]);
116 return math::min(min_constr, _constraints[step::constraint::e_user]);
117 }
118
120 darray<scalar_t, 4> _constraints = {std::numeric_limits<scalar_t>::max(),
121 std::numeric_limits<scalar_t>::max(),
122 std::numeric_limits<scalar_t>::max(),
123 std::numeric_limits<scalar_t>::max()};
124};
125
126} // namespace detray
constexpr double u
atomic mass unit u
Definition Units.hpp:155
Detray include(s).
Definition array_operators.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
Struct that can be configured with a number of different step sizes by other actors and will then res...
Definition constrained_step.hpp:74
void release()
Remove [all] constraints.
Definition constrained_step.hpp:97
scalar_t size(const step::direction dir=step::direction::e_forward) const
Return the strictest active step-size constraint, with direction applied.
Definition constrained_step.hpp:87
void set(const scalar_t step_size)
Register a new.
Definition constrained_step.hpp:78
scalar_t min() const
Definition constrained_step.hpp:109
darray< scalar_t, 4 > _constraints
Current step size constraints from accuracy, actors, aborters or user.
Definition constrained_step.hpp:120
Struct that represents unconstrained stepping.
Definition constrained_step.hpp:50
constexpr void set(const scalar_t) const
Ignore a constraint request because this policy imposes no limits.
Definition constrained_step.hpp:53
constexpr scalar_t size(const step::direction=step::direction::e_forward) const
Definition constrained_step.hpp:59
constexpr void release() const
Remove constraints.
Definition constrained_step.hpp:66