101 class ScheduleState {
124 template <
typename T>
127 const T& get()
const {
128 return *this->m_data;
135 void update(T
object)
137 this->m_data = std::make_shared<T>( std::move(
object) );
146 this->m_data = other.m_data;
149 const T& operator()()
const {
150 return *this->m_data;
153 template<
class Serializer>
160 std::shared_ptr<T> m_data;
175 template <
typename K,
typename T>
178 std::vector<K> keys()
const {
179 std::vector<K> key_vector;
180 std::transform( this->m_data.begin(), this->m_data.end(), std::back_inserter(key_vector), [](
const auto& pair) { return pair.first; });
185 template <
typename Predicate>
186 const T* find(Predicate&& predicate)
const {
187 auto iter = std::find_if( this->m_data.begin(), this->m_data.end(), std::forward<Predicate>(predicate));
188 if (iter == this->m_data.end())
191 return iter->second.get();
195 const std::shared_ptr<T> get_ptr(
const K& key)
const {
196 auto iter = this->m_data.find(key);
197 if (iter != this->m_data.end())
204 bool has(
const K& key)
const {
205 auto ptr = this->get_ptr(key);
206 return (ptr !=
nullptr);
209 void update(
const K& key, std::shared_ptr<T> value) {
210 this->m_data.insert_or_assign(key, std::move(value));
213 void update(T
object) {
214 auto key =
object.name();
215 this->m_data[key] = std::make_shared<T>( std::move(
object) );
219 auto other_ptr = other.get_ptr(key);
221 this->m_data[key] = other.get_ptr(key);
223 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
226 const T& operator()(
const K& key)
const {
227 return this->get(key);
230 const T& get(
const K& key)
const {
231 return *this->m_data.at(key);
234 T& get(
const K& key) {
235 return *this->m_data.at(key);
239 std::vector<std::reference_wrapper<const T>> operator()()
const {
240 std::vector<std::reference_wrapper<const T>> as_vector;
241 for (
const auto& [_, elm_ptr] : this->m_data) {
243 as_vector.push_back( std::cref(*elm_ptr));
249 std::vector<std::reference_wrapper<T>> operator()() {
250 std::vector<std::reference_wrapper<T>> as_vector;
251 for (
const auto& [_, elm_ptr] : this->m_data) {
253 as_vector.push_back( std::ref(*elm_ptr));
260 if (this->m_data.size() != other.m_data.size())
263 for (
const auto& [key1, ptr1] : this->m_data) {
264 const auto& ptr2 = other.get_ptr(key1);
268 if (!(*ptr1 == *ptr2))
275 std::size_t size()
const {
276 return this->m_data.size();
279 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
280 return this->m_data.begin();
283 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
284 return this->m_data.end();
290 T value_object = T::serializationTestObject();
291 K key = value_object.name();
292 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
296 template<
class Serializer>
303 std::unordered_map<K, std::shared_ptr<T>> m_data;
307 std::optional<double> prod_target;
308 std::optional<double> inj_limit;
317 return this->prod_target == rhs.prod_target
318 && this->inj_limit == rhs.inj_limit;
321 template<
class Serializer>
324 serializer(prod_target);
325 serializer(inj_limit);
329 ScheduleState() =
default;
330 explicit ScheduleState(
const time_point& start_time);
331 ScheduleState(
const time_point& start_time,
const time_point& end_time);
332 ScheduleState(
const ScheduleState& src,
const time_point& start_time);
333 ScheduleState(
const ScheduleState& src,
const time_point& start_time,
const time_point& end_time);
336 time_point start_time()
const;
337 time_point end_time()
const;
338 ScheduleState next(
const time_point& next_start);
343 std::size_t sim_step()
const;
347 std::size_t month_num()
const;
348 std::size_t year_num()
const;
349 bool first_in_month()
const;
350 bool first_in_year()
const;
351 bool well_group_contains_lgr(
const Group& grp,
const std::string& lgr_tag)
const;
352 bool group_contains_lgr(
const Group& grp,
const std::string& lgr_tag)
const;
354 std::size_t num_lgr_well_in_group(
const Group& grp,
const std::string& lgr_tag)
const;
355 std::size_t num_lgr_groups_in_group(
const Group& grp,
const std::string& lgr_tag)
const;
358 bool operator==(
const ScheduleState& other)
const;
359 static ScheduleState serializationTestObject();
361 void update_tuning(
Tuning tuning);
363 const Tuning& tuning()
const;
364 double max_next_tstep(
const bool enableTUNING =
false)
const;
366 void init_nupcol(
Nupcol nupcol);
367 void update_nupcol(
int nupcol);
374 void update_events(
Events events);
376 const Events& events()
const;
382 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
383 std::vector<DeckKeyword>& geo_keywords();
384 const std::vector<DeckKeyword>& geo_keywords()
const;
390 WellProducerCMode whistctl()
const;
391 void update_whistctl(WellProducerCMode whistctl);
393 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
394 void update_date(
const time_point& prev_time);
395 void updateSAVE(
bool save);
398 const std::optional<double>& sumthin()
const;
399 void update_sumthin(
double sumthin);
401 bool rptonly()
const;
402 void rptonly(
const bool only);
404 bool has_gpmaint()
const;
406 bool hasAnalyticalAquifers()
const
408 return ! this->aqufluxs.empty();
413 ptr_member<GConSale> gconsale;
414 ptr_member<GConSump> gconsump;
415 ptr_member<GSatProd> gsatprod;
416 ptr_member<GroupEconProductionLimits> gecon;
417 ptr_member<GuideRateConfig> guide_rate;
419 ptr_member<WListManager> wlist_manager;
420 ptr_member<NameOrder> well_order;
421 ptr_member<GroupOrder> group_order;
423 ptr_member<Action::Actions> actions;
424 ptr_member<UDQConfig> udq;
425 ptr_member<UDQActive> udq_active;
427 ptr_member<PAvg> pavg;
428 ptr_member<WellTestConfig> wtest_config;
429 ptr_member<GasLiftOpt> glo;
430 ptr_member<Network::ExtNetwork> network;
431 ptr_member<Network::Balance> network_balance;
432 ptr_member<ReservoirCoupling::CouplingInfo> rescoup;
434 ptr_member<RPTConfig> rpt_config;
435 ptr_member<RFTConfig> rft_config;
436 ptr_member<RSTConfig> rst_config;
438 ptr_member<BHPDefaults> bhp_defaults;
439 ptr_member<Source> source;
440 ptr_member<WCYCLE> wcycle;
442 template <
typename T>
443 ptr_member<T>&
get() {
444 return const_cast<ptr_member<T>&
>(std::as_const(*this).template
get<T>());
447 template <
typename T>
448 const ptr_member<T>& get()
const
450 struct always_false1 : std::false_type {};
452 if constexpr ( std::is_same_v<T, PAvg> )
454 else if constexpr ( std::is_same_v<T, WellTestConfig> )
455 return this->wtest_config;
456 else if constexpr ( std::is_same_v<T, GConSale> )
457 return this->gconsale;
458 else if constexpr ( std::is_same_v<T, GConSump> )
459 return this->gconsump;
460 else if constexpr ( std::is_same_v<T, GSatProd> )
461 return this->gsatprod;
462 else if constexpr ( std::is_same_v<T, GroupEconProductionLimits> )
464 else if constexpr ( std::is_same_v<T, WListManager> )
465 return this->wlist_manager;
466 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
467 return this->network;
468 else if constexpr ( std::is_same_v<T, Network::Balance> )
469 return this->network_balance;
470 else if constexpr ( std::is_same_v<T, ReservoirCoupling::CouplingInfo> )
471 return this->rescoup;
472 else if constexpr ( std::is_same_v<T, RPTConfig> )
473 return this->rpt_config;
474 else if constexpr ( std::is_same_v<T, Action::Actions> )
475 return this->actions;
476 else if constexpr ( std::is_same_v<T, UDQActive> )
477 return this->udq_active;
478 else if constexpr ( std::is_same_v<T, NameOrder> )
479 return this->well_order;
480 else if constexpr ( std::is_same_v<T, GroupOrder> )
481 return this->group_order;
482 else if constexpr ( std::is_same_v<T, UDQConfig> )
484 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
486 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
487 return this->guide_rate;
488 else if constexpr ( std::is_same_v<T, RFTConfig> )
489 return this->rft_config;
490 else if constexpr ( std::is_same_v<T, RSTConfig> )
491 return this->rst_config;
492 else if constexpr ( std::is_same_v<T, BHPDefaults> )
493 return this->bhp_defaults;
494 else if constexpr ( std::is_same_v<T, Source> )
496 else if constexpr ( std::is_same_v<T, WCYCLE> )
499 #if !OPM_IS_COMPILING_WITH_GPU_COMPILER
500 static_assert(always_false1::value,
"Template type <T> not supported in get()");
518 std::unordered_map<int, SingleAquiferFlux> aqufluxs;
523 std::unordered_map<std::string, double> target_wellpi;
524 std::optional<NextStep> next_tstep;
526 template<
class Serializer>
529 serializer(gconsale);
530 serializer(gconsump);
531 serializer(gsatprod);
533 serializer(guide_rate);
534 serializer(wlist_manager);
535 serializer(well_order);
536 serializer(group_order);
539 serializer(udq_active);
541 serializer(wtest_config);
544 serializer(network_balance);
546 serializer(rpt_config);
547 serializer(rft_config);
548 serializer(rst_config);
549 serializer(bhp_defaults);
556 serializer(this->satelliteInjection);
558 serializer(aqufluxs);
560 serializer(inj_streams);
561 serializer(target_wellpi);
562 serializer(this->next_tstep);
563 serializer(m_start_time);
564 serializer(m_end_time);
565 serializer(m_sim_step);
566 serializer(m_month_num);
567 serializer(m_year_num);
568 serializer(m_first_in_year);
569 serializer(m_first_in_month);
570 serializer(m_save_step);
571 serializer(m_tuning);
572 serializer(m_nupcol);
573 serializer(m_oilvap);
574 serializer(m_events);
575 serializer(m_wellgroup_events);
576 serializer(m_geo_keywords);
577 serializer(m_message_limits);
578 serializer(m_whistctl_mode);
579 serializer(m_sumthin);
580 serializer(this->m_rptonly);
584 time_point m_start_time{};
585 std::optional<time_point> m_end_time{};
587 std::size_t m_sim_step = 0;
588 std::size_t m_month_num = 0;
589 std::size_t m_year_num = 0;
590 bool m_first_in_month{
false};
591 bool m_first_in_year{
false};
592 bool m_save_step{
false};
596 OilVaporizationProperties m_oilvap{};
598 WellGroupEvents m_wellgroup_events{};
599 std::vector<DeckKeyword> m_geo_keywords{};
600 MessageLimits m_message_limits{};
601 WellProducerCMode m_whistctl_mode = WellProducerCMode::CMODE_UNDEFINED;
602 std::optional<double> m_sumthin{};
603 bool m_rptonly{
false};