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> changed_wells(std::size_t reportStep)
const;
292 const Well& getWell(std::size_t well_index, std::size_t timeStep)
const;
293 const Well& getWell(
const std::string& wellName, std::size_t timeStep)
const;
294 const Well& getWellatEnd(
const std::string& well_name)
const;
296 std::unordered_set<int> getAquiferFluxSchedule()
const;
297 std::vector<Well> getWells(std::size_t timeStep)
const;
298 std::vector<Well> getWellsatEnd()
const;
301 std::vector<Well> getActiveWellsAtEnd()
const;
304 std::vector<std::string> getInactiveWellNamesAtEnd()
const;
306 const std::unordered_map<std::string, std::set<int>>&
307 getPossibleFutureConnections()
const;
309 void shut_well(
const std::string& well_name, std::size_t report_step);
310 void shut_well(
const std::string& well_name);
311 void stop_well(
const std::string& well_name, std::size_t report_step);
312 void stop_well(
const std::string& well_name);
313 void open_well(
const std::string& well_name, std::size_t report_step);
314 void open_well(
const std::string& well_name);
315 void clear_event(ScheduleEvents::Events, std::size_t report_step);
316 void add_event(ScheduleEvents::Events, std::size_t report_step);
317 void applyWellProdIndexScaling(
const std::string& well_name,
const std::size_t reportStep,
const double scalingFactor);
322 WellProducerCMode getGlobalWhistctlMmode(std::size_t timestep)
const;
324 const UDQConfig& getUDQConfig(std::size_t timeStep)
const;
325 void evalAction(
const SummaryState& summary_state, std::size_t timeStep);
327 GTNode groupTree(std::size_t report_step)
const;
328 GTNode groupTree(
const std::string& root_node, std::size_t report_step)
const;
329 const Group& getGroup(
const std::string& groupName, std::size_t timeStep)
const;
331 std::optional<std::size_t> first_RFT()
const;
337 std::size_t size()
const;
339 bool write_rst_file(std::size_t report_step)
const;
340 const std::map< std::string, int >& rst_keywords(
size_t timestep )
const;
350 const std::unordered_map<std::string, double>& wellpi);
355 const std::unordered_map<std::string, float>& wellpi);
374 const std::unordered_map<std::string, double>& target_wellpi);
381 const std::unordered_map<std::string, float>& target_wellpi);
384 const std::map<std::string, std::vector<Connection>>& extraConns);
386 const GasLiftOpt& glo(std::size_t report_step)
const;
388 bool operator==(
const Schedule& data)
const;
389 std::shared_ptr<const Python> python()
const;
394 std::vector<ScheduleState>::const_iterator begin()
const;
395 std::vector<ScheduleState>::const_iterator end()
const;
396 void create_next(
const time_point& start_time,
const std::optional<time_point>& end_time);
398 void create_first(
const time_point& start_time,
const std::optional<time_point>& end_time);
400 void treat_critical_as_non_critical(
bool value) { this->m_treat_critical_as_non_critical = value; }
408 static bool cmp(
const Schedule& sched1,
const Schedule& sched2, std::size_t report_step);
409 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);
410 void applyKeywords(std::vector<std::unique_ptr<DeckKeyword>>& keywords, std::unordered_map<std::string, double>& target_wellpi,
bool action_mode);
412 template<
class Serializer>
415 serializer(this->m_static);
416 serializer(this->m_sched_deck);
417 serializer(this->action_wgnames);
418 serializer(this->potential_wellopen_patterns);
419 serializer(this->exit_status);
420 serializer(this->snapshots);
421 serializer(this->restart_output);
422 serializer(this->completed_cells);
423 serializer(this->completed_cells_lgr);
424 serializer(this->completed_cells_lgr_map);
425 serializer(this->m_treat_critical_as_non_critical);
426 serializer(this->current_report_step);
427 serializer(this->m_lowActionParsingStrictness);
428 serializer(this->simUpdateFromPython);
437 for (
auto& snapshot : snapshots) {
438 for (
auto& well : snapshot.wells) {
439 well.second->updateUnitSystem(&m_static.m_unit_system);
445 template <
typename T>
446 std::vector<std::pair<std::size_t, T>> unique()
const
448 std::vector<std::pair<std::size_t, T>> values;
449 for (std::size_t index = 0; index < this->snapshots.size(); index++) {
450 const auto& member = this->snapshots[index].get<T>();
451 const auto& value = member.get();
452 if (values.empty() || !(value == values.back().second))
453 values.push_back( std::make_pair(index, value));
458 friend std::ostream& operator<<(std::ostream& os,
const Schedule& sched);
459 void dump_deck(std::ostream& os)
const;
469 bool m_treat_critical_as_non_critical =
false;
473 std::unordered_set<std::string> potential_wellopen_patterns{};
474 std::optional<int> exit_status{};
475 std::vector<ScheduleState> snapshots{};
478 std::vector<CompletedCells> completed_cells_lgr{};
479 std::unordered_map<std::string, std::size_t> completed_cells_lgr_map;
484 bool m_lowActionParsingStrictness =
false;
489 std::unordered_map<std::string, std::set<int>> possibleFutureConnections;
494 std::size_t current_report_step = 0;
499 std::shared_ptr<SimulatorUpdate> simUpdateFromPython{};
501 void init_completed_cells_lgr(
const EclipseGrid& ecl_grid);
502 void init_completed_cells_lgr_map(
const EclipseGrid& ecl_grid);
508 void addWell(
Well well);
509 void addWell(
const std::string& wellName,
510 const std::string& group,
513 Phase preferredPhase,
514 const std::optional<double>& refDepth,
515 double drainageRadius,
517 bool automaticShutIn,
519 WellGasInflowEquation gas_inflow,
520 std::size_t timeStep,
521 ConnectionOrder wellConnectionOrder);
522 bool updateWPAVE(
const std::string& wname, std::size_t report_step,
const PAvg& pavg);
524 void updateGuideRateModel(
const GuideRateModel& new_model, std::size_t report_step);
525 GTNode groupTree(
const std::string& root_node, std::size_t report_step, std::size_t level,
const std::optional<std::string>& parent_name)
const;
527 bool updateWellStatus(
const std::string& well, std::size_t reportStep, WellStatus status, std::optional<KeywordLocation> = {});
528 void addWellToGroup(
const std::string& group_name,
const std::string& well_name , std::size_t timeStep);
529 void iterateScheduleSection(std::size_t load_start,
530 std::size_t load_end,
534 const std::unordered_map<std::string, double> * target_wellpi,
535 const std::string& prefix,
536 const bool keepKeywords,
537 const bool log_to_debug =
false);
539 void addGroupToGroup(
const std::string& parent_group,
const std::string& child_group);
540 void addGroup(
const std::string& groupName , std::size_t timeStep);
541 void addGroup(
Group group);
543 void addWell(
const std::string& wellName,
const DeckRecord& record,
544 std::size_t timeStep, ConnectionOrder connection_order);
545 void checkIfAllConnectionsIsShut(std::size_t currentStep);
546 void end_report(std::size_t report_step);
549 void handleKeyword(std::size_t currentStep,
558 const std::unordered_map<std::string, double>* target_wellpi,
559 std::unordered_map<std::string, double>& wpimult_global_factor,
561 std::set<std::string>* compsegs_wells =
nullptr);
563 void internalWELLSTATUSACTIONXFromPYACTION(
const std::string& well_name, std::size_t report_step,
const std::string& wellStatus);
567 std::vector<std::string> wellNames(
const std::string& pattern,
569 bool allowEmpty =
false);
570 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;
571 static std::string formatDate(std::time_t t);
572 std::string simulationDays(std::size_t currentStep)
const;
573 void applyGlobalWPIMULT(
const std::unordered_map<std::string, double>& wpimult_global_factor);
575 bool must_write_rst_file(std::size_t report_step)
const;
577 bool isWList(std::size_t report_step,
const std::string& pattern)
const;
579 SimulatorUpdate applyAction(std::size_t reportStep,
const std::string& action_name,
const std::vector<std::string>& matching_wells);