20 #ifndef SCHEDULE_TSTEP_HPP
21 #define SCHEDULE_TSTEP_HPP
27 #include <unordered_map>
29 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
30 #include <opm/common/utility/TimeService.hpp>
32 #include <opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp>
33 #include <opm/parser/eclipse/EclipseState/Schedule/Well/PAvg.hpp>
34 #include <opm/parser/eclipse/EclipseState/Schedule/Tuning.hpp>
35 #include <opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp>
36 #include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
37 #include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
38 #include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
39 #include <opm/parser/eclipse/EclipseState/Schedule/Well/NameOrder.hpp>
40 #include <opm/parser/eclipse/EclipseState/Schedule/Well/WListManager.hpp>
41 #include <opm/parser/eclipse/EclipseState/Schedule/MessageLimits.hpp>
42 #include <opm/parser/eclipse/EclipseState/Schedule/Group/GConSump.hpp>
43 #include <opm/parser/eclipse/EclipseState/Schedule/Group/GConSale.hpp>
44 #include <opm/parser/eclipse/EclipseState/Schedule/Network/ExtNetwork.hpp>
45 #include <opm/parser/eclipse/EclipseState/Schedule/Network/Balance.hpp>
46 #include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp>
47 #include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
48 #include <opm/parser/eclipse/EclipseState/Schedule/Action/Actions.hpp>
49 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQActive.hpp>
50 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQConfig.hpp>
51 #include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRateConfig.hpp>
52 #include <opm/parser/eclipse/EclipseState/Schedule/GasLiftOpt.hpp>
53 #include <opm/parser/eclipse/EclipseState/Schedule/RFTConfig.hpp>
54 #include <opm/parser/eclipse/EclipseState/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::serializeObject();
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;
304 void init_nupcol(
Nupcol nupcol);
305 void update_nupcol(
int nupcol);
312 void update_events(
Events events);
314 const Events& events()
const;
320 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
321 std::vector<DeckKeyword>& geo_keywords();
322 const std::vector<DeckKeyword>& geo_keywords()
const;
328 Well::ProducerCMode whistctl()
const;
329 void update_whistctl(Well::ProducerCMode whistctl);
331 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
332 void update_date(
const time_point& prev_time);
333 void updateSAVE(
bool save);
336 const std::optional<double>& sumthin()
const;
337 void update_sumthin(
double sumthin);
339 bool rptonly()
const;
340 void rptonly(
const bool only);
342 bool has_gpmaint()
const;
370 template <
typename T>
372 if constexpr ( std::is_same_v<T, PAvg> )
374 else if constexpr ( std::is_same_v<T, WellTestConfig> )
375 return this->wtest_config;
376 else if constexpr ( std::is_same_v<T, GConSale> )
377 return this->gconsale;
378 else if constexpr ( std::is_same_v<T, GConSump> )
379 return this->gconsump;
380 else if constexpr ( std::is_same_v<T, WListManager> )
381 return this->wlist_manager;
382 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
383 return this->network;
384 else if constexpr ( std::is_same_v<T, Network::Balance> )
385 return this->network_balance;
386 else if constexpr ( std::is_same_v<T, RPTConfig> )
387 return this->rpt_config;
388 else if constexpr ( std::is_same_v<T, Action::Actions> )
389 return this->actions;
390 else if constexpr ( std::is_same_v<T, UDQActive> )
391 return this->udq_active;
392 else if constexpr ( std::is_same_v<T, NameOrder> )
393 return this->well_order;
394 else if constexpr ( std::is_same_v<T, GroupOrder> )
395 return this->group_order;
396 else if constexpr ( std::is_same_v<T, UDQConfig> )
398 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
400 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
401 return this->guide_rate;
402 else if constexpr ( std::is_same_v<T, RFTConfig> )
403 return this->rft_config;
404 else if constexpr ( std::is_same_v<T, RSTConfig> )
405 return this->rst_config;
410 template <
typename T>
411 const ptr_member<T>& get()
const {
412 if constexpr ( std::is_same_v<T, PAvg> )
414 else if constexpr ( std::is_same_v<T, WellTestConfig> )
415 return this->wtest_config;
416 else if constexpr ( std::is_same_v<T, GConSale> )
417 return this->gconsale;
418 else if constexpr ( std::is_same_v<T, GConSump> )
419 return this->gconsump;
420 else if constexpr ( std::is_same_v<T, WListManager> )
421 return this->wlist_manager;
422 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
423 return this->network;
424 else if constexpr ( std::is_same_v<T, Network::Balance> )
425 return this->network_balance;
426 else if constexpr ( std::is_same_v<T, RPTConfig> )
427 return this->rpt_config;
428 else if constexpr ( std::is_same_v<T, Action::Actions> )
429 return this->actions;
430 else if constexpr ( std::is_same_v<T, UDQActive> )
431 return this->udq_active;
432 else if constexpr ( std::is_same_v<T, NameOrder> )
433 return this->well_order;
434 else if constexpr ( std::is_same_v<T, GroupOrder> )
435 return this->group_order;
436 else if constexpr ( std::is_same_v<T, UDQConfig> )
438 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
440 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
441 return this->guide_rate;
442 else if constexpr ( std::is_same_v<T, RFTConfig> )
443 return this->rft_config;
444 else if constexpr ( std::is_same_v<T, RSTConfig> )
445 return this->rst_config;
447 static_assert(always_false1<T>::value,
"Template type <T> not supported in get()");
451 template <
typename K,
typename T>
struct always_false2 : std::false_type {};
452 template <
typename K,
typename T>
454 if constexpr ( std::is_same_v<T, VFPProdTable> )
455 return this->vfpprod;
456 else if constexpr ( std::is_same_v<T, VFPInjTable> )
458 else if constexpr ( std::is_same_v<T, Group> )
460 else if constexpr ( std::is_same_v<T, Well> )
466 map_member<int, VFPProdTable> vfpprod;
467 map_member<int, VFPInjTable> vfpinj;
468 map_member<std::string, Group> groups;
469 map_member<std::string, Well> wells;
470 std::unordered_map<std::string, double> target_wellpi;
473 using WellPIMapType = std::unordered_map<std::string, double>;
474 template<
class Serializer>
476 serializer(m_start_time);
477 serializer(m_end_time);
478 serializer(m_sim_step);
479 serializer(m_month_num);
480 serializer(m_year_num);
481 serializer(m_first_in_year);
482 serializer(m_first_in_month);
483 serializer(m_save_step);
484 serializer(m_sumthin);
485 serializer(this->m_rptonly);
486 m_tuning.serializeOp(serializer);
487 m_nupcol.serializeOp(serializer);
488 m_oilvap.serializeOp(serializer);
489 m_events.serializeOp(serializer);
490 m_wellgroup_events.serializeOp(serializer);
491 serializer.vector(m_geo_keywords);
492 m_message_limits.serializeOp(serializer);
493 serializer(m_whistctl_mode);
494 serializer.template map<WellPIMapType, false>(target_wellpi);
499 time_point m_start_time;
500 std::optional<time_point> m_end_time;
502 std::size_t m_sim_step = 0;
503 std::size_t m_month_num = 0;
504 std::size_t m_year_num = 0;
505 bool m_first_in_month;
506 bool m_first_in_year;
507 bool m_save_step{
false};
511 OilVaporizationProperties m_oilvap;
513 WellGroupEvents m_wellgroup_events;
514 std::vector<DeckKeyword> m_geo_keywords;
515 MessageLimits m_message_limits;
516 Well::ProducerCMode m_whistctl_mode = Well::ProducerCMode::CMODE_UNDEFINED;
517 std::optional<double> m_sumthin;
518 bool m_rptonly{
false};
Definition: Events.hpp:147
Definition: MessageLimits.hpp:28
Definition: Runspec.hpp:380
Definition: OilVaporizationProperties.hpp:34
Definition: RSTConfig.hpp:196
Definition: ScheduleState.hpp:150
Definition: ScheduleState.hpp:105
Definition: ScheduleState.hpp:81
Definition: Serializer.hpp:38
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:368
Definition: ScheduleState.hpp:451
Definition: Tuning.hpp:24