117 template <
typename T>
120 const T& get()
const {
121 return *this->m_data;
128 void update(T
object)
130 this->m_data = std::make_shared<T>( std::move(
object) );
139 this->m_data = other.m_data;
142 const T& operator()()
const {
143 return *this->m_data;
147 std::shared_ptr<T> m_data;
162 template <
typename K,
typename T>
165 std::vector<K> keys()
const {
166 std::vector<K> key_vector;
167 std::transform( this->m_data.begin(), this->m_data.end(), std::back_inserter(key_vector), [](
const auto& pair) { return pair.first; });
172 template <
typename Predicate>
173 const T* find(Predicate&& predicate)
const {
174 auto iter = std::find_if( this->m_data.begin(), this->m_data.end(), std::forward<Predicate>(predicate));
175 if (iter == this->m_data.end())
178 return iter->second.get();
182 const std::shared_ptr<T> get_ptr(
const K& key)
const {
183 auto iter = this->m_data.find(key);
184 if (iter != this->m_data.end())
191 bool has(
const K& key)
const {
192 auto ptr = this->get_ptr(key);
193 return (ptr !=
nullptr);
197 void update(T
object) {
198 auto key =
object.name();
199 this->m_data[key] = std::make_shared<T>( std::move(
object) );
203 auto other_ptr = other.get_ptr(key);
205 this->m_data[key] = other.get_ptr(key);
207 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
210 const T& operator()(
const K& key)
const {
211 return this->get(key);
214 const T& get(
const K& key)
const {
215 return *this->m_data.at(key);
218 T& get(
const K& key) {
219 return *this->m_data.at(key);
223 std::vector<std::reference_wrapper<const T>> operator()()
const {
224 std::vector<std::reference_wrapper<const T>> as_vector;
225 for (
const auto& [_, elm_ptr] : this->m_data) {
227 as_vector.push_back( std::cref(*elm_ptr));
233 std::vector<std::reference_wrapper<T>> operator()() {
234 std::vector<std::reference_wrapper<T>> as_vector;
235 for (
const auto& [_, elm_ptr] : this->m_data) {
237 as_vector.push_back( std::ref(*elm_ptr));
244 if (this->m_data.size() != other.m_data.size())
247 for (
const auto& [key1, ptr1] : this->m_data) {
248 const auto& ptr2 = other.get_ptr(key1);
252 if (!(*ptr1 == *ptr2))
259 std::size_t size()
const {
260 return this->m_data.size();
263 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
264 return this->m_data.begin();
267 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
268 return this->m_data.end();
274 T value_object = T::serializationTestObject();
275 K key = value_object.name();
276 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
282 std::unordered_map<K, std::shared_ptr<T>> m_data;
286 std::optional<double> prod_target;
287 std::optional<double> inj_limit;
296 return this->prod_target == rhs.prod_target
297 && this->inj_limit == rhs.inj_limit;
300 template<
class Serializer>
303 serializer(prod_target);
304 serializer(inj_limit);
310 ScheduleState(
const time_point& start_time,
const time_point& end_time);
315 time_point start_time()
const;
316 time_point end_time()
const;
322 std::size_t sim_step()
const;
326 std::size_t month_num()
const;
327 std::size_t year_num()
const;
328 bool first_in_month()
const;
329 bool first_in_year()
const;
334 void update_tuning(
Tuning tuning);
336 const Tuning& tuning()
const;
337 double max_next_tstep(
const bool enableTUNING =
false)
const;
339 void init_nupcol(
Nupcol nupcol);
340 void update_nupcol(
int nupcol);
347 void update_events(
Events events);
349 const Events& events()
const;
355 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
356 std::vector<DeckKeyword>& geo_keywords();
357 const std::vector<DeckKeyword>& geo_keywords()
const;
363 WellProducerCMode whistctl()
const;
364 void update_whistctl(WellProducerCMode whistctl);
366 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
367 void update_date(
const time_point& prev_time);
368 void updateSAVE(
bool save);
371 const std::optional<double>& sumthin()
const;
372 void update_sumthin(
double sumthin);
374 bool rptonly()
const;
375 void rptonly(
const bool only);
377 bool has_gpmaint()
const;
379 bool hasAnalyticalAquifers()
const
381 return ! this->aqufluxs.empty();
386 ptr_member<GConSale> gconsale;
387 ptr_member<GConSump> gconsump;
388 ptr_member<GroupEconProductionLimits> gecon;
389 ptr_member<GuideRateConfig> guide_rate;
391 ptr_member<WListManager> wlist_manager;
392 ptr_member<NameOrder> well_order;
393 ptr_member<GroupOrder> group_order;
395 ptr_member<Action::Actions> actions;
396 ptr_member<UDQConfig> udq;
397 ptr_member<UDQActive> udq_active;
399 ptr_member<PAvg> pavg;
400 ptr_member<WellTestConfig> wtest_config;
401 ptr_member<GasLiftOpt> glo;
402 ptr_member<Network::ExtNetwork> network;
403 ptr_member<Network::Balance> network_balance;
404 ptr_member<ReservoirCoupling::CouplingInfo> rescoup;
406 ptr_member<RPTConfig> rpt_config;
407 ptr_member<RFTConfig> rft_config;
408 ptr_member<RSTConfig> rst_config;
410 ptr_member<BHPDefaults> bhp_defaults;
411 ptr_member<Source> source;
413 template <
typename T>
414 ptr_member<T>& get() {
415 return const_cast<ptr_member<T>&
>(std::as_const(*this).template get<T>());
418 template <
typename T>
419 const ptr_member<T>& get()
const
421 struct always_false1 : std::false_type {};
423 if constexpr ( std::is_same_v<T, PAvg> )
425 else if constexpr ( std::is_same_v<T, WellTestConfig> )
426 return this->wtest_config;
427 else if constexpr ( std::is_same_v<T, GConSale> )
428 return this->gconsale;
429 else if constexpr ( std::is_same_v<T, GConSump> )
430 return this->gconsump;
431 else if constexpr ( std::is_same_v<T, GroupEconProductionLimits> )
433 else if constexpr ( std::is_same_v<T, WListManager> )
434 return this->wlist_manager;
435 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
436 return this->network;
437 else if constexpr ( std::is_same_v<T, Network::Balance> )
438 return this->network_balance;
439 else if constexpr ( std::is_same_v<T, RPTConfig> )
440 return this->rpt_config;
441 else if constexpr ( std::is_same_v<T, Action::Actions> )
442 return this->actions;
443 else if constexpr ( std::is_same_v<T, UDQActive> )
444 return this->udq_active;
445 else if constexpr ( std::is_same_v<T, NameOrder> )
446 return this->well_order;
447 else if constexpr ( std::is_same_v<T, GroupOrder> )
448 return this->group_order;
449 else if constexpr ( std::is_same_v<T, UDQConfig> )
451 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
453 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
454 return this->guide_rate;
455 else if constexpr ( std::is_same_v<T, RFTConfig> )
456 return this->rft_config;
457 else if constexpr ( std::is_same_v<T, RSTConfig> )
458 return this->rst_config;
459 else if constexpr ( std::is_same_v<T, BHPDefaults> )
460 return this->bhp_defaults;
461 else if constexpr ( std::is_same_v<T, Source> )
465 static_assert(always_false1::value,
"Template type <T> not supported in get()");
469 template <
typename K,
typename T>
470 map_member<K,T>& get_map()
472 struct always_false2 : std::false_type {};
473 if constexpr ( std::is_same_v<T, VFPProdTable> )
474 return this->vfpprod;
475 else if constexpr ( std::is_same_v<T, VFPInjTable> )
477 else if constexpr ( std::is_same_v<T, Group> )
479 else if constexpr ( std::is_same_v<T, Well> )
482 static_assert(always_false2::value,
"Template type <K,T> not supported in get_map()");
485 map_member<int, VFPProdTable> vfpprod;
486 map_member<int, VFPInjTable> vfpinj;
487 map_member<std::string, Group> groups;
488 map_member<std::string, Well> wells;
490 std::unordered_map<int, SingleAquiferFlux> aqufluxs;
492 std::unordered_map<std::string, double> target_wellpi;
493 std::optional<NextStep> next_tstep;
496 using WellPIMapType = std::unordered_map<std::string, double>;
497 template<
class Serializer>
498 void serializeOp(Serializer& serializer) {
499 serializer(m_start_time);
500 serializer(m_end_time);
501 serializer(m_sim_step);
502 serializer(m_month_num);
503 serializer(m_year_num);
504 serializer(m_first_in_year);
505 serializer(m_first_in_month);
506 serializer(m_save_step);
507 serializer(m_sumthin);
508 serializer(this->m_rptonly);
509 serializer(this->next_tstep);
510 serializer(m_tuning);
511 serializer(m_nupcol);
512 serializer(m_oilvap);
513 serializer(m_events);
514 serializer(m_wellgroup_events);
515 serializer(m_geo_keywords);
516 serializer(m_message_limits);
517 serializer(m_whistctl_mode);
518 serializer(target_wellpi);
519 serializer(aqufluxs);
525 time_point m_start_time;
526 std::optional<time_point> m_end_time;
528 std::size_t m_sim_step = 0;
529 std::size_t m_month_num = 0;
530 std::size_t m_year_num = 0;
531 bool m_first_in_month;
532 bool m_first_in_year;
533 bool m_save_step{
false};
537 OilVaporizationProperties m_oilvap;
539 WellGroupEvents m_wellgroup_events;
540 std::vector<DeckKeyword> m_geo_keywords;
541 MessageLimits m_message_limits;
542 WellProducerCMode m_whistctl_mode = WellProducerCMode::CMODE_UNDEFINED;
543 std::optional<double> m_sumthin;
544 bool m_rptonly{
false};