Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:26

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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 celeritas/optical/detail/OpticalUtils.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "celeritas/Constants.hh"
0014 #include "celeritas/Quantities.hh"
0015 
0016 namespace celeritas
0017 {
0018 namespace optical
0019 {
0020 namespace detail
0021 {
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Convert a native-system wavelength into a photon energy.
0025  */
0026 inline CELER_FUNCTION units::MevEnergy
0027 wavelength_to_energy(real_type wavelength)
0028 {
0029     CELER_EXPECT(wavelength > 0);
0030     return native_value_to<units::MevEnergy>(
0031         (constants::h_planck * constants::c_light) / wavelength);
0032 }
0033 
0034 //---------------------------------------------------------------------------//
0035 /*!
0036  * Convert a photon energy to native-system wavelength.
0037  */
0038 inline CELER_FUNCTION real_type energy_to_wavelength(units::MevEnergy energy)
0039 {
0040     CELER_EXPECT(energy > zero_quantity());
0041     return (constants::h_planck * constants::c_light)
0042            / native_value_from(energy);
0043 }
0044 
0045 //---------------------------------------------------------------------------//
0046 }  // namespace detail
0047 }  // namespace optical
0048 
0049 namespace detail
0050 {
0051 //---------------------------------------------------------------------------//
0052 /*!
0053  * Find the index of the distribution from which to generate the primary.
0054  *
0055  * This finds the index in offsets for which offsets[result - 1] <= value <
0056  * offsets[result].
0057  */
0058 inline CELER_FUNCTION size_type find_distribution_index(Span<size_type> offsets,
0059                                                         size_type value)
0060 {
0061     CELER_EXPECT(!offsets.empty());
0062 
0063     auto iter = celeritas::lower_bound(offsets.begin(), offsets.end(), value);
0064     CELER_ASSERT(iter != offsets.end());
0065 
0066     if (value == *iter)
0067     {
0068         ++iter;
0069     }
0070     return iter - offsets.begin();
0071 }
0072 
0073 //---------------------------------------------------------------------------//
0074 }  // namespace detail
0075 }  // namespace celeritas