BioCMAMC-ST
feed_descriptor.hpp
1#ifndef __SIMULATION_FEED_DESCRIPTOR_HPP__
2#define __SIMULATION_FEED_DESCRIPTOR_HPP__
3
4#include <cstddef>
5#include <cstdint>
6#include <optional>
7#include <ranges>
8#include <variant>
9#include <vector>
10
11enum class Phase
12{
13 Liquid,
14 Gas
15};
16
17enum class FeedType : std::uint8_t
18{
19 Constant,
20 Exponential,
21 Linear,
22 // DelayedConstant,
23 // Step,
24 // Pulse,
25 // Custom
26};
27
28template <typename T>
29constexpr decltype(auto)
30move_allow_trivial(T&& t) noexcept
31{
32 return std::move(t); // NOLINT
33}
34
36{
37
38 struct Constant
39 {
40 };
41
43 {
44 double f0;
45 double alpha;
46 };
47
48 struct Linear
49 {
50 double f0;
51 double df;
52 };
53
54 // struct DelayedConstant
55 // {
56 // double t_init;
57 // double t_end;
58 // double stored_value;
59 // };
60
61 // struct Step
62 // {
63 // double t_init = 0.;
64 // };
65
66 // struct Pulse
67 // {
68 // double t_init;
69 // double t_end;
70 // double frequency;
71 // double stored_value;
72 // };
73
74 // struct Custom
75 // {
76 // };
77
78 // using FeedTypeVariant
79 // = std::variant<Constant, Step, Pulse, Custom, DelayedConstant>;
80
81 using FeedTypeVariant = std::variant<Constant, Linear, Exponential>;
82
83 FeedType get_type(const FeedTypeVariant& v);
84
85 struct FeedValue
86 {
88 std::size_t species_index;
89 };
90
92 {
93 double flow{};
94 std::vector<FeedValue> values;
95 std::size_t input_position{};
96 std::optional<std::size_t> output_position;
98 bool use_relative_time = true;
99 void update(double t, double d_t) noexcept;
100 };
101
103 {
104 static FeedDescriptor constant(double flow,
105 double concentration,
106 std::size_t species_index,
107 std::size_t input_position,
108 std::optional<std::size_t> _ouput_position
109 = std::nullopt,
110 bool set_output = true);
111
112 static FeedDescriptor sink(double flow, std::size_t _ouput_position);
113
114 static FeedDescriptor linear(double flow,
115 double df,
116 double concentration,
117 std::size_t species_index,
118 std::size_t input_position,
119 std::optional<std::size_t> _ouput_position
120 = std::nullopt,
121 bool set_output = true);
122
123 static std::vector<FeedDescriptor> gas_feed(double concentration,
124 std::size_t species_index,
125 std::span<std::size_t> inlet_i,
126 std::span<double> inlet_f,
127 std::span<std::size_t> outlet_i,
128 std::span<double> outlet_f,
129 double tol = 1e-10);
130 };
131
133 {
134 private:
135 std::optional<std::vector<FeedDescriptor>> m_liquid;
136 std::optional<std::vector<FeedDescriptor>> m_gas;
137
138 public:
139 void add_liquid(FeedDescriptor&& fd);
140
141 void add_gas(FeedDescriptor&& fd);
142
143 void add_feed(FeedDescriptor&& fd, Phase phase);
144
145 [[nodiscard]] std::size_t n_liquid_flow() const noexcept;
146 [[nodiscard]] std::size_t n_gas_flow() const noexcept;
147
148 // [[nodiscard]] auto
149 // liquid_feeds() const
150 // {
151 // if (m_liquid)
152 // {
153 // return std::ranges::subrange(m_liquid->cbegin(), m_liquid->cend());
154 // }
155 // return std::ranges::subrange(
156 // std::vector<FeedDescriptor>::const_iterator(),
157 // std::vector<FeedDescriptor>::const_iterator());
158 // }
159
160 // [[nodiscard]] auto
161 // gas_feeds() const
162 // {
163 // if (m_gas)
164 // {
165 // return std::ranges::subrange(m_gas->cbegin(), m_gas->cend());
166 // }
167 // return std::ranges::subrange(
168 // std::vector<FeedDescriptor>::const_iterator(),
169 // std::vector<FeedDescriptor>::const_iterator());
170 // }
171 //
172
173 [[nodiscard]] auto
175 {
176 if (m_liquid)
177 {
178 return *m_liquid;
179 }
180 return std::vector<FeedDescriptor>();
181 }
182
183 [[nodiscard]] auto
184 gas_feeds() const
185 {
186 if (m_gas)
187 {
188 return *m_gas;
189 }
190 return std::vector<FeedDescriptor>();
191 }
192
193 auto
195 {
196 if (m_liquid)
197 {
198 return std::ranges::subrange(m_liquid->begin(), m_liquid->end());
199 }
200 return std::ranges::subrange(std::vector<FeedDescriptor>::iterator(),
201 std::vector<FeedDescriptor>::iterator());
202 }
203
204 auto
206 {
207 if (m_gas)
208 {
209 return std::ranges::subrange(m_gas->begin(), m_gas->end());
210 }
211 return std::ranges::subrange(std::vector<FeedDescriptor>::iterator(),
212 std::vector<FeedDescriptor>::iterator());
213 }
214
215 static SimulationFeed empty() noexcept;
216 };
217
218} // namespace Simulation::Feed
219
220#endif
Definition feed_descriptor.hpp:133
std::size_t n_liquid_flow() const noexcept
Definition feed_descriptor.cpp:237
auto liquid_feeds() const
Definition feed_descriptor.hpp:174
std::optional< std::vector< FeedDescriptor > > m_gas
Definition feed_descriptor.hpp:136
std::size_t n_gas_flow() const noexcept
Definition feed_descriptor.cpp:242
static SimulationFeed empty() noexcept
Definition feed_descriptor.cpp:248
auto liquid_feeds()
Definition feed_descriptor.hpp:194
auto gas_feeds() const
Definition feed_descriptor.hpp:184
void add_liquid(FeedDescriptor &&fd)
Definition feed_descriptor.cpp:225
void add_feed(FeedDescriptor &&fd, Phase phase)
Definition feed_descriptor.cpp:210
void add_gas(FeedDescriptor &&fd)
Definition feed_descriptor.cpp:231
std::optional< std::vector< FeedDescriptor > > m_liquid
Definition feed_descriptor.hpp:135
auto gas_feeds()
Definition feed_descriptor.hpp:205
Definition feed_descriptor.hpp:36
std::variant< Constant, Linear, Exponential > FeedTypeVariant
Definition feed_descriptor.hpp:81
FeedType get_type(const FeedTypeVariant &v)
Definition feed_descriptor.cpp:93
Definition feed_descriptor.hpp:39
Definition feed_descriptor.hpp:43
double alpha
Definition feed_descriptor.hpp:45
double f0
Definition feed_descriptor.hpp:44
Definition feed_descriptor.hpp:92
std::size_t input_position
Definition feed_descriptor.hpp:95
FeedTypeVariant extra
Definition feed_descriptor.hpp:97
bool use_relative_time
Definition feed_descriptor.hpp:98
std::vector< FeedValue > values
Definition feed_descriptor.hpp:94
void update(double t, double d_t) noexcept
Definition feed_descriptor.cpp:102
std::optional< std::size_t > output_position
Definition feed_descriptor.hpp:96
double flow
Definition feed_descriptor.hpp:93
Definition feed_descriptor.hpp:103
static FeedDescriptor linear(double flow, double df, double concentration, std::size_t species_index, std::size_t input_position, std::optional< std::size_t > _ouput_position=std::nullopt, bool set_output=true)
Definition feed_descriptor.cpp:143
static std::vector< FeedDescriptor > gas_feed(double concentration, std::size_t species_index, std::span< std::size_t > inlet_i, std::span< double > inlet_f, std::span< std::size_t > outlet_i, std::span< double > outlet_f, double tol=1e-10)
Definition feed_descriptor.cpp:161
static FeedDescriptor constant(double flow, double concentration, std::size_t species_index, std::size_t input_position, std::optional< std::size_t > _ouput_position=std::nullopt, bool set_output=true)
Definition feed_descriptor.cpp:108
static FeedDescriptor sink(double flow, std::size_t _ouput_position)
Definition feed_descriptor.cpp:126
Definition feed_descriptor.hpp:86
double concentration
Definition feed_descriptor.hpp:87
std::size_t species_index
Definition feed_descriptor.hpp:88
Definition feed_descriptor.hpp:49
double f0
Definition feed_descriptor.hpp:50
double df
Definition feed_descriptor.hpp:51
Definition mixture.hpp:10