//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuViewer::slotRangeFilterK() { size_t i, j, k; ijkFromCellIndex(m_currentGridIdx, m_currentCellIndex, &i, &j, &k); RiuMainWindow* mainWindow = RiuMainWindow::instance(); RimUiTreeModelPdm* myModel = mainWindow->uiPdmModel(); if (myModel) { RimCellRangeFilterCollection* rangeFilterCollection = m_reservoirView->rangeFilterCollection(); QModelIndex collectionModelIndex = myModel->getModelIndexFromPdmObject(rangeFilterCollection); QModelIndex insertedIndex; RimCellRangeFilter* rangeFilter = myModel->addRangeFilter(collectionModelIndex, insertedIndex); rangeFilter->name = QString("Slice K (%1)").arg(rangeFilterCollection->rangeFilters().size()); rangeFilter->cellCountK = 1; int startIndex = CVF_MAX(static_cast<int>(k + 1), 1); rangeFilter->startIndexK = startIndex; rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED); rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE); rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw(); mainWindow->setCurrentObjectInTreeView(rangeFilter); } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimScriptCollection::fieldChangedByUi(const caf::PdmFieldHandle *changedField, const QVariant &oldValue, const QVariant &newValue) { if (&directory == changedField) { QFileInfo fi(directory); this->setUiName(fi.baseName()); this->readContentFromDisc(); RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel(); if (treeModel) treeModel->updateUiSubTree(this); } }
//-------------------------------------------------------------------------------------------------- /// This method reads data from octave and puts it into the resInsight Structures //-------------------------------------------------------------------------------------------------- void RiaSocketServer::slotReadPropertyData() { QDataStream socketStream(m_currentClient); socketStream.setVersion(QDataStream::Qt_4_0); // If we have not read the header and there are data enough: Read it. // Do nothing if we have not enough data if (m_timeStepCountToRead == 0 || m_bytesPerTimeStepToRead == 0) { if (m_currentClient->bytesAvailable() < (int)sizeof(quint64)*2) return; socketStream >> m_timeStepCountToRead; socketStream >> m_bytesPerTimeStepToRead; } // If nothing should be read, or we already have read everything, do nothing if ((m_timeStepCountToRead == 0) || (m_currentTimeStepToRead >= m_timeStepCountToRead) ) return; // Check if a complete timestep is available, return and whait for readyRead() if not if (m_currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return; size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double); size_t gridActiveCellCount = m_currentReservoir->reservoirData()->mainGrid()->numActiveCells(); size_t gridTotalCellCount = m_currentReservoir->reservoirData()->mainGrid()->cellCount(); if (cellCountFromOctave != gridActiveCellCount && cellCountFromOctave != gridTotalCellCount) { m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("The number of cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseName() + "\"\n" " Octave: " + QString::number(cellCountFromOctave) + "\n" " " + m_currentReservoir->caseName() + ": Active cell count: " + QString::number(gridActiveCellCount) + " Total cell count: " + QString::number(gridTotalCellCount)) ; cellCountFromOctave = 0; m_invalidActiveCellCountDetected = true; m_currentClient->abort(); return; } // Make sure the size of the retreiving container is correct. // If it is, this is noops m_scalarResultsToAdd->resize(m_timeStepCountToRead); for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx) { m_scalarResultsToAdd->at(tIdx).resize(cellCountFromOctave, HUGE_VAL); } // Read available complete timestepdata while ((m_currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepToRead < m_timeStepCountToRead)) { qint64 bytesRead = 0; double * internalMatrixData = m_scalarResultsToAdd->at(m_currentTimeStepToRead).data(); #if 1 // Use raw data transfer. Faster. bytesRead = m_currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead); #else for (size_t cIdx = 0; cIdx < cellCountFromOctave; ++cIdx) { socketStream >> internalMatrixData[cIdx]; if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double); } #endif if ((int)m_bytesPerTimeStepToRead != bytesRead) { m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Could not read binary double data properly from socket")); } ++m_currentTimeStepToRead; } // If we have read all the data, refresh the views if (m_currentTimeStepToRead == m_timeStepCountToRead) { if (m_currentReservoir != NULL) { // Create a new input property if we have an input reservoir RimInputReservoir* inputRes = dynamic_cast<RimInputReservoir*>(m_currentReservoir); if (inputRes) { RimInputProperty* inputProperty = NULL; inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName); if (!inputProperty) { inputProperty = new RimInputProperty; inputProperty->resultName = m_currentPropertyName; inputProperty->eclipseKeyword = ""; inputProperty->fileName = ""; inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty); RimUiTreeModelPdm* treeModel = RIMainWindow::instance()->uiPdmModel(); treeModel->rebuildUiSubTree(inputRes->m_inputPropertyCollection()); } inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED; } if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T && m_currentReservoir->reservoirData() && m_currentReservoir->reservoirData()->mainGrid() && m_currentReservoir->reservoirData()->mainGrid()->results() ) { m_currentReservoir->reservoirData()->mainGrid()->results()->recalculateMinMax(m_currentScalarIndex); } for (size_t i = 0; i < m_currentReservoir->reservoirViews.size(); ++i) { if (m_currentReservoir->reservoirViews[i]) { m_currentReservoir->reservoirViews[i]->updateCurrentTimeStepAndRedraw(); } } } } }
virtual bool interpretMore(RiaSocketServer* server, QTcpSocket* currentClient) { // std::cout << "RiaSetActiveCellProperty, interpretMore: scalarIndex : " << m_currentScalarIndex; if (m_invalidActiveCellCountDetected) return true; // If nothing should be read, or we already have read everything, do nothing if ((m_timeStepCountToRead == 0) || (m_currentTimeStepNumberToRead >= m_timeStepCountToRead) ) return true; if (!currentClient->bytesAvailable()) return false; if (m_timeStepCountToRead != m_requestedTimesteps.size()) { CVF_ASSERT(false); } // Check if a complete timestep is available, return and whait for readyRead() if not if (currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return false; size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double); RigActiveCellInfo* activeCellInfo = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum); size_t globalActiveCellCount = activeCellInfo->globalActiveCellCount(); size_t totalCellCount = activeCellInfo->globalCellCount(); size_t globalCellResultCount = activeCellInfo->globalCellResultCount(); bool isCoarseningActive = globalCellResultCount != globalActiveCellCount; if (cellCountFromOctave != globalActiveCellCount ) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("The number of cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n" " Octave: " + QString::number(cellCountFromOctave) + "\n" " " + m_currentReservoir->caseUserDescription() + ": Active cell count: " + QString::number(globalActiveCellCount) + " Total cell count: " + QString::number(totalCellCount)) ; cellCountFromOctave = 0; m_invalidActiveCellCountDetected = true; currentClient->abort(); return true; } // Make sure the size of the retreiving container is correct. // If it is, this is noops for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx) { size_t tsId = m_requestedTimesteps[tIdx]; m_scalarResultsToAdd->at(tsId).resize(globalCellResultCount, HUGE_VAL); } std::vector<double> readBuffer; double * internalMatrixData = NULL; if (isCoarseningActive) { readBuffer.resize(cellCountFromOctave, HUGE_VAL); internalMatrixData = readBuffer.data(); } QDataStream socketStream(currentClient); socketStream.setVersion(riOctavePlugin::qtDataStreamVersion); // Read available complete timestepdata while ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepNumberToRead < m_timeStepCountToRead)) { qint64 bytesRead = 0; if ( !isCoarseningActive) { internalMatrixData = m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead]).data(); } #if 1 // Use raw data transfer. Faster. bytesRead = currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead); #else for (size_t cIdx = 0; cIdx < cellCountFromOctave; ++cIdx) { socketStream >> internalMatrixData[cIdx]; if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double); } #endif // Map data from active to result index based container ( Coarsening is active) if (isCoarseningActive) { size_t acIdx = 0; for (size_t gcIdx = 0; gcIdx < totalCellCount; ++gcIdx) { if (activeCellInfo->isActive(gcIdx)) { m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead])[activeCellInfo->cellResultIndex(gcIdx)] = readBuffer[acIdx]; ++acIdx; } } } if ((int)m_bytesPerTimeStepToRead != bytesRead) { server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not read binary double data properly from socket")); } ++m_currentTimeStepNumberToRead; } // If we have read all the data, refresh the views if (m_currentTimeStepNumberToRead == m_timeStepCountToRead) { if (m_currentReservoir != NULL) { // Create a new input property if we have an input reservoir RimInputCase* inputRes = dynamic_cast<RimInputCase*>(m_currentReservoir); if (inputRes) { RimInputProperty* inputProperty = NULL; inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName); if (!inputProperty) { inputProperty = new RimInputProperty; inputProperty->resultName = m_currentPropertyName; inputProperty->eclipseKeyword = ""; inputProperty->fileName = ""; inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty); RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel(); treeModel->updateUiSubTree(inputRes->m_inputPropertyCollection()); } inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED; } if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T && m_currentReservoir->reservoirData() && m_currentReservoir->reservoirData()->results(m_porosityModelEnum) ) { m_currentReservoir->reservoirData()->results(m_porosityModelEnum)->recalculateMinMax(m_currentScalarIndex); } for (size_t i = 0; i < m_currentReservoir->reservoirViews.size(); ++i) { if (m_currentReservoir->reservoirViews[i]) { // As new result might have been introduced, update all editors connected m_currentReservoir->reservoirViews[i]->cellResult->updateConnectedEditors(); // It is usually not needed to create new display model, but if any derived geometry based on generated data (from Octave) // a full display model rebuild is required m_currentReservoir->reservoirViews[i]->scheduleCreateDisplayModelAndRedraw(); } } } return true; } return false; }