BioCMAMC-ST
utils.hpp
1#ifndef __BIO__UTILS_HPP__
2#define __BIO__UTILS_HPP__
3
4#include "Kokkos_Macros.hpp"
5#include <Kokkos_Core.hpp>
6#include <Kokkos_MathematicalConstants.hpp>
7#include <Kokkos_Random.hpp>
8#include <common/traits.hpp>
9#include <mc/alias.hpp>
10#include <mc/prng/prng.hpp>
14namespace Models
15{
16
17 template <FloatingPointType F>
18 static F consteval _get_phi_s_max(F density,
19 F dl,
20 F glucose_to_biomass_yield = 0.5)
21 {
22 // dl and density must be same unit, dl*density -> mass and y is mass yield
23 return (dl * density) / glucose_to_biomass_yield;
24 }
25
26 template <FloatingPointType T>
27 KOKKOS_INLINE_FUNCTION MC::Status
28 check_div(const T l, const T lc)
29 {
30 return (l >= lc) ? MC::Status::Division : MC::Status::Idle;
31 }
32
33 namespace MolarMass
34 {
35 namespace GramPerMole
36 {
37
38 template <FloatingPointType T> constexpr T glucose = static_cast<T>(180);
39 template <FloatingPointType T> constexpr T dioxygen = static_cast<T>(32);
40 template <FloatingPointType T> constexpr T acetate = static_cast<T>(59);
41
42 constexpr double co2 = 44;
43 ;
44 }; // namespace GramPerMole
45
46 constexpr double glucose = GramPerMole::glucose<double> * 1e-3;
47 constexpr double dioxygen = GramPerMole::dioxygen<double> * 1e-3;
48 ;
49 constexpr double acetate = GramPerMole::acetate<double> * 1e-3;
50 ;
51 constexpr double co2 = GramPerMole::co2 * 1e-3;
52 ;
53 [[deprecated]] constexpr double X = 113.1e-3;
54 }; // namespace MolarMass
55
56 template <FloatingPointType F>
57 KOKKOS_INLINE_FUNCTION consteval F
58 c_linear_density(F rho, F d)
59 {
60 return rho * F(Kokkos::numbers::pi) * d * d / F(4.);
61 }
62
63 static constexpr double tau_division_proba = 1e-7;
64
65 KOKKOS_INLINE_FUNCTION bool
67 double gamma,
68 MC::pool_type random_pool)
69 {
70 (void)d_t;
71 // const double proba_div =
72 // (1 - Kokkos::exp(-d_t / tau_division_proba)) * gamma;
73
74 auto generator = random_pool.get_state();
75 const double x = generator.drand(0., 1.);
76 random_pool.free_state(generator);
77
78 return x < gamma;
79 }
80
81 namespace GammaDivision
82 {
83 KOKKOS_INLINE_FUNCTION double
84 threshold_linear(double lenght, double threshold, double upper_bound)
85 {
86 return (lenght <= threshold)
87 ? 0
88 : (lenght - threshold) / (upper_bound - threshold);
89 }
90
91 KOKKOS_INLINE_FUNCTION constexpr float
92 logistic(float x, float xmax, float alpha)
93 {
94 // auto blna = alpha * std::log(xmax);
95 // return 1 / (1 + std::exp(-alpha * std::log(x) + blna));
96 // return x<xmax?1. / (1 + std::exp(alpha * std::log((x-xmax)/xmax ))):1.;
97
98 const auto z = x < xmax ? std::pow(x / (xmax - x), alpha) : 1.;
99 return z / (1. + z);
100 }
101
102 } // namespace GammaDivision
103
104 KOKKOS_INLINE_FUNCTION bool
105 almost_equal(double val, double val2, double tolerance = 1e-8)
106 {
107 return Kokkos::abs(val - val2) < tolerance;
108 }
109
110 KOKKOS_INLINE_FUNCTION constexpr bool
111 almost_zero(double x, double tol = 1e-8)
112 {
113 return (-tol < x) && (x < tol);
114 }
115
116 template <typename... Args>
117 KOKKOS_INLINE_FUNCTION double
118 min_var(Args... args)
119 {
120 return (Kokkos::min)({ args... });
121 }
122 template <>
123 KOKKOS_INLINE_FUNCTION double
125 {
126 return 0.;
127 }
128
129} // namespace Models
130
131#endif
Status
Definition alias.hpp:58
@ Division
Definition alias.hpp:60
@ Idle
Definition alias.hpp:59
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:39
Definition utils.hpp:82
KOKKOS_INLINE_FUNCTION double threshold_linear(double lenght, double threshold, double upper_bound)
Definition utils.hpp:84
KOKKOS_INLINE_FUNCTION constexpr float logistic(float x, float xmax, float alpha)
Definition utils.hpp:92
Definition utils.hpp:36
constexpr T acetate
Definition utils.hpp:40
constexpr T glucose
Definition utils.hpp:38
constexpr T dioxygen
Definition utils.hpp:39
constexpr double co2
Definition utils.hpp:42
Definition utils.hpp:34
constexpr double acetate
Definition utils.hpp:49
constexpr double co2
Definition utils.hpp:51
constexpr double X
Definition utils.hpp:53
constexpr double glucose
Definition utils.hpp:46
constexpr double dioxygen
Definition utils.hpp:47
Models definition.
Definition config_loader.hpp:9
KOKKOS_INLINE_FUNCTION bool check_probability_division(double d_t, double gamma, MC::pool_type random_pool)
Definition utils.hpp:66
KOKKOS_INLINE_FUNCTION double min_var()
Definition utils.hpp:124
KOKKOS_INLINE_FUNCTION constexpr bool almost_zero(double x, double tol=1e-8)
Definition utils.hpp:111
KOKKOS_INLINE_FUNCTION MC::Status check_div(const T l, const T lc)
Definition utils.hpp:28
KOKKOS_INLINE_FUNCTION bool almost_equal(double val, double val2, double tolerance=1e-8)
Definition utils.hpp:105
static F consteval _get_phi_s_max(F density, F dl, F glucose_to_biomass_yield=0.5)
Definition utils.hpp:18
KOKKOS_INLINE_FUNCTION consteval F c_linear_density(F rho, F d)
Definition utils.hpp:58
static constexpr double tau_division_proba
Definition utils.hpp:63