//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicfSetTimeStep::execute() { RimEclipseCase* eclipseCase = nullptr; { bool foundCase = false; for (RimEclipseCase* c : RiaApplication::instance()->project()->activeOilField()->analysisModels()->cases) { if (c->caseId == m_caseId) { eclipseCase = c; foundCase = true; break; } } if (!foundCase) { RiaLogging::error(QString("setTimeStep: Could not find case with ID %1").arg(m_caseId())); return; } } for (Rim3dView* view : eclipseCase->views()) { view->setCurrentTimeStepAndUpdate(m_timeStepIndex); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector<const RigWellPath*> RimSimWellInView::wellPipeBranches() const { RimSimWellInViewCollection* simWellCollection = nullptr; this->firstAncestorOrThisOfTypeAsserted(simWellCollection); RimEclipseCase* eclipseCase = nullptr; this->firstAncestorOrThisOfTypeAsserted(eclipseCase); RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData(); CVF_ASSERT(caseData); bool includeCellCenters = this->isUsingCellCenterForPipe(); bool detectBrances = simWellCollection->isAutoDetectingBranches; return caseData->simulationWellBranches(this->name(), includeCellCenters, detectBrances); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set<QString> RimWellLogExtractionCurve::findSortedWellNames() { std::set<QString> sortedWellNames; RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); if ( eclipseCase && eclipseCase->eclipseCaseData() ) { const cvf::Collection<RigSimWellData>& simWellData = eclipseCase->eclipseCaseData()->wellResults(); for ( size_t wIdx = 0; wIdx < simWellData.size(); ++wIdx ) { sortedWellNames.insert(simWellData[wIdx]->m_wellName); } } return sortedWellNames; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimSimWellInViewCollection::assignDefaultWellColors() { RimEclipseCase* ownerCase; firstAncestorOrThisOfTypeAsserted(ownerCase); for (size_t wIdx = 0; wIdx < wells.size(); ++wIdx) { RimSimWellInView* well = wells[wIdx]; if (well && well->simWellData() ) { well->wellPipeColor = ownerCase->defaultWellColor(well->simWellData()->m_wellName); } } RimSimWellInViewCollection::updateWellAllocationPlots(); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicPasteEclipseViewsFeature::onActionTriggered(bool isChecked) { PdmObjectHandle* destinationObject = dynamic_cast<PdmObjectHandle*>(SelectionManager::instance()->selectedItem()); RimEclipseCase* eclipseCase = RicPasteFeatureImpl::findEclipseCase(destinationObject); assert(eclipseCase); PdmObjectGroup objectGroup; RicPasteFeatureImpl::findObjectsFromClipboardRefs(&objectGroup); if (objectGroup.objects.size() == 0) return; std::vector<caf::PdmPointer<RimEclipseView> > eclipseViews; objectGroup.objectsByType(&eclipseViews); // Add cases to case group for (size_t i = 0; i < eclipseViews.size(); i++) { RimEclipseView* rimReservoirView = dynamic_cast<RimEclipseView*>(eclipseViews[i]->xmlCapability()->copyByXmlSerialization(PdmDefaultObjectFactory::instance())); CVF_ASSERT(rimReservoirView); QString nameOfCopy = QString("Copy of ") + rimReservoirView->name; rimReservoirView->name = nameOfCopy; eclipseCase->reservoirViews().push_back(rimReservoirView); rimReservoirView->setEclipseCase(eclipseCase); // Resolve references after reservoir view has been inserted into Rim structures // Intersections referencing a well path/ simulation well requires this // TODO: initAfterReadRecursively can probably be removed rimReservoirView->initAfterReadRecursively(); rimReservoirView->resolveReferencesRecursively(); rimReservoirView->loadDataAndUpdate(); caf::PdmDocument::updateUiIconStateRecursively(rimReservoirView); eclipseCase->updateConnectedEditors(); } }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { int caseId = args[1].toInt(); RimEclipseCase* rimCase = server->findReservoir(caseId); if (!rimCase) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID : \"%1\"").arg(caseId)); return true; } std::vector<QString> wellNames; const cvf::Collection<RigSingleWellResultsData>& wells = rimCase->reservoirData()->wellResults(); for (size_t wIdx = 0; wIdx < wells.size(); ++wIdx) { wellNames.push_back(wells[wIdx]->m_wellName); } quint64 byteCount = sizeof(quint64); quint64 wellCount = wellNames.size(); for (size_t wIdx = 0; wIdx < wellCount; wIdx++) { byteCount += wellNames[wIdx].size() * sizeof(QChar); } socketStream << byteCount; socketStream << wellCount; for (size_t wIdx = 0; wIdx < wellCount; wIdx++) { socketStream << wellNames[wIdx]; } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rim3dWellLogExtractionCurve::curveValuesAndMds(std::vector<double>* values, std::vector<double>* measuredDepthValues) const { CAF_ASSERT(values != nullptr); CAF_ASSERT(measuredDepthValues != nullptr); cvf::ref<RigEclipseWellLogExtractor> eclExtractor; cvf::ref<RigGeoMechWellLogExtractor> geomExtractor; RimWellPath* wellPath; firstAncestorOrThisOfType(wellPath); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case()); if (eclipseCase) { eclExtractor = RiaExtractionTools::wellLogExtractorEclipseCase(wellPath, eclipseCase); } else { RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case()); if (geomCase) { geomExtractor = RiaExtractionTools::wellLogExtractorGeoMechCase(wellPath, geomCase); } } if (eclExtractor.notNull() && eclipseCase) { *measuredDepthValues = eclExtractor->measuredDepth(); m_eclipseResultDefinition->loadResult(); cvf::ref<RigResultAccessor> resAcc = RigResultAccessorFactory::createFromResultDefinition(eclipseCase->eclipseCaseData(), 0, m_timeStep, m_eclipseResultDefinition); if (resAcc.notNull()) { eclExtractor->curveData(resAcc.p(), values); } } else if (geomExtractor.notNull()) { *measuredDepthValues = geomExtractor->measuredDepth(); m_geomResultDefinition->loadResult(); geomExtractor->curveData(m_geomResultDefinition->resultAddress(), m_timeStep, values); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RimWellLogExtractionCurve::wellDate() const { RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value()); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); QStringList timeStepNames; if (eclipseCase) { if (eclipseCase->eclipseCaseData()) { timeStepNames = eclipseCase->timeStepStrings(); } } else if (geomCase) { if (geomCase->geoMechData()) { timeStepNames = geomCase->timeStepStrings(); } } return (m_timeStep >= 0 && m_timeStep < timeStepNames.size()) ? timeStepNames[m_timeStep] : ""; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RimWellLogExtractionCurve::createCurveAutoName() { RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value()); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); QStringList generatedCurveName; if (m_addWellNameToCurveName) { if (!wellName().isEmpty()) { generatedCurveName += wellName(); if (m_trajectoryType == SIMULATION_WELL && simulationWellBranches().size() > 1) { generatedCurveName.push_back(" Br" + QString::number(m_branchIndex + 1)); } } } if (m_addCaseNameToCurveName && m_case()) { generatedCurveName.push_back(m_case->caseUserDescription()); } if (m_addPropertyToCurveName && !wellLogChannelName().isEmpty()) { generatedCurveName.push_back(wellLogChannelName()); } if (m_addTimestepToCurveName || m_addDateToCurveName) { size_t maxTimeStep = 0; if (eclipseCase) { if (eclipseCase->eclipseCaseData()) { maxTimeStep = eclipseCase->eclipseCaseData()->results(m_eclipseResultDefinition->porosityModel())->maxTimeStepCount(); } } else if (geomCase) { if (geomCase->geoMechData()) { maxTimeStep = geomCase->geoMechData()->femPartResults()->frameCount(); } } if (m_addDateToCurveName) { QString dateString = wellDate(); if (!dateString.isEmpty()) { generatedCurveName.push_back(dateString); } } if (m_addTimestepToCurveName) { generatedCurveName.push_back(QString("[%1/%2]").arg(m_timeStep()).arg(maxTimeStep)); } } return generatedCurveName.join(", "); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { int caseId = args[1].toInt(); QString wellName = args[2]; size_t timeStepIdx = args[3].toInt() - 1; // Interpret timeStepIdx from octave as 1-based RimEclipseCase* rimCase = server->findReservoir(caseId); if (!rimCase) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID : \"%1\"").arg(caseId)); socketStream << (quint64)0; return true; } const cvf::Collection<RigSingleWellResultsData>& allWellRes = rimCase->reservoirData()->wellResults(); cvf::ref<RigSingleWellResultsData> currentWellResult; for (size_t cIdx = 0; cIdx < allWellRes.size(); ++cIdx) { if (allWellRes[cIdx]->m_wellName == wellName) { currentWellResult = allWellRes[cIdx]; break; } } if (currentWellResult.isNull()) { server->errorMessageDialog()->showMessage( RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the well with name : \"%1\"").arg(wellName)); socketStream << (quint64)0; return true; } if (!currentWellResult->hasWellResult(timeStepIdx)) { socketStream << (quint64)0; return true; } std::vector<qint32> cellIs; std::vector<qint32> cellJs; std::vector<qint32> cellKs; std::vector<qint32> gridIndices; std::vector<qint32> cellStatuses; std::vector<qint32> branchIds; std::vector<qint32> segmentIds; // Fetch results const RigWellResultFrame& wellResFrame = currentWellResult->wellResultFrame(timeStepIdx); std::vector<RigGridBase*> grids; rimCase->reservoirData()->allGrids(&grids); for (size_t bIdx = 0; bIdx < wellResFrame.m_wellResultBranches.size(); ++bIdx) { const std::vector<RigWellResultPoint>& branchResPoints = wellResFrame.m_wellResultBranches[bIdx].m_branchResultPoints; for (size_t rpIdx = 0; rpIdx < branchResPoints.size(); ++rpIdx) { const RigWellResultPoint& resPoint = branchResPoints[rpIdx]; if (resPoint.isCell()) { size_t i; size_t j; size_t k; size_t gridIdx = resPoint.m_gridIndex ; grids[gridIdx]->ijkFromCellIndex(resPoint.m_gridCellIndex, &i, &j, &k); bool isOpen = resPoint.m_isOpen; int branchId = resPoint.m_ertBranchId; int segmentId = resPoint.m_ertSegmentId; cellIs .push_back( static_cast<qint32>(i + 1) ); // NB: 1-based index in Octave cellJs .push_back( static_cast<qint32>(j + 1) ); // NB: 1-based index in Octave cellKs .push_back( static_cast<qint32>(k + 1) ); // NB: 1-based index in Octave gridIndices .push_back( static_cast<qint32>(gridIdx) ); cellStatuses.push_back( static_cast<qint32>(isOpen) ); branchIds .push_back( branchId ); segmentIds .push_back( segmentId); } } } quint64 byteCount = sizeof(quint64); quint64 cellCount = cellIs.size(); byteCount += cellCount*( 7 * sizeof(qint32)); socketStream << byteCount; socketStream << cellCount; for (size_t cIdx = 0; cIdx < cellCount; cIdx++) { socketStream << cellIs[cIdx]; socketStream << cellJs[cIdx]; socketStream << cellKs[cIdx]; socketStream << gridIndices[cIdx]; socketStream << cellStatuses[cIdx]; socketStream << branchIds[cIdx]; socketStream << segmentIds[cIdx]; } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellLogExtractionCurve::onLoadDataAndUpdate(bool updateParentPlot) { this->RimPlotCurve::updateCurvePresentation(updateParentPlot); if (isCurveVisible()) { // Make sure we have set correct case data into the result definitions. bool isUsingPseudoLength = false; RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value()); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); m_eclipseResultDefinition->setEclipseCase(eclipseCase); m_geomResultDefinition->setGeoMechCase(geomCase); clampBranchIndex(); RimMainPlotCollection* mainPlotCollection; this->firstAncestorOrThisOfTypeAsserted(mainPlotCollection); RimWellLogPlotCollection* wellLogCollection = mainPlotCollection->wellLogPlotCollection(); cvf::ref<RigEclipseWellLogExtractor> eclExtractor; if (eclipseCase) { if (m_trajectoryType == WELL_PATH) { eclExtractor = wellLogCollection->findOrCreateExtractor(m_wellPath, eclipseCase); } else { std::vector<const RigWellPath*> simWellBranches = simulationWellBranches(); if (m_branchIndex >= 0 && m_branchIndex < static_cast<int>(simWellBranches.size())) { auto wellBranch = simWellBranches[m_branchIndex]; eclExtractor = wellLogCollection->findOrCreateSimWellExtractor(m_simWellName, eclipseCase->caseUserDescription(), wellBranch, eclipseCase->eclipseCaseData()); if (eclExtractor.notNull()) { m_wellPathsWithExtractors.push_back(wellBranch); } isUsingPseudoLength = true; } } } cvf::ref<RigGeoMechWellLogExtractor> geomExtractor = wellLogCollection->findOrCreateExtractor(m_wellPath, geomCase); std::vector<double> values; std::vector<double> measuredDepthValues; std::vector<double> tvDepthValues; RiaDefines::DepthUnitType depthUnit = RiaDefines::UNIT_METER; if (eclExtractor.notNull() && eclipseCase) { measuredDepthValues = eclExtractor->measuredDepth(); tvDepthValues = eclExtractor->trueVerticalDepth(); m_eclipseResultDefinition->loadResult(); cvf::ref<RigResultAccessor> resAcc = RigResultAccessorFactory::createFromResultDefinition(eclipseCase->eclipseCaseData(), 0, m_timeStep, m_eclipseResultDefinition); if (resAcc.notNull()) { eclExtractor->curveData(resAcc.p(), &values); } RiaEclipseUnitTools::UnitSystem eclipseUnitsType = eclipseCase->eclipseCaseData()->unitsType(); if (eclipseUnitsType == RiaEclipseUnitTools::UNITS_FIELD) { // See https://github.com/OPM/ResInsight/issues/538 depthUnit = RiaDefines::UNIT_FEET; } } else if (geomExtractor.notNull()) // geomExtractor { measuredDepthValues = geomExtractor->measuredDepth(); tvDepthValues = geomExtractor->trueVerticalDepth(); m_geomResultDefinition->loadResult(); geomExtractor->curveData(m_geomResultDefinition->resultAddress(), m_timeStep, &values); } m_curveData = new RigWellLogCurveData; if (values.size() && measuredDepthValues.size()) { if (!tvDepthValues.size()) { m_curveData->setValuesAndMD(values, measuredDepthValues, depthUnit, true); } else { m_curveData->setValuesWithTVD(values, measuredDepthValues, tvDepthValues, depthUnit, true); } } RiaDefines::DepthUnitType displayUnit = RiaDefines::UNIT_METER; RimWellLogPlot* wellLogPlot; firstAncestorOrThisOfType(wellLogPlot); CVF_ASSERT(wellLogPlot); if (!wellLogPlot) return; displayUnit = wellLogPlot->depthUnit(); if(wellLogPlot->depthType() == RimWellLogPlot::TRUE_VERTICAL_DEPTH) { m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->trueDepthPlotValues(displayUnit).data(), static_cast<int>(m_curveData->xPlotValues().size())); isUsingPseudoLength = false; } else if (wellLogPlot->depthType() == RimWellLogPlot::MEASURED_DEPTH) { m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->measuredDepthPlotValues(displayUnit).data(), static_cast<int>(m_curveData->xPlotValues().size())); } m_qwtPlotCurve->setLineSegmentStartStopIndices(m_curveData->polylineStartStopIndices()); if (isUsingPseudoLength) { RimWellLogTrack* wellLogTrack; firstAncestorOrThisOfType(wellLogTrack); CVF_ASSERT(wellLogTrack); RiuWellLogTrack* viewer = wellLogTrack->viewer(); if (viewer) { viewer->setDepthTitle("PL/" + wellLogPlot->depthPlotTitle()); } } updateZoomInParentPlot(); setLogScaleFromSelectedResult(); if (m_parentQwtPlot) m_parentQwtPlot->replot(); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimEclipseStatisticsCaseEvaluator::evaluateForResults(const QList<ResSpec>& resultSpecification) { CVF_ASSERT(m_destinationCase); // First build the destination result data structures to receive the statistics for (int i = 0; i < resultSpecification.size(); i++) { RifReaderInterface::PorosityModelResultType poroModel = resultSpecification[i].m_poroModel; RimDefines::ResultCatType resultType = resultSpecification[i].m_resType; QString resultName = resultSpecification[i].m_resVarName; size_t activeCellCount = m_destinationCase->activeCellInfo(poroModel)->reservoirActiveCellCount(); RigCaseCellResultsData* destCellResultsData = m_destinationCase->results(poroModel); // Placeholder data used to be created here, // this is now moved to RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo() // Create new result data structures to contain the statistical values std::vector<QString> statisticalResultNames; statisticalResultNames.push_back(createResultNameMin(resultName)); statisticalResultNames.push_back(createResultNameMax(resultName)); statisticalResultNames.push_back(createResultNameMean(resultName)); statisticalResultNames.push_back(createResultNameDev(resultName)); statisticalResultNames.push_back(createResultNameRange(resultName)); if (m_statisticsConfig.m_calculatePercentiles) { statisticalResultNames.push_back(createResultNamePVal(resultName, m_statisticsConfig.m_pMinPos)); statisticalResultNames.push_back(createResultNamePVal(resultName, m_statisticsConfig.m_pMidPos)); statisticalResultNames.push_back(createResultNamePVal(resultName, m_statisticsConfig.m_pMaxPos)); } if (activeCellCount > 0) { for (size_t i = 0; i < statisticalResultNames.size(); ++i) { addNamedResult(destCellResultsData, resultType, statisticalResultNames[i], activeCellCount); } } } // Start the loop that calculates the statistics caf::ProgressInfo progressInfo(m_timeStepIndices.size(), "Computing Statistics"); for (size_t timeIndicesIdx = 0; timeIndicesIdx < m_timeStepIndices.size(); timeIndicesIdx++) { size_t timeStepIdx = m_timeStepIndices[timeIndicesIdx]; for (size_t gridIdx = 0; gridIdx < m_destinationCase->gridCount(); gridIdx++) { RigGridBase* grid = m_destinationCase->grid(gridIdx); for (int resSpecIdx = 0; resSpecIdx < resultSpecification.size(); resSpecIdx++) { RifReaderInterface::PorosityModelResultType poroModel = resultSpecification[resSpecIdx].m_poroModel; RimDefines::ResultCatType resultType = resultSpecification[resSpecIdx].m_resType; QString resultName = resultSpecification[resSpecIdx].m_resVarName; size_t activeCellCount = m_destinationCase->activeCellInfo(poroModel)->reservoirActiveCellCount(); if (activeCellCount == 0) continue; RigCaseCellResultsData* destCellResultsData = m_destinationCase->results(poroModel); size_t dataAccessTimeStepIndex = timeStepIdx; // Always evaluate statistics once, and always use time step index zero if (resultType == RimDefines::STATIC_NATIVE) { if (timeIndicesIdx > 0) continue; dataAccessTimeStepIndex = 0; } // Build data access objects for source scalar results cvf::Collection<RigResultAccessor> sourceDataAccessList; for (size_t caseIdx = 0; caseIdx < m_sourceCases.size(); caseIdx++) { RimEclipseCase* sourceCase = m_sourceCases.at(caseIdx); // Trigger loading of dataset sourceCase->results(poroModel)->findOrLoadScalarResultForTimeStep(resultType, resultName, dataAccessTimeStepIndex); cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(sourceCase->reservoirData(), gridIdx, poroModel, dataAccessTimeStepIndex, resultName, resultType); if (resultAccessor.notNull()) { sourceDataAccessList.push_back(resultAccessor.p()); } } // Build data access objects for destination scalar results // Find the created result container, if any, and put its resultAccessor into the enum indexed destination collection cvf::Collection<RigResultModifier> destinationDataAccessList; std::vector<QString> statisticalResultNames(STAT_PARAM_COUNT); statisticalResultNames[MIN] = createResultNameMin(resultName); statisticalResultNames[MAX] = createResultNameMax(resultName); statisticalResultNames[RANGE] = createResultNameRange(resultName); statisticalResultNames[MEAN] = createResultNameMean(resultName); statisticalResultNames[STDEV] = createResultNameDev(resultName); statisticalResultNames[PMIN] = createResultNamePVal(resultName, m_statisticsConfig.m_pMinPos); statisticalResultNames[PMID] = createResultNamePVal(resultName, m_statisticsConfig.m_pMidPos); statisticalResultNames[PMAX] = createResultNamePVal(resultName, m_statisticsConfig.m_pMaxPos); for (size_t stIdx = 0; stIdx < statisticalResultNames.size(); ++stIdx) { size_t scalarResultIndex = destCellResultsData->findScalarResultIndex(resultType, statisticalResultNames[stIdx]); cvf::ref<RigResultModifier> resultModifier = RigResultModifierFactory::createResultModifier(m_destinationCase, grid->gridIndex(), poroModel, dataAccessTimeStepIndex, scalarResultIndex); destinationDataAccessList.push_back(resultModifier.p()); } std::vector<double> statParams(STAT_PARAM_COUNT, HUGE_VAL); std::vector<double> values(sourceDataAccessList.size(), HUGE_VAL); // Loop over the cells in the grid, get the case values, and calculate the cell statistics #pragma omp parallel for schedule(dynamic) firstprivate(statParams, values) for (int cellIdx = 0; static_cast<size_t>(cellIdx) < grid->cellCount(); cellIdx++) { size_t reservoirCellIndex = grid->reservoirCellIndex(cellIdx); if (m_destinationCase->activeCellInfo(poroModel)->isActive(reservoirCellIndex)) { // Extract the cell values from each of the cases and assemble them into one vector bool foundAnyValidValues = false; for (size_t caseIdx = 0; caseIdx < sourceDataAccessList.size(); caseIdx++) { double val = sourceDataAccessList.at(caseIdx)->cellScalar(cellIdx); values[caseIdx] = val; if (val != HUGE_VAL) { foundAnyValidValues = true; } } // Do the real statistics calculations if (foundAnyValidValues) { RigStatisticsMath::calculateBasicStatistics(values, &statParams[MIN], &statParams[MAX], &statParams[RANGE], &statParams[MEAN], &statParams[STDEV]); // Calculate percentiles if (m_statisticsConfig.m_calculatePercentiles ) { if (m_statisticsConfig.m_pValMethod == RimEclipseStatisticsCase::NEAREST_OBSERVATION) { std::vector<double> pValPoss; pValPoss.push_back(m_statisticsConfig.m_pMinPos); pValPoss.push_back(m_statisticsConfig.m_pMidPos); pValPoss.push_back(m_statisticsConfig.m_pMaxPos); std::vector<double> pVals = RigStatisticsMath::calculateNearestRankPercentiles(values, pValPoss); statParams[PMIN] = pVals[0]; statParams[PMID] = pVals[1]; statParams[PMAX] = pVals[2]; } else if (m_statisticsConfig.m_pValMethod == RimEclipseStatisticsCase::HISTOGRAM_ESTIMATED) { std::vector<size_t> histogram; RigHistogramCalculator histCalc(statParams[MIN], statParams[MAX], 100, &histogram); histCalc.addData(values); statParams[PMIN] = histCalc.calculatePercentil(m_statisticsConfig.m_pMinPos); statParams[PMID] = histCalc.calculatePercentil(m_statisticsConfig.m_pMidPos); statParams[PMAX] = histCalc.calculatePercentil(m_statisticsConfig.m_pMaxPos); } else if (m_statisticsConfig.m_pValMethod == RimEclipseStatisticsCase::INTERPOLATED_OBSERVATION) { std::vector<double> pValPoss; pValPoss.push_back(m_statisticsConfig.m_pMinPos); pValPoss.push_back(m_statisticsConfig.m_pMidPos); pValPoss.push_back(m_statisticsConfig.m_pMaxPos); std::vector<double> pVals = RigStatisticsMath::calculateInterpolatedPercentiles(values, pValPoss); statParams[PMIN] = pVals[0]; statParams[PMID] = pVals[1]; statParams[PMAX] = pVals[2]; } else { CVF_ASSERT(false); } } } // Set the results into the results data structures for (size_t stIdx = 0; stIdx < statParams.size(); ++stIdx) { if (destinationDataAccessList[stIdx].notNull()) { destinationDataAccessList[stIdx]->setCellScalar(cellIdx, statParams[stIdx]); } } } } } } // When one time step is completed, free memory and clean up // Microsoft note: On Windows, the maximum number of files open at the same time is 512 // http://msdn.microsoft.com/en-us/library/kdfaxaay%28vs.71%29.aspx for (size_t caseIdx = 0; caseIdx < m_sourceCases.size(); caseIdx++) { RimEclipseCase* eclipseCase = m_sourceCases.at(caseIdx); if (!eclipseCase->reservoirViews.size()) { eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->freeAllocatedResultsData(); eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->cellResults()->freeAllocatedResultsData(); } // Todo : These calls really do nothing right now the access actually closes automatically in ert i belive ... eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->close(); eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->readerInterface()->close(); } progressInfo.setProgress(timeIndicesIdx); } }
bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) override { RimEclipseCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args); QString porosityModelName; porosityModelName = args[2]; RiaDefines::PorosityModelType porosityModelEnum = RiaDefines::MATRIX_MODEL; if (porosityModelName.toUpper() == "FRACTURE") { porosityModelEnum = RiaDefines::FRACTURE_MODEL; } if (!rimCase || !rimCase->eclipseCaseData() ) { // No data available socketStream << (quint64)0 << (quint64)0 ; return true; } RigActiveCellInfo* actCellInfo = rimCase->eclipseCaseData()->activeCellInfo(porosityModelEnum); RigMainGrid* mainGrid = rimCase->eclipseCaseData()->mainGrid(); size_t activeCellCount = actCellInfo->reservoirActiveCellCount(); size_t doubleValueCount = activeCellCount * 3 * 8; socketStream << (quint64)activeCellCount; quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // // See riGetCellCorners // // dim_vector dv; // dv.resize(3); // dv(0) = coordCount; // dv(1) = 8; // dv(2) = 3; cvf::Vec3d cornerVerts[8]; size_t blockByteCount = activeCellCount * sizeof(double); std::vector<double> doubleValues(blockByteCount); for (int coordIdx = 0; coordIdx < 3; coordIdx++) { for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; quint64 valueIndex = 0; for (size_t reservoirCellIndex = 0; reservoirCellIndex < mainGrid->globalCellArray().size(); reservoirCellIndex++) { if (!actCellInfo->isActive(reservoirCellIndex)) continue; mainGrid->cellCornerVertices(reservoirCellIndex, cornerVerts); doubleValues[valueIndex++] = getCellCornerWithPositiveDepth(cornerVerts, cornerIndexMapping, coordIdx); } CVF_ASSERT(valueIndex == activeCellCount); RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } return true; }
bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) override { RimEclipseCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args); size_t argGridIndex = args[2].toUInt(); if (!rimCase || !rimCase->eclipseCaseData() || (argGridIndex >= rimCase->eclipseCaseData()->gridCount()) ) { // No data available socketStream << (quint64)0 << (quint64)0 << (quint64)0 << (quint64)0 << (quint64)0; return true; } RigGridBase* rigGrid = rimCase->eclipseCaseData()->grid(argGridIndex); quint64 cellCount = (quint64)rigGrid->cellCount(); quint64 cellCountI = (quint64)rigGrid->cellCountI(); quint64 cellCountJ = (quint64)rigGrid->cellCountJ(); quint64 cellCountK = (quint64)rigGrid->cellCountK(); socketStream << cellCount; socketStream << cellCountI; socketStream << cellCountJ; socketStream << cellCountK; size_t doubleValueCount = cellCount * 3; quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // // See riGetCellCenters // // dim_vector dv; // dv.resize(4); // dv(0) = cellCountI; // dv(1) = cellCountJ; // dv(2) = cellCountK; // dv(3) = 3; size_t blockByteCount = cellCount * sizeof(double); std::vector<double> doubleValues(blockByteCount); for (int coordIdx = 0; coordIdx < 3; coordIdx++) { quint64 valueIndex = 0; for (size_t k = 0; k < cellCountK; k++) { for (size_t j = 0; j < cellCountJ; j++) { for (size_t i = 0; i < cellCountI; i++) { size_t gridLocalCellIndex = rigGrid->cellIndexFromIJK(i, j, k); cvf::Vec3d center = rigGrid->cell(gridLocalCellIndex).center(); convertVec3dToPositiveDepth(¢er); doubleValues[valueIndex++] = center[coordIdx]; } } } CVF_ASSERT(valueIndex == cellCount); RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } return true; }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { int caseId = args[1].toInt(); QString wellName = args[2]; RimEclipseCase* rimCase = server->findReservoir(caseId); if (!rimCase) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID : \"%1\"").arg(caseId)); return true; } // Create a list of all the requested time steps std::vector<size_t> requestedTimesteps; //First find the well result for the correct well const cvf::Collection<RigSingleWellResultsData>& allWellRes = rimCase->reservoirData()->wellResults(); cvf::ref<RigSingleWellResultsData> currentWellResult; for (size_t tsIdx = 0; tsIdx < allWellRes.size(); ++tsIdx) { if (allWellRes[tsIdx]->m_wellName == wellName) { currentWellResult = allWellRes[tsIdx]; break; } } if (currentWellResult.isNull()) { server->errorMessageDialog()->showMessage( RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the well with name : \"%1\"").arg(wellName)); return true; } if (args.size() <= 3) { // Select all timesteps. for (size_t tsIdx = 0; tsIdx < currentWellResult->m_resultTimeStepIndexToWellTimeStepIndex.size(); ++tsIdx) { requestedTimesteps.push_back(tsIdx); } } else { bool timeStepReadError = false; for (int argIdx = 3; argIdx < args.size(); ++argIdx) { bool conversionOk = false; int tsIdx = args[argIdx].toInt(&conversionOk); if (conversionOk) { requestedTimesteps.push_back(tsIdx); } else { timeStepReadError = true; } } if (timeStepReadError) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetGridProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps.")); } } std::vector<QString> wellTypes; std::vector<qint32> wellStatuses; for (size_t tsIdx = 0; tsIdx < requestedTimesteps.size(); ++tsIdx) { QString wellType = "NotDefined"; qint32 wellStatus = 0; if (currentWellResult->hasWellResult(tsIdx)) { switch(currentWellResult->wellResultFrame(tsIdx).m_productionType) { case RigWellResultFrame::PRODUCER: wellType = "Producer"; break; case RigWellResultFrame::OIL_INJECTOR: wellType = "OilInjector"; break; case RigWellResultFrame::WATER_INJECTOR: wellType = "WaterInjector"; break; case RigWellResultFrame::GAS_INJECTOR: wellType = "GasInjector"; break; } wellStatus = currentWellResult->wellResultFrame(tsIdx).m_isOpen ? 1 : 0; } wellTypes.push_back(wellType); wellStatuses.push_back(wellStatus); } quint64 byteCount = sizeof(quint64); quint64 timeStepCount = wellTypes.size(); for (size_t tsIdx = 0; tsIdx < timeStepCount; tsIdx++) { byteCount += wellTypes[tsIdx].size() * sizeof(QChar); byteCount += sizeof(qint32); } socketStream << byteCount; socketStream << timeStepCount; for (size_t tsIdx = 0; tsIdx < timeStepCount; tsIdx++) { socketStream << wellTypes[tsIdx]; socketStream << wellStatuses[tsIdx]; } return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const RigMainGrid* RimGridCollection::mainEclipseGrid() const { RimEclipseCase* eclipseCase; firstAncestorOrThisOfType(eclipseCase); return eclipseCase ? eclipseCase->mainGrid() : nullptr; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString Rim3dWellLogExtractionCurve::createCurveAutoName() const { RimGeoMechCase* geomCase = dynamic_cast<RimGeoMechCase*>(m_case.value()); RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case.value()); QStringList generatedCurveName; if (m_nameConfig->addWellName()) { RimWellPath* wellPath; this->firstAncestorOrThisOfTypeAsserted(wellPath); if (!wellPath->name().isEmpty()) { generatedCurveName += wellPath->name(); } } if (m_nameConfig->addCaseName() && m_case()) { generatedCurveName.push_back(m_case->caseUserDescription()); } if (m_nameConfig->addProperty() && !resultPropertyString().isEmpty()) { generatedCurveName.push_back(resultPropertyString()); } if (m_nameConfig->addTimeStep() || m_nameConfig->addDate()) { size_t maxTimeStep = 0; if (eclipseCase) { RigEclipseCaseData* data = eclipseCase->eclipseCaseData(); if (data) { maxTimeStep = data->results(m_eclipseResultDefinition->porosityModel())->maxTimeStepCount(); } } else if (geomCase) { RigGeoMechCaseData* data = geomCase->geoMechData(); if (data) { maxTimeStep = data->femPartResults()->frameCount(); } } if (m_nameConfig->addDate()) { QString dateString = wellDate(); if (!dateString.isEmpty()) { generatedCurveName.push_back(dateString); } } if (m_nameConfig->addTimeStep()) { generatedCurveName.push_back(QString("[%1/%2]").arg(m_timeStep()).arg(maxTimeStep)); } } return generatedCurveName.join(", "); }