Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 09:04:53

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/univ/detail/Utils.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cmath>
0010 
0011 #include "corecel/Assert.hh"
0012 #include "corecel/Macros.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/NumericLimits.hh"
0015 
0016 #include "Types.hh"
0017 #include "../VolumeView.hh"
0018 
0019 namespace celeritas
0020 {
0021 namespace detail
0022 {
0023 //---------------------------------------------------------------------------//
0024 // FUNCTION-LIKE CLASSES
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Predicate for partitioning valid (finite positive) from invalid distances.
0028  */
0029 struct IsFinite
0030 {
0031     CELER_FORCEINLINE_FUNCTION bool operator()(real_type distance) const
0032     {
0033         return distance < numeric_limits<real_type>::max();
0034     }
0035 };
0036 
0037 //---------------------------------------------------------------------------//
0038 /*!
0039  * Predicate for selecting distances closer to or equal to a maximum.
0040  */
0041 class IsNotFurtherThan
0042 {
0043   public:
0044     explicit CELER_FORCEINLINE_FUNCTION IsNotFurtherThan(real_type md)
0045         : max_dist_(md)
0046     {
0047     }
0048 
0049     CELER_FORCEINLINE_FUNCTION bool operator()(real_type distance) const
0050     {
0051         return distance <= max_dist_;
0052     }
0053 
0054   private:
0055     real_type max_dist_;
0056 };
0057 
0058 //---------------------------------------------------------------------------//
0059 /*!
0060  * Calculate the bump distance for a position.
0061  */
0062 class BumpCalculator
0063 {
0064   public:
0065     explicit CELER_FORCEINLINE_FUNCTION BumpCalculator(Tolerance<> const& tol)
0066         : tol_(tol)
0067     {
0068     }
0069 
0070     CELER_FUNCTION real_type operator()(Real3 const& pos) const
0071     {
0072         real_type result = tol_.abs;
0073         for (real_type p : pos)
0074         {
0075             result = celeritas::max(result, tol_.rel * std::fabs(p));
0076         }
0077         CELER_ENSURE(result > 0);
0078         return result;
0079     }
0080 
0081   private:
0082     Tolerance<> tol_;
0083 };
0084 
0085 //---------------------------------------------------------------------------//
0086 // INLINE DEFINITIONS
0087 //---------------------------------------------------------------------------//
0088 /*!
0089  * Convert an OnLocalSurface (may be null) to an OnFace using a volume view.
0090  */
0091 inline CELER_FUNCTION OnFace find_face(VolumeView const& vol,
0092                                        OnLocalSurface surf)
0093 {
0094     return {surf ? vol.find_face(surf.id()) : FaceId{}, surf.unchecked_sense()};
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Convert an OnFace (may be null) to an OnLocalSurface using a volume view.
0100  */
0101 inline CELER_FUNCTION OnLocalSurface get_surface(VolumeView const& vol,
0102                                                  OnFace face)
0103 {
0104     return {face ? vol.get_surface(face.id()) : LocalSurfaceId{},
0105             face.unchecked_sense()};
0106 }
0107 
0108 //---------------------------------------------------------------------------//
0109 }  // namespace detail
0110 }  // namespace celeritas