BioCMAMC-ST
probability_leaving.hpp
1#ifndef __SIMULATION_PROBA_LEAVING_HPP__
2#define __SIMULATION_PROBA_LEAVING_HPP__
3
4#include <Kokkos_Core.hpp>
5#include <type_traits>
6
7static constexpr bool _use_kokkos_log = true; //FIXME
8
10{
11
12 template <bool use_kokkos_log>
13 KOKKOS_INLINE_FUNCTION typename std::enable_if<!use_kokkos_log, float>::type _ln(float x)
14 {
15 unsigned int bx = *reinterpret_cast<unsigned int*>(&x);
16 const unsigned int ex = bx >> 23;
17 const signed int t = static_cast<signed int>(ex) - static_cast<signed int>(127);
18 // unsigned int s = (t < 0) ? (-t) : t;
19 bx = 1065353216 | (bx & 8388607);
20 x = *reinterpret_cast<float*>(&bx);
21 return -1.49278 + (2.11263 + (-0.729104 + 0.10969 * x) * x) * x + 0.6931471806 * t;
22 }
23
24 template <bool use_kokkos_log>
25 KOKKOS_INLINE_FUNCTION typename std::enable_if<use_kokkos_log, float>::type _ln(float x)
26 {
27 return Kokkos::log(x);
28 }
29
30 KOKKOS_INLINE_FUNCTION bool
31 probability_leaving(float random_number, double volume, double flow, double dt)
32 {
33 return (dt * flow) > (-_ln<_use_kokkos_log>(random_number) * volume);
34 }
35} // namespace Simulation::KernelInline
36
37
38#endif
Definition move_kernel.hpp:19
KOKKOS_INLINE_FUNCTION std::enable_if<!use_kokkos_log, float >::type _ln(float x)
Definition probability_leaving.hpp:13
KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:31