Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:03

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // detray definitions
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/containers.hpp"
0014 #include "detray/definitions/detail/qualifiers.hpp"
0015 #include "detray/definitions/math.hpp"
0016 
0017 // System include(s).
0018 #include <limits>
0019 #include <type_traits>
0020 
0021 namespace detray {
0022 
0023 // Add constraints for steppers
0024 namespace step {
0025 
0026 /// Direction in which the integration is performed
0027 enum class direction : int {
0028   e_forward = 1,
0029   e_unknown = std::numeric_limits<int>::max(),
0030   e_backward = -1,
0031 };
0032 
0033 /// the types of constraints
0034 /// from accuracy - this can vary up and down given a good step estimator
0035 /// from actor    - this would be a typical navigation step
0036 /// from aborter  - this would be a target condition
0037 /// from user     - this is user given for what reason ever
0038 enum constraint : std::size_t {
0039   e_accuracy = 0u,
0040   e_actor = 1u,
0041   e_aborter = 2u,
0042   e_user = 3u,
0043   e_all = 4u
0044 };
0045 
0046 }  // namespace step
0047 
0048 /// Struct that represents unconstrained stepping
0049 template <concepts::scalar scalar_t>
0050 struct unconstrained_step {
0051   /// Register a new @param step_size constraint
0052   template <step::constraint type>
0053   DETRAY_HOST_DEVICE constexpr void set(const scalar_t /*step_size*/) const {
0054     /*Do nothing*/
0055   }
0056 
0057   /// @returns the current step size constraint
0058   template <step::constraint type = step::constraint::e_all>
0059   DETRAY_HOST_DEVICE constexpr scalar_t size(
0060       const step::direction /*dir*/ = step::direction::e_forward) const {
0061     return std::numeric_limits<scalar_t>::max();
0062   }
0063 
0064   /// Remove constraints
0065   template <step::constraint type = step::constraint::e_actor>
0066   DETRAY_HOST_DEVICE constexpr void release() const {
0067     /*Do nothing*/
0068   }
0069 };
0070 
0071 /// Struct that can be configured with a number of different step sizes by other
0072 /// actors and will then resolve the strictest one.
0073 template <concepts::scalar scalar_t>
0074 struct constrained_step {
0075   /// Register a new @param step_size constraint
0076   template <step::constraint type>
0077     requires(type != step::constraint::e_all)
0078   DETRAY_HOST_DEVICE void set(const scalar_t step_size) {
0079     _constraints[type] = math::min(_constraints[type], math::fabs(step_size));
0080   }
0081 
0082   /// @returns the current step size constraint for a given type or overall
0083   template <step::constraint type = step::constraint::e_all>
0084   DETRAY_HOST_DEVICE scalar_t
0085   size(const step::direction dir = step::direction::e_forward) const {
0086     if constexpr (type == step::constraint::e_all) {
0087       return static_cast<scalar_t>(dir) * min();
0088     } else {
0089       return static_cast<scalar_t>(dir) * _constraints[type];
0090     }
0091   }
0092 
0093   /// Remove [all] constraints
0094   template <step::constraint type = step::constraint::e_actor>
0095   DETRAY_HOST_DEVICE void release() {
0096     if constexpr (type == step::constraint::e_all) {
0097       _constraints = {std::numeric_limits<scalar_t>::max(),
0098                       std::numeric_limits<scalar_t>::max(),
0099                       std::numeric_limits<scalar_t>::max(),
0100                       std::numeric_limits<scalar_t>::max()};
0101     } else {
0102       _constraints[type] = std::numeric_limits<scalar_t>::max();
0103     }
0104   }
0105 
0106   /// @returns the strongest constraint
0107   DETRAY_HOST_DEVICE scalar_t min() const {
0108     scalar_t min_constr = std::numeric_limits<scalar_t>::max();
0109     min_constr =
0110         math::min(min_constr, _constraints[step::constraint::e_accuracy]);
0111     min_constr = math::min(min_constr, _constraints[step::constraint::e_actor]);
0112     min_constr =
0113         math::min(min_constr, _constraints[step::constraint::e_aborter]);
0114     return math::min(min_constr, _constraints[step::constraint::e_user]);
0115   }
0116 
0117   /// Current step size constraints from accuracy, actors, aborters or user
0118   darray<scalar_t, 4> _constraints = {std::numeric_limits<scalar_t>::max(),
0119                                       std::numeric_limits<scalar_t>::max(),
0120                                       std::numeric_limits<scalar_t>::max(),
0121                                       std::numeric_limits<scalar_t>::max()};
0122 };
0123 
0124 }  // namespace detray