20 #ifndef SCHEDULE_TSTEP_HPP
21 #define SCHEDULE_TSTEP_HPP
27 #include <unordered_map>
29 #include <opm/input/eclipse/Deck/DeckKeyword.hpp>
30 #include <opm/common/utility/TimeService.hpp>
32 #include <opm/input/eclipse/Schedule/RPTConfig.hpp>
33 #include <opm/input/eclipse/Schedule/Well/PAvg.hpp>
34 #include <opm/input/eclipse/Schedule/Tuning.hpp>
35 #include <opm/input/eclipse/Schedule/OilVaporizationProperties.hpp>
36 #include <opm/input/eclipse/Schedule/Events.hpp>
37 #include <opm/input/eclipse/Schedule/Group/Group.hpp>
38 #include <opm/input/eclipse/Schedule/Well/Well.hpp>
39 #include <opm/input/eclipse/Schedule/Well/NameOrder.hpp>
40 #include <opm/input/eclipse/Schedule/Well/WListManager.hpp>
41 #include <opm/input/eclipse/Schedule/MessageLimits.hpp>
42 #include <opm/input/eclipse/Schedule/Group/GConSump.hpp>
43 #include <opm/input/eclipse/Schedule/Group/GConSale.hpp>
44 #include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
45 #include <opm/input/eclipse/Schedule/Network/Balance.hpp>
46 #include <opm/input/eclipse/Schedule/VFPProdTable.hpp>
47 #include <opm/input/eclipse/Schedule/VFPInjTable.hpp>
48 #include <opm/input/eclipse/Schedule/Action/Actions.hpp>
49 #include <opm/input/eclipse/Schedule/UDQ/UDQActive.hpp>
50 #include <opm/input/eclipse/Schedule/UDQ/UDQConfig.hpp>
51 #include <opm/input/eclipse/Schedule/Group/GuideRateConfig.hpp>
52 #include <opm/input/eclipse/Schedule/GasLiftOpt.hpp>
53 #include <opm/input/eclipse/Schedule/RFTConfig.hpp>
54 #include <opm/input/eclipse/Schedule/RSTConfig.hpp>
59 [[maybe_unused]] std::string as_string(
int value) {
60 return std::to_string(value);
63 [[maybe_unused]] std::string as_string(
const std::string& value) {
104 template <
typename T>
107 const T& get()
const {
108 return *this->m_data;
115 void update(T
object)
117 this->m_data = std::make_shared<T>( std::move(
object) );
126 this->m_data = other.m_data;
129 const T& operator()()
const {
130 return *this->m_data;
134 std::shared_ptr<T> m_data;
149 template <
typename K,
typename T>
152 std::vector<K> keys()
const {
153 std::vector<K> key_vector;
154 std::transform( this->m_data.begin(), this->m_data.end(), std::back_inserter(key_vector), [](
const auto& pair) { return pair.first; });
159 template <
typename Predicate>
160 const T* find(Predicate&& predicate)
const {
161 auto iter = std::find_if( this->m_data.begin(), this->m_data.end(), std::forward<Predicate>(predicate));
162 if (iter == this->m_data.end())
165 return iter->second.get();
169 const std::shared_ptr<T> get_ptr(
const K& key)
const {
170 auto iter = this->m_data.find(key);
171 if (iter != this->m_data.end())
178 bool has(
const K& key)
const {
179 auto ptr = this->get_ptr(key);
180 return (ptr !=
nullptr);
184 void update(T
object) {
185 auto key =
object.name();
186 this->m_data[key] = std::make_shared<T>( std::move(
object) );
190 auto other_ptr = other.get_ptr(key);
192 this->m_data[key] = other.get_ptr(key);
194 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
197 const T& operator()(
const K& key)
const {
198 return this->get(key);
201 const T& get(
const K& key)
const {
202 return *this->m_data.at(key);
205 T& get(
const K& key) {
206 return *this->m_data.at(key);
210 std::vector<std::reference_wrapper<const T>> operator()()
const {
211 std::vector<std::reference_wrapper<const T>> as_vector;
212 for (
const auto& [_, elm_ptr] : this->m_data) {
214 as_vector.push_back( std::cref(*elm_ptr));
220 std::vector<std::reference_wrapper<T>> operator()() {
221 std::vector<std::reference_wrapper<T>> as_vector;
222 for (
const auto& [_, elm_ptr] : this->m_data) {
224 as_vector.push_back( std::ref(*elm_ptr));
231 if (this->m_data.size() != other.m_data.size())
234 for (
const auto& [key1, ptr1] : this->m_data) {
235 const auto& ptr2 = other.get_ptr(key1);
239 if (!(*ptr1 == *ptr2))
246 std::size_t size()
const {
247 return this->m_data.size();
250 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
251 return this->m_data.begin();
254 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
255 return this->m_data.end();
261 T value_object = T::serializationTestObject();
262 K key = value_object.name();
263 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
269 std::unordered_map<K, std::shared_ptr<T>> m_data;
276 ScheduleState(
const time_point& start_time,
const time_point& end_time);
281 time_point start_time()
const;
282 time_point end_time()
const;
288 std::size_t sim_step()
const;
292 std::size_t month_num()
const;
293 std::size_t year_num()
const;
294 bool first_in_month()
const;
295 bool first_in_year()
const;
300 void update_tuning(
Tuning tuning);
302 const Tuning& tuning()
const;
303 double max_next_tstep()
const;
305 void init_nupcol(
Nupcol nupcol);
306 void update_nupcol(
int nupcol);
313 void update_events(
Events events);
315 const Events& events()
const;
321 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
322 std::vector<DeckKeyword>& geo_keywords();
323 const std::vector<DeckKeyword>& geo_keywords()
const;
329 Well::ProducerCMode whistctl()
const;
330 void update_whistctl(Well::ProducerCMode whistctl);
332 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
333 void update_date(
const time_point& prev_time);
334 void updateSAVE(
bool save);
337 const std::optional<double>& sumthin()
const;
338 void update_sumthin(
double sumthin);
340 bool rptonly()
const;
341 void rptonly(
const bool only);
343 bool has_gpmaint()
const;
371 template <
typename T>
373 if constexpr ( std::is_same_v<T, PAvg> )
375 else if constexpr ( std::is_same_v<T, WellTestConfig> )
376 return this->wtest_config;
377 else if constexpr ( std::is_same_v<T, GConSale> )
378 return this->gconsale;
379 else if constexpr ( std::is_same_v<T, GConSump> )
380 return this->gconsump;
381 else if constexpr ( std::is_same_v<T, WListManager> )
382 return this->wlist_manager;
383 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
384 return this->network;
385 else if constexpr ( std::is_same_v<T, Network::Balance> )
386 return this->network_balance;
387 else if constexpr ( std::is_same_v<T, RPTConfig> )
388 return this->rpt_config;
389 else if constexpr ( std::is_same_v<T, Action::Actions> )
390 return this->actions;
391 else if constexpr ( std::is_same_v<T, UDQActive> )
392 return this->udq_active;
393 else if constexpr ( std::is_same_v<T, NameOrder> )
394 return this->well_order;
395 else if constexpr ( std::is_same_v<T, GroupOrder> )
396 return this->group_order;
397 else if constexpr ( std::is_same_v<T, UDQConfig> )
399 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
401 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
402 return this->guide_rate;
403 else if constexpr ( std::is_same_v<T, RFTConfig> )
404 return this->rft_config;
405 else if constexpr ( std::is_same_v<T, RSTConfig> )
406 return this->rst_config;
411 template <
typename T>
412 const ptr_member<T>& get()
const {
413 if constexpr ( std::is_same_v<T, PAvg> )
415 else if constexpr ( std::is_same_v<T, WellTestConfig> )
416 return this->wtest_config;
417 else if constexpr ( std::is_same_v<T, GConSale> )
418 return this->gconsale;
419 else if constexpr ( std::is_same_v<T, GConSump> )
420 return this->gconsump;
421 else if constexpr ( std::is_same_v<T, WListManager> )
422 return this->wlist_manager;
423 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
424 return this->network;
425 else if constexpr ( std::is_same_v<T, Network::Balance> )
426 return this->network_balance;
427 else if constexpr ( std::is_same_v<T, RPTConfig> )
428 return this->rpt_config;
429 else if constexpr ( std::is_same_v<T, Action::Actions> )
430 return this->actions;
431 else if constexpr ( std::is_same_v<T, UDQActive> )
432 return this->udq_active;
433 else if constexpr ( std::is_same_v<T, NameOrder> )
434 return this->well_order;
435 else if constexpr ( std::is_same_v<T, GroupOrder> )
436 return this->group_order;
437 else if constexpr ( std::is_same_v<T, UDQConfig> )
439 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
441 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
442 return this->guide_rate;
443 else if constexpr ( std::is_same_v<T, RFTConfig> )
444 return this->rft_config;
445 else if constexpr ( std::is_same_v<T, RSTConfig> )
446 return this->rst_config;
448 static_assert(always_false1<T>::value,
"Template type <T> not supported in get()");
452 template <
typename K,
typename T>
struct always_false2 : std::false_type {};
453 template <
typename K,
typename T>
455 if constexpr ( std::is_same_v<T, VFPProdTable> )
456 return this->vfpprod;
457 else if constexpr ( std::is_same_v<T, VFPInjTable> )
459 else if constexpr ( std::is_same_v<T, Group> )
461 else if constexpr ( std::is_same_v<T, Well> )
467 map_member<int, VFPProdTable> vfpprod;
468 map_member<int, VFPInjTable> vfpinj;
469 map_member<std::string, Group> groups;
470 map_member<std::string, Well> wells;
471 std::unordered_map<std::string, double> target_wellpi;
472 std::optional<NextStep> next_tstep;
475 using WellPIMapType = std::unordered_map<std::string, double>;
476 template<
class Serializer>
478 serializer(m_start_time);
479 serializer(m_end_time);
480 serializer(m_sim_step);
481 serializer(m_month_num);
482 serializer(m_year_num);
483 serializer(m_first_in_year);
484 serializer(m_first_in_month);
485 serializer(m_save_step);
486 serializer(m_sumthin);
487 serializer(this->m_rptonly);
488 serializer(this->next_tstep);
489 serializer(m_tuning);
490 serializer(m_nupcol);
491 serializer(m_oilvap);
492 serializer(m_events);
493 serializer(m_wellgroup_events);
494 serializer(m_geo_keywords);
495 serializer(m_message_limits);
496 serializer(m_whistctl_mode);
497 serializer(target_wellpi);
502 time_point m_start_time;
503 std::optional<time_point> m_end_time;
505 std::size_t m_sim_step = 0;
506 std::size_t m_month_num = 0;
507 std::size_t m_year_num = 0;
508 bool m_first_in_month;
509 bool m_first_in_year;
510 bool m_save_step{
false};
514 OilVaporizationProperties m_oilvap;
516 WellGroupEvents m_wellgroup_events;
517 std::vector<DeckKeyword> m_geo_keywords;
518 MessageLimits m_message_limits;
519 Well::ProducerCMode m_whistctl_mode = Well::ProducerCMode::CMODE_UNDEFINED;
520 std::optional<double> m_sumthin;
521 bool m_rptonly{
false};
Definition: Events.hpp:147
Definition: MessageLimits.hpp:28
Definition: Runspec.hpp:396
Definition: OilVaporizationProperties.hpp:34
Definition: RSTConfig.hpp:196
Definition: ScheduleState.hpp:150
Definition: ScheduleState.hpp:105
Definition: ScheduleState.hpp:81
Class for (de-)serializing.
Definition: Serializer.hpp:75
Definition: Events.hpp:169
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: ScheduleState.hpp:369
Definition: ScheduleState.hpp:452
Definition: Tuning.hpp:46