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
22 probability_leaving(float random_number,
23 double volume,
24 double flow,
25 double dt)
26 {
27 // Default behavior (with ln)
28 return (dt * flow)
29 > (-CommonMaths::_ln<_use_kokkos_log>(random_number) * volume);
30 }
31
32 // Specialization for when FastSample is provided
33 template <>
34 KOKKOS_INLINE_FUNCTION bool
35 probability_leaving<void>(float random_number,
36 double volume,
37 double flow,
38 double dt)
39 {
40 // Fast version without ln
41 return (dt * flow / volume) > random_number;
42 }
43
44} // namespace Simulation::KernelInline
45
46#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:10
KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:22
KOKKOS_INLINE_FUNCTION bool probability_leaving< void >(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:35