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