20 #ifndef SCHEDULE_TSTEP_HPP 21 #define SCHEDULE_TSTEP_HPP 23 #include <opm/common/utility/gpuDecorators.hpp> 24 #include <opm/common/utility/TimeService.hpp> 26 #include <opm/input/eclipse/EclipseState/Aquifer/AquiferFlux.hpp> 27 #include <opm/input/eclipse/EclipseState/Phase.hpp> 28 #include <opm/input/eclipse/EclipseState/Runspec.hpp> 30 #include <opm/input/eclipse/Schedule/BCProp.hpp> 31 #include <opm/input/eclipse/Schedule/Events.hpp> 32 #include <opm/input/eclipse/Schedule/GasPlantTable.hpp> 33 #include <opm/input/eclipse/Schedule/Group/Group.hpp> 34 #include <opm/input/eclipse/Schedule/MessageLimits.hpp> 35 #include <opm/input/eclipse/Schedule/OilVaporizationProperties.hpp> 36 #include <opm/input/eclipse/Schedule/RSTConfig.hpp> 37 #include <opm/input/eclipse/Schedule/Source.hpp> 38 #include <opm/input/eclipse/Schedule/Tuning.hpp> 39 #include <opm/input/eclipse/Schedule/VFPInjTable.hpp> 40 #include <opm/input/eclipse/Schedule/VFPProdTable.hpp> 41 #include <opm/input/eclipse/Schedule/Well/PAvg.hpp> 42 #include <opm/input/eclipse/Schedule/Well/WCYCLE.hpp> 43 #include <opm/input/eclipse/Schedule/Well/WellEnums.hpp> 45 #include <opm/input/eclipse/Deck/DeckKeyword.hpp> 54 #include <type_traits> 55 #include <unordered_map> 61 [[maybe_unused]] std::string as_string(
int value) {
62 return std::to_string(
value);
65 [[maybe_unused]] std::string as_string(
const std::string&
value) {
79 class GroupEconProductionLimits;
81 class GroupSatelliteInjection;
83 class GuideRateConfig;
89 namespace ReservoirCoupling {
97 class WellFractureSeeds;
131 template <
typename T>
134 const T&
get()
const {
135 return *this->m_data;
142 void update(T
object)
144 this->m_data = std::make_shared<T>( std::move(
object) );
153 this->m_data = other.m_data;
156 const T& operator()()
const {
157 return *this->m_data;
160 template<
class Serializer>
167 std::shared_ptr<T> m_data;
182 template <
typename K,
typename T>
185 std::vector<K> keys()
const {
186 std::vector<K> key_vector;
187 std::ranges::transform(this->m_data, std::back_inserter(key_vector),
188 [](
const auto& pair) {
return pair.first; });
193 template <
typename Predicate>
194 const T* find(Predicate&& predicate)
const {
195 const auto iter = std::ranges::find_if(this->m_data, std::forward<Predicate>(predicate));
196 if (iter == this->m_data.end()) {
200 return iter->second.get();
204 const std::shared_ptr<T> get_ptr(
const K& key)
const {
205 auto iter = this->m_data.find(key);
206 if (iter != this->m_data.end())
213 bool has(
const K& key)
const {
214 auto ptr = this->get_ptr(key);
215 return (ptr !=
nullptr);
218 void update(
const K& key, std::shared_ptr<T>
value) {
219 this->m_data.insert_or_assign(key, std::move(
value));
222 void update(T
object) {
223 auto key =
object.name();
224 this->m_data[key] = std::make_shared<T>( std::move(
object) );
227 void update(
const K& key,
const map_member<K,T>& other) {
228 auto other_ptr = other.get_ptr(key);
230 this->m_data[key] = other.get_ptr(key);
232 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
235 const T& operator()(
const K& key)
const {
236 return this->
get(key);
239 const T&
get(
const K& key)
const {
240 return *this->m_data.at(key);
243 T&
get(
const K& key) {
244 return *this->m_data.at(key);
248 std::vector<std::reference_wrapper<const T>> operator()()
const {
249 std::vector<std::reference_wrapper<const T>> as_vector;
250 for (
const auto& [_, elm_ptr] : this->m_data) {
252 as_vector.push_back( std::cref(*elm_ptr));
258 std::vector<std::reference_wrapper<T>> operator()() {
259 std::vector<std::reference_wrapper<T>> as_vector;
260 for (
const auto& [_, elm_ptr] : this->m_data) {
262 as_vector.push_back( std::ref(*elm_ptr));
268 bool operator==(
const map_member<K,T>& other)
const {
269 if (this->m_data.size() != other.m_data.size())
272 for (
const auto& [key1, ptr1] : this->m_data) {
273 const auto& ptr2 = other.get_ptr(key1);
277 if (!(*ptr1 == *ptr2))
284 std::size_t size()
const {
285 return this->m_data.size();
288 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
289 return this->m_data.begin();
292 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
293 return this->m_data.end();
297 static map_member<K,T> serializationTestObject() {
298 map_member<K,T> map_object;
299 T value_object = T::serializationTestObject();
300 K key = value_object.name();
301 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
305 template<
class Serializer>
306 void serializeOp(Serializer& serializer)
312 std::unordered_map<K, std::shared_ptr<T>> m_data;
316 std::optional<double> prod_target;
317 std::optional<double> inj_limit;
326 return this->prod_target == rhs.prod_target
327 && this->inj_limit == rhs.inj_limit;
330 template<
class Serializer>
333 serializer(prod_target);
334 serializer(inj_limit);
343 enum class Ix : std::size_t {
359 static constexpr
auto index(
const Ix i)
361 return static_cast<std::underlying_type_t<Ix>
>(i);
370 this->listsChanged_[ index(Ix::Static) ] =
true;
377 this->listsChanged_[ index(Ix::Action) ] =
true;
384 return this->listsChanged_[ index(Ix::Static) ];
393 void prepareNextReportStep();
407 return this->listsChanged_ == that.listsChanged_;
415 template <
class Serializer>
418 serializer(this->listsChanged_);
423 using ListChangeStatus = std::array
424 <bool,
static_cast<std::underlying_type_t<Ix>
>(Ix::Num)>;
430 ListChangeStatus listsChanged_{{
false,
false}};
433 ScheduleState() =
default;
434 explicit ScheduleState(
const time_point& start_time);
435 ScheduleState(
const time_point& start_time,
const time_point& end_time);
436 ScheduleState(
const ScheduleState& src,
const time_point& start_time);
437 ScheduleState(
const ScheduleState& src,
const time_point& start_time,
const time_point& end_time);
440 time_point start_time()
const;
441 time_point end_time()
const;
442 ScheduleState next(
const time_point& next_start);
447 std::size_t sim_step()
const;
451 std::size_t month_num()
const;
452 std::size_t year_num()
const;
453 bool first_in_month()
const;
454 bool first_in_year()
const;
455 bool well_group_contains_lgr(
const Group& grp,
const std::string& lgr_tag)
const;
456 bool group_contains_lgr(
const Group& grp,
const std::string& lgr_tag)
const;
458 std::size_t num_lgr_well_in_group(
const Group& grp,
const std::string& lgr_tag)
const;
459 std::size_t num_lgr_groups_in_group(
const Group& grp,
const std::string& lgr_tag)
const;
462 bool operator==(
const ScheduleState& other)
const;
463 static ScheduleState serializationTestObject();
466 void update_tuning(Tuning tuning);
468 const Tuning& tuning()
const;
469 double max_next_tstep(
const bool enableTUNING =
false)
const;
472 void update_tuning_dp(TuningDp tuningDp);
473 TuningDp& tuning_dp();
474 const TuningDp& tuning_dp()
const;
476 void init_nupcol(Nupcol nupcol);
477 void update_nupcol(
int nupcol);
480 void update_events(Events events);
482 const Events& events()
const;
484 WellGroupEvents& wellgroup_events();
485 const WellGroupEvents& wellgroup_events()
const;
487 WellCompletionEvents& wellcompletion_events();
488 const WellCompletionEvents& wellcompletion_events()
const;
490 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
491 std::vector<DeckKeyword>& geo_keywords();
492 const std::vector<DeckKeyword>& geo_keywords()
const;
494 void update_message_limits(MessageLimits message_limits);
495 MessageLimits& message_limits();
496 const MessageLimits& message_limits()
const;
498 WellProducerCMode whistctl()
const;
499 void update_whistctl(WellProducerCMode whistctl);
501 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
502 void update_date(
const time_point& prev_time);
503 void updateSAVE(
bool save);
506 const std::optional<double>& sumthin()
const;
507 void update_sumthin(
double sumthin);
509 bool rptonly()
const;
510 void rptonly(
const bool only);
512 bool has_gpmaint()
const;
514 bool hasAnalyticalAquifers()
const 516 return ! this->aqufluxs.empty();
521 ptr_member<GConSale> gconsale;
522 ptr_member<GConSump> gconsump;
523 ptr_member<GSatProd> gsatprod;
524 ptr_member<GroupEconProductionLimits> gecon;
525 ptr_member<GuideRateConfig> guide_rate;
527 ptr_member<WListManager> wlist_manager;
528 ptr_member<NameOrder> well_order;
529 ptr_member<GroupOrder> group_order;
531 ptr_member<Action::Actions> actions;
532 ptr_member<UDQConfig> udq;
533 ptr_member<UDQActive> udq_active;
535 ptr_member<PAvg> pavg;
536 ptr_member<WellTestConfig> wtest_config;
537 ptr_member<GasLiftOpt> glo;
538 ptr_member<Network::ExtNetwork> network;
539 ptr_member<Network::Balance> network_balance;
540 ptr_member<ReservoirCoupling::CouplingInfo> rescoup;
542 ptr_member<RPTConfig> rpt_config;
543 ptr_member<RFTConfig> rft_config;
544 ptr_member<RSTConfig> rst_config;
546 ptr_member<OilVaporizationProperties> oilvap;
548 ptr_member<BHPDefaults> bhp_defaults;
549 ptr_member<Source> source;
550 ptr_member<WCYCLE> wcycle;
552 ptr_member<WellListChangeTracker> wlist_tracker;
554 template <
typename T>
555 ptr_member<T>&
get() {
556 return const_cast<ptr_member<T>&
>(std::as_const(*this).template get<T>());
559 template <
typename T>
560 const ptr_member<T>&
get()
const 562 struct always_false1 : std::false_type {};
564 if constexpr ( std::is_same_v<T, PAvg> )
566 else if constexpr ( std::is_same_v<T, WellTestConfig> )
567 return this->wtest_config;
568 else if constexpr ( std::is_same_v<T, GConSale> )
569 return this->gconsale;
570 else if constexpr ( std::is_same_v<T, GConSump> )
571 return this->gconsump;
572 else if constexpr ( std::is_same_v<T, GSatProd> )
573 return this->gsatprod;
574 else if constexpr ( std::is_same_v<T, GroupEconProductionLimits> )
576 else if constexpr ( std::is_same_v<T, WListManager> )
577 return this->wlist_manager;
578 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
579 return this->network;
580 else if constexpr ( std::is_same_v<T, Network::Balance> )
581 return this->network_balance;
582 else if constexpr ( std::is_same_v<T, ReservoirCoupling::CouplingInfo> )
583 return this->rescoup;
584 else if constexpr ( std::is_same_v<T, RPTConfig> )
585 return this->rpt_config;
586 else if constexpr ( std::is_same_v<T, Action::Actions> )
587 return this->actions;
588 else if constexpr ( std::is_same_v<T, UDQActive> )
589 return this->udq_active;
590 else if constexpr ( std::is_same_v<T, NameOrder> )
591 return this->well_order;
592 else if constexpr ( std::is_same_v<T, GroupOrder> )
593 return this->group_order;
594 else if constexpr ( std::is_same_v<T, UDQConfig> )
596 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
598 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
599 return this->guide_rate;
600 else if constexpr ( std::is_same_v<T, RFTConfig> )
601 return this->rft_config;
602 else if constexpr ( std::is_same_v<T, RSTConfig> )
603 return this->rst_config;
604 else if constexpr ( std::is_same_v<T, OilVaporizationProperties> )
606 else if constexpr ( std::is_same_v<T, BHPDefaults> )
607 return this->bhp_defaults;
608 else if constexpr ( std::is_same_v<T, Source> )
610 else if constexpr ( std::is_same_v<T, WCYCLE> )
612 else if constexpr ( std::is_same_v<T, WellListChangeTracker> )
613 return this->wlist_tracker;
615 #if !OPM_IS_COMPILING_WITH_GPU_COMPILER // NVCC evaluates this branch for some reason 616 static_assert(always_false1::value,
"Template type <T> not supported in get()");
621 map_member<int, VFPProdTable> vfpprod;
622 map_member<int, VFPInjTable> vfpinj;
623 map_member<int, GasPlantTable> gptable;
624 map_member<std::string, Group> groups;
625 map_member<std::string, Well> wells;
648 std::unordered_map<int, SingleAquiferFlux> aqufluxs;
653 std::unordered_map<std::string, double> target_wellpi;
654 std::optional<NextStep> next_tstep;
656 template<
class Serializer>
659 serializer(gconsale);
660 serializer(gconsump);
661 serializer(gsatprod);
663 serializer(guide_rate);
664 serializer(wlist_manager);
665 serializer(well_order);
666 serializer(group_order);
669 serializer(udq_active);
671 serializer(wtest_config);
674 serializer(network_balance);
676 serializer(rpt_config);
677 serializer(rft_config);
678 serializer(rst_config);
679 serializer(this->oilvap);
680 serializer(bhp_defaults);
683 serializer(this->wlist_tracker);
689 serializer(this->satelliteInjection);
690 serializer(this->injectionNetwork);
692 serializer(aqufluxs);
694 serializer(inj_streams);
695 serializer(target_wellpi);
696 serializer(this->next_tstep);
697 serializer(m_start_time);
698 serializer(m_end_time);
699 serializer(m_sim_step);
700 serializer(m_month_num);
701 serializer(m_year_num);
702 serializer(m_first_in_year);
703 serializer(m_first_in_month);
704 serializer(m_save_step);
705 serializer(m_tuning);
706 serializer(m_tuning_dp);
707 serializer(m_nupcol);
708 serializer(m_events);
709 serializer(m_wellgroup_events);
710 serializer(m_wellcompletion_events);
711 serializer(m_geo_keywords);
712 serializer(m_message_limits);
713 serializer(m_whistctl_mode);
714 serializer(m_sumthin);
715 serializer(this->m_rptonly);
719 time_point m_start_time{};
720 std::optional<time_point> m_end_time{};
722 std::size_t m_sim_step = 0;
723 std::size_t m_month_num = 0;
724 std::size_t m_year_num = 0;
725 bool m_first_in_month{
false};
726 bool m_first_in_year{
false};
727 bool m_save_step{
false};
730 TuningDp m_tuning_dp{};
733 WellGroupEvents m_wellgroup_events{};
734 WellCompletionEvents m_wellcompletion_events{};
735 std::vector<DeckKeyword> m_geo_keywords{};
736 MessageLimits m_message_limits{};
737 WellProducerCMode m_whistctl_mode = WellProducerCMode::CMODE_UNDEFINED;
738 std::optional<double> m_sumthin{};
739 bool m_rptonly{
false};
744 #endif // SCHEDULE_TSTEP_HPP bool changedLists() const
Report whether or not any well lists have changed since the previous report step. ...
Definition: ScheduleState.hpp:382
void recordActionChangedLists()
Record that one or more well lists have changed structurally in response to a WLIST keyword entered i...
Definition: ScheduleState.hpp:375
Definition: ScheduleState.hpp:132
map_member< Phase, Network::ExtNetwork > injectionNetwork
Injection networks defined by GNETINJE.
Definition: ScheduleState.hpp:641
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
void recordStaticChangedLists()
Record that one or more well lists have changed structurally in response to a WLIST keyword entered i...
Definition: ScheduleState.hpp:368
Definition: ScheduleState.hpp:183
Definition: ScheduleState.hpp:315
Definition: BCProp.hpp:91
bool operator==(const WellListChangeTracker &that) const
Equality predicate.
Definition: ScheduleState.hpp:405
map_member< std::string, GroupSatelliteInjection > satelliteInjection
Group level satellite injection rates.
Definition: ScheduleState.hpp:628
Definition: ScheduleState.hpp:108
Flag for structural changes to the run's well list.
Definition: ScheduleState.hpp:339
map_member< std::string, WellFractureSeeds > wseed
Well fracturing seed points and associate fracture plane normal vectors.
Definition: ScheduleState.hpp:645
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition: ScheduleState.hpp:416
Class for (de-)serializing.
Definition: Serializer.hpp:95