BioCMAMC-ST
probability_leaving.hpp
1#ifndef __SIMULATION_PROBA_LEAVING_HPP__
2#define __SIMULATION_PROBA_LEAVING_HPP__
3
4#include <Kokkos_Assert.hpp>
5#include <Kokkos_Core.hpp>
6#include <common/maths.hpp>
7
9{
10
11 using fast_tag = void;
12 using precision_tag = int;
13
14 static constexpr bool _use_kokkos_log = true; // FIXME
15
16 template <typename FastSample = precision_tag>
17 KOKKOS_INLINE_FUNCTION bool
18 probability_leaving(float random_number,
19 double volume,
20 double flow,
21 double dt)
22 {
23 KOKKOS_ASSERT(random_number >= 0. && random_number <= 1.);
24 KOKKOS_ASSERT(volume >= 0.);
25 KOKKOS_ASSERT(flow >= 0.);
26 KOKKOS_ASSERT(dt >= 0.);
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<fast_tag>(float random_number,
36 double volume,
37 double flow,
38 double dt)
39 {
40 KOKKOS_ASSERT(random_number >= 0. && random_number <= 1.);
41 KOKKOS_ASSERT(volume >= 0.);
42 KOKKOS_ASSERT(flow >= 0.);
43 KOKKOS_ASSERT(dt >= 0.);
44 // Fast version without ln
45 return (dt * flow / volume) > random_number;
46 }
47
48} // namespace Simulation::KernelInline
49
50#endif
KOKKOS_INLINE_FUNCTION float _ln(float x)
Definition maths.hpp:11
Definition kernels.hpp:16
static constexpr bool _use_kokkos_log
Definition probability_leaving.hpp:14
KOKKOS_INLINE_FUNCTION bool probability_leaving(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:18
void fast_tag
Definition probability_leaving.hpp:11
int precision_tag
Definition probability_leaving.hpp:12
KOKKOS_INLINE_FUNCTION bool probability_leaving< fast_tag >(float random_number, double volume, double flow, double dt)
Definition probability_leaving.hpp:35