File indexing completed on 2025-02-22 10:31:26
0001
0002
0003
0004
0005
0006
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
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
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 }
0047 }
0048
0049 namespace detail
0050 {
0051
0052
0053
0054
0055
0056
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 }
0075 }