Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:24:49

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/orangeinp/detail/SurfaceGridHash.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cstdlib>
0010 #include <utility>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Array.hh"
0014 #include "orange/OrangeTypes.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace orangeinp
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Hash "similar" surfaces for faster lookups.
0025  *
0026  * This is meant to generate one or more "key" values for a hash of surfaces.
0027  *
0028  * This creates a hash map of local surfaces based on a characteristic
0029  * dimension (i.e. the radius of a sphere), which is used to accelerate surface
0030  * deduplication. For a given surface in bin N, possible duplicates may be
0031  * found in bins N-1, N, N+1.
0032  *
0033  * - Nearby surfaces should always have nearby "hash points", within some
0034  *   comparison tolerance.
0035  * - The comparison tolerance must be less than the grid width, probably \em
0036  *   much less.
0037  * - Different surfaces can have an identical hash point but have
0038  *   different surface types.
0039  * - The bin values will *always* be unique given a surface type.
0040  *
0041  * \sa LocalSurfaceInserter
0042  */
0043 class SurfaceGridHash
0044 {
0045   public:
0046     //!@{
0047     //! \name Type aliases
0048     using key_type = std::size_t;
0049     using result_type = Array<key_type, 2>;
0050     //!@}
0051 
0052   public:
0053     // Construct with maximum tolerance and characteristic scale of grid
0054     SurfaceGridHash(real_type grid_scale, real_type tol);
0055 
0056     // Construct keys for the grid
0057     result_type operator()(SurfaceType type, real_type hash_point) const;
0058 
0059     //! Sentinel value for a hash point being redundant
0060     static constexpr key_type redundant() { return static_cast<key_type>(-1); }
0061 
0062   private:
0063     real_type eps_;
0064     real_type grid_offset_;
0065     real_type inv_grid_width_;
0066 
0067     // Calculate the bin of a new data point
0068     key_type calc_bin(SurfaceType type, real_type hash_point) const;
0069 };
0070 
0071 //---------------------------------------------------------------------------//
0072 }  // namespace detail
0073 }  // namespace orangeinp
0074 }  // namespace celeritas