105 explicit Schedule(std::shared_ptr<const Python> python_handle);
128 std::shared_ptr<const Python> python,
129 const bool lowActionParsingStrictness =
false,
130 const bool slave_mode =
false,
131 const bool keepKeywords =
true,
132 const std::optional<int>& output_interval = {},
144 std::shared_ptr<const Python> python,
145 const bool lowActionParsingStrictness =
false,
146 const bool slave_mode =
false,
147 const bool keepKeywords =
true,
148 const std::optional<int>& output_interval = {},
157 std::shared_ptr<const Python> python,
158 const bool lowActionParsingStrictness =
false,
159 const bool slave_mode =
false,
160 const bool keepKeywords =
true,
161 const std::optional<int>& output_interval = {},
169 std::shared_ptr<const Python> python,
170 const bool lowActionParsingStrictness =
false,
171 const bool slave_mode =
false,
172 const bool keepKeywords =
true,
173 const std::optional<int>& output_interval = {},
176 template <
typename T>
181 std::shared_ptr<const Python> python,
182 const bool lowActionParsingStrictness =
false,
183 const bool slave_mode =
false,
184 const bool keepKeywords =
true,
185 const std::optional<int>& output_interval = {},
190 std::shared_ptr<const Python> python,
191 const bool lowActionParsingStrictness =
false,
192 const bool slave_mode =
false,
193 const bool keepKeywords =
true,
194 const std::optional<int>& output_interval = {},
200 const std::optional<int>& output_interval = {},
205 static Schedule serializationTestObject();
211 std::time_t getStartTime()
const;
212 std::time_t posixStartTime()
const;
213 std::time_t posixEndTime()
const;
214 std::time_t simTime(std::size_t timeStep)
const;
215 double seconds(std::size_t timeStep)
const;
216 double stepLength(std::size_t timeStep)
const;
217 std::optional<int> exitStatus()
const;
218 const UnitSystem& getUnits()
const {
return this->m_static.m_unit_system; }
219 const Runspec& runspec()
const {
return this->m_static.m_runspec; }
221 std::size_t numWells()
const;
222 std::size_t numWells(std::size_t timestep)
const;
223 bool hasWell(
const std::string& wellName)
const;
224 bool hasWell(
const std::string& wellName, std::size_t timeStep)
const;
226 WellMatcher wellMatcher(std::size_t report_step)
const;
227 std::function<std::unique_ptr<SegmentMatcher>()> segmentMatcherFactory(std::size_t report_step)
const;
228 std::vector<std::string> wellNames(
const std::string& pattern, std::size_t timeStep,
const std::vector<std::string>& matching_wells = {})
const;
229 std::vector<std::string> wellNames(
const std::string& pattern)
const;
230 std::vector<std::string> wellNames(std::size_t timeStep)
const;
231 std::vector<std::string> wellNames()
const;
240 bool hasGroup(
const std::string& groupName, std::size_t timeStep)
const;
253 std::vector<std::string>
254 groupNames(
const std::string& pattern, std::size_t timeStep)
const;
262 const std::vector<std::string>&
groupNames(std::size_t timeStep)
const;
272 std::vector<std::string>
groupNames(
const std::string& pattern)
const;
277 const std::vector<std::string>&
groupNames()
const;
289 std::vector<const Group*>
restart_groups(std::size_t timeStep)
const;
291 std::vector<std::string>
292 changed_wells(std::size_t reportStep,
293 std::size_t initialStep = 0)
const;
295 const Well& getWell(std::size_t well_index, std::size_t timeStep)
const;
296 const Well& getWell(
const std::string& wellName, std::size_t timeStep)
const;
297 const Well& getWellatEnd(
const std::string& well_name)
const;
299 std::unordered_set<int> getAquiferFluxSchedule()
const;
300 std::vector<Well> getWells(std::size_t timeStep)
const;
301 std::vector<Well> getWellsatEnd()
const;
304 std::vector<Well> getActiveWellsAtEnd()
const;
307 std::vector<std::string> getInactiveWellNamesAtEnd()
const;
309 const std::unordered_map<std::string, std::set<int>>&
310 getPossibleFutureConnections()
const;
312 void shut_well(
const std::string& well_name, std::size_t report_step);
313 void shut_well(
const std::string& well_name);
314 void stop_well(
const std::string& well_name, std::size_t report_step);
315 void stop_well(
const std::string& well_name);
316 void open_well(
const std::string& well_name, std::size_t report_step);
317 void open_well(
const std::string& well_name);
318 void clear_event(ScheduleEvents::Events, std::size_t report_step);
319 void add_event(ScheduleEvents::Events, std::size_t report_step);
320 void applyWellProdIndexScaling(
const std::string& well_name,
const std::size_t reportStep,
const double scalingFactor);
325 WellProducerCMode getGlobalWhistctlMmode(std::size_t timestep)
const;
327 const UDQConfig& getUDQConfig(std::size_t timeStep)
const;
328 void evalAction(
const SummaryState& summary_state, std::size_t timeStep);
330 GTNode groupTree(std::size_t report_step)
const;
331 GTNode groupTree(
const std::string& root_node, std::size_t report_step)
const;
332 const Group& getGroup(
const std::string& groupName, std::size_t timeStep)
const;
334 std::optional<std::size_t> first_RFT()
const;
340 std::size_t size()
const;
342 bool write_rst_file(std::size_t report_step)
const;
343 const std::map< std::string, int >& rst_keywords(
size_t timestep )
const;
353 const std::unordered_map<std::string, double>& wellpi);
358 const std::unordered_map<std::string, float>& wellpi);
377 const std::unordered_map<std::string, double>& target_wellpi);
384 const std::unordered_map<std::string, float>& target_wellpi);
387 const std::map<std::string, std::vector<Connection>>& extraConns);
389 const GasLiftOpt& glo(std::size_t report_step)
const;
391 bool operator==(
const Schedule& data)
const;
392 std::shared_ptr<const Python> python()
const;
397 std::vector<ScheduleState>::const_iterator begin()
const;
398 std::vector<ScheduleState>::const_iterator end()
const;
399 void create_next(
const time_point& start_time,
const std::optional<time_point>& end_time);
401 void create_first(
const time_point& start_time,
const std::optional<time_point>& end_time);
403 void treat_critical_as_non_critical(
bool value) { this->m_treat_critical_as_non_critical = value; }
411 static bool cmp(
const Schedule& sched1,
const Schedule& sched2, std::size_t report_step);
412 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);
413 void applyKeywords(std::vector<std::unique_ptr<DeckKeyword>>& keywords, std::unordered_map<std::string, double>& target_wellpi,
bool action_mode);
415 template<
class Serializer>
418 serializer(this->m_static);
419 serializer(this->m_sched_deck);
420 serializer(this->action_wgnames);
421 serializer(this->potential_wellopen_patterns);
422 serializer(this->exit_status);
423 serializer(this->snapshots);
424 serializer(this->restart_output);
425 serializer(this->completed_cells);
426 serializer(this->completed_cells_lgr);
427 serializer(this->completed_cells_lgr_map);
428 serializer(this->m_treat_critical_as_non_critical);
429 serializer(this->current_report_step);
430 serializer(this->m_lowActionParsingStrictness);
431 serializer(this->simUpdateFromPython);
440 for (
auto& snapshot : snapshots) {
441 for (
auto& well : snapshot.wells) {
442 well.second->updateUnitSystem(&m_static.m_unit_system);
448 template <
typename T>
449 std::vector<std::pair<std::size_t, T>> unique()
const
451 std::vector<std::pair<std::size_t, T>> values;
452 for (std::size_t index = 0; index < this->snapshots.size(); index++) {
453 const auto& member = this->snapshots[index].get<T>();
454 const auto& value = member.get();
455 if (values.empty() || !(value == values.back().second))
456 values.push_back( std::make_pair(index, value));
461 friend std::ostream& operator<<(std::ostream& os,
const Schedule& sched);
462 void dump_deck(std::ostream& os)
const;
472 bool m_treat_critical_as_non_critical =
false;
476 std::unordered_set<std::string> potential_wellopen_patterns{};
477 std::optional<int> exit_status{};
478 std::vector<ScheduleState> snapshots{};
481 std::vector<CompletedCells> completed_cells_lgr{};
482 std::unordered_map<std::string, std::size_t> completed_cells_lgr_map;
487 bool m_lowActionParsingStrictness =
false;
492 std::unordered_map<std::string, std::set<int>> possibleFutureConnections;
497 std::size_t current_report_step = 0;
502 std::shared_ptr<SimulatorUpdate> simUpdateFromPython{};
504 void init_completed_cells_lgr(
const EclipseGrid& ecl_grid);
505 void init_completed_cells_lgr_map(
const EclipseGrid& ecl_grid);
511 void addWell(
Well well);
512 void addWell(
const std::string& wellName,
513 const std::string& group,
516 Phase preferredPhase,
517 const std::optional<double>& refDepth,
518 double drainageRadius,
520 bool automaticShutIn,
522 WellGasInflowEquation gas_inflow,
523 std::size_t timeStep,
524 ConnectionOrder wellConnectionOrder);
525 bool updateWPAVE(
const std::string& wname, std::size_t report_step,
const PAvg& pavg);
527 void updateGuideRateModel(
const GuideRateModel& new_model, std::size_t report_step);
528 GTNode groupTree(
const std::string& root_node, std::size_t report_step, std::size_t level,
const std::optional<std::string>& parent_name)
const;
530 bool updateWellStatus(
const std::string& well, std::size_t reportStep, WellStatus status, std::optional<KeywordLocation> = {});
531 void addWellToGroup(
const std::string& group_name,
const std::string& well_name , std::size_t timeStep);
532 void iterateScheduleSection(std::size_t load_start,
533 std::size_t load_end,
537 const std::unordered_map<std::string, double> * target_wellpi,
538 const std::string& prefix,
539 const bool keepKeywords,
540 const bool log_to_debug =
false);
542 void addGroupToGroup(
const std::string& parent_group,
const std::string& child_group);
543 void addGroup(
const std::string& groupName , std::size_t timeStep);
544 void addGroup(
Group group);
546 void addWell(
const std::string& wellName,
const DeckRecord& record,
547 std::size_t timeStep, ConnectionOrder connection_order);
548 void checkIfAllConnectionsIsShut(std::size_t currentStep);
549 void end_report(std::size_t report_step);
552 void handleKeyword(std::size_t currentStep,
561 const std::unordered_map<std::string, double>* target_wellpi,
562 std::unordered_map<std::string, double>& wpimult_global_factor,
564 std::set<std::string>* compsegs_wells =
nullptr);
566 void internalWELLSTATUSACTIONXFromPYACTION(
const std::string& well_name, std::size_t report_step,
const std::string& wellStatus);
570 std::vector<std::string> wellNames(
const std::string& pattern,
572 bool allowEmpty =
false);
573 std::vector<std::string> wellNames(
const std::string& pattern, std::size_t timeStep,
const std::vector<std::string>& matching_wells, InputErrorAction error_action,
ErrorGuard& errors,
const KeywordLocation& location)
const;
574 static std::string formatDate(std::time_t t);
575 std::string simulationDays(std::size_t currentStep)
const;
576 void applyGlobalWPIMULT(
const std::unordered_map<std::string, double>& wpimult_global_factor);
578 bool must_write_rst_file(std::size_t report_step)
const;
580 bool isWList(std::size_t report_step,
const std::string& pattern)
const;
582 SimulatorUpdate applyAction(std::size_t reportStep,
const std::string& action_name,
const std::vector<std::string>& matching_wells);