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