40 {
41
42 *a_energyFraction = 1.0;
43
44 if( a_energy <= a_energies[0] ) return( 0 );
45 if( a_energy >= a_energies.
back( ) ) {
46 *a_energyFraction = 0.0;
47 return( ( a_energies.
size( ) - 2 ) );
48 }
49
50 std::size_t index1 = a_hashIndices[a_hashIndex];
51
52#ifdef MCGIDI_CrossSectionLinearSubSearch
53 while( a_energies[index1] > a_energy ) --index1;
54 while( a_energies[index1] < a_energy ) ++index1;
55 --index1;
56#endif
57
58#ifdef MCGIDI_CrossSectionBinarySubSearch
59 std::size_t index2 = a_hashIndices[a_hashIndex];
60 std::size_t index3 = a_energies.
size( ) - 1;
61 if( ( a_hashIndex + 1 ) < a_hashIndices.
size( ) ) index3 = a_hashIndices[a_hashIndex+1] + 1;
62 if( index3 == a_energies.
size( ) ) --index3;
63 if( index2 != index3 ) index2 =
static_cast<std::size_t
>(
binarySearchVectorBounded( a_energy, a_energies, index2, index3,
false ) );
64#endif
65
66#ifdef MCGIDI_CrossSectionBinarySubSearch
67 #ifdef MCGIDI_CrossSectionLinearSubSearch
68 if( index1 != index2 ) {
69 std::cerr << "Help " << index1 << " " << index2 << std::endl;
70 }
71 #endif
72 index1 = index2;
73#endif
74
75 *a_energyFraction = ( a_energies[index1+1] - a_energy ) / ( a_energies[index1+1] - a_energies[index1] );
76
77 return( index1 );
78}
LUPI_HOST_DEVICE std::size_t size() const
LUPI_HOST_DEVICE T & back()
LUPI_HOST_DEVICE int binarySearchVectorBounded(double a_x, Vector< double > const &a_Xs, std::size_t a_lower, std::size_t a_upper, bool a_boundIndex)