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;
309 std::vector<std::string>
311 std::size_t initialStep = 0)
const;
331 std::size_t initialStep = 0)
const;
333 const Well& getWell(std::size_t well_index, std::size_t timeStep)
const;
334 const Well& getWell(
const std::string& wellName, std::size_t timeStep)
const;
335 const Well& getWellatEnd(
const std::string& well_name)
const;
337 std::unordered_set<int> getAquiferFluxSchedule()
const;
338 std::vector<Well> getWells(std::size_t timeStep)
const;
339 std::vector<Well> getWellsatEnd()
const;
342 std::vector<Well> getActiveWellsAtEnd()
const;
345 std::vector<std::string> getInactiveWellNamesAtEnd()
const;
347 const std::unordered_map<std::string, std::set<int>>&
348 getPossibleFutureConnections()
const;
350 void shut_well(
const std::string& well_name, std::size_t report_step);
351 void shut_well(
const std::string& well_name);
352 void stop_well(
const std::string& well_name, std::size_t report_step);
353 void stop_well(
const std::string& well_name);
354 void open_well(
const std::string& well_name, std::size_t report_step);
355 void open_well(
const std::string& well_name);
356 void clear_event(ScheduleEvents::Events, std::size_t report_step);
357 void add_event(ScheduleEvents::Events, std::size_t report_step);
358 void applyWellProdIndexScaling(
const std::string& well_name,
const std::size_t reportStep,
const double scalingFactor);
363 WellProducerCMode getGlobalWhistctlMmode(std::size_t timestep)
const;
365 const UDQConfig& getUDQConfig(std::size_t timeStep)
const;
367 GTNode groupTree(std::size_t report_step)
const;
368 GTNode groupTree(
const std::string& root_node, std::size_t report_step)
const;
369 const Group& getGroup(
const std::string& groupName, std::size_t timeStep)
const;
371 std::optional<std::size_t> first_RFT()
const;
372 std::size_t size()
const;
374 bool write_rst_file(std::size_t report_step)
const;
375 const std::map< std::string, int >& rst_keywords(
size_t timestep )
const;
385 const std::unordered_map<std::string, double>& wellpi,
386 const bool iterateSchedule);
391 const std::unordered_map<std::string, float>& wellpi,
392 const bool iterateSchedule);
411 const std::unordered_map<std::string, double>& target_wellpi);
418 const std::unordered_map<std::string, float>& target_wellpi);
421 const std::map<std::string, std::vector<Connection>>& extraConns);
423 const GasLiftOpt& glo(std::size_t report_step)
const;
425 bool operator==(
const Schedule& data)
const;
426 std::shared_ptr<const Python> python()
const;
438 std::vector<ScheduleState>::const_iterator begin()
const;
439 std::vector<ScheduleState>::const_iterator end()
const;
440 void create_next(
const time_point& start_time,
const std::optional<time_point>& end_time);
442 void create_first(
const time_point& start_time,
const std::optional<time_point>& end_time);
444 void treat_critical_as_non_critical(
bool value) { this->m_treat_critical_as_non_critical = value; }
452 static bool cmp(
const Schedule& sched1,
const Schedule& sched2, std::size_t report_step);
453 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);
454 void applyKeywords(std::vector<std::unique_ptr<DeckKeyword>>& keywords, std::unordered_map<std::string, double>& target_wellpi,
bool action_mode);
456 template<
class Serializer>
459 serializer(this->m_static);
460 serializer(this->m_sched_deck);
461 serializer(this->action_wgnames);
462 serializer(this->potential_wellopen_patterns);
463 serializer(this->exit_status);
464 serializer(this->snapshots);
465 serializer(this->restart_output);
466 serializer(this->completed_cells);
467 serializer(this->completed_cells_lgr);
468 serializer(this->completed_cells_lgr_map);
469 serializer(this->m_treat_critical_as_non_critical);
470 serializer(this->current_report_step);
471 serializer(this->m_lowActionParsingStrictness);
472 serializer(this->simUpdateFromPython);
481 for (
auto& snapshot : snapshots) {
482 for (
auto& well : snapshot.wells) {
483 well.second->updateUnitSystem(&m_static.m_unit_system);
489 template <
typename T>
490 std::vector<std::pair<std::size_t, T>> unique()
const
492 std::vector<std::pair<std::size_t, T>> values;
493 for (std::size_t index = 0; index < this->snapshots.size(); index++) {
494 const auto& member = this->snapshots[index].get<T>();
495 const auto& value = member.get();
496 if (values.empty() || !(value == values.back().second))
497 values.push_back( std::make_pair(index, value));
502 friend std::ostream& operator<<(std::ostream& os,
const Schedule& sched);
503 void dump_deck(std::ostream& os)
const;
506 friend class HandlerContext;
513 bool m_treat_critical_as_non_critical =
false;
517 std::unordered_set<std::string> potential_wellopen_patterns{};
518 std::optional<int> exit_status{};
519 std::vector<ScheduleState> snapshots{};
522 std::vector<CompletedCells> completed_cells_lgr{};
523 std::unordered_map<std::string, std::size_t> completed_cells_lgr_map;
528 bool m_lowActionParsingStrictness =
false;
533 std::unordered_map<std::string, std::set<int>> possibleFutureConnections;
538 std::size_t current_report_step = 0;
543 std::shared_ptr<SimulatorUpdate> simUpdateFromPython{};
545 void init_completed_cells_lgr(
const EclipseGrid& ecl_grid);
546 void init_completed_cells_lgr_map(
const EclipseGrid& ecl_grid);
552 void addWell(
Well well);
553 void addWell(
const std::string& wellName,
554 const std::string& group,
557 Phase preferredPhase,
558 const std::optional<double>& refDepth,
559 double drainageRadius,
561 bool automaticShutIn,
563 WellGasInflowEquation gas_inflow,
564 std::size_t timeStep,
565 ConnectionOrder wellConnectionOrder);
566 bool updateWPAVE(
const std::string& wname, std::size_t report_step,
const PAvg& pavg);
568 void updateGuideRateModel(
const GuideRateModel& new_model, std::size_t report_step);
569 GTNode groupTree(
const std::string& root_node, std::size_t report_step, std::size_t level,
const std::optional<std::string>& parent_name)
const;
570 bool updateWellStatus(
const std::string& well, std::size_t reportStep, WellStatus status, std::optional<KeywordLocation> = {});
571 void addWellToGroup(
const std::string& group_name,
const std::string& well_name , std::size_t timeStep);
572 void iterateScheduleSection(std::size_t load_start,
573 std::size_t load_end,
577 const std::unordered_map<std::string, double> * target_wellpi,
578 const std::string&
prefix,
579 const bool keepKeywords,
580 const bool log_to_debug =
false);
582 void addGroupToGroup(
const std::string& parent_group,
const std::string& child_group);
583 void addGroup(
const std::string& groupName , std::size_t timeStep);
584 void addGroup(
Group group);
586 void addWell(
const std::string& wellName,
const DeckRecord& record,
587 std::size_t timeStep, ConnectionOrder connection_order);
588 void checkIfAllConnectionsIsShut(std::size_t reportStep);
589 void end_report(std::size_t report_step);
592 void handleKeyword(std::size_t currentStep,
601 const std::unordered_map<std::string, double>* target_wellpi,
602 std::unordered_map<std::string, double>& wpimult_global_factor,
604 std::set<std::string>* compsegs_wells =
nullptr,
605 std::set<std::string>* comptraj_wells =
nullptr);
607 void internalWELLSTATUSACTIONXFromPYACTION(
const std::string& well_name, std::size_t report_step,
const std::string& wellStatus);
611 std::vector<std::string> wellNames(
const std::string& pattern,
612 const HandlerContext& context,
613 bool allowEmpty =
false);
614 static std::string formatDate(std::time_t t);
615 void applyGlobalWPIMULT(
const std::unordered_map<std::string, double>& wpimult_global_factor);
616 void updateICDScalingFactors();
618 bool must_write_rst_file(std::size_t report_step)
const;
620 bool isWList(std::size_t report_step,
const std::string& pattern)
const;
622 SimulatorUpdate applyAction(std::size_t reportStep,
const std::string& action_name,
const std::vector<std::string>& matching_wells);