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 linear(double flow,
113 double df,
114 double concentration,
115 std::size_t species_index,
116 std::size_t input_position,
117 std::optional<std::size_t> _ouput_position
118 = std::nullopt,
119 bool set_output = true);
120 };
121
123 {
124 private:
125 std::optional<std::vector<FeedDescriptor>> m_liquid;
126 std::optional<std::vector<FeedDescriptor>> m_gas;
127
128 public:
129 void add_liquid(FeedDescriptor&& fd);
130
131 void add_gas(FeedDescriptor&& fd);
132
133 void add_feed(FeedDescriptor&& fd, Phase phase);
134
135 [[nodiscard]] std::size_t n_liquid_flow() const noexcept;
136 [[nodiscard]] std::size_t n_gas_flow() const noexcept;
137
138 // [[nodiscard]] auto
139 // liquid_feeds() const
140 // {
141 // if (m_liquid)
142 // {
143 // return std::ranges::subrange(m_liquid->cbegin(), m_liquid->cend());
144 // }
145 // return std::ranges::subrange(
146 // std::vector<FeedDescriptor>::const_iterator(),
147 // std::vector<FeedDescriptor>::const_iterator());
148 // }
149
150 // [[nodiscard]] auto
151 // gas_feeds() const
152 // {
153 // if (m_gas)
154 // {
155 // return std::ranges::subrange(m_gas->cbegin(), m_gas->cend());
156 // }
157 // return std::ranges::subrange(
158 // std::vector<FeedDescriptor>::const_iterator(),
159 // std::vector<FeedDescriptor>::const_iterator());
160 // }
161 //
162
163 [[nodiscard]] auto
165 {
166 if (m_liquid)
167 {
168 return *m_liquid;
169 }
170 return std::vector<FeedDescriptor>();
171 }
172
173 [[nodiscard]] auto
174 gas_feeds() const
175 {
176 if (m_gas)
177 {
178 return *m_gas;
179 }
180 return std::vector<FeedDescriptor>();
181 }
182
183 auto
185 {
186 if (m_liquid)
187 {
188 return std::ranges::subrange(m_liquid->begin(), m_liquid->end());
189 }
190 return std::ranges::subrange(std::vector<FeedDescriptor>::iterator(),
191 std::vector<FeedDescriptor>::iterator());
192 }
193
194 auto
196 {
197 if (m_gas)
198 {
199 return std::ranges::subrange(m_gas->begin(), m_gas->end());
200 }
201 return std::ranges::subrange(std::vector<FeedDescriptor>::iterator(),
202 std::vector<FeedDescriptor>::iterator());
203 }
204
205 static SimulationFeed empty() noexcept;
206 };
207
208} // namespace Simulation::Feed
209
210#endif
Definition feed_descriptor.hpp:123
std::size_t n_liquid_flow() const noexcept
Definition feed_descriptor.cpp:169
auto liquid_feeds() const
Definition feed_descriptor.hpp:164
std::optional< std::vector< FeedDescriptor > > m_gas
Definition feed_descriptor.hpp:126
std::size_t n_gas_flow() const noexcept
Definition feed_descriptor.cpp:174
static SimulationFeed empty() noexcept
Definition feed_descriptor.cpp:180
auto liquid_feeds()
Definition feed_descriptor.hpp:184
auto gas_feeds() const
Definition feed_descriptor.hpp:174
void add_liquid(FeedDescriptor &&fd)
Definition feed_descriptor.cpp:157
void add_feed(FeedDescriptor &&fd, Phase phase)
Definition feed_descriptor.cpp:142
void add_gas(FeedDescriptor &&fd)
Definition feed_descriptor.cpp:163
std::optional< std::vector< FeedDescriptor > > m_liquid
Definition feed_descriptor.hpp:125
auto gas_feeds()
Definition feed_descriptor.hpp:195
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:91
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:100
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:124
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:106
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