![]() |
|
|||
File indexing completed on 2025-09-17 09:07:50
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/CachedLazySenseCalculator.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include "corecel/Macros.hh" 0010 #include "corecel/cont/Span.hh" 0011 #include "orange/OrangeTypes.hh" 0012 #include "orange/SenseUtils.hh" 0013 #include "orange/surf/LocalSurfaceVisitor.hh" 0014 0015 #include "LazySenseCalculator.hh" 0016 #include "Types.hh" 0017 #include "../VolumeView.hh" 0018 0019 namespace celeritas 0020 { 0021 namespace detail 0022 { 0023 //---------------------------------------------------------------------------// 0024 /*! 0025 * Calculate senses with a fixed particle position. 0026 * 0027 * This is an implementation detail used in initialization, boundary crossing, 0028 * simple *and* complex intersection. Instances of this class are specific to a 0029 * volume, and a position. Calling an instance evaluates the sense of a 0030 * volume's face with respect to the given position. This class is used to 0031 * lazily calculate sense during evaluation of a logic expression, caching 0032 * previously calculated senses. 0033 * 0034 * The OnFace constructor's parameter is used to store the first face that we 0035 * are "on". 0036 */ 0037 class CachedLazySenseCalculator 0038 { 0039 public: 0040 // Construct from persistent, current, and temporary data 0041 inline CELER_FUNCTION 0042 CachedLazySenseCalculator(LocalSurfaceVisitor const& visit, 0043 VolumeView const& vol, 0044 Real3 const& pos, 0045 Span<SenseValue> sense_cache, 0046 OnFace& face); 0047 0048 // Calculate senses for a single face of the given volume, possibly on a 0049 // face 0050 inline CELER_FUNCTION Sense operator()(FaceId face_id); 0051 0052 //! Flip the sense of a face 0053 CELER_FUNCTION void flip_sense(FaceId face_id) 0054 { 0055 sense_cache_[face_id.get()] = celeritas::flip_sense((*this)(face_id)); 0056 } 0057 0058 private: 0059 //! Sense calculator for the volume 0060 LazySenseCalculator lazy_sense_calculator_; 0061 0062 //! Temporary senses 0063 Span<SenseValue> sense_cache_; 0064 }; 0065 0066 //---------------------------------------------------------------------------// 0067 // INLINE DEFINITIONS 0068 //---------------------------------------------------------------------------// 0069 /*! 0070 * Construct from persistent, current, and temporary data. 0071 */ 0072 CELER_FUNCTION 0073 CachedLazySenseCalculator::CachedLazySenseCalculator( 0074 LocalSurfaceVisitor const& visit, 0075 VolumeView const& vol, 0076 Real3 const& pos, 0077 Span<SenseValue> sense_cache, 0078 OnFace& face) 0079 : lazy_sense_calculator_{visit, vol, pos, face} 0080 , sense_cache_{sense_cache.first(vol.num_faces())} 0081 { 0082 for (auto& sense : sense_cache_) 0083 { 0084 sense.clear(); 0085 } 0086 } 0087 0088 //---------------------------------------------------------------------------// 0089 /*! 0090 * Calculate senses for the given volume. 0091 * 0092 * If the point is exactly on one of the volume's surfaces, the \c face 0093 * reference passed during instance construction will be set. 0094 */ 0095 CELER_FUNCTION auto 0096 CachedLazySenseCalculator::operator()(FaceId face_id) -> Sense 0097 { 0098 CELER_EXPECT(face_id < sense_cache_.size()); 0099 auto& cached_sense = sense_cache_[face_id.get()]; 0100 if (!cached_sense.is_assigned()) 0101 { 0102 cached_sense = lazy_sense_calculator_(face_id); 0103 } 0104 return cached_sense; 0105 } 0106 0107 //---------------------------------------------------------------------------// 0108 } // namespace detail 0109 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |