Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:17:11

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file orange/surf/detail/RecursiveSimplifierImpl.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <variant>
0011 
0012 #include "corecel/Macros.hh"
0013 #include "orange/OrangeTypes.hh"
0014 
0015 #include "../SurfaceSimplifier.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Recursively simplify, then call the given function on the final surface.
0024  *
0025  * This implementation class allows std::visit to be used with the surface
0026  * while retaining updates to the associated Sense that the user requested.
0027  */
0028 template<class F>
0029 class RecursiveSimplifierImpl
0030 {
0031   public:
0032     //! Construct with reference to function and values to be used
0033     RecursiveSimplifierImpl(F& func, Sense sense, real_type abs_tol)
0034         : func_{func}, sense_{sense}, simplify_{&sense_, abs_tol}
0035     {
0036     }
0037 
0038     //! Invoke recursively with a specific surface type
0039     template<class S>
0040     void operator()(S const& surf)
0041     {
0042         auto result = simplify_(surf);
0043         CELER_ASSUME(!result.valueless_by_exception());
0044         if (std::holds_alternative<std::monostate>(result))
0045         {
0046             // Could not simplify further: call back with sense and surface
0047             return func_(sense_, surf);
0048         }
0049         else
0050         {
0051             return std::visit(*this, result);
0052         }
0053     }
0054 
0055     //! Monostate should never be reached
0056     void operator()(std::monostate) { CELER_ASSERT_UNREACHABLE(); }
0057 
0058   private:
0059     F& func_;
0060     Sense sense_;
0061     SurfaceSimplifier simplify_;
0062 };
0063 
0064 //---------------------------------------------------------------------------//
0065 }  // namespace detail
0066 }  // namespace celeritas