Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:47

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-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 corecel/grid/detail/InterpolatorTraits.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <cmath>
0011 
0012 #include "corecel/Macros.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Traits class for interpolating with linear/logarithmic scaling.
0021  */
0022 template<Interp I, class T>
0023 struct InterpolatorTraits;
0024 
0025 template<class T>
0026 struct InterpolatorTraits<Interp::linear, T>
0027 {
0028     static CELER_CONSTEXPR_FUNCTION T transform(T value) { return value; }
0029     static CELER_CONSTEXPR_FUNCTION T negate_transformed(T value)
0030     {
0031         return -value;
0032     }
0033     static CELER_CONSTEXPR_FUNCTION T add_transformed(T left, T right)
0034     {
0035         return left + right;
0036     }
0037     static CELER_CONSTEXPR_FUNCTION T transform_inv(T value) { return value; }
0038     static CELER_CONSTEXPR_FUNCTION bool valid_domain(T) { return true; }
0039 };
0040 
0041 template<class T>
0042 struct InterpolatorTraits<Interp::log, T>
0043 {
0044     static CELER_CONSTEXPR_FUNCTION T transform(T value)
0045     {
0046         return std::log2(value);
0047     }
0048     static CELER_CONSTEXPR_FUNCTION T negate_transformed(T value)
0049     {
0050         return T(1) / value;
0051     }
0052     static CELER_CONSTEXPR_FUNCTION T add_transformed(T left, T right)
0053     {
0054         return transform(left * right);
0055     }
0056     static CELER_CONSTEXPR_FUNCTION T transform_inv(T value)
0057     {
0058         return std::exp2(value);
0059     }
0060     static CELER_CONSTEXPR_FUNCTION bool valid_domain(T value)
0061     {
0062         return value > T(0);
0063     }
0064 };
0065 
0066 //---------------------------------------------------------------------------//
0067 }  // namespace detail
0068 }  // namespace celeritas