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