void TableColumn::applyDefaults( const TableColumn& argColumn ) { if (m_schema.getDefaultMode() == Table::DEFAULT_LINEAR) { if (size() != argColumn.size()) throw std::invalid_argument("Size mismatch with argument column"); for (size_t rowIdx = 0; rowIdx < size(); ++rowIdx) { if (defaultApplied( rowIdx )) { // find first row which was not defaulted before the current one ssize_t rowBeforeIdx = rowIdx; for (; rowBeforeIdx >= 0; -- rowBeforeIdx) if (!defaultApplied(rowBeforeIdx)) break; // find first row which was not defaulted after the current one ssize_t rowAfterIdx = rowIdx; for (; rowAfterIdx < static_cast<ssize_t>(size()); ++ rowAfterIdx) if (!defaultApplied(rowAfterIdx)) break; // switch to extrapolation by a constant at the fringes if (rowBeforeIdx < 0 && rowAfterIdx >= static_cast<ssize_t>(size())) throw std::invalid_argument("Column " + m_schema.name() + " can't be fully defaulted"); else if (rowBeforeIdx < 0) rowBeforeIdx = rowAfterIdx; else if (rowAfterIdx >= static_cast<ssize_t>(size())) rowAfterIdx = rowBeforeIdx; { // linear interpolation double alpha = 0.0; if (rowBeforeIdx != rowAfterIdx) alpha = (argColumn[rowIdx] - argColumn[rowBeforeIdx]) / (argColumn[rowAfterIdx] - argColumn[rowBeforeIdx]); double value = m_values[rowBeforeIdx]*(1-alpha) + m_values[rowAfterIdx]*alpha; updateValue( rowIdx , value ); } } } } }
WellProductionProperties WellProductionProperties::history(DeckRecordConstPtr record) { WellProductionProperties p(record); p.predictionMode = false; // Modes supported in WCONHIST just from {O,W,G}RAT values // // Note: The default value of observed {O,W,G}RAT is zero // (numerically) whence the following control modes are // unconditionally supported. const std::vector<std::string> controlModes{ "ORAT", "WRAT", "GRAT", "LRAT", "RESV" }; for (std::vector<std::string>::const_iterator mode = controlModes.begin(), end = controlModes.end(); mode != end; ++mode) { const WellProducer::ControlModeEnum cmode = WellProducer::ControlModeFromString(*mode); p.addProductionControl(cmode); } // BHP control must be explictly provided. if (!record->getItem("BHP")->defaultApplied(0)) { p.addProductionControl(WellProducer::BHP); } { const auto cmodeItem = record->getItem("CMODE"); if (!cmodeItem->defaultApplied(0)) { const WellProducer::ControlModeEnum cmode = WellProducer::ControlModeFromString( cmodeItem->getString(0) ); if (p.hasProductionControl( cmode )) p.controlMode = cmode; else throw std::invalid_argument("Setting CMODE to unspecified control"); } } return p; }
bool DeckItem::hasData(size_t index) const { return defaultApplied(index) || wasSetInDeck(index); }