114 template <
typename T>
117 const T& get()
const {
118 return *this->m_data;
125 void update(T
object)
127 this->m_data = std::make_shared<T>( std::move(
object) );
136 this->m_data = other.m_data;
139 const T& operator()()
const {
140 return *this->m_data;
144 std::shared_ptr<T> m_data;
159 template <
typename K,
typename T>
162 std::vector<K> keys()
const {
163 std::vector<K> key_vector;
164 std::transform( this->m_data.begin(), this->m_data.end(), std::back_inserter(key_vector), [](
const auto& pair) { return pair.first; });
169 template <
typename Predicate>
170 const T* find(Predicate&& predicate)
const {
171 auto iter = std::find_if( this->m_data.begin(), this->m_data.end(), std::forward<Predicate>(predicate));
172 if (iter == this->m_data.end())
175 return iter->second.get();
179 const std::shared_ptr<T> get_ptr(
const K& key)
const {
180 auto iter = this->m_data.find(key);
181 if (iter != this->m_data.end())
188 bool has(
const K& key)
const {
189 auto ptr = this->get_ptr(key);
190 return (ptr !=
nullptr);
194 void update(T
object) {
195 auto key =
object.name();
196 this->m_data[key] = std::make_shared<T>( std::move(
object) );
200 auto other_ptr = other.get_ptr(key);
202 this->m_data[key] = other.get_ptr(key);
204 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
207 const T& operator()(
const K& key)
const {
208 return this->get(key);
211 const T& get(
const K& key)
const {
212 return *this->m_data.at(key);
215 T& get(
const K& key) {
216 return *this->m_data.at(key);
220 std::vector<std::reference_wrapper<const T>> operator()()
const {
221 std::vector<std::reference_wrapper<const T>> as_vector;
222 for (
const auto& [_, elm_ptr] : this->m_data) {
224 as_vector.push_back( std::cref(*elm_ptr));
230 std::vector<std::reference_wrapper<T>> operator()() {
231 std::vector<std::reference_wrapper<T>> as_vector;
232 for (
const auto& [_, elm_ptr] : this->m_data) {
234 as_vector.push_back( std::ref(*elm_ptr));
241 if (this->m_data.size() != other.m_data.size())
244 for (
const auto& [key1, ptr1] : this->m_data) {
245 const auto& ptr2 = other.get_ptr(key1);
249 if (!(*ptr1 == *ptr2))
256 std::size_t size()
const {
257 return this->m_data.size();
260 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
261 return this->m_data.begin();
264 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
265 return this->m_data.end();
271 T value_object = T::serializationTestObject();
272 K key = value_object.name();
273 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
279 std::unordered_map<K, std::shared_ptr<T>> m_data;
283 std::optional<double> prod_target;
284 std::optional<double> inj_limit;
293 return this->prod_target == rhs.prod_target
294 && this->inj_limit == rhs.inj_limit;
297 template<
class Serializer>
300 serializer(prod_target);
301 serializer(inj_limit);
307 ScheduleState(
const time_point& start_time,
const time_point& end_time);
312 time_point start_time()
const;
313 time_point end_time()
const;
319 std::size_t sim_step()
const;
323 std::size_t month_num()
const;
324 std::size_t year_num()
const;
325 bool first_in_month()
const;
326 bool first_in_year()
const;
331 void update_tuning(
Tuning tuning);
333 const Tuning& tuning()
const;
334 double max_next_tstep(
const bool enableTUNING =
false)
const;
336 void init_nupcol(
Nupcol nupcol);
337 void update_nupcol(
int nupcol);
344 void update_events(
Events events);
346 const Events& events()
const;
352 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
353 std::vector<DeckKeyword>& geo_keywords();
354 const std::vector<DeckKeyword>& geo_keywords()
const;
360 WellProducerCMode whistctl()
const;
361 void update_whistctl(WellProducerCMode whistctl);
363 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
364 void update_date(
const time_point& prev_time);
365 void updateSAVE(
bool save);
368 const std::optional<double>& sumthin()
const;
369 void update_sumthin(
double sumthin);
371 bool rptonly()
const;
372 void rptonly(
const bool only);
374 bool has_gpmaint()
const;
376 bool hasAnalyticalAquifers()
const
378 return ! this->aqufluxs.empty();
383 ptr_member<GConSale> gconsale;
384 ptr_member<GConSump> gconsump;
385 ptr_member<GroupEconProductionLimits> gecon;
386 ptr_member<GuideRateConfig> guide_rate;
388 ptr_member<WListManager> wlist_manager;
389 ptr_member<NameOrder> well_order;
390 ptr_member<GroupOrder> group_order;
392 ptr_member<Action::Actions> actions;
393 ptr_member<UDQConfig> udq;
394 ptr_member<UDQActive> udq_active;
396 ptr_member<PAvg> pavg;
397 ptr_member<WellTestConfig> wtest_config;
398 ptr_member<GasLiftOpt> glo;
399 ptr_member<Network::ExtNetwork> network;
400 ptr_member<Network::Balance> network_balance;
402 ptr_member<RPTConfig> rpt_config;
403 ptr_member<RFTConfig> rft_config;
404 ptr_member<RSTConfig> rst_config;
406 ptr_member<BHPDefaults> bhp_defaults;
407 ptr_member<Source> source;
409 template <
typename T>
410 ptr_member<T>& get() {
411 return const_cast<ptr_member<T>&
>(std::as_const(*this).template get<T>());
414 template <
typename T>
415 const ptr_member<T>& get()
const
417 struct always_false1 : std::false_type {};
419 if constexpr ( std::is_same_v<T, PAvg> )
421 else if constexpr ( std::is_same_v<T, WellTestConfig> )
422 return this->wtest_config;
423 else if constexpr ( std::is_same_v<T, GConSale> )
424 return this->gconsale;
425 else if constexpr ( std::is_same_v<T, GConSump> )
426 return this->gconsump;
427 else if constexpr ( std::is_same_v<T, GroupEconProductionLimits> )
429 else if constexpr ( std::is_same_v<T, WListManager> )
430 return this->wlist_manager;
431 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
432 return this->network;
433 else if constexpr ( std::is_same_v<T, Network::Balance> )
434 return this->network_balance;
435 else if constexpr ( std::is_same_v<T, RPTConfig> )
436 return this->rpt_config;
437 else if constexpr ( std::is_same_v<T, Action::Actions> )
438 return this->actions;
439 else if constexpr ( std::is_same_v<T, UDQActive> )
440 return this->udq_active;
441 else if constexpr ( std::is_same_v<T, NameOrder> )
442 return this->well_order;
443 else if constexpr ( std::is_same_v<T, GroupOrder> )
444 return this->group_order;
445 else if constexpr ( std::is_same_v<T, UDQConfig> )
447 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
449 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
450 return this->guide_rate;
451 else if constexpr ( std::is_same_v<T, RFTConfig> )
452 return this->rft_config;
453 else if constexpr ( std::is_same_v<T, RSTConfig> )
454 return this->rst_config;
455 else if constexpr ( std::is_same_v<T, BHPDefaults> )
456 return this->bhp_defaults;
457 else if constexpr ( std::is_same_v<T, Source> )
461 static_assert(always_false1::value,
"Template type <T> not supported in get()");
465 template <
typename K,
typename T>
466 map_member<K,T>& get_map()
468 struct always_false2 : std::false_type {};
469 if constexpr ( std::is_same_v<T, VFPProdTable> )
470 return this->vfpprod;
471 else if constexpr ( std::is_same_v<T, VFPInjTable> )
473 else if constexpr ( std::is_same_v<T, Group> )
475 else if constexpr ( std::is_same_v<T, Well> )
478 static_assert(always_false2::value,
"Template type <K,T> not supported in get_map()");
481 map_member<int, VFPProdTable> vfpprod;
482 map_member<int, VFPInjTable> vfpinj;
483 map_member<std::string, Group> groups;
484 map_member<std::string, Well> wells;
486 std::unordered_map<int, SingleAquiferFlux> aqufluxs;
488 std::unordered_map<std::string, double> target_wellpi;
489 std::optional<NextStep> next_tstep;
492 using WellPIMapType = std::unordered_map<std::string, double>;
493 template<
class Serializer>
494 void serializeOp(Serializer& serializer) {
495 serializer(m_start_time);
496 serializer(m_end_time);
497 serializer(m_sim_step);
498 serializer(m_month_num);
499 serializer(m_year_num);
500 serializer(m_first_in_year);
501 serializer(m_first_in_month);
502 serializer(m_save_step);
503 serializer(m_sumthin);
504 serializer(this->m_rptonly);
505 serializer(this->next_tstep);
506 serializer(m_tuning);
507 serializer(m_nupcol);
508 serializer(m_oilvap);
509 serializer(m_events);
510 serializer(m_wellgroup_events);
511 serializer(m_geo_keywords);
512 serializer(m_message_limits);
513 serializer(m_whistctl_mode);
514 serializer(target_wellpi);
515 serializer(aqufluxs);
521 time_point m_start_time;
522 std::optional<time_point> m_end_time;
524 std::size_t m_sim_step = 0;
525 std::size_t m_month_num = 0;
526 std::size_t m_year_num = 0;
527 bool m_first_in_month;
528 bool m_first_in_year;
529 bool m_save_step{
false};
533 OilVaporizationProperties m_oilvap;
535 WellGroupEvents m_wellgroup_events;
536 std::vector<DeckKeyword> m_geo_keywords;
537 MessageLimits m_message_limits;
538 WellProducerCMode m_whistctl_mode = WellProducerCMode::CMODE_UNDEFINED;
539 std::optional<double> m_sumthin;
540 bool m_rptonly{
false};