//-------------------------------------------------------------------------------------------------- /// Find the cell index to the maingrid cell containing this cell, and store it as /// m_mainGridCellIndex in each cell. //-------------------------------------------------------------------------------------------------- void RigGridBase::initSubCellsMainGridCellIndex() { RigGridBase* grid = this; if (grid->isMainGrid()) { size_t cellIdx; for (cellIdx = 0; cellIdx < grid->cellCount(); ++cellIdx) { RigCell& cell = grid->cell(cellIdx); cell.setMainGridCellIndex(cellIdx); } } else { size_t cellIdx; for (cellIdx = 0; cellIdx < grid->cellCount(); ++cellIdx) { RigLocalGrid* localGrid = NULL; RigGridBase* parentGrid = NULL; localGrid = static_cast<RigLocalGrid*>(grid); parentGrid = localGrid->parentGrid(); RigCell& cell = localGrid->cell(cellIdx); size_t parentCellIndex = cell.parentCellIndex(); while (!parentGrid->isMainGrid()) { const RigCell& parentCell = parentGrid->cell(parentCellIndex); parentCellIndex = parentCell.parentCellIndex(); localGrid = static_cast<RigLocalGrid*>(parentGrid); parentGrid = localGrid->parentGrid(); } cell.setMainGridCellIndex(parentCellIndex); } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigGridBase::initSubGridParentPointer() { RigGridBase* grid = this; size_t cellIdx; for (cellIdx = 0; cellIdx < grid->cellCount(); ++cellIdx) { RigCell& cell = grid->cell(cellIdx); if (cell.subGrid()) { cell.subGrid()->setParentGrid(grid); } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimCellRangeFilter::computeAndSetValidValues() { CVF_ASSERT(m_parentContainer); RigGridBase* grid = selectedGrid(); if (grid && grid->cellCount() > 0 ) { cellCountI = cvf::Math::clamp(cellCountI.v(), 1, static_cast<int>(grid->cellCountI())); startIndexI = cvf::Math::clamp(startIndexI.v(), 1, static_cast<int>(grid->cellCountI())); cellCountJ = cvf::Math::clamp(cellCountJ.v(), 1, static_cast<int>(grid->cellCountJ())); startIndexJ = cvf::Math::clamp(startIndexJ.v(), 1, static_cast<int>(grid->cellCountJ())); cellCountK = cvf::Math::clamp(cellCountK.v(), 1, static_cast<int>(grid->cellCountK())); startIndexK = cvf::Math::clamp(startIndexK.v(), 1, static_cast<int>(grid->cellCountK())); } this->updateIconState(); }
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; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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); } }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) { int caseId = args[1].toInt(); int gridIdx = args[2].toInt(); QString propertyName = args[3]; QString porosityModelName = args[4]; RimCase*rimCase = server->findReservoir(caseId); if (rimCase == NULL) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the case with ID: \"%1\"").arg(caseId)); // No data available socketStream << (quint64)0 << (quint64)0 << (quint64)0 << (quint64)0 ; return true; } RifReaderInterface::PorosityModelResultType porosityModelEnum = RifReaderInterface::MATRIX_RESULTS; if (porosityModelName == "Fracture") { porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS; } size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; if (gridIdx < 0 || rimCase->reservoirData()->gridCount() <= (size_t)gridIdx) { server->errorMessageDialog()->showMessage("ResInsight SocketServer: riGetGridProperty : \n" "The gridIndex \"" + QString::number(gridIdx) + "\" does not point to an existing grid." ); } else { // Find the requested data if (rimCase && rimCase->results(porosityModelEnum)) { scalarResultIndex = rimCase->results(porosityModelEnum)->findOrLoadScalarResult(propertyName); } } if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the %1 model property named: \"%2\"").arg(porosityModelName).arg(propertyName)); // No data available socketStream << (quint64)0 << (quint64)0 << (quint64)0 << (quint64)0 ; return true; } // Create a list of all the requested time steps std::vector<size_t> requestedTimesteps; if (args.size() <= 5) { // Select all for (size_t tsIdx = 0; tsIdx < rimCase->results(porosityModelEnum)->cellResults()->timeStepCount(scalarResultIndex); ++tsIdx) { requestedTimesteps.push_back(tsIdx); } } else { bool timeStepReadError = false; for (int argIdx = 5; 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.")); } } RigGridBase* rigGrid = rimCase->reservoirData()->grid(gridIdx); quint64 cellCountI = (quint64)rigGrid->cellCountI(); quint64 cellCountJ = (quint64)rigGrid->cellCountJ(); quint64 cellCountK = (quint64)rigGrid->cellCountK(); socketStream << cellCountI; socketStream << cellCountJ; socketStream << cellCountK; // Write time step count quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; size_t doubleValueCount = cellCountI * cellCountJ * cellCountK * timestepCount * sizeof(double); std::vector<double> values(doubleValueCount); size_t valueIdx = 0; for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { cvf::ref<cvf::StructGridScalarDataAccess> cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); if (cellCenterDataAccessObject.isNull()) { continue; } for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); if (cellValue == HUGE_VAL) { cellValue = 0.0; } values[valueIdx++] = cellValue; } } server->currentClient()->write((const char *)values.data(), doubleValueCount); return true; }