1#ifndef __ACETATE_MODEL_HPP__
2#define __ACETATE_MODEL_HPP__
4#include "Kokkos_Assert.hpp"
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"
12#include <mc/prng/prng_extension.hpp>
13#include <mc/traits.hpp>
33 inline constexpr double m_o2 = 32.0;
47 e_surplus(
double m_cmol_sub,
double gamma_sub,
double y_x)
56 y_o2_ox(
double m_cmol_sub,
double gamma_sub,
double y_x)
63 y_ac_fer(
double m_cmol_sub,
double gamma_sub,
double y_x)
137 static constexpr std::string_view
name =
"acetate";
141 static constexpr std::size_t
n_c = 3;
221 "i_go: y_x too high, negative O2 or CO2");
225 "i_ao: y_x too high, negative O2 or CO2");
227 "i_fe: y_x too high, cannot grow and excrete as much acetate "
228 "as the pure overflow");
279 std::size_t position_index,
282 KOKKOS_INLINE_FUNCTION
static void
299 KOKKOS_INLINE_FUNCTION
static double
305 static std::array<std::string_view, Self::n_var>
309 "length",
"l_max",
"a_p",
"a_max",
"a_e",
"a_go",
310 "a_fe",
"a_ao",
"phi_s",
"phi_o2",
"phi_a",
314 static std::array<std::string_view, Self::n_c>
317 return {
"glucose",
"O2",
"acetate" };
323 KOKKOS_INLINE_FUNCTION
void
329 MODEL_CONSTANT
auto a_max_dist
333 static constexpr auto ld =
l_dist;
334 static constexpr auto lm =
l_dist;
335 auto gen = random_pool.get_state();
340 random_pool.free_state(gen);
356 constexpr auto zero =
static_cast<FloatType>(0);
363 r[
i_go] = Kokkos::min(s_ox_max, nu_p /
y_x_go);
368 r[
i_ov] = Kokkos::max(s_ox_max - r[
i_go], zero);
374 r[
i_ao] = Kokkos::min(Kokkos::min(phi[
Ac], o2_res /
y_o2_ao),
375 Kokkos::max(nu_p - nu, zero) /
y_x_ao);
380 r[
i_fe] = Kokkos::min(s_res, Kokkos::max(nu_p - nu, zero) /
y_x_fe);
383 KOKKOS_ASSERT(r[
i_go] >= zero);
384 KOKKOS_ASSERT(r[
i_fe] >= zero);
385 KOKKOS_ASSERT(r[
i_ov] >= zero);
386 KOKKOS_ASSERT(r[
i_ao] >= zero);
387 KOKKOS_ASSERT(nu >= zero && nu <= nu_p *
static_cast<FloatType>(1.001));
405 const std::size_t position_index,
408 const auto c_s = GET_CLAMPED_CONCENTRATION_CAST(
FloatType,
S);
409 const auto c_o2 = GET_CLAMPED_CONCENTRATION_CAST(
FloatType,
O2);
410 const auto c_ac = GET_CLAMPED_CONCENTRATION_CAST(
FloatType,
Ac);
424 phi[
S] = phi_s_max_p * c_s / (c_s +
k_s);
425 phi[
O2] = Kokkos::min(phi_o2_max_p * c_o2 / (c_o2 +
k_o), share * c_o2);
426 phi[
Ac] = Kokkos::min(phi_ac_max_p * c_ac / (c_ac +
k_a), share * c_ac);
466 KOKKOS_INLINE_FUNCTION
void
474 ComputeSpace::array_layout,
475 Kokkos::MemoryTraits<Kokkos::MemoryTraitsFlags::Restrict>>
476 buffer_e = buffer_arr;
479 const FloatType new_current_length = current_l / 2.F;
483 for (
auto i = binf; i < bsup; ++i)
485 COPY_PROPERTY_TO(i, idx2, buffer_e);
505 auto gen = random_pool.get_state();
506 const double sigma = 0.2;
508 = Kokkos::log(
static_cast<double>(a_target)) - sigma * sigma / 2;
513 const auto gen1 = Kokkos::clamp(
514 static_cast<FloatType>(dist.draw(gen)), ap_min, a_max_i);
515 const auto gen2 = Kokkos::clamp(
516 static_cast<FloatType>(dist.draw(gen)), ap_min, a_max_i);
519 const FloatType lmax1 = local_l.draw(gen);
520 const FloatType lmax2 = local_l.draw(gen);
527 random_pool.free_state(gen);
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
Compile time elemental closure of the reactions of Models::Acetate.
Definition acetate.hpp:32
constexpr double e_surplus(double m_cmol_sub, double gamma_sub, double y_x)
Definition acetate.hpp:47
constexpr double gamma_biomass
4 + 1.8 - 1.0 - 0.6
Definition acetate.hpp:41
constexpr double m_o2
[g/mol]
Definition acetate.hpp:33
constexpr double y_o2_ox(double m_cmol_sub, double gamma_sub, double y_x)
Definition acetate.hpp:56
constexpr double m_cmol_biomass
CH1.8O0.5N0.2 [g/Cmol].
Definition acetate.hpp:36
constexpr double m_cmol_glucose
C6H12O6, 180/6 [g/Cmol].
Definition acetate.hpp:34
constexpr double m_cmol_acetate
C2H4O2, 60/2 [g/Cmol].
Definition acetate.hpp:35
constexpr double y_ac_fer(double m_cmol_sub, double gamma_sub, double y_x)
sub -> X + Ac + CO2 (+H2O) : gAc per g of substrate
Definition acetate.hpp:63
constexpr double gamma_acetate
(2*4 + 4 - 2*2)/2
Definition acetate.hpp:40
constexpr double gamma_glucose
Degree of reduction per C-mole.
Definition acetate.hpp:39
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
Represents a LogNormal (Gaussian) probability distribution.
Definition prng_extension.hpp:525
Represents a TruncatedNormal (Gaussian) probability distribution.
Definition prng_extension.hpp:354
Acetate model with explicit oxygen limitation.
Definition acetate.hpp:110
Acetate Self
Definition acetate.hpp:112
species_index
Species indices, O2 has to stay at index 1 (gas/liquid transfer)
Definition acetate.hpp:153
@ O2
Definition acetate.hpp:155
@ Ac
Definition acetate.hpp:156
@ S
Definition acetate.hpp:154
@ N_N
Definition acetate.hpp:157
MODEL_CONSTANT FloatType k_s
Monod affinity constants [kg/m^3].
Definition acetate.hpp:181
MODEL_CONSTANT FloatType phi_s_max
Definition acetate.hpp:240
MODEL_CONSTANT FloatType f_pos
One explicit step removes at most 1/f_pos of the local concentration.
Definition acetate.hpp:247
MODEL_CONSTANT auto l_dist
Definition acetate.hpp:266
std::nullopt_t Config
Definition acetate.hpp:114
MODEL_CONSTANT FloatType x_c_max
Definition acetate.hpp:245
MODEL_CONSTANT FloatType y_x_go
gX/gS
Definition acetate.hpp:189
MODEL_CONSTANT FloatType d_t_floor
Only there so that d_t = 0 does not divide by zero.
Definition acetate.hpp:249
MODEL_CONSTANT FloatType l_max_m
Definition acetate.hpp:174
MC::ParticlesContribs< Self::n_c, Self::FloatType > SelfContribs
Definition acetate.hpp:143
static std::array< std::string_view, Self::n_var > names()
Definition acetate.hpp:306
MODEL_CONSTANT FloatType a_p_min
Definition acetate.hpp:254
MODEL_CONSTANT FloatType k_a
Definition acetate.hpp:185
MODEL_CONSTANT FloatType f_o2_max
Definition acetate.hpp:236
MC::ParticlesModel< Self::n_var, Self::FloatType > SelfParticle
Definition acetate.hpp:138
static std::array< std::string_view, Self::n_c > species()
Definition acetate.hpp:315
MODEL_CONSTANT FloatType y_x_ov
overflow does not grow
Definition acetate.hpp:191
MODEL_CONSTANT FloatType l_min_m
Definition acetate.hpp:175
MODEL_CONSTANT FloatType f_ac_max
Acetate uptake capacity relative to the glucose one.
Definition acetate.hpp:238
MODEL_CONSTANT FloatType k_o
Definition acetate.hpp:184
Kokkos::Array< FloatType, N_N > uptake_rates
Definition acetate.hpp:171
MODEL_CONSTANT FloatType y_o2_ao
gO2/gAc
Definition acetate.hpp:200
MODEL_CONSTANT FloatType y_x_fe
gX/gS
Definition acetate.hpp:190
reaction_index
Reaction indices.
Definition acetate.hpp:162
@ N_R
Definition acetate.hpp:167
@ i_fe
Definition acetate.hpp:164
@ i_go
Definition acetate.hpp:163
@ i_ov
Definition acetate.hpp:165
@ i_ao
Definition acetate.hpp:166
static constexpr std::size_t n_var
Definition acetate.hpp:135
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 acetate.hpp:400
MODEL_CONSTANT FloatType a_max_m
Definition acetate.hpp:173
particle_var
Definition acetate.hpp:117
@ phi_s
Definition acetate.hpp:128
@ length
Definition acetate.hpp:118
@ a_e
Definition acetate.hpp:123
@ phi_o2
Definition acetate.hpp:129
@ a_fe
Definition acetate.hpp:125
@ phi_a
Definition acetate.hpp:130
@ l_max
Definition acetate.hpp:119
@ __COUNT__
Definition acetate.hpp:131
@ a_go
Definition acetate.hpp:124
@ a_ao
Definition acetate.hpp:126
@ a_max
Definition acetate.hpp:121
@ a_p
Definition acetate.hpp:120
Kokkos::Array< FloatType, N_R > reaction_rates
Definition acetate.hpp:170
float FloatType
Definition acetate.hpp:113
MODEL_CONSTANT FloatType lin_density
Definition acetate.hpp:178
std::true_type uniform_weight
Definition acetate.hpp:111
static KOKKOS_INLINE_FUNCTION double mass(std::size_t idx, const SelfParticle &arr)
Definition acetate.hpp:300
MODEL_CONSTANT FloatType y_o2_go
gO2/gS, 0.384
Definition acetate.hpp:195
MODEL_CONSTANT FloatType a_p_recovery
Definition acetate.hpp:260
static constexpr std::size_t n_c
Liquid species: glucose, dioxygen, acetate.
Definition acetate.hpp:141
MODEL_CONSTANT auto l_max_dist
Definition acetate.hpp:263
static constexpr std::string_view name
Definition acetate.hpp:137
MODEL_CONSTANT FloatType d_m
Definition acetate.hpp:176
static KOKKOS_INLINE_FUNCTION void init(const MC::pool_type &random_pool, std::size_t idx, const SelfParticle &arr)
Definition acetate.hpp:324
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 acetate.hpp:467
static KOKKOS_INLINE_FUNCTION reaction_rates metabolism(const uptake_rates &phi, FloatType nu_p, FloatType &nu)
Distribute the available uptake fluxes over the four reactions.
Definition acetate.hpp:352
MODEL_CONSTANT FloatType y_ac_fe
gAc/gS produced by fermentation, 0.808
Definition acetate.hpp:206
MODEL_CONSTANT FloatType y_ac_ov
gAc/gS produced by overflow. C6H12O6 -> 3 C2H4O2 balances as is, so 1
Definition acetate.hpp:211
MODEL_CONSTANT FloatType y_x_ao
gX/gAc
Definition acetate.hpp:192