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/EclipseState/Runspec.hpp>
33#include <opm/input/eclipse/EclipseState/Aquifer/AquiferFlux.hpp>
34#include <opm/input/eclipse/Schedule/Well/PAvg.hpp>
35#include <opm/input/eclipse/Schedule/Tuning.hpp>
36#include <opm/input/eclipse/Schedule/OilVaporizationProperties.hpp>
37#include <opm/input/eclipse/Schedule/Events.hpp>
38#include <opm/input/eclipse/Schedule/Group/Group.hpp>
39#include <opm/input/eclipse/Schedule/Well/WellEnums.hpp>
40#include <opm/input/eclipse/Schedule/MessageLimits.hpp>
41#include <opm/input/eclipse/Schedule/VFPProdTable.hpp>
42#include <opm/input/eclipse/Schedule/VFPInjTable.hpp>
43#include <opm/input/eclipse/Schedule/RSTConfig.hpp>
48[[maybe_unused]] std::string as_string(
int value) {
49 return std::to_string(value);
52[[maybe_unused]] std::string as_string(
const std::string& value) {
67 class GuideRateConfig;
111 template <
typename T>
114 const T& get()
const {
115 return *this->m_data;
122 void update(T
object)
124 this->m_data = std::make_shared<T>( std::move(
object) );
133 this->m_data = other.m_data;
136 const T& operator()()
const {
137 return *this->m_data;
141 std::shared_ptr<T> m_data;
156 template <
typename K,
typename T>
159 std::vector<K> keys()
const {
160 std::vector<K> key_vector;
161 std::transform( this->m_data.begin(), this->m_data.end(), std::back_inserter(key_vector), [](
const auto& pair) { return pair.first; });
166 template <
typename Predicate>
167 const T* find(Predicate&& predicate)
const {
168 auto iter = std::find_if( this->m_data.begin(), this->m_data.end(), std::forward<Predicate>(predicate));
169 if (iter == this->m_data.end())
172 return iter->second.get();
176 const std::shared_ptr<T> get_ptr(
const K& key)
const {
177 auto iter = this->m_data.find(key);
178 if (iter != this->m_data.end())
185 bool has(
const K& key)
const {
186 auto ptr = this->get_ptr(key);
187 return (ptr !=
nullptr);
191 void update(T
object) {
192 auto key =
object.name();
193 this->m_data[key] = std::make_shared<T>( std::move(
object) );
197 auto other_ptr = other.get_ptr(key);
199 this->m_data[key] = other.get_ptr(key);
201 throw std::logic_error(std::string{
"Tried to update member: "} + as_string(key) + std::string{
"with uninitialized object"});
204 const T& operator()(
const K& key)
const {
205 return this->get(key);
208 const T& get(
const K& key)
const {
209 return *this->m_data.at(key);
212 T& get(
const K& key) {
213 return *this->m_data.at(key);
217 std::vector<std::reference_wrapper<const T>> operator()()
const {
218 std::vector<std::reference_wrapper<const T>> as_vector;
219 for (
const auto& [_, elm_ptr] : this->m_data) {
221 as_vector.push_back( std::cref(*elm_ptr));
227 std::vector<std::reference_wrapper<T>> operator()() {
228 std::vector<std::reference_wrapper<T>> as_vector;
229 for (
const auto& [_, elm_ptr] : this->m_data) {
231 as_vector.push_back( std::ref(*elm_ptr));
238 if (this->m_data.size() != other.m_data.size())
241 for (
const auto& [key1, ptr1] : this->m_data) {
242 const auto& ptr2 = other.get_ptr(key1);
246 if (!(*ptr1 == *ptr2))
253 std::size_t size()
const {
254 return this->m_data.size();
257 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator begin()
const {
258 return this->m_data.begin();
261 typename std::unordered_map<K, std::shared_ptr<T>>::const_iterator end()
const {
262 return this->m_data.end();
268 T value_object = T::serializationTestObject();
269 K key = value_object.name();
270 map_object.m_data.emplace( key, std::make_shared<T>( std::move(value_object) ));
276 std::unordered_map<K, std::shared_ptr<T>> m_data;
283 ScheduleState(
const time_point& start_time,
const time_point& end_time);
288 time_point start_time()
const;
289 time_point end_time()
const;
295 std::size_t sim_step()
const;
299 std::size_t month_num()
const;
300 std::size_t year_num()
const;
301 bool first_in_month()
const;
302 bool first_in_year()
const;
307 void update_tuning(
Tuning tuning);
309 const Tuning& tuning()
const;
310 double max_next_tstep()
const;
312 void init_nupcol(
Nupcol nupcol);
313 void update_nupcol(
int nupcol);
320 void update_events(
Events events);
322 const Events& events()
const;
328 void update_geo_keywords(std::vector<DeckKeyword> geo_keywords);
329 std::vector<DeckKeyword>& geo_keywords();
330 const std::vector<DeckKeyword>& geo_keywords()
const;
336 WellProducerCMode whistctl()
const;
337 void update_whistctl(WellProducerCMode whistctl);
339 bool rst_file(
const RSTConfig& rst_config,
const time_point& previous_restart_output_time)
const;
340 void update_date(
const time_point& prev_time);
341 void updateSAVE(
bool save);
344 const std::optional<double>& sumthin()
const;
345 void update_sumthin(
double sumthin);
347 bool rptonly()
const;
348 void rptonly(
const bool only);
350 bool has_gpmaint()
const;
352 bool hasAnalyticalAquifers()
const
354 return ! this->aqufluxs.empty();
359 ptr_member<GConSale> gconsale;
360 ptr_member<GConSump> gconsump;
361 ptr_member<GuideRateConfig> guide_rate;
363 ptr_member<WListManager> wlist_manager;
364 ptr_member<NameOrder> well_order;
365 ptr_member<GroupOrder> group_order;
367 ptr_member<Action::Actions> actions;
368 ptr_member<UDQConfig> udq;
369 ptr_member<UDQActive> udq_active;
371 ptr_member<PAvg> pavg;
372 ptr_member<WellTestConfig> wtest_config;
373 ptr_member<GasLiftOpt> glo;
374 ptr_member<Network::ExtNetwork> network;
375 ptr_member<Network::Balance> network_balance;
377 ptr_member<RPTConfig> rpt_config;
378 ptr_member<RFTConfig> rft_config;
379 ptr_member<RSTConfig> rst_config;
383 template <
typename T>
385 if constexpr ( std::is_same_v<T, PAvg> )
387 else if constexpr ( std::is_same_v<T, WellTestConfig> )
388 return this->wtest_config;
389 else if constexpr ( std::is_same_v<T, GConSale> )
390 return this->gconsale;
391 else if constexpr ( std::is_same_v<T, GConSump> )
392 return this->gconsump;
393 else if constexpr ( std::is_same_v<T, WListManager> )
394 return this->wlist_manager;
395 else if constexpr ( std::is_same_v<T, Network::ExtNetwork> )
396 return this->network;
397 else if constexpr ( std::is_same_v<T, Network::Balance> )
398 return this->network_balance;
399 else if constexpr ( std::is_same_v<T, RPTConfig> )
400 return this->rpt_config;
401 else if constexpr ( std::is_same_v<T, Action::Actions> )
402 return this->actions;
403 else if constexpr ( std::is_same_v<T, UDQActive> )
404 return this->udq_active;
405 else if constexpr ( std::is_same_v<T, NameOrder> )
406 return this->well_order;
407 else if constexpr ( std::is_same_v<T, GroupOrder> )
408 return this->group_order;
409 else if constexpr ( std::is_same_v<T, UDQConfig> )
411 else if constexpr ( std::is_same_v<T, GasLiftOpt> )
413 else if constexpr ( std::is_same_v<T, GuideRateConfig> )
414 return this->guide_rate;
415 else if constexpr ( std::is_same_v<T, RFTConfig> )
416 return this->rft_config;
417 else if constexpr ( std::is_same_v<T, RSTConfig> )
418 return this->rst_config;
423 template <
typename T>
424 const ptr_member<T>& get()
const {
425 if constexpr ( std::is_same_v<T, PAvg> )
427 else if constexpr ( std::is_same_v<T, WellTestConfig> )
428 return this->wtest_config;
429 else if constexpr ( std::is_same_v<T, GConSale> )
430 return this->gconsale;
431 else if constexpr ( std::is_same_v<T, GConSump> )
432 return this->gconsump;
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;
460 static_assert(always_false1<T>::value,
"Template type <T> not supported in get()");
464 template <
typename K,
typename T>
struct always_false2 : std::false_type {};
465 template <
typename K,
typename T>
467 if constexpr ( std::is_same_v<T, VFPProdTable> )
468 return this->vfpprod;
469 else if constexpr ( std::is_same_v<T, VFPInjTable> )
471 else if constexpr ( std::is_same_v<T, Group> )
473 else if constexpr ( std::is_same_v<T, Well> )
479 map_member<int, VFPProdTable> vfpprod;
480 map_member<int, VFPInjTable> vfpinj;
481 map_member<std::string, Group> groups;
482 map_member<std::string, Well> wells;
484 std::unordered_map<int, SingleAquiferFlux> aqufluxs;
485 std::unordered_map<std::string, double> target_wellpi;
486 std::optional<NextStep> next_tstep;
489 using WellPIMapType = std::unordered_map<std::string, double>;
490 template<
class Serializer>
492 serializer(m_start_time);
493 serializer(m_end_time);
494 serializer(m_sim_step);
495 serializer(m_month_num);
496 serializer(m_year_num);
497 serializer(m_first_in_year);
498 serializer(m_first_in_month);
499 serializer(m_save_step);
500 serializer(m_sumthin);
501 serializer(this->m_rptonly);
502 serializer(this->next_tstep);
503 serializer(m_tuning);
504 serializer(m_nupcol);
505 serializer(m_oilvap);
506 serializer(m_events);
507 serializer(m_wellgroup_events);
508 serializer(m_geo_keywords);
509 serializer(m_message_limits);
510 serializer(m_whistctl_mode);
511 serializer(target_wellpi);
512 serializer(aqufluxs);
517 time_point m_start_time;
518 std::optional<time_point> m_end_time;
520 std::size_t m_sim_step = 0;
521 std::size_t m_month_num = 0;
522 std::size_t m_year_num = 0;
523 bool m_first_in_month;
524 bool m_first_in_year;
525 bool m_save_step{
false};
529 OilVaporizationProperties m_oilvap;
531 WellGroupEvents m_wellgroup_events;
532 std::vector<DeckKeyword> m_geo_keywords;
533 MessageLimits m_message_limits;
534 WellProducerCMode m_whistctl_mode = WellProducerCMode::CMODE_UNDEFINED;
535 std::optional<double> m_sumthin;
536 bool m_rptonly{
false};
Definition: Events.hpp:147
Definition: MessageLimits.hpp:28
Definition: Runspec.hpp:377
Definition: OilVaporizationProperties.hpp:34
Definition: RSTConfig.hpp:196
Definition: ScheduleState.hpp:157
Definition: ScheduleState.hpp:112
Definition: ScheduleState.hpp:88
Class for (de-)serializing.
Definition: Serializer.hpp:84
Definition: Events.hpp:169
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: ScheduleState.hpp:381
Definition: ScheduleState.hpp:464
Definition: Tuning.hpp:46