BioCMAMC-ST
fixed_length.hpp
1
2#ifndef __FIXED_LENGTH_MODEL_HPP__
3#define __FIXED_LENGTH_MODEL_HPP__
4
5#include "Kokkos_Core_fwd.hpp"
6#include "Kokkos_Macros.hpp"
7#include "common/common.hpp"
8#include "common/traits.hpp"
9#include "mc/alias.hpp"
10#include "mc/macros.hpp"
11#include "models/utils.hpp"
12#include <mc/prng/prng_extension.hpp>
13#include <mc/traits.hpp>
14#include <string_view>
15
16namespace Models
17{
18
20 {
21 using uniform_weight = std::true_type;
23 using FloatType = float;
24
25 using Config = Kokkos::View<const FloatType*, ComputeSpace>;
26
27 enum class particle_var : int // NOLINT
28 {
29 length = 0,
32 };
33
34 MODEL_CONSTANT std::size_t n_var = INDEX_FROM_ENUM(particle_var::__COUNT__);
35
36 MODEL_CONSTANT std::size_t n_c = 1;
37
38 MODEL_CONSTANT std::string_view name = "fixed-length";
41
42 MODEL_CONSTANT FloatType l_dot_max = 2e-6 / 3600.; // m
43 MODEL_CONSTANT FloatType l_max_m = 2e-6; // m
44 MODEL_CONSTANT FloatType l_min_m = l_max_m / 2.; // m
45 MODEL_CONSTANT FloatType k = 1e-3; // m
46 MODEL_CONSTANT FloatType d_m = 0.6e-6; // m
47 MODEL_CONSTANT FloatType lin_density
48 = c_linear_density(static_cast<FloatType>(1000), d_m);
49
50 MODEL_CONSTANT FloatType phi_s_max
52
54
55 static Self::Config get_config(std::size_t n);
56
57 KOKKOS_INLINE_FUNCTION static void init(const MC::pool_type& random_pool,
58 std::size_t idx,
59 const SelfParticle& arr,
60 const Config& params);
61
62 KOKKOS_INLINE_FUNCTION static MC::Status
63 update(const MC::pool_type& random_pool,
64 FloatType d_t,
65 std::size_t idx,
66 const SelfParticle& arr,
67 const SelfContribs& arr_contribs,
68 std::size_t position_index,
69 const MC::LocalConcentration& c);
70
71 KOKKOS_INLINE_FUNCTION static void
72 division(const MC::pool_type& random_pool,
73 std::size_t idx,
74 std::size_t idx2,
75 const SelfParticle& arr,
76 const SelfParticle& buffer_arr);
77
78 KOKKOS_INLINE_FUNCTION static double
79 mass(std::size_t idx, const SelfParticle& arr)
80 {
81 return GET_PROPERTY(Self::particle_var::length) * lin_density;
82 }
83
84 static std::vector<std::string_view>
86 {
87 return {
88
89 "length",
90 };
91 }
92
93 static std::vector<std::size_t>
95 {
96 return { INDEX_FROM_ENUM(particle_var::length) };
97 }
98
99 static std::vector<std::string_view>
101 {
102 return { "S" };
103 }
104 };
105
106 CHECK_MODEL(FixedLength)
107
108 KOKKOS_INLINE_FUNCTION void
109 FixedLength::init([[maybe_unused]] const MC::pool_type& random_pool,
110 std::size_t idx,
111 const SelfParticle& arr,
112 const Config& config)
113 {
114 auto gen = random_pool.get_state();
115 const auto linit = config(idx);
116 random_pool.free_state(gen);
117 GET_PROPERTY(particle_var::length) = linit;
118 GET_PROPERTY(particle_var::l_max) = l_max_m;
119 // GET_PROPERTY(particle_var::phi_s) = 0.;
120 }
121
122 KOKKOS_INLINE_FUNCTION MC::Status
123 FixedLength::update([[maybe_unused]] const MC::pool_type& random_pool,
124 FloatType d_t,
125 std::size_t idx,
126 const SelfParticle& arr,
127 const SelfContribs& arr_contribs,
128 const std::size_t position_index,
129 const MC::LocalConcentration& c)
130 {
131 auto& l = GET_PROPERTY(Self::particle_var::length);
132 const auto l_max = GET_PROPERTY(Self::particle_var::l_max);
133 const auto s = static_cast<FloatType>(GET_CONCENTRATION(0));
134 auto& c_phi_s = GET_CONTRIBS(0);
135
136 const FloatType g = s / (k + s);
137 const FloatType phi_s = phi_s_max * g;
138 const FloatType ldot = l_dot_max * g;
139 l += d_t * ldot;
140 c_phi_s = -phi_s;
141 return check_div(l, l_max);
142 }
143
144 KOKKOS_INLINE_FUNCTION void
145 FixedLength::division([[maybe_unused]] const MC::pool_type& random_pool,
146 std::size_t idx,
147 std::size_t idx2,
148 const SelfParticle& arr,
149 const SelfParticle& buffer_arr)
150 {
151
152 const FloatType new_current_length
153 = GET_PROPERTY(particle_var::length) / 2.F;
154
155 GET_PROPERTY(particle_var::length) = new_current_length;
156 GET_PROPERTY(particle_var::l_max) = l_max_m;
157
158 GET_PROPERTY_FROM(idx2, buffer_arr, particle_var::length)
159 = new_current_length;
160 GET_PROPERTY_FROM(idx2, buffer_arr, particle_var::l_max) = l_max_m;
161 }
162
163} // namespace Models
164
165#endif
Status
Definition alias.hpp:125
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:100
KernelConcentrationType LocalConcentration
Definition alias.hpp:170
Kokkos::View< F *[Nc], ComputeSpace::array_layout, ComputeSpace, Kokkos::MemoryTraits< Kokkos::MemoryTraitsFlags::Restrict > > ParticlesContribs
Definition alias.hpp:66
Kokkos::View< F *[Nd], ComputeSpace::array_layout, ComputeSpace, Kokkos::MemoryTraits< Kokkos::MemoryTraitsFlags::Restrict > > ParticlesModel
Definition alias.hpp:52
Models definition.
Definition config_loader.hpp:9
KOKKOS_INLINE_FUNCTION MC::Status check_div(const T l, const T lc)
Definition utils.hpp:64
KOKKOS_INLINE_FUNCTION consteval F c_linear_density(F rho, F d)
Definition utils.hpp:94
static F constexpr _get_phi_s_max(F density, F dl, F glucose_to_biomass_yield=0.5)
Definition utils.hpp:45
Definition alias.hpp:133
Definition fixed_length.hpp:20
MC::ParticlesModel< Self::n_var, Self::FloatType > SelfParticle
Definition fixed_length.hpp:39
MODEL_CONSTANT std::size_t n_c
Definition fixed_length.hpp:36
FixedLength Self
Definition fixed_length.hpp:22
particle_var
Definition fixed_length.hpp:28
@ length
Definition fixed_length.hpp:29
@ l_max
Definition fixed_length.hpp:30
@ __COUNT__
Definition fixed_length.hpp:31
MODEL_CONSTANT std::string_view name
Definition fixed_length.hpp:38
static KOKKOS_INLINE_FUNCTION void division(const MC::pool_type &random_pool, std::size_t idx, std::size_t idx2, const SelfParticle &arr, const SelfParticle &buffer_arr)
Definition fixed_length.hpp:145
MODEL_CONSTANT FloatType l_max_m
Definition fixed_length.hpp:43
static std::vector< std::size_t > get_number()
Definition fixed_length.hpp:94
MODEL_CONSTANT FloatType l_dot_max
Definition fixed_length.hpp:42
MODEL_CONSTANT FloatType l_min_m
Definition fixed_length.hpp:44
static std::vector< std::string_view > species()
Definition fixed_length.hpp:100
MODEL_CONSTANT std::size_t n_var
Definition fixed_length.hpp:34
MODEL_CONSTANT FloatType d_m
Definition fixed_length.hpp:46
MODEL_CONSTANT FloatType phi_s_max
Definition fixed_length.hpp:51
MODEL_CONSTANT FloatType lin_density
Definition fixed_length.hpp:48
static std::vector< std::string_view > names()
Definition fixed_length.hpp:85
static MC::ContribIndexBounds get_bounds()
MODEL_CONSTANT FloatType k
Definition fixed_length.hpp:45
MC::ParticlesContribs< Self::n_c, Self::FloatType > SelfContribs
Definition fixed_length.hpp:40
float FloatType
Definition fixed_length.hpp:23
std::true_type uniform_weight
Definition fixed_length.hpp:21
static Self::Config get_config(std::size_t n)
Definition config_loader.cpp:13
static KOKKOS_INLINE_FUNCTION MC::Status update(const MC::pool_type &random_pool, FloatType d_t, std::size_t idx, const SelfParticle &arr, const SelfContribs &arr_contribs, std::size_t position_index, const MC::LocalConcentration &c)
Definition fixed_length.hpp:123
static KOKKOS_INLINE_FUNCTION void init(const MC::pool_type &random_pool, std::size_t idx, const SelfParticle &arr, const Config &params)
Definition fixed_length.hpp:109
static KOKKOS_INLINE_FUNCTION double mass(std::size_t idx, const SelfParticle &arr)
Definition fixed_length.hpp:79
Kokkos::View< const FloatType *, ComputeSpace > Config
Definition fixed_length.hpp:25