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 <common/maths.hpp>
6
8{
9
10 static constexpr bool _use_kokkos_log = true; // FIXME
11 // KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number,
12 // double volume,
13 // double flow,
14 // double dt)
15 // {
16 // return (dt * flow) >
17 // (-CommonMaths::_ln<_use_kokkos_log>(random_number) * volume);
18 // }
19
20 template <typename FastSample = int>
21 KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number,
22 double volume,
23 double flow,
24 double dt)
25 {
26 // Default behavior (with ln)
27 return (dt * flow) >
28 (-CommonMaths::_ln<_use_kokkos_log>(random_number) * volume);
29 }
30
31 // Specialization for when FastSample is provided
32 template <>
33 KOKKOS_INLINE_FUNCTION bool probability_leaving<void>(float random_number,
34 double volume,
35 double flow,
36 double dt)
37 {
38 // Fast version without ln
39 return (dt * flow / volume) > random_number;
40 }
41
42} // namespace Simulation::KernelInline
43
44#endif
KOKKOS_INLINE_FUNCTION float _ln(float x)
Definition maths.hpp:10
Definition kernels.hpp:11
static constexpr bool _use_kokkos_log
Definition probability_leaving.hpp:10
KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:21
KOKKOS_INLINE_FUNCTION bool probability_leaving< void >(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:33