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