103 Schedule() =
default;
105 explicit Schedule(std::shared_ptr<const Python> python_handle);
123 Schedule(
const Deck& deck,
130 std::shared_ptr<const Python> python,
131 const bool lowActionParsingStrictness =
false,
132 const bool slave_mode =
false,
133 const bool keepKeywords =
true,
134 const std::optional<int>& output_interval = {},
139 Schedule(
const Deck& deck,
146 std::shared_ptr<const Python> python,
147 const bool lowActionParsingStrictness =
false,
148 const bool slave_mode =
false,
149 const bool keepKeywords =
true,
150 const std::optional<int>& output_interval = {},
154 Schedule(
const Deck& deck,
159 std::shared_ptr<const Python> python,
160 const bool lowActionParsingStrictness =
false,
161 const bool slave_mode =
false,
162 const bool keepKeywords =
true,
163 const std::optional<int>& output_interval = {},
167 Schedule(
const Deck& deck,
171 std::shared_ptr<const Python> python,
172 const bool lowActionParsingStrictness =
false,
173 const bool slave_mode =
false,
174 const bool keepKeywords =
true,
175 const std::optional<int>& output_interval = {},
178 template <
typename T>
179 Schedule(
const Deck& deck,
183 std::shared_ptr<const Python> python,
184 const bool lowActionParsingStrictness =
false,
185 const bool slave_mode =
false,
186 const bool keepKeywords =
true,
187 const std::optional<int>& output_interval = {},
190 Schedule(
const Deck& deck,
192 std::shared_ptr<const Python> python,
193 const bool lowActionParsingStrictness =
false,
194 const bool slave_mode =
false,
195 const bool keepKeywords =
true,
196 const std::optional<int>& output_interval = {},
200 Schedule(
const Deck& deck,
202 const std::optional<int>& output_interval = {},
205 ~Schedule() =
default;
207 static Schedule serializationTestObject();
213 std::time_t getStartTime()
const;
214 std::time_t posixStartTime()
const;
215 std::time_t posixEndTime()
const;
216 std::time_t simTime(std::size_t timeStep)
const;
217 double seconds(std::size_t timeStep)
const;
218 double stepLength(std::size_t timeStep)
const;
219 std::optional<int> exitStatus()
const;
220 const UnitSystem& getUnits()
const {
return this->m_static.m_unit_system; }
221 const Runspec& runspec()
const {
return this->m_static.m_runspec; }
223 std::size_t numWells()
const;
224 std::size_t numWells(std::size_t timestep)
const;
225 bool hasWell(
const std::string& wellName)
const;
226 bool hasWell(
const std::string& wellName, std::size_t timeStep)
const;
228 WellMatcher wellMatcher(std::size_t report_step)
const;
229 std::function<std::unique_ptr<SegmentMatcher>()> segmentMatcherFactory(std::size_t report_step)
const;
230 std::vector<std::string> wellNames(
const std::string& pattern, std::size_t timeStep,
const std::vector<std::string>& matching_wells = {})
const;
231 std::vector<std::string> wellNames(
const std::string& pattern)
const;
232 std::vector<std::string> wellNames(std::size_t timeStep)
const;
233 std::vector<std::string> wellNames()
const;
242 bool hasGroup(
const std::string& groupName, std::size_t timeStep)
const;
255 std::vector<std::string>
256 groupNames(
const std::string& pattern, std::size_t timeStep)
const;
264 const std::vector<std::string>&
groupNames(std::size_t timeStep)
const;
274 std::vector<std::string>
groupNames(
const std::string& pattern)
const;
279 const std::vector<std::string>&
groupNames()
const;
291 std::vector<const Group*>
restart_groups(std::size_t timeStep)
const;
293 std::vector<std::string>
294 changed_wells(std::size_t reportStep,
295 std::size_t initialStep = 0)
const;
297 const Well& getWell(std::size_t well_index, std::size_t timeStep)
const;
298 const Well& getWell(
const std::string& wellName, std::size_t timeStep)
const;
299 const Well& getWellatEnd(
const std::string& well_name)
const;
301 std::unordered_set<int> getAquiferFluxSchedule()
const;
302 std::vector<Well> getWells(std::size_t timeStep)
const;
303 std::vector<Well> getWellsatEnd()
const;
306 std::vector<Well> getActiveWellsAtEnd()
const;
309 std::vector<std::string> getInactiveWellNamesAtEnd()
const;
311 const std::unordered_map<std::string, std::set<int>>&
312 getPossibleFutureConnections()
const;
314 void shut_well(
const std::string& well_name, std::size_t report_step);
315 void shut_well(
const std::string& well_name);
316 void stop_well(
const std::string& well_name, std::size_t report_step);
317 void stop_well(
const std::string& well_name);
318 void open_well(
const std::string& well_name, std::size_t report_step);
319 void open_well(
const std::string& well_name);
320 void clear_event(ScheduleEvents::Events, std::size_t report_step);
321 void add_event(ScheduleEvents::Events, std::size_t report_step);
322 void applyWellProdIndexScaling(
const std::string& well_name,
const std::size_t reportStep,
const double scalingFactor);
327 WellProducerCMode getGlobalWhistctlMmode(std::size_t timestep)
const;
329 const UDQConfig& getUDQConfig(std::size_t timeStep)
const;
331 GTNode groupTree(std::size_t report_step)
const;
332 GTNode groupTree(
const std::string& root_node, std::size_t report_step)
const;
333 const Group& getGroup(
const std::string& groupName, std::size_t timeStep)
const;
335 std::optional<std::size_t> first_RFT()
const;
341 std::size_t size()
const;
343 bool write_rst_file(std::size_t report_step)
const;
344 const std::map< std::string, int >& rst_keywords(
size_t timestep )
const;
354 const std::unordered_map<std::string, double>& wellpi,
355 const bool iterateSchedule);
360 const std::unordered_map<std::string, float>& wellpi,
361 const bool iterateSchedule);
380 const std::unordered_map<std::string, double>& target_wellpi);
387 const std::unordered_map<std::string, float>& target_wellpi);
390 const std::map<std::string, std::vector<Connection>>& extraConns);
392 const GasLiftOpt& glo(std::size_t report_step)
const;
394 bool operator==(
const Schedule& data)
const;
395 std::shared_ptr<const Python> python()
const;
407 std::vector<ScheduleState>::const_iterator begin()
const;
408 std::vector<ScheduleState>::const_iterator end()
const;
409 void create_next(
const time_point& start_time,
const std::optional<time_point>& end_time);
411 void create_first(
const time_point& start_time,
const std::optional<time_point>& end_time);
413 void treat_critical_as_non_critical(
bool value) { this->m_treat_critical_as_non_critical = value; }
421 static bool cmp(
const Schedule& sched1,
const Schedule& sched2, std::size_t report_step);
422 void applyKeywords(std::vector<std::unique_ptr<DeckKeyword>>& keywords, std::unordered_map<std::string, double>& target_wellpi,
bool action_mode, std::size_t report_step);
423 void applyKeywords(std::vector<std::unique_ptr<DeckKeyword>>& keywords, std::unordered_map<std::string, double>& target_wellpi,
bool action_mode);
425 template<
class Serializer>
428 serializer(this->m_static);
429 serializer(this->m_sched_deck);
430 serializer(this->action_wgnames);
431 serializer(this->potential_wellopen_patterns);
432 serializer(this->exit_status);
433 serializer(this->snapshots);
434 serializer(this->restart_output);
435 serializer(this->completed_cells);
436 serializer(this->completed_cells_lgr);
437 serializer(this->completed_cells_lgr_map);
438 serializer(this->m_treat_critical_as_non_critical);
439 serializer(this->current_report_step);
440 serializer(this->m_lowActionParsingStrictness);
441 serializer(this->simUpdateFromPython);
450 for (
auto& snapshot : snapshots) {
451 for (
auto& well : snapshot.wells) {
452 well.second->updateUnitSystem(&m_static.m_unit_system);
458 template <
typename T>
459 std::vector<std::pair<std::size_t, T>> unique()
const
461 std::vector<std::pair<std::size_t, T>> values;
462 for (std::size_t index = 0; index < this->snapshots.size(); index++) {
463 const auto& member = this->snapshots[index].get<T>();
464 const auto& value = member.get();
465 if (values.empty() || !(value == values.back().second))
466 values.push_back( std::make_pair(index, value));
471 friend std::ostream& operator<<(std::ostream& os,
const Schedule& sched);
472 void dump_deck(std::ostream& os)
const;
475 friend class HandlerContext;
482 bool m_treat_critical_as_non_critical =
false;
486 std::unordered_set<std::string> potential_wellopen_patterns{};
487 std::optional<int> exit_status{};
488 std::vector<ScheduleState> snapshots{};
491 std::vector<CompletedCells> completed_cells_lgr{};
492 std::unordered_map<std::string, std::size_t> completed_cells_lgr_map;
497 bool m_lowActionParsingStrictness =
false;
502 std::unordered_map<std::string, std::set<int>> possibleFutureConnections;
507 std::size_t current_report_step = 0;
512 std::shared_ptr<SimulatorUpdate> simUpdateFromPython{};
514 void init_completed_cells_lgr(
const EclipseGrid& ecl_grid);
515 void init_completed_cells_lgr_map(
const EclipseGrid& ecl_grid);
521 void addWell(
Well well);
522 void addWell(
const std::string& wellName,
523 const std::string& group,
526 Phase preferredPhase,
527 const std::optional<double>& refDepth,
528 double drainageRadius,
530 bool automaticShutIn,
532 WellGasInflowEquation gas_inflow,
533 std::size_t timeStep,
534 ConnectionOrder wellConnectionOrder);
535 bool updateWPAVE(
const std::string& wname, std::size_t report_step,
const PAvg& pavg);
537 void updateGuideRateModel(
const GuideRateModel& new_model, std::size_t report_step);
538 GTNode groupTree(
const std::string& root_node, std::size_t report_step, std::size_t level,
const std::optional<std::string>& parent_name)
const;
539 bool updateWellStatus(
const std::string& well, std::size_t reportStep, WellStatus status, std::optional<KeywordLocation> = {});
540 void addWellToGroup(
const std::string& group_name,
const std::string& well_name , std::size_t timeStep);
541 void iterateScheduleSection(std::size_t load_start,
542 std::size_t load_end,
546 const std::unordered_map<std::string, double> * target_wellpi,
547 const std::string&
prefix,
548 const bool keepKeywords,
549 const bool log_to_debug =
false);
551 void addGroupToGroup(
const std::string& parent_group,
const std::string& child_group);
552 void addGroup(
const std::string& groupName , std::size_t timeStep);
553 void addGroup(
Group group);
555 void addWell(
const std::string& wellName,
const DeckRecord& record,
556 std::size_t timeStep, ConnectionOrder connection_order);
557 void checkIfAllConnectionsIsShut(std::size_t reportStep);
558 void end_report(std::size_t report_step);
561 void handleKeyword(std::size_t currentStep,
570 const std::unordered_map<std::string, double>* target_wellpi,
571 std::unordered_map<std::string, double>& wpimult_global_factor,
573 std::set<std::string>* compsegs_wells =
nullptr);
575 void internalWELLSTATUSACTIONXFromPYACTION(
const std::string& well_name, std::size_t report_step,
const std::string& wellStatus);
579 std::vector<std::string> wellNames(
const std::string& pattern,
580 const HandlerContext& context,
581 bool allowEmpty =
false);
582 static std::string formatDate(std::time_t t);
583 void applyGlobalWPIMULT(
const std::unordered_map<std::string, double>& wpimult_global_factor);
585 bool must_write_rst_file(std::size_t report_step)
const;
587 bool isWList(std::size_t report_step,
const std::string& pattern)
const;
589 SimulatorUpdate applyAction(std::size_t reportStep,
const std::string& action_name,
const std::vector<std::string>& matching_wells);