BioCMAMC-ST
monod.hpp
1#ifndef __MODEL_MONOD_HPP__
2#define __MODEL_MONOD_HPP__
3
4#include "mc/macros.hpp"
5#include "models/utils.hpp"
6#include <Kokkos_MathematicalConstants.hpp>
7#include <mc/alias.hpp>
8#include <mc/prng/prng_extension.hpp>
9#include <mc/traits.hpp>
10#include <optional>
11namespace Models
12{
13
14 struct Monod
15 {
25
26 static constexpr std::size_t n_var =
27 INDEX_FROM_ENUM(particle_var::__COUNT__);
28 static constexpr std::string_view name = "monod";
29 using uniform_weight = std::true_type; // Using type alias
30 using Self = Monod;
31 using FloatType = float;
33 using Config = std::nullopt_t;
34
35 MODEL_CONSTANT FloatType y_s_x = 2; // m
36 MODEL_CONSTANT FloatType mu_max = 0.77 / 3600.; // m
37 MODEL_CONSTANT FloatType tau_meta = 1. / mu_max; // m
38 MODEL_CONSTANT FloatType l_max_m = 2e-6; // m
39 MODEL_CONSTANT FloatType l_min_m = l_max_m / 2.; // m
40 MODEL_CONSTANT FloatType k_s = 1e-3; // m
41 MODEL_CONSTANT FloatType d_m = 0.6e-6; // m
42 MODEL_CONSTANT FloatType lin_density =
43 c_linear_density(static_cast<FloatType>(1000), d_m);
44
45 KOKKOS_INLINE_FUNCTION static void
46 init([[maybe_unused]] const MC::KPRNG::pool_type& random_pool,
47 [[maybe_unused]] std::size_t idx,
48 [[maybe_unused]] const SelfParticle& arr)
49 {
50 auto generator = random_pool.get_state();
51 // static constexpr auto mu_dist =
52 // MC::Distributions::TruncatedNormal<float>(
53 // 0.5/3600, 0.5/3600/5, 0., mu_max);
54
55 static constexpr auto l_dist =
57 l_max_m * 0.75, l_max_m * 0.75 / 4, l_min_m, l_max_m);
58
59 const auto l0 = l_dist.draw(generator);
60 const auto mu_0 = mu_max; // mu_dist.draw(generator);
61 random_pool.free_state(generator);
62
63 GET_PROPERTY(particle_var::l) = l0;
64 GET_PROPERTY(particle_var::l_max) = l_max_m;
65 GET_PROPERTY(particle_var::mu) = mu_0;
67 l_max_m / 2. / 0.69314718056;
68 }
69
70 KOKKOS_INLINE_FUNCTION static double
71 mass([[maybe_unused]] std::size_t idx,
72 [[maybe_unused]] const SelfParticle& arr)
73 {
74 return GET_PROPERTY(Self::particle_var::l) * lin_density;
75 }
76
77 KOKKOS_INLINE_FUNCTION static MC::Status
78 update([[maybe_unused]] const MC::KPRNG::pool_type& random_pool,
79 [[maybe_unused]] FloatType d_t,
80 [[maybe_unused]] std::size_t idx,
81 [[maybe_unused]] const SelfParticle& arr,
82 [[maybe_unused]] const MC::LocalConcentration& c)
83 {
84 const FloatType s = static_cast<FloatType>(Kokkos::max(0., c(0)));
85 const FloatType mu_p = mu_max * s / (k_s + s);
86 const FloatType mu_eff =
87 Kokkos::min(GET_PROPERTY(Self::particle_var::mu), mu_p);
88
89 GET_PROPERTY(Self::particle_var::l) +=
90 d_t * (mu_eff *
92
93 GET_PROPERTY(Self::particle_var::mu) +=
94 d_t * (1.0 / tau_meta) *
95 (mu_p - GET_PROPERTY(Self::particle_var::mu));
96
97 GET_PROPERTY(Self::particle_var::phi_s_c) =
98 -mu_eff * y_s_x * mass(idx, arr);
99
100 return check_div(GET_PROPERTY(Self::particle_var::l),
101 GET_PROPERTY(Self::particle_var::l_max));
102 }
103
104 KOKKOS_INLINE_FUNCTION static void
105 division([[maybe_unused]] const MC::KPRNG::pool_type& random_pool,
106 [[maybe_unused]] std::size_t idx,
107 [[maybe_unused]] std::size_t idx2,
108 [[maybe_unused]] const SelfParticle& arr,
109 [[maybe_unused]] const SelfParticle& buffer_arr)
110 {
111 const FloatType new_current_length = GET_PROPERTY(particle_var::l) / 2.F;
112 GET_PROPERTY(particle_var::l) = new_current_length;
113
114 // Newborn cell
115 GET_PROPERTY_FROM(idx2, buffer_arr, particle_var::l) = new_current_length;
116 GET_PROPERTY_FROM(idx2, buffer_arr, particle_var::l_max) = l_max_m;
117 GET_PROPERTY_FROM(idx2, buffer_arr, particle_var::mu) =
118 GET_PROPERTY(particle_var::mu);
119 GET_PROPERTY_FROM(
122 }
123
125 {
126 int begin = INDEX_FROM_ENUM(Self::particle_var::phi_s_c);
127 return {.begin = begin, .end = begin + 1};
128 }
129
130 static std::vector<std::string_view> names()
131 {
132 return {
133
134 "length", "mu"};
135 }
136
137 static std::vector<std::size_t> get_number()
138 {
139 return {INDEX_FROM_ENUM(particle_var::l),
140 INDEX_FROM_ENUM(particle_var::mu)};
141 }
142 };
143
144 CHECK_MODEL(Monod)
145} // namespace Models
146#endif
pool_type pool_type
Definition prng.hpp:21
Status
Definition alias.hpp:49
Kokkos::Subview< KernelConcentrationType, int, decltype(Kokkos::ALL)> LocalConcentration
Definition alias.hpp:84
Kokkos::View< F *[Nd], Kokkos::LayoutRight > ParticlesModel
Definition alias.hpp:16
Models definition.
Definition config_loader.hpp:9
KOKKOS_INLINE_FUNCTION MC::Status check_div(const T l, const T lc)
Definition utils.hpp:18
KOKKOS_INLINE_FUNCTION consteval F c_linear_density(F rho, F d)
Definition utils.hpp:47
Definition alias.hpp:57
Represents a TruncatedNormal (Gaussian) probability distribution.
Definition prng_extension.hpp:277
Definition monod.hpp:15
MODEL_CONSTANT FloatType tau_meta
Definition monod.hpp:37
static KOKKOS_INLINE_FUNCTION void division(const MC::KPRNG::pool_type &random_pool, std::size_t idx, std::size_t idx2, const SelfParticle &arr, const SelfParticle &buffer_arr)
Definition monod.hpp:105
static constexpr std::string_view name
Definition monod.hpp:28
static MC::ContribIndexBounds get_bounds()
Definition monod.hpp:124
MODEL_CONSTANT FloatType d_m
Definition monod.hpp:41
static constexpr std::size_t n_var
Definition monod.hpp:26
static KOKKOS_INLINE_FUNCTION double mass(std::size_t idx, const SelfParticle &arr)
Definition monod.hpp:71
static KOKKOS_INLINE_FUNCTION void init(const MC::KPRNG::pool_type &random_pool, std::size_t idx, const SelfParticle &arr)
Definition monod.hpp:46
float FloatType
Definition monod.hpp:31
static std::vector< std::size_t > get_number()
Definition monod.hpp:137
static KOKKOS_INLINE_FUNCTION MC::Status update(const MC::KPRNG::pool_type &random_pool, FloatType d_t, std::size_t idx, const SelfParticle &arr, const MC::LocalConcentration &c)
Definition monod.hpp:78
MODEL_CONSTANT FloatType l_min_m
Definition monod.hpp:39
particle_var
Definition monod.hpp:17
@ l
Definition monod.hpp:18
@ phi_s_c
Definition monod.hpp:22
@ mu
Definition monod.hpp:20
@ l_max
Definition monod.hpp:19
@ __COUNT__
Definition monod.hpp:23
@ _init_only_cell_lenghtening
Definition monod.hpp:21
MODEL_CONSTANT FloatType lin_density
Definition monod.hpp:42
std::nullopt_t Config
Definition monod.hpp:33
MODEL_CONSTANT FloatType l_max_m
Definition monod.hpp:38
Monod Self
Definition monod.hpp:30
static std::vector< std::string_view > names()
Definition monod.hpp:130
MC::ParticlesModel< Self::n_var, Self::FloatType > SelfParticle
Definition monod.hpp:32
MODEL_CONSTANT FloatType k_s
Definition monod.hpp:40
MODEL_CONSTANT FloatType mu_max
Definition monod.hpp:36
MODEL_CONSTANT FloatType y_s_x
Definition monod.hpp:35
std::true_type uniform_weight
Definition monod.hpp:29