Merge pull request #26 from OPM/internal

Update to version 0.9.4
This commit is contained in:
Magne Sjaastad 2013-04-12 07:29:07 -07:00
commit ae618a6c69
624 changed files with 31637 additions and 8793 deletions

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafLog.h"
#include "cafEffectCache.h"
@ -26,20 +26,20 @@
#include "cvfStructGridGeometryGenerator.h"
#include "RIVersionInfo.h"
#include "RIBaseDefs.h"
#include "RiaVersionInfo.h"
#include "RiaBaseDefs.h"
#include "RIApplication.h"
#include "RIMainWindow.h"
#include "RIViewer.h"
#include "RIProcessMonitor.h"
#include "RIPreferences.h"
#include "RiaApplication.h"
#include "RiuMainWindow.h"
#include "RiuViewer.h"
#include "RiuProcessMonitor.h"
#include "RiaPreferences.h"
#include "RimResultReservoir.h"
#include "RimInputReservoir.h"
#include "RimResultCase.h"
#include "RimInputCase.h"
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RigCell.h"
#include "RigReservoirBuilderMock.h"
@ -55,15 +55,17 @@
#include "RimUiTreeModelPdm.h"
#include "RiaImageCompareReporter.h"
#include "RiaImageFileCompare.h"
#include "cafProgressInfo.h"
#include "RigGridManager.h"
namespace caf
{
template<>
void AppEnum< RIApplication::RINavigationPolicy >::setUp()
void AppEnum< RiaApplication::RINavigationPolicy >::setUp()
{
addItem(RIApplication::NAVIGATION_POLICY_CEETRON, "NAVIGATION_POLICY_CEETRON", "Ceetron");
addItem(RIApplication::NAVIGATION_POLICY_CAD, "NAVIGATION_POLICY_CAD", "CAD");
setDefault(RIApplication::NAVIGATION_POLICY_CAD);
addItem(RiaApplication::NAVIGATION_POLICY_CEETRON, "NAVIGATION_POLICY_CEETRON", "Ceetron");
addItem(RiaApplication::NAVIGATION_POLICY_CAD, "NAVIGATION_POLICY_CAD", "CAD");
setDefault(RiaApplication::NAVIGATION_POLICY_CAD);
}
}
@ -82,7 +84,7 @@ namespace RegTestNames
//==================================================================================================
///
/// \class RIApplication
/// \class RiaApplication
///
/// Application class
///
@ -92,7 +94,7 @@ namespace RegTestNames
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIApplication::RIApplication(int& argc, char** argv)
RiaApplication::RiaApplication(int& argc, char** argv)
: QApplication(argc, argv)
{
// USed to get registry settings in the right place
@ -105,7 +107,7 @@ RIApplication::RIApplication(int& argc, char** argv)
//cvf::Trace::enable(false);
m_preferences = new RIPreferences;
m_preferences = new RiaPreferences;
readPreferences();
applyPreferences();
@ -132,14 +134,14 @@ RIApplication::RIApplication(int& argc, char** argv)
#ifdef WIN32
//m_startupDefaultDirectory += "/My Documents/";
#endif
setDefaultFileDialogDirectory("MULTICASEIMPORT", "/");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIApplication::~RIApplication()
RiaApplication::~RiaApplication()
{
delete m_preferences;
}
@ -148,18 +150,18 @@ RIApplication::~RIApplication()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIApplication* RIApplication::instance()
RiaApplication* RiaApplication::instance()
{
return static_cast<RIApplication*>qApp;
return static_cast<RiaApplication*>qApp;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::setWindowCaptionFromAppState()
void RiaApplication::setWindowCaptionFromAppState()
{
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (!mainWnd) return;
// The stuff being done here should really be handled by Qt automatically as a result of
@ -185,7 +187,7 @@ void RIApplication::setWindowCaptionFromAppState()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::processNonGuiEvents()
void RiaApplication::processNonGuiEvents()
{
processEvents(QEventLoop::ExcludeUserInputEvents);
}
@ -194,7 +196,7 @@ void RIApplication::processNonGuiEvents()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const char* RIApplication::getVersionStringApp(bool includeCrtInfo)
const char* RiaApplication::getVersionStringApp(bool includeCrtInfo)
{
// Use static buf so we can return ptr
static char szBuf[1024];
@ -220,15 +222,25 @@ const char* RIApplication::getVersionStringApp(bool includeCrtInfo)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::loadProject(const QString& projectFileName)
bool RiaApplication::loadProject(const QString& projectFileName)
{
// First Close the current project
if (!closeProject(true)) return false;
// Open the project file and read the serialized data.
// Will initialize itself.
if (!QFile::exists(projectFileName)) return false;
m_project->fileName = projectFileName;
m_project->readFile();
m_project->fileName = projectFileName; // Make sure we overwrite the old filename read from the project file
// Propagate possible new location of project
m_project->setProjectFileNameAndUpdateDependencies(projectFileName);
// On error, delete everything, and bail out.
if (m_project->projectFileVersionString().isEmpty())
{
@ -237,35 +249,82 @@ bool RIApplication::loadProject(const QString& projectFileName)
QString tmp = QString("Unknown project file version detected in file \n%1\n\nCould not open project.").arg(projectFileName);
QMessageBox::warning(NULL, "Error when opening project file", tmp);
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
mainWnd->setPdmRoot(NULL);
// Delete all object possibly generated by readFile()
delete m_project;
m_project = new RimProject;
onProjectOpenedOrClosed();
return true;
}
else
///////
// Load the external data, and initialize stuff that needs specific ordering
m_preferences->lastUsedProjectFileName = projectFileName;
writePreferences();
for (size_t cgIdx = 0; cgIdx < m_project->caseGroups.size(); ++cgIdx)
{
m_preferences->lastUsedProjectFileName = projectFileName;
writePreferences();
// Load the Main case of each IdenticalGridCaseGroup
size_t i;
for (i = 0; i < m_project->reservoirs().size(); ++i)
RimIdenticalGridCaseGroup* igcg = m_project->caseGroups[cgIdx];
igcg->loadMainCaseAndActiveCellInfo();
}
// Now load the ReservoirViews for the cases
std::vector<RimCase*> casesToLoad;
// Add all "native" cases in the project
for (size_t cIdx = 0; cIdx < m_project->reservoirs().size(); ++cIdx)
{
casesToLoad.push_back(m_project->reservoirs()[cIdx]);
}
// Add all statistics cases as well
for (size_t cgIdx = 0; cgIdx < m_project->caseGroups().size(); ++cgIdx)
{
if (m_project->caseGroups[cgIdx]->statisticsCaseCollection())
{
RimReservoir* ri = m_project->reservoirs()[i];
CVF_ASSERT(ri);
size_t j;
for (j = 0; j < ri->reservoirViews().size(); j++)
caf::PdmPointersField<RimCase*> & statCases = m_project->caseGroups[cgIdx]->statisticsCaseCollection()->reservoirs();
for (size_t scIdx = 0; scIdx < statCases.size(); ++scIdx)
{
RimReservoirView* riv = ri->reservoirViews()[j];
CVF_ASSERT(riv);
riv->loadDataAndUpdate();
casesToLoad.push_back(statCases[scIdx]);
}
}
}
caf::ProgressInfo caseProgress(casesToLoad.size() , "Reading Cases");
for (size_t cIdx = 0; cIdx < casesToLoad.size(); ++cIdx)
{
RimCase* ri = casesToLoad[cIdx];
CVF_ASSERT(ri);
caseProgress.setProgressDescription(ri->caseUserDescription());
caf::ProgressInfo viewProgress(ri->reservoirViews().size() , "Creating Views");
size_t j;
for (j = 0; j < ri->reservoirViews().size(); j++)
{
RimReservoirView* riv = ri->reservoirViews[j];
CVF_ASSERT(riv);
viewProgress.setProgressDescription(riv->name());
riv->loadDataAndUpdate();
viewProgress.incrementProgress();
}
caseProgress.incrementProgress();
}
onProjectOpenedOrClosed();
return true;
@ -275,7 +334,7 @@ bool RIApplication::loadProject(const QString& projectFileName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::loadLastUsedProject()
bool RiaApplication::loadLastUsedProject()
{
return loadProject(m_preferences->lastUsedProjectFileName);
}
@ -284,7 +343,7 @@ bool RIApplication::loadLastUsedProject()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::saveProject()
bool RiaApplication::saveProject()
{
CVF_ASSERT(m_project.notNull());
@ -302,11 +361,11 @@ bool RIApplication::saveProject()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::saveProjectPromptForFileName()
bool RiaApplication::saveProjectPromptForFileName()
{
//if (m_project.isNull()) return true;
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString startPath;
if (!m_project->fileName().isEmpty())
@ -341,7 +400,7 @@ bool RIApplication::saveProjectPromptForFileName()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::saveProjectAs(const QString& fileName)
bool RiaApplication::saveProjectAs(const QString& fileName)
{
m_project->fileName = fileName;
m_project->writeFile();
@ -356,9 +415,9 @@ bool RIApplication::saveProjectAs(const QString& fileName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::closeProject(bool askToSaveIfDirty)
bool RiaApplication::closeProject(bool askToSaveIfDirty)
{
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
terminateProcess();
@ -396,9 +455,9 @@ bool RIApplication::closeProject(bool askToSaveIfDirty)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::onProjectOpenedOrClosed()
void RiaApplication::onProjectOpenedOrClosed()
{
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (!mainWnd) return;
mainWnd->initializeGuiNewProjectLoaded();
@ -411,7 +470,7 @@ void RIApplication::onProjectOpenedOrClosed()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RIApplication::currentProjectFileName() const
QString RiaApplication::currentProjectFileName() const
{
return m_project->fileName();
}
@ -420,7 +479,7 @@ QString RIApplication::currentProjectFileName() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::openEclipseCaseFromFile(const QString& fileName)
bool RiaApplication::openEclipseCaseFromFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
@ -434,27 +493,19 @@ bool RIApplication::openEclipseCaseFromFile(const QString& fileName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::openEclipseCase(const QString& caseName, const QString& caseFileName)
bool RiaApplication::openEclipseCase(const QString& caseName, const QString& caseFileName)
{
QFileInfo gridFileName(caseFileName);
QString casePath = gridFileName.absolutePath();
RimResultReservoir* rimResultReservoir = new RimResultReservoir();
rimResultReservoir->caseName = caseName;
rimResultReservoir->caseFileName = caseFileName;
rimResultReservoir->caseDirectory = casePath;
RimResultCase* rimResultReservoir = new RimResultCase();
rimResultReservoir->setCaseInfo(caseName, caseFileName);
m_project->reservoirs.push_back(rimResultReservoir);
RimReservoirView* riv = rimResultReservoir->createAndAddReservoirView();
if (m_preferences->autocomputeSOIL)
{
// Select SOIL as default result variable
riv->cellResult()->resultType = RimDefines::DYNAMIC_NATIVE;
riv->cellResult()->resultVariable = "SOIL";
riv->animationMode = true;
}
// Select SOIL as default result variable
riv->cellResult()->resultType = RimDefines::DYNAMIC_NATIVE;
riv->cellResult()->resultVariable = "SOIL";
riv->animationMode = true;
riv->loadDataAndUpdate();
@ -472,10 +523,10 @@ bool RIApplication::openEclipseCase(const QString& caseName, const QString& case
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::openInputEclipseCase(const QString& caseName, const QStringList& caseFileNames)
bool RiaApplication::openInputEclipseCase(const QString& caseName, const QStringList& caseFileNames)
{
RimInputReservoir* rimInputReservoir = new RimInputReservoir();
rimInputReservoir->caseName = caseName;
RimInputCase* rimInputReservoir = new RimInputCase();
rimInputReservoir->caseUserDescription = caseName;
rimInputReservoir->openDataFileSet(caseFileNames);
m_project->reservoirs.push_back(rimInputReservoir);
@ -502,7 +553,7 @@ bool RIApplication::openInputEclipseCase(const QString& caseName, const QStringL
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::createMockModel()
void RiaApplication::createMockModel()
{
openEclipseCase("Result Mock Debug Model Simple", "Result Mock Debug Model Simple");
}
@ -510,7 +561,7 @@ void RIApplication::createMockModel()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::createResultsMockModel()
void RiaApplication::createResultsMockModel()
{
openEclipseCase("Result Mock Debug Model With Results", "Result Mock Debug Model With Results");
}
@ -519,7 +570,7 @@ void RIApplication::createResultsMockModel()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::createLargeResultsMockModel()
void RiaApplication::createLargeResultsMockModel()
{
openEclipseCase("Result Mock Debug Model Large With Results", "Result Mock Debug Model Large With Results");
}
@ -527,7 +578,7 @@ void RIApplication::createLargeResultsMockModel()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::createInputMockModel()
void RiaApplication::createInputMockModel()
{
openInputEclipseCase("Input Mock Debug Model Simple", QStringList("Input Mock Debug Model Simple"));
}
@ -535,7 +586,7 @@ void RIApplication::createInputMockModel()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RimReservoirView* RIApplication::activeReservoirView() const
const RimReservoirView* RiaApplication::activeReservoirView() const
{
return m_activeReservoirView;
}
@ -543,7 +594,7 @@ const RimReservoirView* RIApplication::activeReservoirView() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirView* RIApplication::activeReservoirView()
RimReservoirView* RiaApplication::activeReservoirView()
{
return m_activeReservoirView;
}
@ -551,7 +602,7 @@ RimReservoirView* RIApplication::activeReservoirView()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::setActiveReservoirView(RimReservoirView* rv)
void RiaApplication::setActiveReservoirView(RimReservoirView* rv)
{
m_activeReservoirView = rv;
}
@ -559,7 +610,7 @@ void RIApplication::setActiveReservoirView(RimReservoirView* rv)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::setUseShaders(bool enable)
void RiaApplication::setUseShaders(bool enable)
{
m_preferences->useShaders = enable;
writePreferences();
@ -568,7 +619,7 @@ void RIApplication::setUseShaders(bool enable)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::useShaders() const
bool RiaApplication::useShaders() const
{
if (!m_preferences->useShaders) return false;
@ -582,7 +633,7 @@ bool RIApplication::useShaders() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIApplication::RINavigationPolicy RIApplication::navigationPolicy() const
RiaApplication::RINavigationPolicy RiaApplication::navigationPolicy() const
{
return m_preferences->navigationPolicy();
}
@ -591,7 +642,7 @@ RIApplication::RINavigationPolicy RIApplication::navigationPolicy() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::setShowPerformanceInfo(bool enable)
void RiaApplication::setShowPerformanceInfo(bool enable)
{
m_preferences->showHud = enable;
writePreferences();
@ -601,7 +652,7 @@ void RIApplication::setShowPerformanceInfo(bool enable)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::showPerformanceInfo() const
bool RiaApplication::showPerformanceInfo() const
{
return m_preferences->showHud;
}
@ -610,7 +661,7 @@ bool RIApplication::showPerformanceInfo() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::parseArguments()
bool RiaApplication::parseArguments()
{
QStringList arguments = QCoreApplication::arguments();
@ -765,7 +816,7 @@ bool RIApplication::parseArguments()
if (isRunRegressionTest)
{
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (mainWnd)
{
mainWnd->hideAllDockWindows();
@ -830,7 +881,7 @@ bool RIApplication::parseArguments()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RIApplication::scriptDirectory() const
QString RiaApplication::scriptDirectory() const
{
return m_preferences->scriptDirectory();
}
@ -838,7 +889,7 @@ QString RIApplication::scriptDirectory() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RIApplication::scriptEditorPath() const
QString RiaApplication::scriptEditorPath() const
{
return m_preferences->scriptEditorExecutable();
}
@ -846,7 +897,7 @@ QString RIApplication::scriptEditorPath() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RIApplication::octavePath() const
QString RiaApplication::octavePath() const
{
return m_preferences->octaveExecutable();
}
@ -854,9 +905,9 @@ QString RIApplication::octavePath() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
void RiaApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
RIMainWindow::instance()->processMonitor()->stopMonitorWorkProcess();
RiuMainWindow::instance()->processMonitor()->stopMonitorWorkProcess();
// Execute delete later so that other slots that are hooked up
// get a chance to run before we delete the object
@ -888,14 +939,14 @@ void RIApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RIApplication::launchProcess(const QString& program, const QStringList& arguments)
bool RiaApplication::launchProcess(const QString& program, const QStringList& arguments)
{
if (m_workerProcess == NULL)
{
m_workerProcess = new caf::UiProcess(this);
connect(m_workerProcess, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(slotWorkerProcessFinished(int, QProcess::ExitStatus)));
RIMainWindow::instance()->processMonitor()->startMonitorWorkProcess(m_workerProcess);
RiuMainWindow::instance()->processMonitor()->startMonitorWorkProcess(m_workerProcess);
m_workerProcess->start(program, arguments);
if (!m_workerProcess->waitForStarted(1000))
@ -903,9 +954,9 @@ bool RIApplication::launchProcess(const QString& program, const QStringList& arg
m_workerProcess->close();
m_workerProcess = NULL;
RIMainWindow::instance()->processMonitor()->stopMonitorWorkProcess();
RiuMainWindow::instance()->processMonitor()->stopMonitorWorkProcess();
QMessageBox::warning(RIMainWindow::instance(), "Script execution", "Failed to start script executable located at\n" + program);
QMessageBox::warning(RiuMainWindow::instance(), "Script execution", "Failed to start script executable located at\n" + program);
return false;
}
@ -922,7 +973,7 @@ bool RIApplication::launchProcess(const QString& program, const QStringList& arg
//--------------------------------------------------------------------------------------------------
/// Read fields of a Pdm object using QSettings
//--------------------------------------------------------------------------------------------------
void RIApplication::readPreferences()
void RiaApplication::readPreferences()
{
QSettings settings;
std::vector<caf::PdmFieldHandle*> fields;
@ -944,7 +995,7 @@ void RIApplication::readPreferences()
//--------------------------------------------------------------------------------------------------
/// Write fields of a Pdm object using QSettings
//--------------------------------------------------------------------------------------------------
void RIApplication::writePreferences()
void RiaApplication::writePreferences()
{
QSettings settings;
@ -963,7 +1014,7 @@ void RIApplication::writePreferences()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIPreferences* RIApplication::preferences()
RiaPreferences* RiaApplication::preferences()
{
return m_preferences;
}
@ -971,7 +1022,7 @@ RIPreferences* RIApplication::preferences()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::applyPreferences()
void RiaApplication::applyPreferences()
{
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
@ -999,7 +1050,7 @@ void RIApplication::applyPreferences()
if (this->project())
{
this->project()->setUserScriptPath(m_preferences->scriptDirectory());
RimUiTreeModelPdm* treeModel = RIMainWindow::instance()->uiPdmModel();
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
if (treeModel) treeModel->rebuildUiSubTree(this->project()->scriptCollection());
}
@ -1008,7 +1059,7 @@ void RIApplication::applyPreferences()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::terminateProcess()
void RiaApplication::terminateProcess()
{
if (m_workerProcess)
{
@ -1021,7 +1072,7 @@ void RIApplication::terminateProcess()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RIApplication::defaultFileDialogDirectory(const QString& dialogName)
QString RiaApplication::defaultFileDialogDirectory(const QString& dialogName)
{
QString defaultDirectory = m_startupDefaultDirectory;
std::map<QString, QString>::iterator it;
@ -1038,7 +1089,7 @@ QString RIApplication::defaultFileDialogDirectory(const QString& dialogName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::setDefaultFileDialogDirectory(const QString& dialogName, const QString& defaultDirectory)
void RiaApplication::setDefaultFileDialogDirectory(const QString& dialogName, const QString& defaultDirectory)
{
m_fileDialogDefaultDirectories[dialogName] = defaultDirectory;
}
@ -1046,7 +1097,7 @@ void RIApplication::setDefaultFileDialogDirectory(const QString& dialogName, con
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotPromtpForFilename()
void RiaApplication::saveSnapshotPromtpForFilename()
{
QString startPath;
if (!m_project->fileName().isEmpty())
@ -1076,7 +1127,7 @@ void RIApplication::saveSnapshotPromtpForFilename()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotAs(const QString& fileName)
void RiaApplication::saveSnapshotAs(const QString& fileName)
{
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
@ -1095,7 +1146,7 @@ void RIApplication::saveSnapshotAs(const QString& fileName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::copySnapshotToClipboard()
void RiaApplication::copySnapshotToClipboard()
{
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
@ -1112,9 +1163,9 @@ void RIApplication::copySnapshotToClipboard()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
{
RIMainWindow* mainWnd = RIMainWindow::instance();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if (!mainWnd) return;
if (m_project.isNull()) return;
@ -1134,7 +1185,7 @@ void RIApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
for (size_t i = 0; i < m_project->reservoirs().size(); ++i)
{
RimReservoir* ri = m_project->reservoirs()[i];
RimCase* ri = m_project->reservoirs()[i];
if (!ri) continue;
for (size_t j = 0; j < ri->reservoirViews().size(); j++)
@ -1145,13 +1196,13 @@ void RIApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
{
setActiveReservoirView(riv);
RIViewer* viewer = riv->viewer();
RiuViewer* viewer = riv->viewer();
mainWnd->setActiveViewer(viewer);
// Process all events to avoid a black image when grabbing frame buffer
QCoreApplication::processEvents();
QString fileName = ri->caseName() + "-" + riv->name();
QString fileName = ri->caseUserDescription() + "-" + riv->name();
QString absoluteFileName = caf::Utils::constructFullFileName(snapshotPath, fileName, ".png");
saveSnapshotAs(absoluteFileName);
@ -1174,7 +1225,7 @@ void removeDirectoryWithContent(QDir dirToDelete )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::runRegressionTest(const QString& testRootPath)
void RiaApplication::runRegressionTest(const QString& testRootPath)
{
QString generatedFolderName = RegTestNames::generatedFolderName;
QString diffFolderName = RegTestNames::diffFolderName;
@ -1227,6 +1278,7 @@ void RIApplication::runRegressionTest(const QString& testRootPath)
imageCompareReporter.generateHTMLReport(testDir.filePath(RegTestNames::reportFileName).toStdString());
// Generate diff images
this->preferences()->resetToDefaults();
for (int dirIdx = 0; dirIdx < folderList.size(); ++dirIdx)
{
@ -1253,6 +1305,8 @@ void RIApplication::runRegressionTest(const QString& testRootPath)
qDebug() << "Error comparing :" << imgComparator.errorMessage() << "\n" << imgComparator.errorDetails();
}
}
closeProject(false);
}
}
}
@ -1260,7 +1314,7 @@ void RIApplication::runRegressionTest(const QString& testRootPath)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::updateRegressionTest(const QString& testRootPath)
void RiaApplication::updateRegressionTest(const QString& testRootPath)
{
// Find all sub folders
@ -1291,3 +1345,80 @@ void RIApplication::updateRegressionTest(const QString& testRootPath)
}
}
}
//--------------------------------------------------------------------------------------------------
/// Make sure changes in this functions is validated to RimIdenticalGridCaseGroup::initAfterRead()
//--------------------------------------------------------------------------------------------------
bool RiaApplication::addEclipseCases(const QStringList& fileNames)
{
if (fileNames.size() == 0) return true;
// First file is read completely including grid.
// The main grid from the first case is reused directly in for the other cases.
// When reading active cell info, only the total cell count is tested for consistency
RimResultCase* mainResultCase = NULL;
std::vector< std::vector<int> > mainCaseGridDimensions;
{
QString firstFileName = fileNames[0];
QFileInfo gridFileName(firstFileName);
QString caseName = gridFileName.completeBaseName();
RimResultCase* rimResultReservoir = new RimResultCase();
rimResultReservoir->setCaseInfo(caseName, firstFileName);
if (!rimResultReservoir->openEclipseGridFile())
{
delete rimResultReservoir;
return false;
}
rimResultReservoir->readGridDimensions(mainCaseGridDimensions);
m_project->reservoirs.push_back(rimResultReservoir);
m_project->moveEclipseCaseIntoCaseGroup(rimResultReservoir);
mainResultCase = rimResultReservoir;
}
caf::ProgressInfo info(fileNames.size(), "Reading Active Cell data");
for (int i = 1; i < fileNames.size(); i++)
{
QString caseFileName = fileNames[i];
QFileInfo gridFileName(caseFileName);
QString caseName = gridFileName.completeBaseName();
RimResultCase* rimResultReservoir = new RimResultCase();
rimResultReservoir->setCaseInfo(caseName, caseFileName);
std::vector< std::vector<int> > caseGridDimensions;
rimResultReservoir->readGridDimensions(caseGridDimensions);
bool identicalGrid = RigGridManager::isGridDimensionsEqual(mainCaseGridDimensions, caseGridDimensions);
if (identicalGrid)
{
if (rimResultReservoir->openAndReadActiveCellData(mainResultCase->reservoirData()))
{
m_project->reservoirs.push_back(rimResultReservoir);
m_project->moveEclipseCaseIntoCaseGroup(rimResultReservoir);
}
else
{
delete rimResultReservoir;
}
}
else
{
delete rimResultReservoir;
}
info.setProgress(i);
}
onProjectOpenedOrClosed();
return true;
}

View File

@ -30,11 +30,11 @@
#include "RimProject.h"
class RIProcess;
class RigReservoir;
class RimReservoir;
class RigCaseData;
class RimCase;
class Drawable;
class RiaSocketServer;
class RIPreferences;
class RiaPreferences;
namespace caf
{
@ -46,7 +46,7 @@ namespace caf
//
//
//==================================================================================================
class RIApplication : public QApplication
class RiaApplication : public QApplication
{
Q_OBJECT
@ -58,9 +58,9 @@ public:
};
public:
RIApplication(int& argc, char** argv);
~RIApplication();
static RIApplication* instance();
RiaApplication(int& argc, char** argv);
~RiaApplication();
static RiaApplication* instance();
bool parseArguments();
@ -80,6 +80,7 @@ public:
bool openEclipseCaseFromFile(const QString& fileName);
bool openEclipseCase(const QString& caseName, const QString& caseFileName);
bool addEclipseCases(const QStringList& fileNames);
bool openInputEclipseCase(const QString& caseName, const QStringList& caseFileNames);
bool loadLastUsedProject();
@ -115,7 +116,7 @@ public:
bool launchProcess(const QString& program, const QStringList& arguments);
void terminateProcess();
RIPreferences* preferences();
RiaPreferences* preferences();
void readPreferences();
void writePreferences();
void applyPreferences();
@ -138,7 +139,7 @@ private:
caf::UiProcess* m_workerProcess;
RIPreferences* m_preferences;
RiaPreferences* m_preferences;
std::map<QString, QString> m_fileDialogDefaultDirectories;
QString m_startupDefaultDirectory;

View File

@ -16,17 +16,17 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RIPreferences.h"
#include "RiaStdInclude.h"
#include "RiaPreferences.h"
#include "cafPdmUiFilePathEditor.h"
CAF_PDM_SOURCE_INIT(RIPreferences, "RIPreferences");
CAF_PDM_SOURCE_INIT(RiaPreferences, "RiaPreferences");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIPreferences::RIPreferences(void)
RiaPreferences::RiaPreferences(void)
{
CAF_PDM_InitField(&navigationPolicy, "navigationPolicy", caf::AppEnum<RIApplication::RINavigationPolicy>(RIApplication::NAVIGATION_POLICY_CAD), "Navigation mode", "", "", "");
CAF_PDM_InitField(&navigationPolicy, "navigationPolicy", caf::AppEnum<RiaApplication::RINavigationPolicy>(RiaApplication::NAVIGATION_POLICY_CAD), "Navigation mode", "", "", "");
CAF_PDM_InitFieldNoDefault(&scriptDirectory, "scriptDirectory", "Shared Script Folder", "", "", "");
scriptDirectory.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
@ -38,6 +38,9 @@ RIPreferences::RIPreferences(void)
octaveExecutable.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
CAF_PDM_InitField(&defaultGridLines, "defaultGridLines", true, "Gridlines", "", "", "");
CAF_PDM_InitField(&defaultGridLineColors, "defaultGridLineColors", cvf::Color3f(0.92f, 0.92f, 0.92f), "Mesh color", "", "", "");
CAF_PDM_InitField(&defaultFaultGridLineColors, "defaultFaultGridLineColors", cvf::Color3f(0.08f, 0.08f, 0.08f), "Mesh color along faults", "", "", "");
CAF_PDM_InitField(&defaultScaleFactorZ, "defaultScaleFactorZ", 5, "Z scale factor", "", "", "");
CAF_PDM_InitField(&useShaders, "useShaders", true, "Use Shaders", "", "", "");
@ -53,7 +56,7 @@ RIPreferences::RIPreferences(void)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIPreferences::~RIPreferences(void)
RiaPreferences::~RiaPreferences(void)
{
}
@ -61,7 +64,7 @@ RIPreferences::~RIPreferences(void)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIPreferences::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
void RiaPreferences::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
{
if (field == &scriptDirectory)
{
@ -76,7 +79,7 @@ void RIPreferences::defineEditorAttribute(const caf::PdmFieldHandle* field, QStr
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const
void RiaPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&navigationPolicy);
@ -88,9 +91,26 @@ void RIPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& u
caf::PdmUiGroup* defaultSettingsGroup = uiOrdering.addNewGroup("Default settings");
defaultSettingsGroup->add(&defaultScaleFactorZ);
defaultSettingsGroup->add(&defaultGridLines);
defaultSettingsGroup->add(&defaultGridLineColors);
defaultSettingsGroup->add(&defaultFaultGridLineColors);
caf::PdmUiGroup* autoComputeGroup = uiOrdering.addNewGroup("Compute when loading new case");
autoComputeGroup->add(&autocomputeSOIL);
autoComputeGroup->add(&autocomputeDepthRelatedProperties);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaPreferences::resetToDefaults()
{
std::vector<caf::PdmFieldHandle*> fields;
this->fields(fields);
for (size_t i = 0; i < fields.size(); ++i)
{
fields[i]->resetToDefaultValue();
}
}

View File

@ -19,18 +19,20 @@
#pragma once
#include "cafPdmObject.h"
#include "RIApplication.h"
#include "RiaApplication.h"
class RIPreferences : public caf::PdmObject
class RiaPreferences : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RIPreferences(void);
virtual ~RIPreferences(void);
RiaPreferences(void);
virtual ~RiaPreferences(void);
void resetToDefaults();
public: // Pdm Fields
caf::PdmField<caf::AppEnum< RIApplication::RINavigationPolicy > > navigationPolicy;
caf::PdmField<caf::AppEnum< RiaApplication::RINavigationPolicy > > navigationPolicy;
caf::PdmField<QString> scriptDirectory;
caf::PdmField<QString> scriptEditorExecutable;
@ -38,6 +40,8 @@ public: // Pdm Fields
caf::PdmField<int> defaultScaleFactorZ;
caf::PdmField<bool> defaultGridLines;
caf::PdmField<cvf::Color3f> defaultGridLineColors;
caf::PdmField<cvf::Color3f> defaultFaultGridLineColors;
caf::PdmField<bool> useShaders;
caf::PdmField<bool> showHud;
@ -51,5 +55,5 @@ public: // Pdm Fields
protected:
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) ;
};

View File

@ -4,8 +4,8 @@ project (ApplicationCode)
# NB: The generated file is written to Cmake binary folder to avoid source tree pollution
# This folder is added to include_directories
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RIVersionInfo.h.cmake
${CMAKE_BINARY_DIR}/Generated/RIVersionInfo.h
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.h.cmake
${CMAKE_BINARY_DIR}/Generated/RiaVersionInfo.h
)
@ -20,20 +20,21 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel
${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel
${CMAKE_BINARY_DIR}/Generated
${CMAKE_CURRENT_BINARY_DIR}
)
# Use all cpp and h files in the subdirectories
# Use all h files in the subdirectories to make them available in the project
file( GLOB_RECURSE HEADER_FILES *.h )
list( APPEND CPP_SOURCES
RIMain.cpp
RIStdInclude.cpp
RiaMain.cpp
RiaStdInclude.cpp
)
list( APPEND CPP_SOURCES
Application/RIApplication.cpp
Application/RIPreferences.cpp
Application/RiaApplication.cpp
Application/RiaPreferences.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
)
@ -49,22 +50,12 @@ list( APPEND CPP_SOURCES
ModelVisualization/RivWellHeadPartMgr.cpp
)
list( APPEND CPP_SOURCES
FileInterface/RifEclipseInputFileTools.cpp
FileInterface/RifEclipseOutputFileTools.cpp
FileInterface/RifEclipseRestartFilesetAccess.cpp
FileInterface/RifEclipseRestartDataAccess.cpp
FileInterface/RifEclipseUnifiedRestartFileAccess.cpp
FileInterface/RifReaderEclipseInput.cpp
FileInterface/RifReaderEclipseOutput.cpp
FileInterface/RifReaderMockModel.cpp
)
list( APPEND CPP_SOURCES
SocketInterface/RiaSocketServer.cpp
)
list( APPEND CPP_SOURCES
ProjectDataModel/RimCaseCollection.cpp
ProjectDataModel/RimCellFilter.cpp
ProjectDataModel/RimCellPropertyFilter.cpp
ProjectDataModel/RimCellPropertyFilterCollection.cpp
@ -73,11 +64,12 @@ list( APPEND CPP_SOURCES
ProjectDataModel/RimDefines.cpp
ProjectDataModel/RimLegendConfig.cpp
ProjectDataModel/RimProject.cpp
ProjectDataModel/RimReservoir.cpp
ProjectDataModel/RimCase.cpp
ProjectDataModel/RimIdenticalGridCaseGroup.cpp
ProjectDataModel/RimInputProperty.cpp
ProjectDataModel/RimInputPropertyCollection.cpp
ProjectDataModel/RimInputReservoir.cpp
ProjectDataModel/RimResultReservoir.cpp
ProjectDataModel/RimInputCase.cpp
ProjectDataModel/RimResultCase.cpp
ProjectDataModel/RimReservoirView.cpp
ProjectDataModel/RimResultDefinition.cpp
ProjectDataModel/RimResultSlot.cpp
@ -85,55 +77,62 @@ list( APPEND CPP_SOURCES
ProjectDataModel/RimWell.cpp
ProjectDataModel/RimWellCollection.cpp
ProjectDataModel/RimScriptCollection.cpp
ProjectDataModel/RimStatisticsCase.cpp
ProjectDataModel/RimStatisticsCaseCollection.cpp
ProjectDataModel/RimCalcScript.cpp
ProjectDataModel/RimExportInputPropertySettings.cpp
ProjectDataModel/RimBinaryExportSettings.cpp
ProjectDataModel/Rim3dOverlayInfoConfig.cpp
ProjectDataModel/RimUiTreeModelPdm.cpp
ProjectDataModel/RimUiTreeView.cpp
ProjectDataModel/RimReservoirCellResultsCacher.cpp
ProjectDataModel/RimStatisticsCaseEvaluator.cpp
)
# Populate the filenames into variable lists
include ("ReservoirDataModel/CMakeLists_files.cmake")
include ("FileInterface/CMakeLists_files.cmake")
list( APPEND CPP_SOURCES
${CODE_SOURCE_FILES}
)
list( APPEND CPP_SOURCES
ReservoirDataModel/RigCell.cpp
ReservoirDataModel/RigGridBase.cpp
ReservoirDataModel/RigReservoirCellResults.cpp
ReservoirDataModel/RigLocalGrid.cpp
ReservoirDataModel/RigMainGrid.cpp
ReservoirDataModel/RigReservoir.cpp
ReservoirDataModel/RigReservoirBuilderMock.cpp
ReservoirDataModel/RigWellResults.cpp
ReservoirDataModel/RigGridScalarDataAccess.cpp
)
list( APPEND CPP_SOURCES
UserInterface/RICursors.cpp
UserInterface/RIMainWindow.cpp
UserInterface/RIPreferencesDialog.cpp
UserInterface/RIResultInfoPanel.cpp
UserInterface/RIViewer.cpp
UserInterface/RiuCursors.cpp
UserInterface/RiuMainWindow.cpp
UserInterface/RiuPreferencesDialog.cpp
UserInterface/RiuResultInfoPanel.cpp
UserInterface/RiuViewer.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RIProcessMonitor.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
UserInterface/RiuProcessMonitor.cpp
)
# Define files for MOC-ing
set ( QT_MOC_HEADERS
Application/RIApplication.h
Application/RiaApplication.h
ProjectDataModel/RimUiTreeModelPdm.h
ProjectDataModel/RimUiTreeView.h
UserInterface/RIMainWindow.h
UserInterface/RIPreferencesDialog.h
UserInterface/RIResultInfoPanel.h
UserInterface/RIViewer.h
UserInterface/RIProcessMonitor.h
UserInterface/RiuMainWindow.h
UserInterface/RiuPreferencesDialog.h
UserInterface/RiuResultInfoPanel.h
UserInterface/RiuViewer.h
UserInterface/RiuProcessMonitor.h
SocketInterface/RiaSocketServer.h
UserInterface/RiuMultiCaseImportDialog.h
)
qt4_wrap_cpp( MOC_FILES_CPP ${QT_MOC_HEADERS} )
# Define files for the uic compiler
set ( QT_UI_FILES
UserInterface/RiuMultiCaseImportDialog.ui
)
qt4_wrap_ui( FORM_FILES_CPP ${QT_UI_FILES} )
# NOTE! Resources in subfolders must append to QRC_FILES using the following statement
# set( QRC_FILES
# ${QRC_FILES}
@ -149,25 +148,30 @@ set( QRC_FILES
# Runs RCC on specified files
qt4_add_resources( QRC_FILES_CPP ${QRC_FILES} )
# Adding resource (RC) files for Windows
if ( MSVC )
set( WIN_RESOURCE Resources/ResInsight.rc )
endif()
#############################################################################
# creating PCH's for MSVC and GCC on Linux
#############################################################################
set( RAW_SOURCES ${CPP_SOURCES} )
list( REMOVE_ITEM RAW_SOURCES RIStdInclude.cpp)
list( REMOVE_ITEM RAW_SOURCES ReservoirDataModel/RigReaderInterfaceECL.cpp)
list( REMOVE_ITEM RAW_SOURCES ReservoirDataModel/RigGridScalarDataAccess.cpp)
list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivCellEdgeEffectGenerator.cpp)
list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivPipeGeometryGenerator.cpp)
list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivWellPipesPartMgr.cpp)
list( REMOVE_ITEM RAW_SOURCES ModelVisualization/RivWellHeadPartMgr.cpp)
list( REMOVE_ITEM RAW_SOURCES Application/RiaImageFileCompare.cpp)
list( REMOVE_ITEM RAW_SOURCES Application/RiaImageCompareReporter.cpp)
list( REMOVE_ITEM RAW_SOURCES
RiaStdInclude.cpp
${CODE_SOURCE_FILES}
ModelVisualization/RivCellEdgeEffectGenerator.cpp
ModelVisualization/RivPipeGeometryGenerator.cpp
ModelVisualization/RivWellPipesPartMgr.cpp
ModelVisualization/RivWellHeadPartMgr.cpp
Application/RiaImageFileCompare.cpp
Application/RiaImageCompareReporter.cpp
FileInterface/RifEclipseInputFileTools.cpp
FileInterface/RifEclipseOutputFileTools.cpp
FileInterface/RifEclipseRestartFilesetAccess.cpp
@ -175,8 +179,9 @@ list( REMOVE_ITEM RAW_SOURCES
FileInterface/RifEclipseUnifiedRestartFileAccess.cpp
FileInterface/RifReaderEclipseInput.cpp
FileInterface/RifReaderEclipseOutput.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
UserInterface/RiuMultiCaseImportDialog.cpp
)
include( CustomPCH.cmake )
@ -189,7 +194,7 @@ set( ALL_INCLUDES
${QT_INCLUDES}
)
set( PCH_NAME RIStdInclude )
set( PCH_NAME RiaStdInclude )
set( GCC_PCH_TARGET gccPCH )
set( PCH_COMPILER_DEFINE EMPTY )
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@ -205,7 +210,9 @@ precompiled_header( RAW_SOURCES ALL_INCLUDES ${GCC_PCH_TARGET} ${PCH_NAME} ${PCH
add_executable(ResInsight
${CPP_SOURCES}
${MOC_FILES_CPP}
${FORM_FILES_CPP}
${QRC_FILES_CPP}
${WIN_RESOURCE}
${HEADER_FILES}
)

View File

@ -0,0 +1,31 @@
# Use this workaround until we're on 2.8.3 on all platforms and can use CMAKE_CURRENT_LIST_DIR directly
if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
set(CEE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/)
endif()
list(APPEND CODE_HEADER_FILES
${CEE_CURRENT_LIST_DIR}RifEclipseInputFileTools.h
${CEE_CURRENT_LIST_DIR}RifEclipseOutputFileTools.h
${CEE_CURRENT_LIST_DIR}RifEclipseRestartDataAccess.h
${CEE_CURRENT_LIST_DIR}RifEclipseRestartFilesetAccess.h
${CEE_CURRENT_LIST_DIR}RifEclipseUnifiedRestartFileAccess.h
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.h
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.h
${CEE_CURRENT_LIST_DIR}RifReaderInterface.h
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.h
)
list(APPEND CODE_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RifEclipseInputFileTools.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseOutputFileTools.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseRestartDataAccess.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseRestartFilesetAccess.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseUnifiedRestartFileAccess.cpp
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.cpp
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.cpp
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.cpp
)

View File

@ -18,39 +18,39 @@ include_directories(
${ResInsight_SOURCE_DIR}/cafProjectDataModel
${ResInsight_SOURCE_DIR}/CommonCode
#Remove when RigStatistics is out
${ResInsight_SOURCE_DIR}/ApplicationCode/ModelVisualization
)
set( FILEINTERFACE_CPP_SOURCES
../RifEclipseInputFileTools.cpp
../RifEclipseOutputFileTools.cpp
../RifEclipseRestartFilesetAccess.cpp
../RifEclipseRestartDataAccess.cpp
../RifEclipseUnifiedRestartFileAccess.cpp
../RifReaderEclipseOutput.cpp
../RifReaderEclipseInput.cpp
../RifReaderMockModel.cpp
)
set( RESERVOIRDATAMODEL_CPP_SOURCES
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigCell.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigGridBase.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigLocalGrid.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoir.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigWellResults.cpp
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp
# Populate variables from read from CMakeLists_files.cmake
set (CODE_SOURCE_FILES )
include ("${ResInsight_SOURCE_DIR}/ApplicationCode/FileInterface/CMakeLists_files.cmake")
set( CPP_SOURCES
${CPP_SOURCES}
${CODE_SOURCE_FILES}
)
source_group( "FileInterface" FILES ${CODE_SOURCE_FILES} )
# Populate variables from read from CMakeLists_files.cmake
set (CODE_SOURCE_FILES )
include ("${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake")
set( CPP_SOURCES
${CPP_SOURCES}
${CODE_SOURCE_FILES}
)
source_group( "ReservoirDataModel" FILES ${CODE_SOURCE_FILES} )
set( CPP_SOURCES
${CPP_SOURCES}
${ResInsight_SOURCE_DIR}/cafUserInterface/cafProgressInfo.cpp
)
set( CPP_SOURCES
${FILEINTERFACE_CPP_SOURCES}
${RESERVOIRDATAMODEL_CPP_SOURCES}
)
source_group( "FileInterface" FILES ${FILEINTERFACE_CPP_SOURCES} )
source_group( "ReservoirDataModel" FILES ${RESERVOIRDATAMODEL_CPP_SOURCES} )
source_group( "Headers" FILES ${CODE_HEADER_FILES} )
set( UNIT_TEST_CPP_SOURCES
main.cpp
@ -58,7 +58,6 @@ set( UNIT_TEST_CPP_SOURCES
Ert-Test.cpp
)
set( LINK_LIBRARIES
CommonCode
@ -75,20 +74,22 @@ set( LINK_LIBRARIES
${QT_LIBRARIES}
)
add_executable( ${ProjectName}
${CODE_HEADER_FILES}
${CPP_SOURCES}
${UNIT_TEST_CPP_SOURCES}
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
${ResInsight_SOURCE_DIR}/ApplicationCode/FileInterface/CMakeLists_files.cmake
${ResInsight_SOURCE_DIR}/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake
)
set( EXTERNAL_LINK_LIBRARIES ${ERT_LIBRARY_LIST} )
target_link_libraries( ${ProjectName} ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES})
# Copy Dlls
if (MSVC)
@ -101,21 +102,4 @@ if (MSVC)
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>)
endforeach( qtlib )
# DLLs ERT depends on
# add_custom_command(TARGET ${ProjectName} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "${PROJECT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/bin/"
# ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>)
# ERT DLLs
# set (ERT_MODULES ecl geometry util well)
# foreach (ert_module ${ERT_MODULES})
# add_custom_command(TARGET ${ProjectName} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# "${CMAKE_CURRENT_SOURCE_DIR}/../../../ThirdParty/Ert-windows/${ert_module}/lib/lib${ert_module}.dll"
# ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>)
# endforeach()
endif(MSVC)

View File

@ -23,7 +23,6 @@
#include <util.h>
#include <int_vector.h>
#include <ecl_intehead.h>
#include <ecl_file.h>
#include <ecl_kw.h>
#include <ecl_kw_magic.h>
@ -37,7 +36,7 @@
#include "gtest/gtest.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RifReaderEclipseInput.h"
#if 0

View File

@ -18,15 +18,15 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "gtest/gtest.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RifReaderEclipseOutput.h"
#include "ecl_file.h"
#include "RifEclipseOutputFileTools.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
@ -68,7 +68,7 @@ TEST(RigReservoirTest, FileOutputToolsTest)
void buildResultInfoString(RigReservoir* reservoir, RifReaderInterface::PorosityModelResultType porosityModel, RimDefines::ResultCatType resultType)
{
RigReservoirCellResults* matrixResults = reservoir->mainGrid()->results(porosityModel);
RigCaseCellResultsData* matrixResults = reservoir->results(porosityModel);
{
QStringList resultNames = matrixResults->resultNames(resultType);
@ -247,7 +247,7 @@ TEST(RigReservoirTest, BasicTest)
TEST(RigReservoirTest, WellTest)
{
cvf::ref<RifReaderEclipseOutput> readerInterfaceEcl = new RifReaderEclipseOutput;
cvf::ref<RigReservoir> reservoir = new RigReservoir;
cvf::ref<RigCaseData> reservoir = new RigCaseData;
// Location of test dataset received from Håkon Høgstøl in July 2011 with 10k active cells
#ifdef WIN32

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cvfBase.h"

View File

@ -18,9 +18,9 @@
#include "RifEclipseInputFileTools.h"
#include "RifReaderEclipseOutput.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "cafProgressInfo.h"
#include <vector>
@ -61,9 +61,9 @@ RifEclipseInputFileTools::~RifEclipseInputFileTools()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigReservoir* reservoir)
bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigCaseData* eclipseCase)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
qint64 coordPos = -1;
qint64 zcornPos = -1;
@ -154,7 +154,7 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigReservoi
progress.setProgress(6);
RifReaderEclipseOutput::transferGeometry(inputGrid, reservoir);
RifReaderEclipseOutput::transferGeometry(inputGrid, eclipseCase);
progress.setProgress(7);
progress.setProgressDescription("Cleaning up ...");
@ -176,7 +176,7 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigReservoi
//--------------------------------------------------------------------------------------------------
/// Read known properties from the input file
//--------------------------------------------------------------------------------------------------
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString &fileName, RigReservoir *reservoir)
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString &fileName, RigCaseData *reservoir)
{
CVF_ASSERT(reservoir);
@ -212,11 +212,11 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ECL_FLOAT_TYPE);
if (eclKeyWordData)
{
QString newResultName = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);
QString newResultName = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);
size_t resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName); // Should really merge with inputProperty object information because we need to use PropertyName, and not keyword
size_t resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false); // Should really merge with inputProperty object information because we need to use PropertyName, and not keyword
std::vector< std::vector<double> >& newPropertyData = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
std::vector< std::vector<double> >& newPropertyData = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
newPropertyData.push_back(std::vector<double>());
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
@ -282,9 +282,9 @@ std::vector< RifKeywordAndFilePos > RifEclipseInputFileTools::findKeywordsOnFile
/// Reads the property data requested into the \a reservoir, overwriting any previous
/// propeties with the same name.
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, const QString& resultName)
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, const QString& resultName)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
if (!filePointer) return false;
@ -294,13 +294,13 @@ bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigReservoi
if (eclKeyWordData)
{
QString newResultName = resultName;
size_t resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
size_t resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
{
resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName);
resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
}
std::vector< std::vector<double> >& newPropertyData = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
std::vector< std::vector<double> >& newPropertyData = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
newPropertyData.resize(1);
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
@ -370,11 +370,11 @@ const std::vector<QString>& RifEclipseInputFileTools::knownPropertyKeywords()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::writePropertyToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord)
bool RifEclipseInputFileTools::writePropertyToTextFile(const QString& fileName, RigCaseData* eclipseCase, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
size_t resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultName);
size_t resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
{
return false;
@ -386,7 +386,7 @@ bool RifEclipseInputFileTools::writePropertyToTextFile(const QString& fileName,
return false;
}
std::vector< std::vector<double> >& resultData = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
std::vector< std::vector<double> >& resultData = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
if (resultData.size() == 0)
{
return false;
@ -402,11 +402,11 @@ bool RifEclipseInputFileTools::writePropertyToTextFile(const QString& fileName,
/// Create and write a result vector with values for all cells.
/// undefinedValue is used for cells with no result
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileName, RigReservoir* reservoir, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue)
bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileName, RigCaseData* eclipseCase, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
size_t resultIndex = reservoir->mainGrid()->results(porosityModel)->findScalarResultIndex(resultName);
size_t resultIndex = eclipseCase->results(porosityModel)->findScalarResultIndex(resultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
{
return false;
@ -418,7 +418,7 @@ bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileNa
return false;
}
cvf::ref<RigGridScalarDataAccess> dataAccessObject = reservoir->mainGrid()->dataAccessObject(porosityModel, timeStep, resultIndex);
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->dataAccessObject(eclipseCase->mainGrid(), porosityModel, timeStep, resultIndex);
if (dataAccessObject.isNull())
{
return false;
@ -426,13 +426,13 @@ bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileNa
std::vector<double> resultData;
size_t i, j, k;
for (k = 0; k < reservoir->mainGrid()->cellCountK(); k++)
for (k = 0; k < eclipseCase->mainGrid()->cellCountK(); k++)
{
for (j = 0; j < reservoir->mainGrid()->cellCountJ(); j++)
for (j = 0; j < eclipseCase->mainGrid()->cellCountJ(); j++)
{
for (i = 0; i < reservoir->mainGrid()->cellCountI(); i++)
for (i = 0; i < eclipseCase->mainGrid()->cellCountI(); i++)
{
double resultValue = dataAccessObject->cellScalar(i, j, k);
double resultValue = dataAccessObject->cellScalar(eclipseCase->mainGrid()->cellIndexFromIJK(i, j, k));
if (resultValue == HUGE_VAL)
{
resultValue = undefinedValue;
@ -519,9 +519,9 @@ void RifEclipseInputFileTools::findGridKeywordPositions(const QString& filename,
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName)
bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
if (!filePointer) return false;
@ -532,13 +532,13 @@ bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileNam
if (eclKeyWordData)
{
QString newResultName = resultName;
size_t resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
size_t resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
{
resultIndex = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName);
resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
}
std::vector< std::vector<double> >& newPropertyData = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
std::vector< std::vector<double> >& newPropertyData = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
newPropertyData.resize(1);
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());

View File

@ -27,7 +27,7 @@
#include "RifReaderInterface.h"
class RigReservoir;
class RigCaseData;
class QFile;
@ -52,19 +52,19 @@ public:
RifEclipseInputFileTools();
virtual ~RifEclipseInputFileTools();
static bool openGridFile(const QString& fileName, RigReservoir* reservoir);
static bool openGridFile(const QString& fileName, RigCaseData* eclipseCase);
// Returns map of assigned resultName and Eclipse Keyword.
static std::map<QString, QString> readProperties(const QString& fileName, RigReservoir* reservoir);
static bool readProperty (const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, const QString& resultName );
static bool readPropertyAtFilePosition (const QString& fileName, RigReservoir* reservoir, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName );
static std::map<QString, QString> readProperties(const QString& fileName, RigCaseData* eclipseCase);
static bool readProperty (const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, const QString& resultName );
static bool readPropertyAtFilePosition (const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName );
static std::vector< RifKeywordAndFilePos > findKeywordsOnFile(const QString &fileName);
static const std::vector<QString>& knownPropertyKeywords();
static bool writePropertyToTextFile(const QString& fileName, RigReservoir* reservoir, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord);
static bool writeBinaryResultToTextFile(const QString& fileName, RigReservoir* reservoir, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue);
static bool writePropertyToTextFile(const QString& fileName, RigCaseData* eclipseCase, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord);
static bool writeBinaryResultToTextFile(const QString& fileName, RigCaseData* eclipseCase, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue);
private:
static void writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector<double>& resultData);

View File

@ -20,8 +20,8 @@
#include "util.h"
#include "ecl_file.h"
#include "ecl_intehead.h"
#include "ecl_kw_magic.h"
#include "ecl_grid.h"
#include <QFileInfo>
#include <QDebug>
@ -46,7 +46,7 @@ RifEclipseOutputFileTools::~RifEclipseOutputFileTools()
//--------------------------------------------------------------------------------------------------
/// Get list of time step texts (dates)
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTime>* timeSteps, bool* detectedFractionOfDay )
void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, bool* detectedFractionOfDay )
{
CVF_ASSERT(timeSteps);
CVF_ASSERT(ecl_file);
@ -84,7 +84,7 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
}
}
QList<QDateTime> timeStepsFound;
std::vector<QDateTime> timeStepsFound;
if (hasFractionOfDay)
{
@ -102,15 +102,15 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
double floorDayValue = cvf::Math::floor(dayValue);
double dayFraction = dayValue - floorDayValue;
int seconds = (dayFraction * 24.0 * 60.0 * 60.0);
int seconds = static_cast<int>(dayFraction * 24.0 * 60.0 * 60.0);
QTime time(0, 0);
time = time.addSecs(seconds);
QDate reportDate = simulationStart;
reportDate = reportDate.addDays(floorDayValue);
reportDate = reportDate.addDays(static_cast<int>(floorDayValue));
QDateTime reportDateTime(reportDate, time);
if (timeStepsFound.indexOf(reportDateTime) < 0)
if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) == timeStepsFound.end())
{
timeStepsFound.push_back(reportDateTime);
}
@ -132,7 +132,7 @@ void RifEclipseOutputFileTools::timeSteps(ecl_file_type* ecl_file, QList<QDateTi
CVF_ASSERT(reportDate.isValid());
QDateTime reportDateTime(reportDate);
if (timeStepsFound.indexOf(reportDateTime) < 0)
if (std::find(timeStepsFound.begin(), timeStepsFound.end(), reportDateTime) == timeStepsFound.end())
{
timeStepsFound.push_back(reportDateTime);
}
@ -172,11 +172,33 @@ bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QStri
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values)
{
ecl_kw_type* kwData = ecl_file_iget_named_kw(ecl_file, keyword.toAscii().data(), static_cast<int>(fileKeywordOccurrence));
if (kwData)
{
size_t numValues = ecl_kw_get_size(kwData);
std::vector<int> integerData;
integerData.resize(numValues);
ecl_kw_get_memcpy_int_data(kwData, integerData.data());
values->insert(values->end(), integerData.begin(), integerData.end());
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
/// Get first occurrence of file of given type in given list of filenames, as filename or NULL if not found
//--------------------------------------------------------------------------------------------------
QString RifEclipseOutputFileTools::fileNameByType(const QStringList& fileSet, ecl_file_enum fileType)
QString RifEclipseOutputFileTools::firstFileNameOfType(const QStringList& fileSet, ecl_file_enum fileType)
{
int i;
for (i = 0; i < fileSet.count(); i++)
@ -194,9 +216,9 @@ QString RifEclipseOutputFileTools::fileNameByType(const QStringList& fileSet, ec
//--------------------------------------------------------------------------------------------------
/// Get all files of file of given type in given list of filenames, as filename or NULL if not found
/// Get all files of the given type from the provided list of filenames
//--------------------------------------------------------------------------------------------------
QStringList RifEclipseOutputFileTools::fileNamesByType(const QStringList& fileSet, ecl_file_enum fileType)
QStringList RifEclipseOutputFileTools::filterFileNamesOfType(const QStringList& fileSet, ecl_file_enum fileType)
{
QStringList fileNames;
@ -218,14 +240,14 @@ QStringList RifEclipseOutputFileTools::fileNamesByType(const QStringList& fileSe
//--------------------------------------------------------------------------------------------------
/// Get set of Eclipse files based on an input file and its path
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::fileSet(const QString& fileName, QStringList* fileSet)
bool RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(const QString& fullPathFileName, QStringList* baseNameFiles)
{
CVF_ASSERT(fileSet);
fileSet->clear();
CVF_ASSERT(baseNameFiles);
baseNameFiles->clear();
QString filePath = QFileInfo(fileName).absoluteFilePath();
QString filePath = QFileInfo(fullPathFileName).absoluteFilePath();
filePath = QFileInfo(filePath).path();
QString fileNameBase = QFileInfo(fileName).baseName();
QString fileNameBase = QFileInfo(fullPathFileName).baseName();
stringlist_type* eclipseFiles = stringlist_alloc_new();
ecl_util_select_filelist(filePath.toAscii().data(), fileNameBase.toAscii().data(), ECL_OTHER_FILE, false, eclipseFiles);
@ -233,12 +255,12 @@ bool RifEclipseOutputFileTools::fileSet(const QString& fileName, QStringList* fi
int i;
for (i = 0; i < stringlist_get_size(eclipseFiles); i++)
{
fileSet->append(stringlist_safe_iget(eclipseFiles, i));
baseNameFiles->append(stringlist_safe_iget(eclipseFiles, i));
}
stringlist_free(eclipseFiles);
return fileSet->count() > 0;
return baseNameFiles->count() > 0;
}
@ -280,3 +302,20 @@ void RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(ecl_file_type* ecl
info.setProgress(i);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseOutputFileTools::readGridDimensions(const QString& gridFileName, std::vector< std::vector<int> >& gridDimensions)
{
int gridDims[3];
bool ret = ecl_grid_file_dims(gridFileName.toAscii().data(), NULL, gridDims);
if (ret)
{
gridDimensions.resize(1);
gridDimensions[0].push_back(gridDims[0]);
gridDimensions[0].push_back(gridDims[1]);
gridDimensions[0].push_back(gridDims[2]);
}
}

View File

@ -45,12 +45,15 @@ public:
static void findKeywordsAndDataItemCounts(ecl_file_type* ecl_file, QStringList* keywords, std::vector<size_t>* keywordDataItemCounts);
static bool keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<double>* values);
static bool keywordData(ecl_file_type* ecl_file, const QString& keyword, size_t fileKeywordOccurrence, std::vector<int>* values);
// static void timeStepsText(ecl_file_type* ecl_file, QStringList* timeSteps);
static void timeSteps(ecl_file_type* ecl_file, QList<QDateTime>* timeSteps, bool* detectedFractionOfDay = NULL);
static void timeSteps(ecl_file_type* ecl_file, std::vector<QDateTime>* timeSteps, bool* detectedFractionOfDay = NULL);
static bool fileSet(const QString& fileName, QStringList* fileSet);
static bool findSiblingFilesWithSameBaseName(const QString& fileName, QStringList* fileSet);
static QString fileNameByType(const QStringList& fileSet, ecl_file_enum fileType);
static QStringList fileNamesByType(const QStringList& fileSet, ecl_file_enum fileType);
static QString firstFileNameOfType(const QStringList& fileSet, ecl_file_enum fileType);
static QStringList filterFileNamesOfType(const QStringList& fileSet, ecl_file_enum fileType);
static void readGridDimensions(const QString& gridFileName, std::vector< std::vector<int> >& gridDimensions);
};

View File

@ -42,11 +42,13 @@ public:
RifEclipseRestartDataAccess();
virtual ~RifEclipseRestartDataAccess();
virtual bool open(const QStringList& fileSet) = 0;
virtual bool open() = 0;
virtual void setRestartFiles(const QStringList& fileSet) = 0;
virtual void close() = 0;
virtual void setTimeSteps(const std::vector<QDateTime>& timeSteps) {};
virtual size_t timeStepCount() = 0;
virtual QList<QDateTime> timeSteps() = 0;
virtual std::vector<QDateTime> timeSteps() = 0;
virtual void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts) = 0;
virtual bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values) = 0;

View File

@ -40,30 +40,45 @@ RifEclipseRestartFilesetAccess::~RifEclipseRestartFilesetAccess()
//--------------------------------------------------------------------------------------------------
/// Open files
//--------------------------------------------------------------------------------------------------
bool RifEclipseRestartFilesetAccess::open(const QStringList& fileSet)
bool RifEclipseRestartFilesetAccess::open()
{
close();
int numFiles = fileSet.size();
caf::ProgressInfo progInfo(numFiles,"");
int i;
for (i = 0; i < numFiles; i++)
if (m_fileNames.size() > 0)
{
progInfo.setProgressDescription(fileSet[i]);
caf::ProgressInfo progInfo(m_fileNames.size(), "");
ecl_file_type* ecl_file = ecl_file_open(fileSet[i].toAscii().data());
if (!ecl_file) return false;
int i;
for (i = 0; i < m_fileNames.size(); i++)
{
progInfo.setProgressDescription(m_fileNames[i]);
m_ecl_files.push_back(ecl_file);
openTimeStep(i);
progInfo.incrementProgress();
progInfo.incrementProgress();
}
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseRestartFilesetAccess::setRestartFiles(const QStringList& fileSet)
{
close();
m_ecl_files.clear();
m_fileNames = fileSet;
m_fileNames.sort(); // To make sure they are sorted in increasing *.X000N order. Hack. Should probably be actual time stored on file.
for (int i = 0; i < m_fileNames.size(); i++)
{
m_ecl_files.push_back(NULL);
}
CVF_ASSERT(m_fileNames.size() == static_cast<int>(m_ecl_files.size()));
}
//--------------------------------------------------------------------------------------------------
/// Close files
//--------------------------------------------------------------------------------------------------
@ -71,10 +86,22 @@ void RifEclipseRestartFilesetAccess::close()
{
for (size_t i = 0; i < m_ecl_files.size(); i++)
{
ecl_file_close(m_ecl_files[i]);
}
m_ecl_files.clear();
if (m_ecl_files[i])
{
ecl_file_close(m_ecl_files[i]);
}
m_ecl_files[i] = NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseRestartFilesetAccess::setTimeSteps(const std::vector<QDateTime>& timeSteps)
{
CVF_ASSERT((size_t)m_fileNames.size() == timeSteps.size());
m_timeSteps = timeSteps;
}
//--------------------------------------------------------------------------------------------------
@ -82,35 +109,39 @@ void RifEclipseRestartFilesetAccess::close()
//--------------------------------------------------------------------------------------------------
size_t RifEclipseRestartFilesetAccess::timeStepCount()
{
return m_ecl_files.size();
return m_timeSteps.size();
}
//--------------------------------------------------------------------------------------------------
/// Get the time steps
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RifEclipseRestartFilesetAccess::timeSteps()
std::vector<QDateTime> RifEclipseRestartFilesetAccess::timeSteps()
{
QList<QDateTime> timeSteps;
size_t numSteps = timeStepCount();
size_t i;
for (i = 0; i < numSteps; i++)
if (m_timeSteps.size() == 0)
{
QList<QDateTime> stepTime;
RifEclipseOutputFileTools::timeSteps(m_ecl_files[i], &stepTime);
if (stepTime.size() == 1)
size_t numSteps = m_fileNames.size();
size_t i;
for (i = 0; i < numSteps; i++)
{
timeSteps.push_back(stepTime[0]);
}
else
{
timeSteps.push_back(QDateTime());
std::vector<QDateTime> stepTime;
openTimeStep(i);
RifEclipseOutputFileTools::timeSteps(m_ecl_files[i], &stepTime);
if (stepTime.size() == 1)
{
m_timeSteps.push_back(stepTime[0]);
}
else
{
m_timeSteps.push_back(QDateTime());
}
}
}
return timeSteps;
return m_timeSteps;
}
//--------------------------------------------------------------------------------------------------
@ -120,6 +151,8 @@ void RifEclipseRestartFilesetAccess::resultNames(QStringList* resultNames, std::
{
CVF_ASSERT(timeStepCount() > 0);
openTimeStep(0);
std::vector<size_t> valueCountForOneFile;
RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(m_ecl_files[0], resultNames, &valueCountForOneFile);
@ -134,28 +167,35 @@ void RifEclipseRestartFilesetAccess::resultNames(QStringList* resultNames, std::
//--------------------------------------------------------------------------------------------------
bool RifEclipseRestartFilesetAccess::results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values)
{
size_t numOccurrences = ecl_file_get_num_named_kw(m_ecl_files[timeStep], resultName.toAscii().data());
if (timeStep >= timeStepCount())
{
return false;
}
openTimeStep(timeStep);
size_t fileGridCount = ecl_file_get_num_named_kw(m_ecl_files[timeStep], resultName.toAscii().data());
// No results for this result variable for current time step found
if (numOccurrences == 0) return true;
if (fileGridCount == 0) return true;
// Result handling depends on presents of result values for all grids
if (gridCount != numOccurrences)
if (gridCount != fileGridCount)
{
return false;
}
size_t i;
for (i = 0; i < numOccurrences; i++)
for (i = 0; i < fileGridCount; i++)
{
std::vector<double> partValues;
std::vector<double> gridValues;
if (!RifEclipseOutputFileTools::keywordData(m_ecl_files[timeStep], resultName, i, &partValues))
if (!RifEclipseOutputFileTools::keywordData(m_ecl_files[timeStep], resultName, i, &gridValues))
{
return false;
}
values->insert(values->end(), partValues.begin(), partValues.end());
values->insert(values->end(), gridValues.begin(), gridValues.end());
}
return true;
@ -171,6 +211,8 @@ void RifEclipseRestartFilesetAccess::readWellData(well_info_type* well_info)
for (size_t i = 0; i < m_ecl_files.size(); i++)
{
openTimeStep(i);
const char* fileName = ecl_file_get_src_file(m_ecl_files[i]);
int reportNumber = ecl_util_filename_report_nr(fileName);
if(reportNumber != -1)
@ -179,3 +221,20 @@ void RifEclipseRestartFilesetAccess::readWellData(well_info_type* well_info)
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseRestartFilesetAccess::openTimeStep(size_t timeStep)
{
CVF_ASSERT(timeStep < m_ecl_files.size());
if (m_ecl_files[timeStep] == NULL)
{
int index = static_cast<int>(timeStep);
ecl_file_type* ecl_file = ecl_file_open(m_fileNames[index].toAscii().data());
m_ecl_files[timeStep] = ecl_file;
}
}

View File

@ -35,11 +35,13 @@ public:
RifEclipseRestartFilesetAccess();
virtual ~RifEclipseRestartFilesetAccess();
bool open(const QStringList& fileSet);
bool open();
void setRestartFiles(const QStringList& fileSet);
void close();
void setTimeSteps(const std::vector<QDateTime>& timeSteps);
size_t timeStepCount();
QList<QDateTime> timeSteps();
std::vector<QDateTime> timeSteps();
void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts);
bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values);
@ -47,5 +49,11 @@ public:
virtual void readWellData(well_info_type* well_info);
private:
std::vector< ecl_file_type* > m_ecl_files;
void openTimeStep(size_t timeStep);
private:
QStringList m_fileNames;
std::vector<QDateTime> m_timeSteps;
std::vector< ecl_file_type* > m_ecl_files;
};

View File

@ -38,22 +38,23 @@ RifEclipseUnifiedRestartFileAccess::RifEclipseUnifiedRestartFileAccess()
//--------------------------------------------------------------------------------------------------
RifEclipseUnifiedRestartFileAccess::~RifEclipseUnifiedRestartFileAccess()
{
if (m_ecl_file)
{
ecl_file_close(m_ecl_file);
}
m_ecl_file = NULL;
close();
}
//--------------------------------------------------------------------------------------------------
/// Open file
//--------------------------------------------------------------------------------------------------
bool RifEclipseUnifiedRestartFileAccess::open(const QStringList& fileSet)
bool RifEclipseUnifiedRestartFileAccess::open()
{
QString fileName = fileSet[0];
return true;
}
m_ecl_file = ecl_file_open(fileName.toAscii().data());
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseUnifiedRestartFileAccess::openFile()
{
m_ecl_file = ecl_file_open(m_filename.toAscii().data());
if (!m_ecl_file) return false;
return true;
@ -64,6 +65,12 @@ bool RifEclipseUnifiedRestartFileAccess::open(const QStringList& fileSet)
//--------------------------------------------------------------------------------------------------
void RifEclipseUnifiedRestartFileAccess::close()
{
if (m_ecl_file)
{
ecl_file_close(m_ecl_file);
}
m_ecl_file = NULL;
}
//--------------------------------------------------------------------------------------------------
@ -71,18 +78,25 @@ void RifEclipseUnifiedRestartFileAccess::close()
//--------------------------------------------------------------------------------------------------
size_t RifEclipseUnifiedRestartFileAccess::timeStepCount()
{
if (!openFile())
{
return 0;
}
return timeSteps().size();
}
//--------------------------------------------------------------------------------------------------
/// Get the time steps
//--------------------------------------------------------------------------------------------------
QList<QDateTime> RifEclipseUnifiedRestartFileAccess::timeSteps()
std::vector<QDateTime> RifEclipseUnifiedRestartFileAccess::timeSteps()
{
CVF_ASSERT(m_ecl_file != NULL);
std::vector<QDateTime> timeSteps;
QList<QDateTime> timeSteps;
RifEclipseOutputFileTools::timeSteps(m_ecl_file, &timeSteps);
if (openFile())
{
RifEclipseOutputFileTools::timeSteps(m_ecl_file, &timeSteps);
}
return timeSteps;
}
@ -92,7 +106,10 @@ QList<QDateTime> RifEclipseUnifiedRestartFileAccess::timeSteps()
//--------------------------------------------------------------------------------------------------
void RifEclipseUnifiedRestartFileAccess::resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts)
{
RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(m_ecl_file, resultNames, resultDataItemCounts);
if (openFile())
{
RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(m_ecl_file, resultNames, resultDataItemCounts);
}
}
//--------------------------------------------------------------------------------------------------
@ -100,6 +117,11 @@ void RifEclipseUnifiedRestartFileAccess::resultNames(QStringList* resultNames, s
//--------------------------------------------------------------------------------------------------
bool RifEclipseUnifiedRestartFileAccess::results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values)
{
if (!openFile())
{
return false;
}
size_t numOccurrences = ecl_file_get_num_named_kw(m_ecl_file, resultName.toAscii().data());
size_t startIndex = timeStep * gridCount;
@ -124,8 +146,19 @@ bool RifEclipseUnifiedRestartFileAccess::results(const QString& resultName, size
void RifEclipseUnifiedRestartFileAccess::readWellData(well_info_type* well_info)
{
if (!well_info) return;
CVF_ASSERT(m_ecl_file);
well_info_add_UNRST_wells(well_info, m_ecl_file);
if (openFile())
{
well_info_add_UNRST_wells(well_info, m_ecl_file);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseUnifiedRestartFileAccess::setRestartFiles(const QStringList& fileSet)
{
m_filename = fileSet[0];
}

View File

@ -37,11 +37,12 @@ public:
RifEclipseUnifiedRestartFileAccess();
virtual ~RifEclipseUnifiedRestartFileAccess();
bool open(const QStringList& fileSet);
void setRestartFiles(const QStringList& fileSet);
bool open();
void close();
size_t timeStepCount();
QList<QDateTime> timeSteps();
std::vector<QDateTime> timeSteps();
void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts);
bool results(const QString& resultName, size_t timeStep, size_t gridCount, std::vector<double>* values);
@ -49,5 +50,9 @@ public:
virtual void readWellData(well_info_type * well_info);
private:
bool openFile();
private:
QString m_filename;
ecl_file_type* m_ecl_file;
};

View File

@ -19,8 +19,8 @@
#include "cvfBase.h"
#include "RigMainGrid.h"
#include "RigReservoir.h"
#include "RigReservoirCellResults.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "RifReaderEclipseInput.h"
#include "RifReaderEclipseOutput.h"
@ -57,9 +57,9 @@ RifReaderEclipseInput::~RifReaderEclipseInput()
//--------------------------------------------------------------------------------------------------
/// Open file and read geometry into given reservoir object
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseInput::open(const QString& fileName, RigReservoir* reservoir)
bool RifReaderEclipseInput::open(const QString& fileName, RigCaseData* eclipseCase)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
// Make sure everything's closed
close();
@ -84,9 +84,9 @@ bool RifReaderEclipseInput::open(const QString& fileName, RigReservoir* reservoi
// create InputProperty object
bool isOk = false;
if (reservoir->mainGrid()->gridPointDimensions() == cvf::Vec3st(0,0,0))
if (eclipseCase->mainGrid()->gridPointDimensions() == cvf::Vec3st(0,0,0))
{
isOk = RifEclipseInputFileTools::openGridFile(fileName, reservoir);
isOk = RifEclipseInputFileTools::openGridFile(fileName, eclipseCase);
}
return isOk;

View File

@ -32,7 +32,7 @@ public:
virtual ~RifReaderEclipseInput();
// Virtual interface implementation
virtual bool open(const QString& fileName, RigReservoir* reservoir);
virtual bool open(const QString& fileName, RigCaseData* eclipseCase);

View File

@ -19,8 +19,8 @@
#include "cvfBase.h"
#include "RigMainGrid.h"
#include "RigReservoir.h"
#include "RigReservoirCellResults.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "RifReaderEclipseOutput.h"
#include "RifEclipseOutputFileTools.h"
@ -32,6 +32,8 @@
#include "ecl_grid.h"
#include "well_state.h"
#include "ecl_kw_magic.h"
#include "cafProgressInfo.h"
//--------------------------------------------------------------------------------------------------
@ -84,8 +86,10 @@ static const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
// Static functions
//**************************************************************************************************
bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const ecl_grid_type* localEclGrid, size_t matrixActiveStartIndex, size_t fractureActiveStartIndex)
bool transferGridCellData(RigMainGrid* mainGrid, RigActiveCellInfo* activeCellInfo, RigActiveCellInfo* fractureActiveCellInfo, RigGridBase* localGrid, const ecl_grid_type* localEclGrid, size_t matrixActiveStartIndex, size_t fractureActiveStartIndex)
{
CVF_ASSERT(activeCellInfo && fractureActiveCellInfo);
int cellCount = ecl_grid_get_global_size(localEclGrid);
size_t cellStartIndex = mainGrid->cells().size();
size_t nodeStartIndex = mainGrid->nodes().size();
@ -103,39 +107,31 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const e
// Loop over cells and fill them with data
#pragma omp parallel for
for (int gIdx = 0; gIdx < cellCount; ++gIdx)
for (int localCellIdx = 0; localCellIdx < cellCount; ++localCellIdx)
{
RigCell& cell = mainGrid->cells()[cellStartIndex + gIdx];
RigCell& cell = mainGrid->cells()[cellStartIndex + localCellIdx];
bool invalid = ecl_grid_cell_invalid1(localEclGrid, gIdx);
bool invalid = ecl_grid_cell_invalid1(localEclGrid, localCellIdx);
cell.setInvalid(invalid);
cell.setCellIndex(gIdx);
cell.setCellIndex(localCellIdx);
// Active cell index
int matrixActiveIndex = ecl_grid_get_active_index1(localEclGrid, gIdx);
int matrixActiveIndex = ecl_grid_get_active_index1(localEclGrid, localCellIdx);
if (matrixActiveIndex != -1)
{
cell.setActiveIndexInMatrixModel(matrixActiveStartIndex + matrixActiveIndex);
}
else
{
cell.setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
activeCellInfo->setCellResultIndex(cellStartIndex + localCellIdx, matrixActiveStartIndex + matrixActiveIndex);
}
int fractureActiveIndex = ecl_grid_get_active_fracture_index1(localEclGrid, gIdx);
int fractureActiveIndex = ecl_grid_get_active_fracture_index1(localEclGrid, localCellIdx);
if (fractureActiveIndex != -1)
{
cell.setActiveIndexInFractureModel(fractureActiveStartIndex + fractureActiveIndex);
}
else
{
cell.setActiveIndexInFractureModel(cvf::UNDEFINED_SIZE_T);
fractureActiveCellInfo->setCellResultIndex(cellStartIndex + localCellIdx, fractureActiveStartIndex + fractureActiveIndex);
}
// Parent cell index
int parentCellIndex = ecl_grid_get_parent_cell1(localEclGrid, gIdx);
int parentCellIndex = ecl_grid_get_parent_cell1(localEclGrid, localCellIdx);
if (parentCellIndex == -1)
{
cell.setParentCellIndex(cvf::UNDEFINED_SIZE_T);
@ -146,21 +142,21 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const e
}
// Coarse cell info
ecl_coarse_cell_type * coarseCellData = ecl_grid_get_cell_coarse_group1( localEclGrid , gIdx);
ecl_coarse_cell_type * coarseCellData = ecl_grid_get_cell_coarse_group1( localEclGrid , localCellIdx);
cell.setInCoarseCell(coarseCellData != NULL);
// Corner coordinates
int cIdx;
for (cIdx = 0; cIdx < 8; ++cIdx)
{
double * point = mainGrid->nodes()[nodeStartIndex + gIdx * 8 + cellMappingECLRi[cIdx]].ptr();
ecl_grid_get_corner_xyz1(localEclGrid, gIdx, cIdx, &(point[0]), &(point[1]), &(point[2]));
double * point = mainGrid->nodes()[nodeStartIndex + localCellIdx * 8 + cellMappingECLRi[cIdx]].ptr();
ecl_grid_get_corner_xyz1(localEclGrid, localCellIdx, cIdx, &(point[0]), &(point[1]), &(point[2]));
point[2] = -point[2];
cell.cornerIndices()[cIdx] = nodeStartIndex + gIdx*8 + cIdx;
cell.cornerIndices()[cIdx] = nodeStartIndex + localCellIdx*8 + cIdx;
}
// Sub grid in cell
const ecl_grid_type* subGrid = ecl_grid_get_cell_lgr1(localEclGrid, gIdx);
const ecl_grid_type* subGrid = ecl_grid_get_cell_lgr1(localEclGrid, localCellIdx);
if (subGrid != NULL)
{
int subGridFileIndex = ecl_grid_get_grid_nr(subGrid);
@ -169,7 +165,9 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const e
}
// Mark inactive long pyramid looking cells as invalid
if (!invalid && (cell.isInCoarseCell() || (!cell.isActiveInMatrixModel() && !cell.isActiveInFractureModel()) ) )
// Forslag
//if (!invalid && (cell.isInCoarseCell() || (!cell.isActiveInMatrixModel() && !cell.isActiveInFractureModel()) ) )
if (!invalid)
{
cell.setInvalid(cell.isLongPyramidCell());
}
@ -193,7 +191,15 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigGridBase* localGrid, const e
//--------------------------------------------------------------------------------------------------
RifReaderEclipseOutput::RifReaderEclipseOutput()
{
ground();
m_fileName.clear();
m_filesWithSameBaseName.clear();
m_timeSteps.clear();
m_eclipseCase = NULL;
m_ecl_init_file = NULL;
m_dynamicResultsAccess = NULL;
}
//--------------------------------------------------------------------------------------------------
@ -201,37 +207,33 @@ RifReaderEclipseOutput::RifReaderEclipseOutput()
//--------------------------------------------------------------------------------------------------
RifReaderEclipseOutput::~RifReaderEclipseOutput()
{
close();
}
//--------------------------------------------------------------------------------------------------
/// Ground members
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::ground()
{
m_fileName.clear();
m_fileSet.clear();
m_timeSteps.clear();
m_mainGrid = NULL;
}
//--------------------------------------------------------------------------------------------------
/// Close interface (for now, no files are kept open after calling methods, so just clear members)
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::close()
{
m_ecl_file = NULL;
m_dynamicResultsAccess = NULL;
if (m_ecl_init_file)
{
ecl_file_close(m_ecl_init_file);
}
m_ecl_init_file = NULL;
ground();
if (m_dynamicResultsAccess.notNull())
{
m_dynamicResultsAccess->close();
}
}
//--------------------------------------------------------------------------------------------------
/// Read geometry from file given by name into given reservoir object
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid, RigReservoir* reservoir)
bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid, RigCaseData* eclipseCase)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
if (!mainEclGrid)
{
@ -239,7 +241,12 @@ bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid,
return false;
}
RigMainGrid* mainGrid = reservoir->mainGrid();
RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS);
RigActiveCellInfo* fractureActiveCellInfo = eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS);
CVF_ASSERT(activeCellInfo && fractureActiveCellInfo);
RigMainGrid* mainGrid = eclipseCase->mainGrid();
{
cvf::Vec3st gridPointDim(0,0,0);
gridPointDim.x() = ecl_grid_get_nx(mainEclGrid) + 1;
@ -274,6 +281,9 @@ bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid,
totalCellCount += ecl_grid_get_global_size(localEclGrid);
}
activeCellInfo->setGlobalCellCount(totalCellCount);
fractureActiveCellInfo->setGlobalCellCount(totalCellCount);
// Reserve room for the cells and nodes and fill them with data
mainGrid->cells().reserve(totalCellCount);
@ -283,15 +293,20 @@ bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid,
progInfo.setProgressDescription("Main Grid");
progInfo.setNextProgressIncrement(3);
transferGridCellData(mainGrid, mainGrid, mainEclGrid, 0, 0);
transferGridCellData(mainGrid, activeCellInfo, fractureActiveCellInfo, mainGrid, mainEclGrid, 0, 0);
progInfo.setProgress(3);
size_t globalMatrixActiveSize = ecl_grid_get_nactive(mainEclGrid);
size_t globalFractureActiveSize = ecl_grid_get_nactive_fracture(mainEclGrid);
mainGrid->setMatrixModelActiveCellCount(globalMatrixActiveSize);
mainGrid->setFractureModelActiveCellCount(globalFractureActiveSize);
activeCellInfo->setGridCount(1 + numLGRs);
fractureActiveCellInfo->setGridCount(1 + numLGRs);
activeCellInfo->setGridActiveCellCounts(0, globalMatrixActiveSize);
fractureActiveCellInfo->setGridActiveCellCounts(0, globalFractureActiveSize);
for (lgrIdx = 0; lgrIdx < numLGRs; ++lgrIdx)
{
@ -300,22 +315,21 @@ bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid,
ecl_grid_type* localEclGrid = ecl_grid_iget_lgr(mainEclGrid, lgrIdx);
RigLocalGrid* localGrid = static_cast<RigLocalGrid*>(mainGrid->gridByIndex(lgrIdx+1));
transferGridCellData(mainGrid, localGrid, localEclGrid, globalMatrixActiveSize, globalFractureActiveSize);
transferGridCellData(mainGrid, activeCellInfo, fractureActiveCellInfo, localGrid, localEclGrid, globalMatrixActiveSize, globalFractureActiveSize);
int activeCellCount = ecl_grid_get_nactive(localEclGrid);
localGrid->setMatrixModelActiveCellCount(activeCellCount);
globalMatrixActiveSize += activeCellCount;
int matrixActiveCellCount = ecl_grid_get_nactive(localEclGrid);
globalMatrixActiveSize += matrixActiveCellCount;
activeCellCount = ecl_grid_get_nactive_fracture(localEclGrid);
localGrid->setFractureModelActiveCellCount(activeCellCount);
globalFractureActiveSize += activeCellCount;
int fractureActiveCellCount = ecl_grid_get_nactive_fracture(localEclGrid);
globalFractureActiveSize += fractureActiveCellCount;
activeCellInfo->setGridActiveCellCounts(lgrIdx + 1, matrixActiveCellCount);
fractureActiveCellInfo->setGridActiveCellCounts(lgrIdx + 1, fractureActiveCellCount);
progInfo.setProgress(3 + lgrIdx);
}
mainGrid->setGlobalMatrixModelActiveCellCount(globalMatrixActiveSize);
mainGrid->setGlobalFractureModelActiveCellCount(globalFractureActiveSize);
activeCellInfo->computeDerivedData();
fractureActiveCellInfo->computeDerivedData();
return true;
}
@ -323,9 +337,9 @@ bool RifReaderEclipseOutput::transferGeometry(const ecl_grid_type* mainEclGrid,
//--------------------------------------------------------------------------------------------------
/// Open file and read geometry into given reservoir object
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservoir)
bool RifReaderEclipseOutput::open(const QString& fileName, RigCaseData* eclipseCase)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(eclipseCase);
caf::ProgressInfo progInfo(100, "");
progInfo.setProgressDescription("Reading Grid");
@ -335,13 +349,13 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservo
// Get set of files
QStringList fileSet;
if (!RifEclipseOutputFileTools::fileSet(fileName, &fileSet)) return false;
if (!RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(fileName, &fileSet)) return false;
progInfo.incrementProgress();
progInfo.setNextProgressIncrement(20);
// Keep the set of files of interest
m_fileSet = fileSet;
m_filesWithSameBaseName = fileSet;
// Read geometry
ecl_grid_type * mainEclGrid = ecl_grid_alloc( fileName.toAscii().data() );
@ -351,7 +365,7 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservo
progInfo.setNextProgressIncrement(10);
progInfo.setProgressDescription("Transferring grid geometry");
if (!transferGeometry(mainEclGrid, reservoir)) return false;
if (!transferGeometry(mainEclGrid, eclipseCase)) return false;
progInfo.incrementProgress();
progInfo.setProgressDescription("Releasing reader memory");
@ -361,47 +375,177 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigReservoir* reservo
progInfo.setProgressDescription("Reading Result index");
progInfo.setNextProgressIncrement(60);
m_mainGrid = reservoir->mainGrid();
reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(this);
reservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(this);
m_eclipseCase = eclipseCase;
// Build results meta data
if (!buildMetaData(reservoir)) return false;
if (!buildMetaData()) return false;
progInfo.incrementProgress();
progInfo.setNextProgressIncrement(8);
progInfo.setProgressDescription("Reading Well information");
readWellCells(reservoir);
readWellCells();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName, const std::vector<QDateTime>& mainCaseTimeSteps, RigCaseData* eclipseCase)
{
CVF_ASSERT(eclipseCase);
// It is required to have a main grid before reading active cell data
if (!eclipseCase->mainGrid())
{
return false;
}
close();
// Get set of files
QStringList fileSet;
if (!RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(fileName, &fileSet)) return false;
// Keep the set of files of interest
m_filesWithSameBaseName = fileSet;
m_eclipseCase = eclipseCase;
if (!readActiveCellInfo())
{
return false;
}
// Reading of metadata and well cells is not performed here
//if (!buildMetaData()) return false;
// readWellCells();
m_dynamicResultsAccess = createDynamicResultsAccess();
m_dynamicResultsAccess->setTimeSteps(mainCaseTimeSteps);
return true;
}
//--------------------------------------------------------------------------------------------------
///
/// See also RigStatistics::computeActiveCellUnion()
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::readActiveCellInfo()
{
CVF_ASSERT(m_eclipseCase);
CVF_ASSERT(m_eclipseCase->mainGrid());
QString egridFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_EGRID_FILE);
if (egridFileName.size() > 0)
{
ecl_file_type* ecl_file = ecl_file_open(egridFileName.toAscii().data());
if (!ecl_file) return false;
int actnumKeywordCount = ecl_file_get_num_named_kw(ecl_file, ACTNUM_KW);
if (actnumKeywordCount > 0)
{
std::vector<std::vector<int> > actnumValuesPerGrid;
actnumValuesPerGrid.resize(actnumKeywordCount);
size_t globalCellCount = 0;
for (size_t gridIdx = 0; gridIdx < static_cast<size_t>(actnumKeywordCount); gridIdx++)
{
RifEclipseOutputFileTools::keywordData(ecl_file, ACTNUM_KW, gridIdx, &actnumValuesPerGrid[gridIdx]);
globalCellCount += actnumValuesPerGrid[gridIdx].size();
}
// Check if number of cells is matching
if (m_eclipseCase->mainGrid()->cells().size() != globalCellCount)
{
return false;
}
RigActiveCellInfo* activeCellInfo = m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS);
RigActiveCellInfo* fractureActiveCellInfo = m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS);
activeCellInfo->setGlobalCellCount(globalCellCount);
fractureActiveCellInfo->setGlobalCellCount(globalCellCount);
activeCellInfo->setGridCount(actnumKeywordCount);
fractureActiveCellInfo->setGridCount(actnumKeywordCount);
size_t cellIdx = 0;
size_t globalActiveMatrixIndex = 0;
size_t globalActiveFractureIndex = 0;
for (size_t gridIdx = 0; gridIdx < static_cast<size_t>(actnumKeywordCount); gridIdx++)
{
size_t activeMatrixIndex = 0;
size_t activeFractureIndex = 0;
std::vector<int>& actnumValues = actnumValuesPerGrid[gridIdx];
for (size_t i = 0; i < actnumValues.size(); i++)
{
if (actnumValues[i] == 1 || actnumValues[i] == 3)
{
activeCellInfo->setCellResultIndex(cellIdx, globalActiveMatrixIndex++);
activeMatrixIndex++;
}
if (actnumValues[i] == 2 || actnumValues[i] == 3)
{
fractureActiveCellInfo->setCellResultIndex(cellIdx, globalActiveFractureIndex++);
activeFractureIndex++;
}
cellIdx++;
}
activeCellInfo->setGridActiveCellCounts(gridIdx, activeMatrixIndex);
fractureActiveCellInfo->setGridActiveCellCounts(gridIdx, activeFractureIndex);
}
activeCellInfo->computeDerivedData();
fractureActiveCellInfo->computeDerivedData();
}
ecl_file_close(ecl_file);
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
/// Build meta data - get states and results info
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
bool RifReaderEclipseOutput::buildMetaData()
{
CVF_ASSERT(reservoir);
CVF_ASSERT(m_fileSet.size() > 0);
CVF_ASSERT(m_eclipseCase);
CVF_ASSERT(m_filesWithSameBaseName.size() > 0);
caf::ProgressInfo progInfo(m_fileSet.size() + 3,"");
caf::ProgressInfo progInfo(m_filesWithSameBaseName.size() + 3,"");
progInfo.setNextProgressIncrement(m_fileSet.size());
progInfo.setNextProgressIncrement(m_filesWithSameBaseName.size());
// Create access object for dynamic results
m_dynamicResultsAccess = dynamicResultsAccess(m_fileSet);
m_dynamicResultsAccess = createDynamicResultsAccess();
if (m_dynamicResultsAccess.isNull())
{
return false;
}
m_dynamicResultsAccess->open();
progInfo.incrementProgress();
RigReservoirCellResults* matrixModelResults = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS);
RigReservoirCellResults* fractureModelResults = reservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS);
RigCaseCellResultsData* matrixModelResults = m_eclipseCase->results(RifReaderInterface::MATRIX_RESULTS);
RigCaseCellResultsData* fractureModelResults = m_eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS);
if (m_dynamicResultsAccess.notNull())
{
@ -413,21 +557,27 @@ bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
m_dynamicResultsAccess->resultNames(&resultNames, &resultNamesDataItemCounts);
{
QStringList matrixResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts, RifReaderInterface::MATRIX_RESULTS, m_dynamicResultsAccess->timeStepCount());
QStringList matrixResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts,
m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS),
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::MATRIX_RESULTS, m_dynamicResultsAccess->timeStepCount());
for (int i = 0; i < matrixResultNames.size(); ++i)
{
size_t resIndex = matrixModelResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, matrixResultNames[i]);
size_t resIndex = matrixModelResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, matrixResultNames[i], false);
matrixModelResults->setTimeStepDates(resIndex, m_timeSteps);
}
}
{
QStringList fractureResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts, RifReaderInterface::FRACTURE_RESULTS, m_dynamicResultsAccess->timeStepCount());
QStringList fractureResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts,
m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS),
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::FRACTURE_RESULTS, m_dynamicResultsAccess->timeStepCount());
for (int i = 0; i < fractureResultNames.size(); ++i)
{
size_t resIndex = fractureModelResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, fractureResultNames[i]);
size_t resIndex = fractureModelResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, fractureResultNames[i], false);
fractureModelResults->setTimeStepDates(resIndex, m_timeSteps);
}
}
@ -436,22 +586,23 @@ bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
progInfo.incrementProgress();
QString initFileName = RifEclipseOutputFileTools::fileNameByType(m_fileSet, ECL_INIT_FILE);
if (initFileName.size() > 0)
openInitFile();
progInfo.incrementProgress();
if (m_ecl_init_file)
{
ecl_file_type* ecl_file = ecl_file_open(initFileName.toAscii().data());
if (!ecl_file) return false;
progInfo.incrementProgress();
QStringList resultNames;
std::vector<size_t> resultNamesDataItemCounts;
RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(ecl_file, &resultNames, &resultNamesDataItemCounts);
RifEclipseOutputFileTools::findKeywordsAndDataItemCounts(m_ecl_init_file, &resultNames, &resultNamesDataItemCounts);
{
QStringList matrixResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts, RifReaderInterface::MATRIX_RESULTS, 1);
QStringList matrixResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts,
m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS),
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::MATRIX_RESULTS, 1);
QList<QDateTime> staticDate;
std::vector<QDateTime> staticDate;
if (m_timeSteps.size() > 0)
{
staticDate.push_back(m_timeSteps.front());
@ -459,15 +610,18 @@ bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
for (int i = 0; i < matrixResultNames.size(); ++i)
{
size_t resIndex = matrixModelResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, matrixResultNames[i]);
size_t resIndex = matrixModelResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, matrixResultNames[i], false);
matrixModelResults->setTimeStepDates(resIndex, staticDate);
}
}
{
QStringList fractureResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts, RifReaderInterface::FRACTURE_RESULTS, 1);
QStringList fractureResultNames = validKeywordsForPorosityModel(resultNames, resultNamesDataItemCounts,
m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS),
m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS),
RifReaderInterface::FRACTURE_RESULTS, 1);
QList<QDateTime> staticDate;
std::vector<QDateTime> staticDate;
if (m_timeSteps.size() > 0)
{
staticDate.push_back(m_timeSteps.front());
@ -475,12 +629,10 @@ bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
for (int i = 0; i < fractureResultNames.size(); ++i)
{
size_t resIndex = fractureModelResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, fractureResultNames[i]);
size_t resIndex = fractureModelResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, fractureResultNames[i], false);
fractureModelResults->setTimeStepDates(resIndex, staticDate);
}
}
m_ecl_file = ecl_file;
}
return true;
@ -489,39 +641,28 @@ bool RifReaderEclipseOutput::buildMetaData(RigReservoir* reservoir)
//--------------------------------------------------------------------------------------------------
/// Create results access object (.UNRST or .X0001 ... .XNNNN)
//--------------------------------------------------------------------------------------------------
RifEclipseRestartDataAccess* RifReaderEclipseOutput::dynamicResultsAccess(const QStringList& fileSet)
RifEclipseRestartDataAccess* RifReaderEclipseOutput::createDynamicResultsAccess()
{
RifEclipseRestartDataAccess* resultsAccess = NULL;
// Look for unified restart file
QString unrstFileName = RifEclipseOutputFileTools::fileNameByType(fileSet, ECL_UNIFIED_RESTART_FILE);
QString unrstFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_UNIFIED_RESTART_FILE);
if (unrstFileName.size() > 0)
{
resultsAccess = new RifEclipseUnifiedRestartFileAccess();
if (!resultsAccess->open(QStringList(unrstFileName)))
{
delete resultsAccess;
return NULL;
}
resultsAccess->setRestartFiles(QStringList(unrstFileName));
}
else
{
// Look for set of restart files (one file per time step)
QStringList restartFiles = RifEclipseOutputFileTools::fileNamesByType(fileSet, ECL_RESTART_FILE);
QStringList restartFiles = RifEclipseOutputFileTools::filterFileNamesOfType(m_filesWithSameBaseName, ECL_RESTART_FILE);
if (restartFiles.size() > 0)
{
resultsAccess = new RifEclipseRestartFilesetAccess();
if (!resultsAccess->open(restartFiles))
{
delete resultsAccess;
return NULL;
}
resultsAccess->setRestartFiles(restartFiles);
}
}
// !! could add support for formatted result files
// !! consider priorities in case multiple types exist (.UNRST, .XNNNN, ...)
return resultsAccess;
}
@ -531,16 +672,22 @@ RifEclipseRestartDataAccess* RifReaderEclipseOutput::dynamicResultsAccess(const
bool RifReaderEclipseOutput::staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values)
{
CVF_ASSERT(values);
CVF_ASSERT(m_ecl_file);
if (!openInitFile())
{
return false;
}
CVF_ASSERT(m_ecl_init_file);
std::vector<double> fileValues;
size_t numOccurrences = ecl_file_get_num_named_kw(m_ecl_file, result.toAscii().data());
size_t numOccurrences = ecl_file_get_num_named_kw(m_ecl_init_file, result.toAscii().data());
size_t i;
for (i = 0; i < numOccurrences; i++)
{
std::vector<double> partValues;
RifEclipseOutputFileTools::keywordData(m_ecl_file, result, i, &partValues);
RifEclipseOutputFileTools::keywordData(m_ecl_init_file, result, i, &partValues);
fileValues.insert(fileValues.end(), partValues.begin(), partValues.end());
}
@ -554,10 +701,19 @@ bool RifReaderEclipseOutput::staticResult(const QString& result, PorosityModelRe
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values)
{
CVF_ASSERT(m_dynamicResultsAccess.notNull());
if (m_dynamicResultsAccess.isNull())
{
m_dynamicResultsAccess = createDynamicResultsAccess();
}
if (m_dynamicResultsAccess.isNull())
{
CVF_ASSERT(false);
return false;
}
std::vector<double> fileValues;
if (!m_dynamicResultsAccess->results(result, stepIndex, m_mainGrid->gridCount(), &fileValues))
if (!m_dynamicResultsAccess->results(result, stepIndex, m_eclipseCase->mainGrid()->gridCount(), &fileValues))
{
return false;
}
@ -570,9 +726,9 @@ bool RifReaderEclipseOutput::dynamicResult(const QString& result, PorosityModelR
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
void RifReaderEclipseOutput::readWellCells()
{
CVF_ASSERT(reservoir);
CVF_ASSERT(m_eclipseCase);
if (m_dynamicResultsAccess.isNull()) return;
@ -581,11 +737,11 @@ void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
m_dynamicResultsAccess->readWellData(ert_well_info);
RigMainGrid* mainGrid = reservoir->mainGrid();
RigMainGrid* mainGrid = m_eclipseCase->mainGrid();
std::vector<RigGridBase*> grids;
reservoir->allGrids(&grids);
m_eclipseCase->allGrids(&grids);
cvf::Collection<RigWellResults> wells;
cvf::Collection<RigSingleWellResultsData> wells;
caf::ProgressInfo progress(well_info_get_num_wells(ert_well_info), "");
int wellIdx;
@ -594,7 +750,7 @@ void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
const char* wellName = well_info_iget_well_name(ert_well_info, wellIdx);
CVF_ASSERT(wellName);
cvf::ref<RigWellResults> wellResults = new RigWellResults;
cvf::ref<RigSingleWellResultsData> wellResults = new RigSingleWellResultsData;
wellResults->m_wellName = wellName;
well_ts_type* ert_well_time_series = well_info_get_ts(ert_well_info , wellName);
@ -671,7 +827,7 @@ void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
// If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1
// Adjust K so index is always in valid grid region
if (cellK >= grids[gridNr]->cellCountK())
if (cellK >= static_cast<int>(grids[gridNr]->cellCountK()))
{
cellK -= static_cast<int>(grids[gridNr]->cellCountK());
}
@ -716,7 +872,7 @@ void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
// If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1
// Adjust K so index is always in valid grid region
if (cellK >= grids[gridNr]->cellCountK())
if (cellK >= static_cast<int>(grids[gridNr]->cellCountK()))
{
cellK -= static_cast<int>(grids[gridNr]->cellCountK());
}
@ -743,41 +899,27 @@ void RifReaderEclipseOutput::readWellCells(RigReservoir* reservoir)
well_info_free(ert_well_info);
reservoir->setWellResults(wells);
m_eclipseCase->setWellResults(wells);
}
//--------------------------------------------------------------------------------------------------
// For case DUALPORO, the well K index is reported outside the grid. If this happens,
// for the given IJ position, search from K=0 and upwards for first active cell.
//--------------------------------------------------------------------------------------------------
int RifReaderEclipseOutput::findSmallestActiveCellIndexK(const RigGridBase* grid, int cellI, int cellJ)
{
if (!grid) return -1;
for (int candidateCellK = 0; candidateCellK < grid->cellCountK(); candidateCellK++ )
{
if (grid->isCellActive(cellI, cellJ, candidateCellK))
{
return candidateCellK;
}
}
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RifReaderEclipseOutput::validKeywordsForPorosityModel(const QStringList& keywords, const std::vector<size_t>& keywordDataItemCounts, PorosityModelResultType matrixOrFracture, size_t timeStepCount) const
QStringList RifReaderEclipseOutput::validKeywordsForPorosityModel(const QStringList& keywords, const std::vector<size_t>& keywordDataItemCounts,
const RigActiveCellInfo* activeCellInfo, const RigActiveCellInfo* fractureActiveCellInfo,
PorosityModelResultType matrixOrFracture, size_t timeStepCount) const
{
if (keywords.size() != keywordDataItemCounts.size())
CVF_ASSERT(activeCellInfo);
if (keywords.size() != static_cast<int>(keywordDataItemCounts.size()))
{
return QStringList();
}
if (matrixOrFracture == RifReaderInterface::FRACTURE_RESULTS)
{
if (m_mainGrid->globalFractureModelActiveCellCount() == 0)
if (fractureActiveCellInfo->globalActiveCellCount() == 0)
{
return QStringList();
}
@ -790,17 +932,27 @@ QStringList RifReaderEclipseOutput::validKeywordsForPorosityModel(const QStringL
QString keyword = keywords[i];
size_t keywordDataCount = keywordDataItemCounts[i];
size_t timeStepsMatrix = keywordDataItemCounts[i] / m_mainGrid->globalMatrixModelActiveCellCount();
size_t timeStepsMatrixRest = keywordDataItemCounts[i] % m_mainGrid->globalMatrixModelActiveCellCount();
size_t timeStepsMatrixAndFracture = keywordDataItemCounts[i] / (m_mainGrid->globalMatrixModelActiveCellCount() + m_mainGrid->globalFractureModelActiveCellCount());
size_t timeStepsMatrixAndFractureRest = keywordDataItemCounts[i] % (m_mainGrid->globalMatrixModelActiveCellCount() + m_mainGrid->globalFractureModelActiveCellCount());
if (matrixOrFracture == RifReaderInterface::MATRIX_RESULTS)
if (activeCellInfo->globalActiveCellCount() > 0)
{
if (timeStepsMatrixRest == 0 || timeStepsMatrixAndFractureRest == 0)
size_t timeStepsMatrix = keywordDataItemCounts[i] / activeCellInfo->globalActiveCellCount();
size_t timeStepsMatrixRest = keywordDataItemCounts[i] % activeCellInfo->globalActiveCellCount();
size_t timeStepsMatrixAndFracture = keywordDataItemCounts[i] / (activeCellInfo->globalActiveCellCount() + fractureActiveCellInfo->globalActiveCellCount());
size_t timeStepsMatrixAndFractureRest = keywordDataItemCounts[i] % (activeCellInfo->globalActiveCellCount() + fractureActiveCellInfo->globalActiveCellCount());
if (matrixOrFracture == RifReaderInterface::MATRIX_RESULTS)
{
if (timeStepCount == timeStepsMatrix || timeStepCount == timeStepsMatrixAndFracture)
if (timeStepsMatrixRest == 0 || timeStepsMatrixAndFractureRest == 0)
{
if (timeStepCount == timeStepsMatrix || timeStepCount == timeStepsMatrixAndFracture)
{
keywordsWithCorrectNumberOfDataItems.push_back(keywords[i]);
}
}
}
else
{
if (timeStepsMatrixAndFractureRest == 0 && timeStepCount == timeStepsMatrixAndFracture)
{
keywordsWithCorrectNumberOfDataItems.push_back(keywords[i]);
}
@ -808,57 +960,87 @@ QStringList RifReaderEclipseOutput::validKeywordsForPorosityModel(const QStringL
}
else
{
if (timeStepsMatrixAndFractureRest == 0 && timeStepCount == timeStepsMatrixAndFracture)
{
keywordsWithCorrectNumberOfDataItems.push_back(keywords[i]);
}
keywordsWithCorrectNumberOfDataItems.push_back(keywords[i]);
}
}
return keywordsWithCorrectNumberOfDataItems;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::extractResultValuesBasedOnPorosityModel(PorosityModelResultType matrixOrFracture, std::vector<double>* destinationResultValues, const std::vector<double>& sourceResultValues)
{
if (matrixOrFracture == RifReaderInterface::MATRIX_RESULTS)
RigActiveCellInfo* fracActCellInfo = m_eclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS);
if (matrixOrFracture == RifReaderInterface::MATRIX_RESULTS && fracActCellInfo->globalActiveCellCount() == 0)
{
if (m_mainGrid->globalFractureModelActiveCellCount() == 0)
{
destinationResultValues->insert(destinationResultValues->end(), sourceResultValues.begin(), sourceResultValues.end());
}
else
{
size_t dataItemCount = 0;
size_t sourceStartPosition = 0;
for (size_t i = 0; i < m_mainGrid->gridCount(); i++)
{
size_t matrixActiveCellCount = m_mainGrid->gridByIndex(i)->matrixModelActiveCellCount();
size_t fractureActiveCellCount = m_mainGrid->gridByIndex(i)->matrixModelActiveCellCount();
destinationResultValues->insert(destinationResultValues->end(), sourceResultValues.begin() + sourceStartPosition, sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount);
sourceStartPosition += (matrixActiveCellCount + fractureActiveCellCount);
}
}
destinationResultValues->insert(destinationResultValues->end(), sourceResultValues.begin(), sourceResultValues.end());
}
else
{
RigActiveCellInfo* actCellInfo = m_eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS);
size_t dataItemCount = 0;
size_t sourceStartPosition = 0;
for (size_t i = 0; i < m_mainGrid->gridCount(); i++)
for (size_t i = 0; i < m_eclipseCase->mainGrid()->gridCount(); i++)
{
size_t matrixActiveCellCount = m_mainGrid->gridByIndex(i)->matrixModelActiveCellCount();
size_t fractureActiveCellCount = m_mainGrid->gridByIndex(i)->matrixModelActiveCellCount();
size_t matrixActiveCellCount = 0;
size_t fractureActiveCellCount = 0;
destinationResultValues->insert(destinationResultValues->end(), sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount, sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount + fractureActiveCellCount);
actCellInfo->gridActiveCellCounts(i, matrixActiveCellCount);
fracActCellInfo->gridActiveCellCounts(i, fractureActiveCellCount);
if (matrixOrFracture == RifReaderInterface::MATRIX_RESULTS)
{
destinationResultValues->insert(destinationResultValues->end(),
sourceResultValues.begin() + sourceStartPosition,
sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount);
}
else
{
destinationResultValues->insert(destinationResultValues->end(),
sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount,
sourceResultValues.begin() + sourceStartPosition + matrixActiveCellCount + fractureActiveCellCount);
}
sourceStartPosition += (matrixActiveCellCount + fractureActiveCellCount);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseOutput::openInitFile()
{
if (m_ecl_init_file)
{
return true;
}
QString initFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_INIT_FILE);
if (initFileName.size() > 0)
{
m_ecl_init_file = ecl_file_open(initFileName.toAscii().data());
if (m_ecl_init_file)
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QDateTime> RifReaderEclipseOutput::timeSteps()
{
return m_timeSteps;
}

View File

@ -26,6 +26,7 @@ class RifEclipseOutputFileTools;
class RifEclipseRestartDataAccess;
class RigGridBase;
class RigMainGrid;
class RigActiveCellInfo;
typedef struct ecl_grid_struct ecl_grid_type;
typedef struct ecl_file_struct ecl_file_type;
@ -42,36 +43,38 @@ public:
RifReaderEclipseOutput();
virtual ~RifReaderEclipseOutput();
bool open(const QString& fileName, RigReservoir* reservoir);
bool open(const QString& fileName, RigCaseData* eclipseCase);
virtual bool openAndReadActiveCellData(const QString& fileName, const std::vector<QDateTime>& mainCaseTimeSteps, RigCaseData* eclipseCase);
void close();
bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values);
bool dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values);
static bool transferGeometry(const ecl_grid_type* mainEclGrid, RigReservoir* reservoir);
static bool transferGeometry(const ecl_grid_type* mainEclGrid, RigCaseData* eclipseCase);
private:
void ground();
bool buildMetaData(RigReservoir* reservoir);
void readWellCells(RigReservoir* reservoir);
bool readActiveCellInfo();
bool buildMetaData();
void readWellCells();
bool openInitFile();
bool openDynamicAccess();
void extractResultValuesBasedOnPorosityModel(PorosityModelResultType matrixOrFracture, std::vector<double>* values, const std::vector<double>& fileValues);
int findSmallestActiveCellIndexK( const RigGridBase* grid, int cellI, int cellJ);
RifEclipseRestartDataAccess* createDynamicResultsAccess();
static RifEclipseRestartDataAccess* staticResultsAccess(const QStringList& fileSet);
static RifEclipseRestartDataAccess* dynamicResultsAccess(const QStringList& fileSet);
QStringList validKeywordsForPorosityModel(const QStringList& keywords, const std::vector<size_t>& keywordDataItemCounts, PorosityModelResultType matrixOrFracture, size_t timeStepCount) const;
QStringList validKeywordsForPorosityModel(const QStringList& keywords, const std::vector<size_t>& keywordDataItemCounts, const RigActiveCellInfo* activeCellInfo, const RigActiveCellInfo* fractureActiveCellInfo, PorosityModelResultType matrixOrFracture, size_t timeStepCount) const;
virtual std::vector<QDateTime> timeSteps();
private:
QString m_fileName; // Name of file used to start accessing Eclipse output files
QStringList m_fileSet; // Set of files in filename's path with same base name as filename
QStringList m_filesWithSameBaseName; // Set of files in filename's path with same base name as filename
cvf::cref<RigMainGrid> m_mainGrid;
RigCaseData* m_eclipseCase;
QList<QDateTime> m_timeSteps;
std::vector<QDateTime> m_timeSteps;
ecl_file_type* m_ecl_file; // File access to static results
ecl_file_type* m_ecl_init_file; // File access to static results
cvf::ref<RifEclipseRestartDataAccess> m_dynamicResultsAccess; // File access to dynamic results
};

View File

@ -24,9 +24,10 @@
#include <QString>
#include <QStringList>
#include <QDateTime>
class RigReservoir;
class RigCaseData;
//==================================================================================================
//
@ -46,10 +47,11 @@ public:
RifReaderInterface() {}
virtual ~RifReaderInterface() {}
virtual bool open(const QString& fileName, RigReservoir* reservoir) = 0;
virtual bool open(const QString& fileName, RigCaseData* eclipseCase) = 0;
virtual void close() = 0;
virtual bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector<double>* values) = 0;
virtual bool dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values) = 0;
};
virtual std::vector<QDateTime> timeSteps() { std::vector<QDateTime> timeSteps; return timeSteps; }
};

View File

@ -16,25 +16,25 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RifReaderMockModel.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RifReaderInterface.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderMockModel::open(const QString& fileName, RigReservoir* reservoir)
bool RifReaderMockModel::open(const QString& fileName, RigCaseData* eclipseCase)
{
m_reservoirBuilder.populateReservoir(reservoir);
m_reservoirBuilder.populateReservoir(eclipseCase);
m_reservoir = reservoir;
m_reservoir = eclipseCase;
RigReservoirCellResults* cellResults = reservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS);
RigCaseCellResultsData* cellResults = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS);
QList<QDateTime> dates;
std::vector<QDateTime> dates;
for (int i = 0; i < static_cast<int>(m_reservoirBuilder.timeStepCount()); i++)
{
@ -43,13 +43,13 @@ bool RifReaderMockModel::open(const QString& fileName, RigReservoir* reservoir)
for (size_t i = 0; i < m_reservoirBuilder.resultCount(); i++)
{
size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, QString("Dynamic_Result_%1").arg(i));
size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, QString("Dynamic_Result_%1").arg(i), false);
cellResults->setTimeStepDates(resIdx, dates);
}
if (m_reservoirBuilder.timeStepCount() == 0) return true;
QList<QDateTime> staticDates;
std::vector<QDateTime> staticDates;
staticDates.push_back(dates[0]);
for (int i = 0; i < static_cast<int>(m_reservoirBuilder.resultCount()); i++)
{
@ -59,7 +59,7 @@ bool RifReaderMockModel::open(const QString& fileName, RigReservoir* reservoir)
int resIndex = 0;
if (i > 1) resIndex = i;
size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, QString("Static_Result_%1%2").arg(resIndex).arg(varEnd));
size_t resIdx = cellResults->addEmptyScalarResult(RimDefines::STATIC_NATIVE, QString("Static_Result_%1%2").arg(resIndex).arg(varEnd), false);
cellResults->setTimeStepDates(resIdx, staticDates);
}
@ -68,7 +68,7 @@ bool RifReaderMockModel::open(const QString& fileName, RigReservoir* reservoir)
{ \
size_t resIdx; \
QString resultName(Name); \
resIdx = cellResults->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, resultName); \
resIdx = cellResults->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, resultName, false); \
cellResults->setTimeStepDates(resIdx, staticDates); \
cellResults->cellScalarResults(resIdx).resize(1); \
std::vector<double>& values = cellResults->cellScalarResults(resIdx)[0]; \
@ -96,7 +96,7 @@ void RifReaderMockModel::close()
//--------------------------------------------------------------------------------------------------
bool RifReaderMockModel::inputProperty(const QString& propertyName, std::vector<double>* values)
{
return m_reservoirBuilder.inputProperty(m_reservoir.p(), propertyName, values);
return m_reservoirBuilder.inputProperty(m_reservoir, propertyName, values);
}
//--------------------------------------------------------------------------------------------------
@ -104,7 +104,7 @@ bool RifReaderMockModel::inputProperty(const QString& propertyName, std::vector<
//--------------------------------------------------------------------------------------------------
bool RifReaderMockModel::staticResult(const QString& result, RifReaderInterface::PorosityModelResultType matrixOrFracture, std::vector<double>* values)
{
m_reservoirBuilder.staticResult(m_reservoir.p(), result, values);
m_reservoirBuilder.staticResult(m_reservoir, result, values);
return true;
}
@ -114,7 +114,7 @@ bool RifReaderMockModel::staticResult(const QString& result, RifReaderInterface:
//--------------------------------------------------------------------------------------------------
bool RifReaderMockModel::dynamicResult(const QString& result, RifReaderInterface::PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values)
{
m_reservoirBuilder.dynamicResult(m_reservoir.p(), result, stepIndex, values);
m_reservoirBuilder.dynamicResult(m_reservoir, result, stepIndex, values);
return true;
}
@ -170,8 +170,8 @@ void RifReaderMockModel::addLocalGridRefinement(const cvf::Vec3st& minCellPositi
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderMockModel::populateReservoir(RigReservoir* reservoir)
void RifReaderMockModel::populateReservoir(RigCaseData* eclipseCase)
{
m_reservoirBuilder.populateReservoir(reservoir);
m_reservoirBuilder.populateReservoir(eclipseCase);
}

View File

@ -33,17 +33,17 @@ public:
void addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors);
virtual bool open( const QString& fileName, RigReservoir* reservoir );
virtual bool open( const QString& fileName, RigCaseData* eclipseCase );
virtual void close();
virtual bool staticResult( const QString& result, RifReaderInterface::PorosityModelResultType matrixOrFracture, std::vector<double>* values );
virtual bool dynamicResult( const QString& result, RifReaderInterface::PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values );
private:
void populateReservoir(RigReservoir* reservoir);
void populateReservoir(RigCaseData* eclipseCase);
bool inputProperty( const QString& propertyName, std::vector<double>* values );
RigReservoirBuilderMock m_reservoirBuilder;
cvf::ref<RigReservoir> m_reservoir;
RigCaseData* m_reservoir;
};

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RivCellEdgeEffectGenerator.h"
@ -33,20 +33,27 @@
#include "cvfShaderProgram.h"
#include "cvfRenderStateCullFace.h"
#include <vector>
#include <QFile>
#include <QTextStream>
#include "RimReservoirView.h"
#include "RigGridBase.h"
#include "RigMainGrid.h"
#include "RigReservoirCellResults.h"
#include "cvfTextureImage.h"
#include "cvfTexture.h"
#include "cvfSampler.h"
#include "cvfScalarMapper.h"
#include "cafEffectGenerator.h"
#include <vector>
#include <QFile>
#include <QTextStream>
#include "RimReservoirView.h"
#include "RimResultSlot.h"
#include "RigGridBase.h"
#include "RigMainGrid.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigActiveCellInfo.h"
//--------------------------------------------------------------------------------------------------
///
@ -87,12 +94,12 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultSlot->legendConfig()->scalarMapper();
const RigGridBase* grid = dynamic_cast<const RigGridBase*>(generator->activeGrid());
CVF_ASSERT(grid != NULL);
bool cellScalarResultUseGlobalActiveIndex = true;
bool edgeScalarResultUseGlobalActiveIndex[6];
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
CVF_ASSERT(eclipseCase != NULL);
cvf::ref<cvf::StructGridScalarDataAccess> cellCenterDataAccessObject = NULL;
if (cellResultSlot->hasResult())
{
if (!cellResultSlot->hasDynamicResult())
@ -101,23 +108,30 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
timeStepIndex = 0;
}
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
cellScalarResultUseGlobalActiveIndex = grid->mainGrid()->results(porosityModel)->isUsingGlobalActiveIndex(cellResultSlot->gridScalarIndex());
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
cellCenterDataAccessObject = eclipseCase->dataAccessObject(grid, porosityModel, timeStepIndex, cellResultSlot->gridScalarIndex());
}
CVF_ASSERT(cellEdgeResultSlot->hasResult());
size_t resultIndices[6];
cellEdgeResultSlot->gridScalarIndices(resultIndices);
if (cellEdgeResultSlot->hasResult())
cvf::Collection<cvf::StructGridScalarDataAccess> cellEdgeDataAccessObjects;
size_t cubeFaceIdx;
for (cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
size_t cubeFaceIdx;
for (cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
cvf::ref<cvf::StructGridScalarDataAccess> daObj;
if (resultIndices[cubeFaceIdx] != cvf::UNDEFINED_SIZE_T)
{
if (resultIndices[cubeFaceIdx] != cvf::UNDEFINED_SIZE_T)
{
edgeScalarResultUseGlobalActiveIndex[cubeFaceIdx] = grid->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->isUsingGlobalActiveIndex(resultIndices[cubeFaceIdx]);
}
// Assuming static values to be mapped onto cell edge, always using time step zero
// TODO: Now hardcoded matrix results, should it be possible to use fracture results?
daObj = eclipseCase->dataAccessObject(grid, RifReaderInterface::MATRIX_RESULTS, 0, resultIndices[cubeFaceIdx]);
}
cellEdgeDataAccessObjects.push_back(daObj.p());
}
double ignoredScalarValue = cellEdgeResultSlot->ignoredScalarValue();
@ -138,15 +152,14 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color
size_t cellIndex = quadToCell[quadIdx];
size_t resultValueIndex = cellIndex;
if (cellScalarResultUseGlobalActiveIndex)
{
resultValueIndex = grid->cell(cellIndex).activeIndexInMatrixModel();
}
double scalarValue = HUGE_VAL;
if (cellCenterDataAccessObject.notNull())
{
scalarValue = cellCenterDataAccessObject->cellScalar(cellIndex);
}
{
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
double scalarValue = grid->mainGrid()->results(porosityModel)->cellScalarResult(timeStepIndex, cellResultSlot->gridScalarIndex(), resultValueIndex);
if (scalarValue != HUGE_VAL)
{
cellColorTextureCoord = cellResultScalarMapper->mapToTextureCoord(scalarValue)[0];
@ -168,14 +181,12 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
{
edgeColor = -1.0f; // Undefined texture coord. Shader handles this.
resultValueIndex = cellIndex;
if (edgeScalarResultUseGlobalActiveIndex[cubeFaceIdx])
double scalarValue = HUGE_VAL;
if (cellEdgeDataAccessObjects[cubeFaceIdx].notNull())
{
resultValueIndex = grid->cell(cellIndex).activeIndexInMatrixModel();
scalarValue = cellEdgeDataAccessObjects[cubeFaceIdx]->cellScalar(cellIndex);
}
// Assuming static values to be mapped onto cell edge, always using time step zero
double scalarValue = grid->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResult(0, resultIndices[cubeFaceIdx], resultValueIndex);
if (scalarValue != HUGE_VAL && scalarValue != ignoredScalarValue)
{
edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RivGridPartMgr.h"
#include "cvfPart.h"
#include "cafEffectGenerator.h"
@ -28,7 +28,10 @@
#include "RimResultSlot.h"
#include "RimCellEdgeResultSlot.h"
#include "RigGridScalarDataAccess.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
//--------------------------------------------------------------------------------------------------
@ -143,10 +146,12 @@ void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoB
part->setTransform(m_scaleTransform.p());
part->updateBoundingBox();
RiaPreferences* prefs = RiaApplication::instance()->preferences();
cvf::ref<cvf::Effect> eff;
if (faultGeometry)
{
caf::MeshEffectGenerator effGen(cvf::Color3f::BLACK);
caf::MeshEffectGenerator effGen(prefs->defaultFaultGridLineColors());
eff = effGen.generateEffect();
part->setEnableMask(meshFaultBit);
@ -155,7 +160,7 @@ void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoB
}
else
{
caf::MeshEffectGenerator effGen(cvf::Color3f::WHITE);
caf::MeshEffectGenerator effGen(prefs->defaultGridLineColors());
eff = effGen.generateEffect();
// Set priority to make sure fault lines are rendered first
@ -204,6 +209,23 @@ void RivGridPartMgr::updateCellColor(cvf::Color4f color)
m_opacityLevel = color.a();
m_defaultColor = color.toColor3f();
// Update mesh colors as well, in case of change
RiaPreferences* prefs = RiaApplication::instance()->preferences();
cvf::ref<cvf::Effect> eff;
if (m_faultFaces.notNull())
{
caf::MeshEffectGenerator faultEffGen(prefs->defaultFaultGridLineColors());
eff = faultEffGen.generateEffect();
m_faultGridLines->setEffect(eff.p());
}
if (m_surfaceFaces.notNull())
{
caf::MeshEffectGenerator effGen(prefs->defaultGridLineColors());
eff = effGen.generateEffect();
m_surfaceGridLines->setEffect(eff.p());
}
}
//--------------------------------------------------------------------------------------------------
@ -220,8 +242,11 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
size_t resTimeStepIdx = timeStepIndex;
if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0;
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
cvf::ref<RigGridScalarDataAccess> dataAccessObject = m_grid->dataAccessObject(porosityModel, resTimeStepIdx, scalarSetIndex);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->dataAccessObject(m_grid.p(), porosityModel, resTimeStepIdx, scalarSetIndex);
if (dataAccessObject.isNull()) return;
// Outer surface

View File

@ -83,6 +83,7 @@ void RivPipeGeometryGenerator::setBendScalingFactor(double scaleFactor)
//--------------------------------------------------------------------------------------------------
void RivPipeGeometryGenerator::setRadius(double radius)
{
CVF_ASSERT(0 <= radius && radius < 1e100);
m_radius = radius;
clearComputedData();
@ -93,6 +94,7 @@ void RivPipeGeometryGenerator::setRadius(double radius)
//--------------------------------------------------------------------------------------------------
void RivPipeGeometryGenerator::setCrossSectionVertexCount(size_t nodeCount)
{
CVF_ASSERT( 2 < nodeCount && nodeCount < 1000000);
m_crossSectionNodeCount = nodeCount;
clearComputedData();

View File

@ -16,23 +16,23 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RivReservoirPartMgr.h"
#include "RivGridPartMgr.h"
#include "cvfStructGrid.h"
#include "cvfModelBasicList.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivReservoirPartMgr::clearAndSetReservoir(const RigReservoir* reservoir)
void RivReservoirPartMgr::clearAndSetReservoir(const RigCaseData* eclipseCase)
{
m_allGrids.clear();
if (reservoir)
if (eclipseCase)
{
std::vector<const RigGridBase*> grids;
reservoir->allGrids(&grids);
eclipseCase->allGrids(&grids);
for (size_t i = 0; i < grids.size() ; ++i)
{
m_allGrids.push_back(new RivGridPartMgr(grids[i], i) );

View File

@ -30,7 +30,7 @@ namespace cvf
class RimResultSlot;
class RimCellEdgeResultSlot;
class RivGridPartMgr;
class RigReservoir;
class RigCaseData;
//==================================================================================================
@ -43,7 +43,7 @@ class RigReservoir;
class RivReservoirPartMgr: public cvf::Object
{
public:
void clearAndSetReservoir(const RigReservoir* reservoir);
void clearAndSetReservoir(const RigCaseData* eclipseCase);
void setTransform(cvf::Transform* scaleTransform);
void setCellVisibility(size_t gridIndex, cvf::UByteArray* cellVisibilities );

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RivReservoirPipesPartMgr.h"
#include "RimReservoirView.h"
@ -33,6 +33,8 @@ RivReservoirPipesPartMgr::RivReservoirPipesPartMgr(RimReservoirView* reservoirVi
m_reservoirView = reservoirView;
m_scaleTransform = new cvf::Transform();
m_font = new cvf::FixedAtlasFont(cvf::FixedAtlasFont::LARGE);
}
//--------------------------------------------------------------------------------------------------
@ -46,42 +48,25 @@ RivReservoirPipesPartMgr::~RivReservoirPipesPartMgr()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivReservoirPipesPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex)
void RivReservoirPipesPartMgr::clearGeometryCache()
{
if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::FORCE_ALL_OFF) return;
if (m_reservoirView->wellCollection()->wells.size() != m_wellPipesPartMgrs.size())
{
m_wellPipesPartMgrs.clear();
m_wellHeadPartMgrs.clear();
for (size_t i = 0; i < m_reservoirView->wellCollection()->wells.size(); ++i)
{
RivWellPipesPartMgr * wppmgr = new RivWellPipesPartMgr(m_reservoirView, m_reservoirView->wellCollection()->wells[i]);
m_wellPipesPartMgrs.push_back(wppmgr);
wppmgr->setScaleTransform(m_scaleTransform.p());
RivWellHeadPartMgr* wellHeadMgr = new RivWellHeadPartMgr(m_reservoirView, m_reservoirView->wellCollection()->wells[i]);
m_wellHeadPartMgrs.push_back(wellHeadMgr);
wellHeadMgr->setScaleTransform(m_scaleTransform.p());
}
}
for (size_t wIdx = 0; wIdx != m_wellPipesPartMgrs.size(); ++ wIdx)
{
m_wellPipesPartMgrs[wIdx]->appendDynamicGeometryPartsToModel(model, frameIndex);
m_wellHeadPartMgrs[wIdx]->appendDynamicGeometryPartsToModel(model, frameIndex);
}
m_wellPipesPartMgrs.clear();
m_wellHeadPartMgrs.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivReservoirPipesPartMgr::updatePipeResultColor(size_t frameIndex)
void RivReservoirPipesPartMgr::scheduleGeometryRegen()
{
for (size_t wIdx = 0; wIdx != m_wellPipesPartMgrs.size(); ++ wIdx)
{
m_wellPipesPartMgrs[wIdx]->updatePipeResultColor( frameIndex);
m_wellPipesPartMgrs[wIdx]->scheduleGeometryRegen();
}
for (size_t wIdx = 0; wIdx != m_wellHeadPartMgrs.size(); ++ wIdx)
{
//m_wellHeadPartMgrs[wIdx]->scheduleGeometryRegen(scaleTransform);
}
}
@ -103,15 +88,44 @@ void RivReservoirPipesPartMgr::setScaleTransform(cvf::Transform * scaleTransform
}
}
void RivReservoirPipesPartMgr::scheduleGeometryRegen()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivReservoirPipesPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex)
{
if (m_reservoirView->wellCollection()->wellPipeVisibility() == RimWellCollection::FORCE_ALL_OFF) return;
if (m_reservoirView->wellCollection()->wells.size() != m_wellPipesPartMgrs.size())
{
clearGeometryCache();
for (size_t i = 0; i < m_reservoirView->wellCollection()->wells.size(); ++i)
{
RivWellPipesPartMgr * wppmgr = new RivWellPipesPartMgr(m_reservoirView, m_reservoirView->wellCollection()->wells[i]);
m_wellPipesPartMgrs.push_back(wppmgr);
wppmgr->setScaleTransform(m_scaleTransform.p());
RivWellHeadPartMgr* wellHeadMgr = new RivWellHeadPartMgr(m_reservoirView, m_reservoirView->wellCollection()->wells[i], m_font.p());
m_wellHeadPartMgrs.push_back(wellHeadMgr);
wellHeadMgr->setScaleTransform(m_scaleTransform.p());
}
}
for (size_t wIdx = 0; wIdx != m_wellPipesPartMgrs.size(); ++ wIdx)
{
m_wellPipesPartMgrs[wIdx]->appendDynamicGeometryPartsToModel(model, frameIndex);
m_wellHeadPartMgrs[wIdx]->appendDynamicGeometryPartsToModel(model, frameIndex);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivReservoirPipesPartMgr::updatePipeResultColor(size_t frameIndex)
{
for (size_t wIdx = 0; wIdx != m_wellPipesPartMgrs.size(); ++ wIdx)
{
m_wellPipesPartMgrs[wIdx]->scheduleGeometryRegen();
}
for (size_t wIdx = 0; wIdx != m_wellHeadPartMgrs.size(); ++ wIdx)
{
//m_wellHeadPartMgrs[wIdx]->scheduleGeometryRegen(scaleTransform);
m_wellPipesPartMgrs[wIdx]->updatePipeResultColor( frameIndex);
}
}

View File

@ -33,15 +33,18 @@ public:
RivReservoirPipesPartMgr(RimReservoirView* reservoirView);
~RivReservoirPipesPartMgr();
void setScaleTransform(cvf::Transform * scaleTransform);
void clearGeometryCache();
void scheduleGeometryRegen();
void setScaleTransform(cvf::Transform * scaleTransform);
void appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model, size_t frameIndex);
void updatePipeResultColor(size_t frameIndex);
private:
caf::PdmPointer<RimReservoirView> m_reservoirView;
cvf::ref<cvf::Transform> m_scaleTransform;
cvf::ref<cvf::Font> m_font;
cvf::Collection< RivWellPipesPartMgr > m_wellPipesPartMgrs;
cvf::Collection< RivWellHeadPartMgr > m_wellHeadPartMgrs;

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RivReservoirViewPartMgr.h"
#include "RivGridPartMgr.h"
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RigGridBase.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RigGridScalarDataAccess.h"
//--------------------------------------------------------------------------------------------------
@ -125,10 +125,10 @@ void RivReservoirViewPartMgr::scheduleGeometryRegen(ReservoirGeometryCacheType g
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::clearGeometryCache(ReservoirGeometryCacheType geomType)
{
RigReservoir* reservoir = NULL;
RigCaseData* eclipseCase = NULL;
if (m_reservoirView != NULL && m_reservoirView->eclipseCase())
{
reservoir = m_reservoirView->eclipseCase()->reservoirData();
eclipseCase = m_reservoirView->eclipseCase()->reservoirData();
}
if (geomType == PROPERTY_FILTERED)
@ -138,7 +138,7 @@ void RivReservoirViewPartMgr::clearGeometryCache(ReservoirGeometryCacheType geom
m_propFilteredGeometryFramesNeedsRegen[i] = true;
if (m_propFilteredGeometryFrames[i].notNull())
{
m_propFilteredGeometryFrames[i]->clearAndSetReservoir(reservoir);
m_propFilteredGeometryFrames[i]->clearAndSetReservoir(eclipseCase);
m_propFilteredGeometryFrames[i]->setTransform(m_scaleTransform.p());
}
}
@ -150,7 +150,7 @@ void RivReservoirViewPartMgr::clearGeometryCache(ReservoirGeometryCacheType geom
m_propFilteredWellGeometryFramesNeedsRegen[i] = true;
if (m_propFilteredWellGeometryFrames[i].notNull())
{
m_propFilteredWellGeometryFrames[i]->clearAndSetReservoir(reservoir);
m_propFilteredWellGeometryFrames[i]->clearAndSetReservoir(eclipseCase);
m_propFilteredWellGeometryFrames[i]->setTransform(m_scaleTransform.p());
}
}
@ -158,7 +158,7 @@ void RivReservoirViewPartMgr::clearGeometryCache(ReservoirGeometryCacheType geom
else
{
m_geometriesNeedsRegen[geomType] = true;
m_geometries[geomType].clearAndSetReservoir(reservoir);
m_geometries[geomType].clearAndSetReservoir(eclipseCase);
m_geometries[geomType].setTransform(m_scaleTransform.p());
}
}
@ -224,7 +224,7 @@ void RivReservoirViewPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicL
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::createGeometry(ReservoirGeometryCacheType geometryType)
{
RigReservoir* res = m_reservoirView->eclipseCase()->reservoirData();
RigCaseData* res = m_reservoirView->eclipseCase()->reservoirData();
m_geometries[geometryType].clearAndSetReservoir(res);
m_geometries[geometryType].setTransform(m_scaleTransform.p());
std::vector<RigGridBase*> grids;
@ -246,13 +246,16 @@ void RivReservoirViewPartMgr::createGeometry(ReservoirGeometryCacheType geometry
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, ReservoirGeometryCacheType geometryType, RigGridBase* grid, size_t gridIdx)
{
RigCaseData* eclipseCase = m_reservoirView->eclipseCase()->reservoirData();
RigActiveCellInfo* activeCellInfo = m_reservoirView->currentActiveCellInfo();
switch (geometryType)
{
case ACTIVE:
computeNativeVisibility(cellVisibility, grid, false, false, true, m_reservoirView->showMainGrid() );
computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx), false, false, true, m_reservoirView->showMainGrid() );
break;
case ALL_WELL_CELLS:
computeAllWellCellsVisibility(cellVisibility, grid);
copyByteArray(cellVisibility, eclipseCase->wellCellsInGrid(gridIdx));
break;
case VISIBLE_WELL_CELLS:
{
@ -287,7 +290,7 @@ void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility,
}
break;
case INACTIVE:
computeNativeVisibility(cellVisibility, grid, m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid());
computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx), m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid());
break;
case RANGE_FILTERED:
{
@ -367,7 +370,7 @@ void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility,
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::createPropertyFilteredGeometry(size_t frameIndex)
{
RigReservoir* res = m_reservoirView->eclipseCase()->reservoirData();
RigCaseData* res = m_reservoirView->eclipseCase()->reservoirData();
if ( frameIndex >= m_propFilteredGeometryFrames.size())
{
@ -382,28 +385,29 @@ void RivReservoirViewPartMgr::createPropertyFilteredGeometry(size_t frameIndex)
bool hasActiveRangeFilters = m_reservoirView->rangeFilterCollection()->hasActiveFilters() || m_reservoirView->wellCollection()->hasVisibleWellCells();
for (size_t i = 0; i < grids.size(); ++i)
for (size_t gIdx = 0; gIdx < grids.size(); ++gIdx)
{
cvf::ref<cvf::UByteArray> cellVisibility = m_propFilteredGeometryFrames[frameIndex]->cellVisibility(i);
cvf::ref<cvf::UByteArray> cellVisibility = m_propFilteredGeometryFrames[frameIndex]->cellVisibility(gIdx);
cvf::ref<cvf::UByteArray> rangeVisibility;
cvf::ref<cvf::UByteArray> fenceVisibility;
cvf::cref<cvf::UByteArray> cellIsWellCellStatuses = res->wellCellsInGrid(gIdx);
if (m_geometriesNeedsRegen[RANGE_FILTERED]) createGeometry(RANGE_FILTERED);
if (m_geometriesNeedsRegen[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER]) createGeometry(VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER);
rangeVisibility = m_geometries[RANGE_FILTERED].cellVisibility(i);
fenceVisibility = m_geometries[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(i);
rangeVisibility = m_geometries[RANGE_FILTERED].cellVisibility(gIdx);
fenceVisibility = m_geometries[VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx);
cellVisibility->resize(rangeVisibility->size());
#pragma omp parallel for
for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
{
(*cellVisibility)[cellIdx] = (!hasActiveRangeFilters && !grids[i]->cell(cellIdx).isWellCell()) || (*rangeVisibility)[cellIdx] || (*fenceVisibility)[cellIdx];
(*cellVisibility)[cellIdx] = (!hasActiveRangeFilters && !(*cellIsWellCellStatuses)[cellIdx]) || (*rangeVisibility)[cellIdx] || (*fenceVisibility)[cellIdx];
}
computePropertyVisibility(cellVisibility.p(), grids[i], frameIndex, cellVisibility.p(), m_reservoirView->propertyFilterCollection());
computePropertyVisibility(cellVisibility.p(), grids[gIdx], frameIndex, cellVisibility.p(), m_reservoirView->propertyFilterCollection());
m_propFilteredGeometryFrames[frameIndex]->setCellVisibility(i, cellVisibility.p());
m_propFilteredGeometryFrames[frameIndex]->setCellVisibility(gIdx, cellVisibility.p());
}
m_propFilteredGeometryFramesNeedsRegen[frameIndex] = false;
@ -414,7 +418,7 @@ void RivReservoirViewPartMgr::createPropertyFilteredGeometry(size_t frameIndex)
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameIndex)
{
RigReservoir* res = m_reservoirView->eclipseCase()->reservoirData();
RigCaseData* res = m_reservoirView->eclipseCase()->reservoirData();
if ( frameIndex >= m_propFilteredWellGeometryFrames.size())
{
@ -432,26 +436,28 @@ void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameInd
bool hasActiveRangeFilters = m_reservoirView->rangeFilterCollection()->hasActiveFilters() || m_reservoirView->wellCollection()->hasVisibleWellCells();
for (size_t i = 0; i < grids.size(); ++i)
for (size_t gIdx = 0; gIdx < grids.size(); ++gIdx)
{
cvf::ref<cvf::UByteArray> cellVisibility = m_propFilteredWellGeometryFrames[frameIndex]->cellVisibility(i);
cvf::ref<cvf::UByteArray> cellVisibility = m_propFilteredWellGeometryFrames[frameIndex]->cellVisibility(gIdx);
cvf::ref<cvf::UByteArray> rangeVisibility;
cvf::ref<cvf::UByteArray> wellCellsOutsideVisibility;
cvf::cref<cvf::UByteArray> cellIsWellCellStatuses = res->wellCellsInGrid(gIdx);
if (m_geometriesNeedsRegen[RANGE_FILTERED_WELL_CELLS]) createGeometry(RANGE_FILTERED_WELL_CELLS);
rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(i);
rangeVisibility = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gIdx);
if (m_geometriesNeedsRegen[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER]) createGeometry(VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER);
wellCellsOutsideVisibility = m_geometries[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(i);
wellCellsOutsideVisibility = m_geometries[VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER].cellVisibility(gIdx);
cellVisibility->resize(rangeVisibility->size());
#pragma omp parallel for
for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
{
(*cellVisibility)[cellIdx] = (!hasActiveRangeFilters && grids[i]->cell(cellIdx).isWellCell()) || (*rangeVisibility)[cellIdx] || (*wellCellsOutsideVisibility)[cellIdx];
(*cellVisibility)[cellIdx] = (!hasActiveRangeFilters && (*cellIsWellCellStatuses)[cellIdx]) || (*rangeVisibility)[cellIdx] || (*wellCellsOutsideVisibility)[cellIdx];
}
computePropertyVisibility(cellVisibility.p(), grids[i], frameIndex, cellVisibility.p(), m_reservoirView->propertyFilterCollection());
m_propFilteredWellGeometryFrames[frameIndex]->setCellVisibility(i, cellVisibility.p());
computePropertyVisibility(cellVisibility.p(), grids[gIdx], frameIndex, cellVisibility.p(), m_reservoirView->propertyFilterCollection());
m_propFilteredWellGeometryFrames[frameIndex]->setCellVisibility(gIdx, cellVisibility.p());
}
m_propFilteredWellGeometryFramesNeedsRegen[frameIndex] = false;
@ -460,7 +466,7 @@ void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameInd
//--------------------------------------------------------------------------------------------------
/// Evaluate visibility based on cell state
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid,
void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, const cvf::UByteArray* cellIsInWellStatuses,
bool invalidCellsIsVisible,
bool inactiveCellsIsVisible,
bool activeCellsIsVisible,
@ -468,18 +474,23 @@ void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisib
{
CVF_ASSERT(cellVisibility != NULL);
CVF_ASSERT(grid != NULL);
CVF_ASSERT(activeCellInfo != NULL);
CVF_ASSERT(cellIsInWellStatuses != NULL);
CVF_ASSERT(cellIsInWellStatuses->size() >= grid->cellCount());
cellVisibility->resize(grid->cellCount());
#pragma omp parallel for
for (int cellIndex = 0; cellIndex < static_cast<int>(grid->cellCount()); cellIndex++)
{
const RigCell& cell = grid->cell(cellIndex);
size_t globalCellIndex = cell.mainGridCellIndex();
if ( !invalidCellsIsVisible && cell.isInvalid()
|| !inactiveCellsIsVisible && !cell.isActiveInMatrixModel()
|| !activeCellsIsVisible && cell.isActiveInMatrixModel()
|| !inactiveCellsIsVisible && !activeCellInfo->isActive(globalCellIndex)
|| !activeCellsIsVisible && activeCellInfo->isActive(globalCellIndex)
|| mainGridIsVisible && (cell.subGrid() != NULL)
|| cell.isWellCell()
|| (*cellIsInWellStatuses)[cellIndex]
)
{
(*cellVisibility)[cellIndex] = false;
@ -493,27 +504,23 @@ void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisib
//--------------------------------------------------------------------------------------------------
/// Evaluate Well cell visibility based on cell state
/// Copy the data from source into destination. This is not trivial to do using cvf::Array ...
/// using parallelized operator [] and not memcopy. Do not know what is faster.
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::computeAllWellCellsVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid )
void RivReservoirViewPartMgr::copyByteArray(cvf::UByteArray* destination, const cvf::UByteArray* source )
{
CVF_ASSERT(cellVisibility != NULL);
CVF_ASSERT(grid != NULL);
cellVisibility->resize(grid->cellCount());
CVF_ASSERT(destination != NULL);
CVF_ASSERT(source != NULL);
if (destination->size() != source->size())
{
destination->resize(source->size());
}
#pragma omp parallel for
for (int cellIndex = 0; cellIndex < static_cast<int>(grid->cellCount()); cellIndex++)
for (int cellIndex = 0; cellIndex < static_cast<int>(source->size()); cellIndex++)
{
const RigCell& cell = grid->cell(cellIndex);
if ( cell.isWellCell() )
{
(*cellVisibility)[cellIndex] = true;
}
else
{
(*cellVisibility)[cellIndex] = false;
}
(*destination)[cellIndex] = (*source)[cellIndex];
}
}
@ -599,8 +606,10 @@ void RivReservoirViewPartMgr::computePropertyVisibility(cvf::UByteArray* cellVis
const RimCellFilter::FilterModeType filterType = (*pfIt)->filterMode();
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel((*pfIt)->resultDefinition()->porosityModel());
cvf::ref<RigGridScalarDataAccess> dataAccessObject = grid->dataAccessObject(porosityModel, timeStepIndex, scalarResultIndex);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel((*pfIt)->resultDefinition()->porosityModel());
RigCaseData* eclipseCase = propFilterColl->reservoirView()->eclipseCase()->reservoirData();
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->dataAccessObject(grid, porosityModel, timeStepIndex, scalarResultIndex);
CVF_ASSERT(dataAccessObject.notNull());
#pragma omp parallel for schedule(dynamic)

View File

@ -28,6 +28,7 @@ class RimReservoirView;
class RigGridBase;
class RimCellRangeFilterCollection;
class RimCellPropertyFilterCollection;
class RigActiveCellInfo;
class RivReservoirViewPartMgr: public cvf::Object
{
@ -77,10 +78,10 @@ private:
void clearGeometryCache(ReservoirGeometryCacheType geomType);
static void computeNativeVisibility (cvf::UByteArray* cellVisibility, const RigGridBase* grid, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible);
static void computeRangeVisibility (cvf::UByteArray* cellVisibility, const RigGridBase* grid, const cvf::UByteArray* nativeVisibility, const RimCellRangeFilterCollection* rangeFilterColl);
static void computePropertyVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex, const cvf::UByteArray* rangeFilterVisibility, RimCellPropertyFilterCollection* propFilterColl);
static void computeAllWellCellsVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid );
static void computeNativeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, const cvf::UByteArray* cellIsInWellStatuses, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible);
static void computeRangeVisibility (cvf::UByteArray* cellVisibilities, const RigGridBase* grid, const cvf::UByteArray* nativeVisibility, const RimCellRangeFilterCollection* rangeFilterColl);
static void computePropertyVisibility(cvf::UByteArray* cellVisibilities, const RigGridBase* grid, size_t timeStepIndex, const cvf::UByteArray* rangeFilterVisibility, RimCellPropertyFilterCollection* propFilterColl);
static void copyByteArray(cvf::UByteArray* cellVisibilities, const cvf::UByteArray* cellIsWellStatuses );
private:

View File

@ -36,7 +36,7 @@
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RigCell.h"
#include "RivPipeGeometryGenerator.h"
@ -46,12 +46,12 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivWellHeadPartMgr::RivWellHeadPartMgr(RimReservoirView* reservoirView, RimWell* well)
RivWellHeadPartMgr::RivWellHeadPartMgr(RimReservoirView* reservoirView, RimWell* well, cvf::Font* font)
{
m_rimReservoirView = reservoirView;
m_rimWell = well;
m_font = new cvf::FixedAtlasFont(cvf::FixedAtlasFont::LARGE);
m_font = font;
}
//--------------------------------------------------------------------------------------------------
@ -72,11 +72,11 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex)
if (m_rimReservoirView.isNull()) return;
RigReservoir* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData();
RigCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData();
RimWell* well = m_rimWell;
RigWellResults* wellResults = well->wellResults();
RigSingleWellResultsData* wellResults = well->wellResults();
if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0)
{
@ -90,7 +90,7 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex)
const RigCell& whCell = rigReservoir->cellFromWellResultCell(wellResultFrame.m_wellHead);
double characteristicCellSize = rigReservoir->mainGrid()->characteristicCellSize();
double characteristicCellSize = rigReservoir->mainGrid()->characteristicIJCellSize();
// Match this position with pipe start position in RivWellPipesPartMgr::calculateWellPipeCenterline()
cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K);
@ -232,6 +232,8 @@ void RivWellHeadPartMgr::buildWellHeadParts(size_t frameIndex)
if (m_rimReservoirView->wellCollection()->showWellLabel() && well->showWellLabel())
{
CVF_ASSERT(m_font.p());
cvf::ref<cvf::DrawableText> drawableText = new cvf::DrawableText;
drawableText->setFont(m_font.p());
drawableText->setCheckPosVisible(false);

View File

@ -38,7 +38,7 @@ class RimReservoirView;
class RivWellHeadPartMgr : public cvf::Object
{
public:
RivWellHeadPartMgr(RimReservoirView* reservoirView, RimWell* well);
RivWellHeadPartMgr(RimReservoirView* reservoirView, RimWell* well, cvf::Font* font);
~RivWellHeadPartMgr();
void setScaleTransform(cvf::Transform * scaleTransform) { m_scaleTransform = scaleTransform;}

View File

@ -19,8 +19,8 @@
#include "cvfLibCore.h"
#include "RimReservoir.h"
#include "RigReservoir.h"
#include "RimCase.h"
#include "RigCaseData.h"
#include "RivWellPipesPartMgr.h"
#include "RigCell.h"
#include "RivPipeGeometryGenerator.h"
@ -86,7 +86,7 @@ void RivWellPipesPartMgr::buildWellPipeParts()
calculateWellPipeCenterline(pipeBranchesCLCoords, pipeBranchesCellIds);
double characteristicCellSize = m_rimReservoirView->eclipseCase()->reservoirData()->mainGrid()->characteristicCellSize();
double characteristicCellSize = m_rimReservoirView->eclipseCase()->reservoirData()->mainGrid()->characteristicIJCellSize();
double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize;
for (size_t brIdx = 0; brIdx < pipeBranchesCellIds.size(); ++brIdx)
@ -158,8 +158,8 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector
bool isAutoDetectBranches = m_rimReservoirView->wellCollection()->isAutoDetectingBranches();
RigReservoir* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData();
RigWellResults* wellResults = m_rimWell->wellResults();
RigCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData();
RigSingleWellResultsData* wellResults = m_rimWell->wellResults();
const RigWellResultFrame& staticWellFrame = m_rimWell->wellResults()->m_staticWellCells;
@ -357,7 +357,7 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex)
{
if (m_rimWell == NULL) return;
RigWellResults* wRes = m_rimWell->wellResults();
RigSingleWellResultsData* wRes = m_rimWell->wellResults();
if (wRes == NULL) return;
if (frameIndex < wRes->firstResultTimeStep()) return; // Or reset colors or something

View File

@ -20,7 +20,7 @@
#include "cafPdmPointer.h"
#include <list>
#include "RigWellResults.h"
#include "RigSingleWellResultsData.h"
namespace cvf
{

View File

@ -16,15 +16,15 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "Rim3dOverlayInfoConfig.h"
#include "RimReservoirView.h"
#include "RIViewer.h"
#include "RimReservoir.h"
#include "RigReservoir.h"
#include "RiuViewer.h"
#include "RimCase.h"
#include "RigCaseData.h"
#include "RigMainGrid.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
CAF_PDM_SOURCE_INIT(Rim3dOverlayInfoConfig, "View3dOverlayInfoConfig");
@ -70,7 +70,8 @@ void Rim3dOverlayInfoConfig::setPosition(cvf::Vec2ui position)
//--------------------------------------------------------------------------------------------------
void Rim3dOverlayInfoConfig::update3DInfo()
{
if (!m_reservoirView && m_reservoirView->viewer()) return;
if (!m_reservoirView) return;
if (!m_reservoirView->viewer()) return;
m_reservoirView->viewer()->showInfoText(showInfoText());
m_reservoirView->viewer()->showHistogram(false);
@ -80,16 +81,22 @@ void Rim3dOverlayInfoConfig::update3DInfo()
{
QString caseName;
QString totCellCount;
QString activeCellCount;
QString activeCellCountText;
QString fractureActiveCellCount;
QString iSize, jSize, kSize;
QString propName;
QString cellEdgeName;
if (m_reservoirView->eclipseCase() && m_reservoirView->eclipseCase()->reservoirData())
if (m_reservoirView->eclipseCase() && m_reservoirView->eclipseCase()->reservoirData() && m_reservoirView->eclipseCase()->reservoirData()->mainGrid())
{
caseName = m_reservoirView->eclipseCase()->caseName();
caseName = m_reservoirView->eclipseCase()->caseUserDescription();
totCellCount = QString::number(m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->cells().size());
activeCellCount = QString::number(m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->globalMatrixModelActiveCellCount());
size_t mxActCellCount = m_reservoirView->eclipseCase()->reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->globalActiveCellCount();
size_t frActCellCount = m_reservoirView->eclipseCase()->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->globalActiveCellCount();
if (frActCellCount > 0) activeCellCountText += "Matrix : ";
activeCellCountText += QString::number(mxActCellCount);
if (frActCellCount > 0) activeCellCountText += " Fracture : " + QString::number(frActCellCount);
iSize = QString::number(m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->cellCountI());
jSize = QString::number(m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->cellCountJ());
kSize = QString::number(m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->cellCountK());
@ -100,7 +107,7 @@ void Rim3dOverlayInfoConfig::update3DInfo()
QString infoText = QString(
"<p><b><center>-- %1 --</center></b><p> "
"<b>Cell count. Total:</b> %2 <b>Active:</b> %3 <br>"
"<b>Main Grid I,J,K:</b> %4, %5, %6 <br>").arg(caseName, totCellCount, activeCellCount, iSize, jSize, kSize);
"<b>Main Grid I,J,K:</b> %4, %5, %6 <br>").arg(caseName, totCellCount, activeCellCountText, iSize, jSize, kSize);
if (m_reservoirView->animationMode() && m_reservoirView->cellResult()->hasResult())
{
@ -110,9 +117,9 @@ void Rim3dOverlayInfoConfig::update3DInfo()
double p10, p90;
double mean;
size_t scalarIndex = m_reservoirView->cellResult()->gridScalarIndex();
m_reservoirView->gridCellResults()->minMaxCellScalarValues(scalarIndex, min, max);
m_reservoirView->gridCellResults()->p10p90CellScalarValues(scalarIndex, p10, p90);
m_reservoirView->gridCellResults()->meanCellScalarValues(scalarIndex, mean);
m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(scalarIndex, min, max);
m_reservoirView->currentGridCellResults()->cellResults()->p10p90CellScalarValues(scalarIndex, p10, p90);
m_reservoirView->currentGridCellResults()->cellResults()->meanCellScalarValues(scalarIndex, mean);
//infoText += QString("<blockquote><b>Min:</b> %1 <b>P10:</b> %2 <b>Mean:</b> %3 <b>P90:</b> %4 <b>Max:</b> %5 </blockquote>").arg(min).arg(p10).arg(mean).arg(p90).arg(max);
//infoText += QString("<blockquote><pre>Min: %1 P10: %2 Mean: %3 \n P90: %4 Max: %5 </pre></blockquote>").arg(min).arg(p10).arg(mean).arg(p90).arg(max);
@ -134,7 +141,7 @@ void Rim3dOverlayInfoConfig::update3DInfo()
|| m_reservoirView->wellCollection()->hasVisibleWellPipes())
{
int currentTimeStep = m_reservoirView->currentTimeStep();
QDateTime date = m_reservoirView->gridCellResults()->timeStepDate(0, currentTimeStep);
QDateTime date = m_reservoirView->currentGridCellResults()->cellResults()->timeStepDate(0, currentTimeStep);
infoText += QString("<b>Time Step:</b> %1 <b>Time:</b> %2").arg(currentTimeStep).arg(date.toString("dd.MMM yyyy"));
}
@ -150,12 +157,12 @@ void Rim3dOverlayInfoConfig::update3DInfo()
double mean;
size_t scalarIndex = m_reservoirView->cellResult()->gridScalarIndex();
m_reservoirView->gridCellResults()->minMaxCellScalarValues(scalarIndex, min, max);
m_reservoirView->gridCellResults()->p10p90CellScalarValues(scalarIndex, p10, p90);
m_reservoirView->gridCellResults()->meanCellScalarValues(scalarIndex, mean);
m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(scalarIndex, min, max);
m_reservoirView->currentGridCellResults()->cellResults()->p10p90CellScalarValues(scalarIndex, p10, p90);
m_reservoirView->currentGridCellResults()->cellResults()->meanCellScalarValues(scalarIndex, mean);
m_reservoirView->viewer()->showHistogram(true);
m_reservoirView->viewer()->setHistogram(min, max, m_reservoirView->gridCellResults()->cellScalarValuesHistogram(scalarIndex));
m_reservoirView->viewer()->setHistogram(min, max, m_reservoirView->currentGridCellResults()->cellResults()->cellScalarValuesHistogram(scalarIndex));
m_reservoirView->viewer()->setHistogramPercentiles(p10, p90, mean);
}
}

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimBinaryExportSettings.h"
#include "cafPdmUiFilePathEditor.h"

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafPdmField.h"
@ -35,6 +35,7 @@ RimCalcScript::RimCalcScript()
CAF_PDM_InitField(&absolutePath, "AbsolutePath", QString(), "Location", "", "" ,"");
CAF_PDM_InitField(&content, "Content", QString(), "Directory", "", "" ,"");
content.setUiHidden(true);
content.setIOWritable(false);
absolutePath.setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
}

View File

@ -0,0 +1,479 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RifReaderEclipseOutput.h"
#include "RifReaderMockModel.h"
#include "RimCase.h"
#include "RimReservoirView.h"
#include "RigCaseData.h"
#include "RigMainGrid.h"
#include "RigCaseCellResultsData.h"
#include "cvfAssert.h"
#include "cafPdmUiPushButtonEditor.h"
#include <QString>
#include "RimProject.h"
#include "RimReservoirCellResultsCacher.h"
CAF_PDM_SOURCE_INIT(RimCase, "RimReservoir");
//------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCase::RimCase()
{
CAF_PDM_InitField(&caseUserDescription, "CaseUserDescription", QString(), "Case name", "", "" ,"");
CAF_PDM_InitFieldNoDefault(&reservoirViews, "ReservoirViews", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_matrixModelResults, "MatrixModelResults", "", "", "", "");
m_matrixModelResults.setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_fractureModelResults, "FractureModelResults", "", "", "", "");
m_fractureModelResults.setUiHidden(true);
// Obsolete field
CAF_PDM_InitField(&caseName, "CaseName", QString(), "Obsolete", "", "" ,"");
caseName.setIOWritable(false);
caseName.setUiHidden(true);
m_matrixModelResults = new RimReservoirCellResultsStorage;
m_fractureModelResults = new RimReservoirCellResultsStorage;
this->setReservoirData( NULL );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCase::~RimCase()
{
reservoirViews.deleteAllChildObjects();
delete m_matrixModelResults();
delete m_fractureModelResults();
if (this->reservoirData())
{
// At this point, we assume that memory should be released
CVF_ASSERT(this->reservoirData()->refCount() == 1);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigCaseData* RimCase::reservoirData()
{
return m_rigEclipseCase.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigCaseData* RimCase::reservoirData() const
{
return m_rigEclipseCase.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCase::initAfterRead()
{
size_t j;
for (j = 0; j < reservoirViews().size(); j++)
{
RimReservoirView* riv = reservoirViews()[j];
CVF_ASSERT(riv);
riv->setEclipseCase(this);
}
if (caseUserDescription().isEmpty() && !caseName().isEmpty())
{
caseUserDescription = caseName;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirView* RimCase::createAndAddReservoirView()
{
RimReservoirView* riv = new RimReservoirView();
riv->setEclipseCase(this);
size_t i = reservoirViews().size();
riv->name = QString("View %1").arg(i + 1);
reservoirViews().push_back(riv);
return riv;
}
//--------------------------------------------------------------------------------------------------
/// TODO: Move this functionality to PdmPointersField
//--------------------------------------------------------------------------------------------------
void RimCase::removeReservoirView(RimReservoirView* reservoirView)
{
std::vector<size_t> indices;
size_t i;
for (i = 0; i < reservoirViews().size(); i++)
{
if (reservoirViews()[i] == reservoirView)
{
indices.push_back(i);
}
}
// NB! Make sure the ordering goes from large to low index
while (!indices.empty())
{
reservoirViews().erase(indices.back());
indices.pop_back();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCase::removeResult(const QString& resultName)
{
size_t i;
for (i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
RimResultSlot* result = reservoirView->cellResult;
CVF_ASSERT(result);
bool rebuildDisplayModel = false;
// Set cell result variable to none if displaying
if (result->resultVariable() == resultName)
{
result->resultVariable.v() = RimDefines::undefinedResultName();
result->loadResult();
rebuildDisplayModel = true;
}
std::list< caf::PdmPointer< RimCellPropertyFilter > >::iterator it;
RimCellPropertyFilterCollection* propFilterCollection = reservoirView->propertyFilterCollection();
for (it = propFilterCollection->propertyFilters.v().begin(); it != propFilterCollection->propertyFilters.v().end(); ++it)
{
RimCellPropertyFilter* propertyFilter = *it;
if (propertyFilter->resultDefinition->resultVariable.v() == resultName)
{
propertyFilter->resultDefinition->resultVariable.v() = RimDefines::undefinedResultName();
propertyFilter->resultDefinition->loadResult();
propertyFilter->setDefaultValues();
rebuildDisplayModel = true;
}
}
if (rebuildDisplayModel)
{
reservoirViews()[i]->createDisplayModelAndRedraw();
}
// TODO
// CellEdgeResults are not considered, as they do not support display of input properties yet
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (changedField == &releaseResultMemory)
{
if (this->reservoirData())
{
for (size_t i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
RimResultSlot* result = reservoirView->cellResult;
CVF_ASSERT(result);
result->resultVariable.v() = RimDefines::undefinedResultName();
result->loadResult();
RimCellEdgeResultSlot* cellEdgeResult = reservoirView->cellEdgeResult;
CVF_ASSERT(cellEdgeResult);
cellEdgeResult->resultVariable.v() = RimDefines::undefinedResultName();
cellEdgeResult->loadResult();
reservoirView->createDisplayModelAndRedraw();
}
RigCaseCellResultsData* matrixModelResults = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS);
if (matrixModelResults)
{
matrixModelResults->clearAllResults();
}
RigCaseCellResultsData* fractureModelResults = reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS);
if (fractureModelResults)
{
fractureModelResults->clearAllResults();
}
}
releaseResultMemory = oldValue.toBool();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCase::computeCachedData()
{
RigCaseData* rigEclipseCase = reservoirData();
if (rigEclipseCase)
{
rigEclipseCase->computeActiveCellBoundingBoxes();
rigEclipseCase->mainGrid()->computeCachedData();
std::vector<RigGridBase*> grids;
rigEclipseCase->allGrids(&grids);
size_t i;
for (i = 0; i < grids.size(); i++)
{
grids[i]->computeFaults();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCaseCollection* RimCase::parentCaseCollection()
{
std::vector<RimCaseCollection*> parentObjects;
this->parentObjectsOfType(parentObjects);
if (parentObjects.size() > 0)
{
return parentObjects[0];
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimCase::parentGridCaseGroup()
{
RimCaseCollection* caseColl = parentCaseCollection();
if (caseColl)
{
return caseColl->parentCaseGroup();
}
else
{
return NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCase::setReservoirData(RigCaseData* eclipseCase)
{
m_rigEclipseCase = eclipseCase;
if (this->reservoirData())
{
m_fractureModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS));
m_matrixModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::MATRIX_RESULTS));
m_fractureModelResults()->setMainGrid(this->reservoirData()->mainGrid());
m_matrixModelResults()->setMainGrid(this->reservoirData()->mainGrid());
}
else
{
m_fractureModelResults()->setCellResults(NULL);
m_matrixModelResults()->setCellResults(NULL);
m_fractureModelResults()->setMainGrid(NULL);
m_matrixModelResults()->setMainGrid(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorage* RimCase::results(RifReaderInterface::PorosityModelResultType porosityModel)
{
if (porosityModel == RifReaderInterface::MATRIX_RESULTS)
{
return m_matrixModelResults();
}
return m_fractureModelResults();
}
//--------------------------------------------------------------------------------------------------
/// Relocate the supplied file name, based on the search path as follows:
/// fileName, newProjectPath/fileNameWoPath, relocatedPath/fileNameWoPath
/// If the file is not found in any of the positions, the fileName is returned unchanged
///
/// The relocatedPath is found in this way:
/// use the start of newProjectPath
/// plus the end of the path to m_gridFileName
/// such that the common start of oldProjectPath and m_gridFileName is removed from m_gridFileName
/// and replaced with the start of newProjectPath up to where newProjectPath starts to be equal to oldProjectPath
//--------------------------------------------------------------------------------------------------
QString RimCase::relocateFile(const QString& fileName, const QString& newProjectPath, const QString& oldProjectPath,
bool* foundFile, std::vector<QString>* searchedPaths)
{
if (foundFile) *foundFile = true;
if (searchedPaths) searchedPaths->push_back(fileName);
if (QFile::exists(fileName))
{
return fileName;
}
// First check in the new project file directory
{
QString fileNameWithoutPath = QFileInfo(fileName).fileName();
QString candidate = QDir::fromNativeSeparators(newProjectPath + QDir::separator() + fileNameWithoutPath);
if (searchedPaths) searchedPaths->push_back(candidate);
if (QFile::exists(candidate))
{
return candidate;
}
}
// Then find the possible move of a directory structure where projects and files referenced are moved in "paralell"
QFileInfo gridFileInfo(QDir::fromNativeSeparators(fileName));
QString gridFilePath = gridFileInfo.path();
QString gridFileNameWoPath = gridFileInfo.fileName();
QStringList gridPathElements = gridFilePath.split("/", QString::KeepEmptyParts);
QString oldProjPath = QDir::fromNativeSeparators(oldProjectPath);
QStringList oldProjPathElements = oldProjPath.split("/", QString::KeepEmptyParts);
QString newProjPath = QDir::fromNativeSeparators(newProjectPath);
QStringList newProjPathElements = newProjPath.split("/", QString::KeepEmptyParts);
// Find the possible equal start of the old project path, and the referenced file
bool pathStartsAreEqual = false;
bool pathEndsDiffer = false;
int firstDiffIdx = 0;
for ( firstDiffIdx = 0; firstDiffIdx < gridPathElements.size() && firstDiffIdx < oldProjPathElements.size(); ++firstDiffIdx)
{
if (gridPathElements[firstDiffIdx] == oldProjPathElements[firstDiffIdx])
{
pathStartsAreEqual = pathStartsAreEqual || !gridPathElements[firstDiffIdx].isEmpty();
}
else
{
pathEndsDiffer = true;
break;
}
}
if (!pathEndsDiffer && firstDiffIdx < gridPathElements.size() || firstDiffIdx < oldProjPathElements.size())
{
pathEndsDiffer = true;
}
// If the path starts are equal, try to substitute it in the referenced file, with the corresponding new project path start
if (pathStartsAreEqual)
{
if (pathEndsDiffer)
{
QString oldGridFilePathEnd;
for (int i = firstDiffIdx; i < gridPathElements.size(); ++i)
{
oldGridFilePathEnd += gridPathElements[i];
oldGridFilePathEnd += "/";
}
// Find the new Project File Start Path
QStringList oldProjectFilePathEndElements;
for (int i = firstDiffIdx; i < oldProjPathElements.size(); ++i)
{
oldProjectFilePathEndElements.push_back(oldProjPathElements[i]);
}
int ppIdx = oldProjectFilePathEndElements.size() -1;
int lastDiffIdx = newProjPathElements.size() -1;
for (; lastDiffIdx >= 0 && ppIdx >= 0; --lastDiffIdx, --ppIdx)
{
if (oldProjectFilePathEndElements[ppIdx] != newProjPathElements[lastDiffIdx])
{
break;
}
}
QString newProjecetFileStartPath;
for (int i = 0; i <= lastDiffIdx; ++i)
{
newProjecetFileStartPath += newProjPathElements[i];
newProjecetFileStartPath += "/";
}
QString relocationPath = newProjecetFileStartPath + oldGridFilePathEnd;
QString relocatedFileName = relocationPath + gridFileNameWoPath;
if (searchedPaths) searchedPaths->push_back(relocatedFileName);
if (QFile::exists(relocatedFileName))
{
return relocatedFileName;
}
}
else
{
// The Grid file was located in the same dir as the Project file. This is supposed to be handled above.
// So we did not find it
}
}
// return the unchanged filename, if we could not find a valid relocation file
if (foundFile) *foundFile = false;
return fileName;
}

View File

@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimReservoirCellResultsCacher.h"
#include "RifReaderInterface.h"
class QString;
class RigCaseData;
class RigGridBase;
class RimReservoirView;
class RimCaseCollection;
class RimIdenticalGridCaseGroup;
//class RimReservoirCellResultsCacher;
//==================================================================================================
//
// Interface for reservoirs.
//
//==================================================================================================
class RimCase : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimCase();
virtual ~RimCase();
// Fields:
caf::PdmField<QString> caseUserDescription;
caf::PdmField<bool> releaseResultMemory;
caf::PdmPointersField<RimReservoirView*> reservoirViews;
virtual bool openEclipseGridFile() { return false;}; // Should be pure virtual but PDM does not allow that.
RigCaseData* reservoirData();
const RigCaseData* reservoirData() const;
RimReservoirCellResultsStorage* results(RifReaderInterface::PorosityModelResultType porosityModel);
RimReservoirView* createAndAddReservoirView();
void removeReservoirView(RimReservoirView* reservoirView);
void removeResult(const QString& resultName);
virtual QString locationOnDisc() const { return QString(); }
virtual QString gridFileName() const { return QString(); }
virtual void updateFilePathsFromProjectPath(const QString& projectPath, const QString& oldProjectPath) { };
RimCaseCollection* parentCaseCollection();
RimIdenticalGridCaseGroup* parentGridCaseGroup();
// Overridden methods from PdmObject
public:
virtual caf::PdmFieldHandle* userDescriptionField() { return &caseUserDescription; }
protected:
virtual void initAfterRead();
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
// Internal methods
protected:
void computeCachedData();
void setReservoirData(RigCaseData* eclipseCase);
static QString relocateFile(const QString& fileName, const QString& newProjectPath, const QString& oldProjectPath,
bool* foundFile, std::vector<QString>* searchedPaths);
private:
cvf::ref<RigCaseData> m_rigEclipseCase;
private:
caf::PdmField<RimReservoirCellResultsStorage*> m_matrixModelResults;
caf::PdmField<RimReservoirCellResultsStorage*> m_fractureModelResults;
// Obsolete fields
protected:
caf::PdmField<QString> caseName;
};

View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimCaseCollection.h"
#include "RimReservoirView.h"
#include "RimIdenticalGridCaseGroup.h"
CAF_PDM_SOURCE_INIT(RimCaseCollection, "RimCaseCollection");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCaseCollection::RimCaseCollection()
{
CAF_PDM_InitObject("Derived Statistics", "", "", "");
CAF_PDM_InitFieldNoDefault(&reservoirs, "Reservoirs", "", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCaseCollection::~RimCaseCollection()
{
reservoirs.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimCaseCollection::parentCaseGroup()
{
std::vector<RimIdenticalGridCaseGroup*> parentObjects;
this->parentObjectsOfType(parentObjects);
if (parentObjects.size() > 0)
{
return parentObjects[0];
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCase* RimCaseCollection::findByDescription(const QString& caseDescription) const
{
for (size_t i = 0; i < reservoirs.size(); i++)
{
if (caseDescription == reservoirs[i]->caseUserDescription())
{
return reservoirs[i];
}
}
return NULL;
}

View File

@ -0,0 +1,48 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimStatisticsCase.h"
//==================================================================================================
//
//
//
//==================================================================================================
class RimCaseCollection : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimCaseCollection();
virtual ~RimCaseCollection();
caf::PdmPointersField<RimCase*> reservoirs;
RimIdenticalGridCaseGroup* parentCaseGroup();
RimCase* findByDescription(const QString& caseDescription) const;
private:
};

View File

@ -16,15 +16,15 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimCellEdgeResultSlot.h"
#include "RimLegendConfig.h"
#include "RimReservoirView.h"
#include "RimReservoir.h"
#include "RimCase.h"
#include "RimReservoirView.h"
#include "RigReservoirCellResults.h"
#include "RigReservoir.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "cafPdmUiListEditor.h"
@ -71,7 +71,7 @@ void RimCellEdgeResultSlot::setReservoirView(RimReservoirView* ownerReservoirVie
//--------------------------------------------------------------------------------------------------
void RimCellEdgeResultSlot::loadResult()
{
CVF_ASSERT(m_reservoirView && m_reservoirView->gridCellResults());
CVF_ASSERT(m_reservoirView && m_reservoirView->currentGridCellResults());
resetResultIndices();
QStringList vars = findResultVariableNames();
@ -80,7 +80,7 @@ void RimCellEdgeResultSlot::loadResult()
int i;
for (i = 0; i < vars.size(); ++i)
{
size_t resultindex = m_reservoirView->gridCellResults()->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, vars[i]);
size_t resultindex = m_reservoirView->currentGridCellResults()->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, vars[i]);
int cubeFaceIdx;
for (cubeFaceIdx = 0; cubeFaceIdx < 6; ++cubeFaceIdx)
{
@ -130,10 +130,10 @@ QList<caf::PdmOptionItemInfo> RimCellEdgeResultSlot::calculateValueOptions(const
{
if (fieldNeedingOptions == &resultVariable)
{
if (m_reservoirView && m_reservoirView->gridCellResults())
if (m_reservoirView && m_reservoirView->currentGridCellResults())
{
QStringList varList;
varList = m_reservoirView->gridCellResults()->resultNames(RimDefines::STATIC_NATIVE);
varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(RimDefines::STATIC_NATIVE);
//TODO: Must also handle input properties
//varList += m_reservoirView->gridCellResults()->resultNames(RimDefines::INPUT_PROPERTY);
@ -205,10 +205,10 @@ QStringList RimCellEdgeResultSlot::findResultVariableNames()
{
QStringList varNames;
if (m_reservoirView && m_reservoirView->gridCellResults() && !resultVariable().isEmpty())
if (m_reservoirView && m_reservoirView->currentGridCellResults() && !resultVariable().isEmpty())
{
QStringList varList;
varList = m_reservoirView->gridCellResults()->resultNames(RimDefines::STATIC_NATIVE);
varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(RimDefines::STATIC_NATIVE);
//TODO: Must handle Input properties
int i;
@ -313,7 +313,7 @@ void RimCellEdgeResultSlot::minMaxCellEdgeValues(double& min, double& max)
{
double cMin, cMax;
m_reservoirView->gridCellResults()->minMaxCellScalarValues(resultIndices[idx], cMin, cMax);
m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(resultIndices[idx], cMin, cMax);
globalMin = CVF_MIN(globalMin, cMin);
globalMax = CVF_MAX(globalMax, cMax);

View File

@ -23,7 +23,7 @@
#include "cafAppEnum.h"
#include "RimDefines.h"
class RigReservoirCellResults;
class RigCaseCellResultsData;
namespace caf
{

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafAppEnum.h"

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimReservoirView.h"
#include "RimCellPropertyFilter.h"
#include "RimCellPropertyFilterCollection.h"
#include "RigGridBase.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "cafPdmUiDoubleSliderEditor.h"
@ -143,10 +143,10 @@ void RimCellPropertyFilter::setDefaultValues()
size_t scalarIndex = resultDefinition->gridScalarIndex();
if (scalarIndex != cvf::UNDEFINED_SIZE_T)
{
RigReservoirCellResults* results = m_parentContainer->reservoirView()->gridCellResults();
RimReservoirCellResultsStorage* results = m_parentContainer->reservoirView()->currentGridCellResults();
if (results)
{
results->minMaxCellScalarValues(scalarIndex, min, max);
results->cellResults()->minMaxCellScalarValues(scalarIndex, min, max);
}
}
@ -163,7 +163,7 @@ void RimCellPropertyFilter::setDefaultValues()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCellPropertyFilter::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const
void RimCellPropertyFilter::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
// Fields declared in RimCellFilter
uiOrdering.add(&name);

View File

@ -32,7 +32,7 @@ class RimCellPropertyFilterCollection;
class RimResultDefinition;
class RigGridBase;
class RigReservoirCellResults;
class RigCaseCellResultsData;
namespace cvf
{
@ -72,7 +72,7 @@ public:
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly );
protected:
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) const;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) ;
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
private:

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimCellPropertyFilterCollection.h"
#include "RimReservoirView.h"
#include "RigGridBase.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
CAF_PDM_SOURCE_INIT(RimCellPropertyFilterCollection, "CellPropertyFilters");

View File

@ -16,12 +16,12 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimCellRangeFilter.h"
#include "RimCellRangeFilterCollection.h"
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "cafPdmUiSliderEditor.h"
@ -115,11 +115,11 @@ void RimCellRangeFilter::setDefaultValues()
{
CVF_ASSERT(m_parentContainer);
RigMainGrid* mainGrid = m_parentContainer->mainGrid();
if (mainGrid)
RigActiveCellInfo* actCellInfo = m_parentContainer->activeCellInfo();
if (actCellInfo)
{
cvf::Vec3st min, max;
mainGrid->matrixModelActiveCellsBoundingBox(min, max);
actCellInfo->IJKBoundingBox(min, max);
// Adjust to Eclipse indexing
min.x() = min.x() + 1;
@ -159,10 +159,13 @@ void RimCellRangeFilter::defineEditorAttribute(const caf::PdmFieldHandle* field,
}
RigMainGrid* mainGrid = m_parentContainer->mainGrid();
if (mainGrid)
CVF_ASSERT(mainGrid);
RigActiveCellInfo* actCellInfo = m_parentContainer->activeCellInfo();
if (actCellInfo)
{
cvf::Vec3st min, max;
mainGrid->matrixModelActiveCellsBoundingBox(min, max);
actCellInfo->IJKBoundingBox(min, max);
// Adjust to Eclipse indexing
min.x() = min.x() + 1;

View File

@ -16,12 +16,12 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimCellRangeFilterCollection.h"
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
@ -97,8 +97,6 @@ void RimCellRangeFilterCollection::compoundCellRangeFilter(cvf::CellRangeFilter*
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -126,9 +124,21 @@ RigMainGrid* RimCellRangeFilterCollection::mainGrid() const
m_reservoirView->eclipseCase()->reservoirData()->mainGrid())
{
RigMainGrid* mainGrid = m_reservoirView->eclipseCase()->reservoirData()->mainGrid();
return m_reservoirView->eclipseCase()->reservoirData()->mainGrid();
}
return mainGrid;
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigActiveCellInfo* RimCellRangeFilterCollection::activeCellInfo() const
{
if (m_reservoirView )
{
return m_reservoirView->currentActiveCellInfo();
}
return NULL;
@ -209,3 +219,4 @@ bool RimCellRangeFilterCollection::hasActiveFilters() const
return false;
}

View File

@ -20,6 +20,8 @@
#include "RimCellRangeFilter.h"
class RigActiveCellInfo;
//==================================================================================================
///
///
@ -42,9 +44,10 @@ public:
void compoundCellRangeFilter(cvf::CellRangeFilter* cellRangeFilter) const;
bool hasActiveFilters() const;
void setReservoirView(RimReservoirView* reservoirView);
RimReservoirView* reservoirView();
RigMainGrid* mainGrid() const;
void setReservoirView(RimReservoirView* reservoirView);
RimReservoirView* reservoirView();
RigMainGrid* mainGrid() const;
RigActiveCellInfo* activeCellInfo() const;
// Overridden methods
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimDefines.h"
#include "cafAppEnum.h"

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimExportInputPropertySettings.h"
#include "cafPdmUiFilePathEditor.h"

View File

@ -0,0 +1,454 @@
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimCase.h"
#include "RimReservoirView.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "RimStatisticsCase.h"
#include "RimStatisticsCaseCollection.h"
#include "RimResultCase.h"
#include "cafProgressInfo.h"
#include "RigActiveCellInfo.h"
#include "RigGridManager.h"
CAF_PDM_SOURCE_INIT(RimIdenticalGridCaseGroup, "RimIdenticalGridCaseGroup");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup::RimIdenticalGridCaseGroup()
{
CAF_PDM_InitObject("Grid Case Group", ":/GridCaseGroup16x16.png", "", "");
CAF_PDM_InitField(&name, "UserDescription", QString("Grid Case Group"), "Name", "", "", "");
CAF_PDM_InitFieldNoDefault(&statisticsCaseCollection, "StatisticsCaseCollection", "Derived Statistics", ":/Histograms16x16.png", "", "");
CAF_PDM_InitFieldNoDefault(&caseCollection, "CaseCollection", "Cases", ":/Cases16x16.png", "", "");
caseCollection = new RimCaseCollection;
statisticsCaseCollection = new RimCaseCollection;
m_mainGrid = NULL;
m_unionOfMatrixActiveCells = new RigActiveCellInfo;
m_unionOfFractureActiveCells = new RigActiveCellInfo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup::~RimIdenticalGridCaseGroup()
{
m_mainGrid = NULL;
delete caseCollection;
caseCollection = NULL;
delete statisticsCaseCollection;
statisticsCaseCollection = NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::addCase(RimCase* reservoir)
{
CVF_ASSERT(reservoir);
if (!reservoir) return;
if (!m_mainGrid)
{
m_mainGrid = reservoir->reservoirData()->mainGrid();
}
else
{
reservoir->reservoirData()->setMainGrid(m_mainGrid);
}
caseCollection()->reservoirs().push_back(reservoir);
clearActiveCellUnions();
clearStatisticsResults();
updateMainGridAndActiveCellsForStatisticsCases();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::removeCase(RimCase* reservoir)
{
if (caseCollection()->reservoirs().count(reservoir) == 0)
{
return;
}
caseCollection()->reservoirs().removeChildObject(reservoir);
if (caseCollection()->reservoirs().size() == 0)
{
m_mainGrid = NULL;
}
clearActiveCellUnions();
clearStatisticsResults();
updateMainGridAndActiveCellsForStatisticsCases();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigMainGrid* RimIdenticalGridCaseGroup::mainGrid()
{
if (m_mainGrid) return m_mainGrid;
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimIdenticalGridCaseGroup::userDescriptionField()
{
return &name;
}
//--------------------------------------------------------------------------------------------------
/// Make sure changes in this functions is validated to RiaApplication::addEclipseCases()
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo()
{
if (caseCollection()->reservoirs().size() == 0)
{
return;
}
// Read the main case completely including grid.
// The mainGrid from the first case is reused directly in for the other cases.
// When reading active cell info, only the total cell count is tested for consistency
RimCase* mainCase = caseCollection()->reservoirs[0];
mainCase->openEclipseGridFile();
RigCaseData* mainEclipseCase = mainCase->reservoirData();
if (!mainEclipseCase)
{
// Error message
return;
}
// Read active cell info from all source cases
caf::ProgressInfo info(caseCollection()->reservoirs.size(), "Case group - Reading Active Cell data");
for (size_t i = 1; i < caseCollection()->reservoirs.size(); i++)
{
RimResultCase* rimReservoir = dynamic_cast<RimResultCase*>(caseCollection()->reservoirs[i]);
if(!rimReservoir) continue; // Input reservoir
if (!rimReservoir->openAndReadActiveCellData(mainEclipseCase))
{
// Error message
continue;
}
info.incrementProgress();
}
m_mainGrid = mainEclipseCase->mainGrid();
// Check if we need to calculate the union of the active cells
bool foundResultsInCache = false;
for (size_t i = 0; i < statisticsCaseCollection()->reservoirs.size(); i++)
{
RimCase* rimReservoir = statisticsCaseCollection()->reservoirs[i];
// Check if any results are stored in cache
if (rimReservoir->results(RifReaderInterface::MATRIX_RESULTS)->storedResultsCount() > 0 ||
rimReservoir->results(RifReaderInterface::FRACTURE_RESULTS)->storedResultsCount() > 0)
{
foundResultsInCache = true;
break;
}
}
if (foundResultsInCache)
{
computeUnionOfActiveCells();
}
// "Load" the statistical cases
for (size_t i = 0; i < statisticsCaseCollection()->reservoirs.size(); i++)
{
RimCase* rimReservoir = statisticsCaseCollection()->reservoirs[i];
rimReservoir->openEclipseGridFile();
if (i == 0)
{
rimReservoir->reservoirData()->computeActiveCellBoundingBoxes();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::computeUnionOfActiveCells()
{
if (m_unionOfMatrixActiveCells->globalActiveCellCount() > 0)
{
return;
}
if (caseCollection->reservoirs.size() == 0 || !m_mainGrid)
{
this->clearActiveCellUnions();
return;
}
m_unionOfMatrixActiveCells->setGlobalCellCount(m_mainGrid->cells().size());
m_unionOfFractureActiveCells->setGlobalCellCount(m_mainGrid->cells().size());
m_unionOfMatrixActiveCells->setGridCount(m_mainGrid->gridCount());
m_unionOfFractureActiveCells->setGridCount(m_mainGrid->gridCount());
size_t globalActiveMatrixIndex = 0;
size_t globalActiveFractureIndex = 0;
for (size_t gridIdx = 0; gridIdx < m_mainGrid->gridCount(); gridIdx++)
{
RigGridBase* grid = m_mainGrid->gridByIndex(gridIdx);
std::vector<char> activeM(grid->cellCount(), 0);
std::vector<char> activeF(grid->cellCount(), 0);
for (size_t localGridCellIdx = 0; localGridCellIdx < grid->cellCount(); localGridCellIdx++)
{
for (size_t caseIdx = 0; caseIdx < caseCollection->reservoirs.size(); caseIdx++)
{
size_t globalCellIdx = grid->globalGridCellIndex(localGridCellIdx);
if (activeM[localGridCellIdx] == 0)
{
if (caseCollection->reservoirs[caseIdx]->reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->isActive(globalCellIdx))
{
activeM[localGridCellIdx] = 1;
}
}
if (activeF[localGridCellIdx] == 0)
{
if (caseCollection->reservoirs[caseIdx]->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->isActive(globalCellIdx))
{
activeF[localGridCellIdx] = 1;
}
}
}
}
size_t activeMatrixIndex = 0;
size_t activeFractureIndex = 0;
for (size_t localGridCellIdx = 0; localGridCellIdx < grid->cellCount(); localGridCellIdx++)
{
size_t globalCellIdx = grid->globalGridCellIndex(localGridCellIdx);
if (activeM[localGridCellIdx] != 0)
{
m_unionOfMatrixActiveCells->setCellResultIndex(globalCellIdx, globalActiveMatrixIndex++);
activeMatrixIndex++;
}
if (activeF[localGridCellIdx] != 0)
{
m_unionOfFractureActiveCells->setCellResultIndex(globalCellIdx, globalActiveFractureIndex++);
activeFractureIndex++;
}
}
m_unionOfMatrixActiveCells->setGridActiveCellCounts(gridIdx, activeMatrixIndex);
m_unionOfFractureActiveCells->setGridActiveCellCounts(gridIdx, activeFractureIndex);
}
m_unionOfMatrixActiveCells->computeDerivedData();
m_unionOfFractureActiveCells->computeDerivedData();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCase* RimIdenticalGridCaseGroup::createAndAppendStatisticsCase()
{
RimStatisticsCase* newStatisticsCase = new RimStatisticsCase;
newStatisticsCase->caseUserDescription = QString("Statistics ") + QString::number(statisticsCaseCollection()->reservoirs.size()+1);
statisticsCaseCollection()->reservoirs.push_back(newStatisticsCase);
newStatisticsCase->openEclipseGridFile();
return newStatisticsCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::updateMainGridAndActiveCellsForStatisticsCases()
{
for (size_t i = 0; i < statisticsCaseCollection->reservoirs().size(); i++)
{
RimCase* rimStaticsCase = statisticsCaseCollection->reservoirs[i];
rimStaticsCase->reservoirData()->setMainGrid(this->mainGrid());
if (i == 0)
{
rimStaticsCase->reservoirData()->computeActiveCellBoundingBoxes();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::clearStatisticsResults()
{
for (size_t i = 0; i < statisticsCaseCollection->reservoirs().size(); i++)
{
RimCase* rimStaticsCase = statisticsCaseCollection->reservoirs[i];
if (!rimStaticsCase) continue;
rimStaticsCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->clearAllResults();
rimStaticsCase->results(RifReaderInterface::FRACTURE_RESULTS)->cellResults()->clearAllResults();
for (size_t j = 0; j < rimStaticsCase->reservoirViews.size(); j++)
{
RimReservoirView* rimReservoirView = rimStaticsCase->reservoirViews[j];
rimReservoirView->cellResult()->resultVariable = RimDefines::undefinedResultName();
rimReservoirView->cellEdgeResult()->resultVariable = RimDefines::undefinedResultName();
rimReservoirView->loadDataAndUpdate();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIdenticalGridCaseGroup::clearActiveCellUnions()
{
m_unionOfMatrixActiveCells->clear();
m_unionOfFractureActiveCells->clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimIdenticalGridCaseGroup::contains(RimCase* reservoir) const
{
CVF_ASSERT(reservoir);
for (size_t i = 0; i < caseCollection()->reservoirs().size(); i++)
{
RimCase* rimReservoir = caseCollection()->reservoirs()[i];
if (reservoir->gridFileName() == rimReservoir->gridFileName())
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigActiveCellInfo* RimIdenticalGridCaseGroup::unionOfActiveCells(RifReaderInterface::PorosityModelResultType porosityType)
{
if (porosityType == RifReaderInterface::MATRIX_RESULTS)
{
return m_unionOfMatrixActiveCells.p();
}
else
{
return m_unionOfFractureActiveCells.p();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimIdenticalGridCaseGroup::isStatisticsCaseCollection(RimCaseCollection* rimCaseCollection)
{
std::vector<caf::PdmFieldHandle*> fields;
rimCaseCollection->parentFields(fields);
if (fields.size() == 1)
{
if (fields[0]->keyword() == "StatisticsCaseCollection")
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCase* RimIdenticalGridCaseGroup::mainCase()
{
if(caseCollection()->reservoirs().size())
{
return caseCollection()->reservoirs()[0];
}
else
{
return NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimIdenticalGridCaseGroup::canCaseBeAdded(RimCase* reservoir) const
{
CVF_ASSERT(reservoir && reservoir->reservoirData() && reservoir->reservoirData()->mainGrid());
if (!m_mainGrid)
{
// Empty case group, reservoir can be added
return true;
}
RigMainGrid* incomingMainGrid = reservoir->reservoirData()->mainGrid();
if (RigGridManager::isEqual(m_mainGrid, incomingMainGrid))
{
return true;
}
return false;
}

View File

@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimStatisticsCaseCollection.h"
#include "RimCaseCollection.h"
class RimCase;
class RigMainGrid;
class RigActiveCellInfo;
//==================================================================================================
//
//
//
//==================================================================================================
class RimIdenticalGridCaseGroup : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimIdenticalGridCaseGroup();
virtual ~RimIdenticalGridCaseGroup();
caf::PdmField<QString> name;
caf::PdmField<RimCaseCollection*> caseCollection;
caf::PdmField<RimCaseCollection*> statisticsCaseCollection;
void addCase(RimCase* reservoir);
void removeCase(RimCase* reservoir);
bool contains(RimCase* reservoir) const;
bool canCaseBeAdded(RimCase* reservoir) const;
RimStatisticsCase* createAndAppendStatisticsCase();
RimCase* mainCase();
void loadMainCaseAndActiveCellInfo();
RigMainGrid* mainGrid();
RigActiveCellInfo* unionOfActiveCells(RifReaderInterface::PorosityModelResultType porosityType);
void computeUnionOfActiveCells();
static bool isStatisticsCaseCollection(RimCaseCollection* rimCaseCollection);
protected:
virtual caf::PdmFieldHandle* userDescriptionField();
private:
void updateMainGridAndActiveCellsForStatisticsCases();
void clearStatisticsResults();
void clearActiveCellUnions();
private:
RigMainGrid* m_mainGrid;
cvf::ref<RigActiveCellInfo> m_unionOfMatrixActiveCells;
cvf::ref<RigActiveCellInfo> m_unionOfFractureActiveCells;
};

View File

@ -16,16 +16,16 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimInputReservoir.h"
#include "RimInputCase.h"
#include "RimInputProperty.h"
#include "RimReservoirView.h"
#include "RifReaderEclipseInput.h"
#include "RigReservoir.h"
#include "RigReservoirCellResults.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "cvfAssert.h"
@ -34,21 +34,22 @@
#include "RifEclipseInputFileTools.h"
#include "cafProgressInfo.h"
#include "RIApplication.h"
#include "RIPreferences.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
CAF_PDM_SOURCE_INIT(RimInputReservoir, "RimInputReservoir");
CAF_PDM_SOURCE_INIT(RimInputCase, "RimInputReservoir");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimInputReservoir::RimInputReservoir()
: RimReservoir()
RimInputCase::RimInputCase()
: RimCase()
{
CAF_PDM_InitObject("RimInputReservoir", ":/EclipseInput48x48.png", "", "");
CAF_PDM_InitObject("RimInputCase", ":/EclipseInput48x48.png", "", "");
CAF_PDM_InitField(&m_gridFileName, "GridFileName", QString(), "Case grid filename", "", "" ,"");
m_gridFileName.setUiReadOnly(true);
CAF_PDM_InitFieldNoDefault(&m_additionalFileNames, "AdditionalFileNames", "Additional files", "", "" ,"");
m_additionalFileNames.setUiReadOnly(true);
CAF_PDM_InitFieldNoDefault(&m_inputPropertyCollection, "InputPropertyCollection", "", "", "", "");
m_inputPropertyCollection = new RimInputPropertyCollection;
@ -58,7 +59,7 @@ RimInputReservoir::RimInputReservoir()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimInputReservoir::~RimInputReservoir()
RimInputCase::~RimInputCase()
{
delete m_inputPropertyCollection;
}
@ -67,42 +68,23 @@ RimInputReservoir::~RimInputReservoir()
/// Open the supplied file set. If no grid data has been read, it will first find the possible
/// grid data among the files then read all supported properties from the files matching the grid
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::openDataFileSet(const QStringList& filenames)
void RimInputCase::openDataFileSet(const QStringList& filenames)
{
if (caseName().contains("Input Mock Debug Model"))
if (filenames.contains("Input Mock Debug Model"))
{
cvf::ref<RifReaderInterface> readerInterface = this->createMockModel(this->caseName());
m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
m_rigReservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
cvf::ref<RifReaderInterface> readerInterface = this->createMockModel(filenames[0]);
results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
size_t matrixActiveCellCount = 0;
size_t fractureActiveCellCount = 0;
for (size_t cellIdx = 0; cellIdx < m_rigReservoir->mainGrid()->cells().size(); cellIdx++)
{
const RigCell& cell = m_rigReservoir->mainGrid()->cells()[cellIdx];
if (cell.isActiveInMatrixModel())
{
matrixActiveCellCount++;
}
if (cell.isActiveInFractureModel())
{
fractureActiveCellCount++;
}
}
m_rigReservoir->mainGrid()->setGlobalMatrixModelActiveCellCount(matrixActiveCellCount);
m_rigReservoir->mainGrid()->setGlobalFractureModelActiveCellCount(fractureActiveCellCount);
reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->computeDerivedData();
reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->computeDerivedData();
return;
}
if (m_rigReservoir.isNull())
if (this->reservoirData() == NULL)
{
RigReservoir* reservoir = new RigReservoir;
m_rigReservoir = reservoir;
this->setReservoirData(new RigCaseData);
}
// First find and read the grid data
@ -114,8 +96,7 @@ void RimInputReservoir::openDataFileSet(const QStringList& filenames)
{
m_gridFileName = filenames[i];
m_rigReservoir->computeFaults();
m_rigReservoir->mainGrid()->computeCachedData();
computeCachedData();
break;
}
@ -174,46 +155,45 @@ void RimInputReservoir::openDataFileSet(const QStringList& filenames)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimInputReservoir::openEclipseGridFile()
bool RimInputCase::openEclipseGridFile()
{
// Early exit if reservoir data is created
if (m_rigReservoir.isNull())
if (this->reservoirData() == NULL)
{
cvf::ref<RifReaderInterface> readerInterface;
if (caseName().contains("Input Mock Debug Model"))
if (m_gridFileName().contains("Input Mock Debug Model"))
{
readerInterface = this->createMockModel(this->caseName());
readerInterface = this->createMockModel(this->m_gridFileName());
}
else
{
RigReservoir* reservoir = new RigReservoir;
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
readerInterface = new RifReaderEclipseInput;
if (!readerInterface->open(m_gridFileName, reservoir))
if (!readerInterface->open(m_gridFileName, eclipseCase.p()))
{
delete reservoir;
return false;
}
m_rigReservoir = reservoir;
loadAndSyncronizeInputProperties();
this->setReservoirData( eclipseCase.p() );
}
CVF_ASSERT(m_rigReservoir.notNull());
CVF_ASSERT(this->reservoirData());
CVF_ASSERT(readerInterface.notNull());
m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
m_rigReservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
m_rigReservoir->computeFaults();
m_rigReservoir->mainGrid()->computeCachedData();
results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
computeCachedData();
loadAndSyncronizeInputProperties();
}
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
if (app->preferences()->autocomputeDepthRelatedProperties)
{
RigReservoirCellResults* matrixResults = m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS);
RigReservoirCellResults* fractureResults = m_rigReservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS);
RimReservoirCellResultsStorage* matrixResults = results(RifReaderInterface::MATRIX_RESULTS);
RimReservoirCellResultsStorage* fractureResults = results(RifReaderInterface::FRACTURE_RESULTS);
matrixResults->computeDepthRelatedResults();
fractureResults->computeDepthRelatedResults();
@ -227,11 +207,11 @@ bool RimInputReservoir::openEclipseGridFile()
/// Loads input property data from the gridFile and additional files
/// Creates new InputProperties if necessary, and flags the unused ones as obsolete
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::loadAndSyncronizeInputProperties()
void RimInputCase::loadAndSyncronizeInputProperties()
{
// Make sure we actually have reservoir data
CVF_ASSERT(m_rigReservoir.notNull());
CVF_ASSERT(this->reservoirData());
CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0,0,0));
// Then read the properties from all the files referenced by the InputReservoir
@ -305,7 +285,7 @@ void RimInputReservoir::loadAndSyncronizeInputProperties()
{
if (fileKeywordSet.count(knownKeywords[fkIt]))
{
QString resultName = this->reservoirData()->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(knownKeywords[fkIt]);
QString resultName = this->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(knownKeywords[fkIt]);
if (RifEclipseInputFileTools::readProperty(filenames[i], this->reservoirData(), knownKeywords[fkIt], resultName))
{
RimInputProperty* inputProperty = new RimInputProperty;
@ -334,7 +314,7 @@ void RimInputReservoir::loadAndSyncronizeInputProperties()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
void RimInputCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
}
@ -342,7 +322,7 @@ void RimInputReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::addFiles(const QStringList& newFileNames)
void RimInputCase::addFiles(const QStringList& newFileNames)
{
}
@ -351,7 +331,7 @@ void RimInputReservoir::addFiles(const QStringList& newFileNames)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::removeFiles(const QStringList& obsoleteFileNames)
void RimInputCase::removeFiles(const QStringList& obsoleteFileNames)
{
}
@ -359,7 +339,7 @@ void RimInputReservoir::removeFiles(const QStringList& obsoleteFileNames)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimInputReservoir::removeProperty(RimInputProperty* inputProperty)
void RimInputCase::removeProperty(RimInputProperty* inputProperty)
{
bool isPropertyFileReferencedByOthers = false;
@ -380,7 +360,7 @@ void RimInputReservoir::removeProperty(RimInputProperty* inputProperty)
}
// Remove the results pointed to by this input property
RigReservoirCellResults* results = m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS);
RigCaseCellResultsData* results = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS);
results->removeResult(inputProperty->resultName);
this->removeResult(inputProperty->resultName);
@ -389,13 +369,15 @@ void RimInputReservoir::removeProperty(RimInputProperty* inputProperty)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RifReaderInterface> RimInputReservoir::createMockModel(QString modelName)
cvf::ref<RifReaderInterface> RimInputCase::createMockModel(QString modelName)
{
cvf::ref<RigReservoir> reservoir = new RigReservoir;
cvf::ref<RigCaseData> reservoir = new RigCaseData;
cvf::ref<RifReaderMockModel> mockFileInterface = new RifReaderMockModel;
if (modelName == "Input Mock Debug Model Simple")
{
m_gridFileName = modelName;
// Create the mock file interface and and RigSerervoir and set them up.
mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6));
@ -405,12 +387,16 @@ cvf::ref<RifReaderInterface> RimInputReservoir::createMockModel(QString modelNam
mockFileInterface->open("", reservoir.p());
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4);
reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
//TODO: Rewrite active cell info in mock models
//reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3);
reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
//TODO: Rewrite active cell info in mock models
//reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
// Add a property
@ -421,7 +407,7 @@ cvf::ref<RifReaderInterface> RimInputReservoir::createMockModel(QString modelNam
m_inputPropertyCollection->inputProperties.push_back(inputProperty);
}
m_rigReservoir = reservoir;
this->setReservoirData( reservoir.p() );
return mockFileInterface.p();
}
@ -429,10 +415,26 @@ cvf::ref<RifReaderInterface> RimInputReservoir::createMockModel(QString modelNam
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimInputReservoir::locationOnDisc() const
QString RimInputCase::locationOnDisc() const
{
if (m_gridFileName().isEmpty()) return QString();
QFileInfo fi(m_gridFileName);
return fi.absolutePath();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimInputCase::updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath)
{
bool foundFile = false;
std::vector<QString> searchedPaths;
m_gridFileName = relocateFile(m_gridFileName(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths);
for (size_t i = 0; i < m_additionalFileNames().size(); i++)
{
m_additionalFileNames.v()[i] = relocateFile(m_additionalFileNames()[i], newProjectPath, oldProjectPath, &foundFile, &searchedPaths);
}
}

View File

@ -23,7 +23,7 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimReservoir.h"
#include "RimCase.h"
#include "RimInputPropertyCollection.h"
@ -36,38 +36,43 @@ class RifReaderInterface;
//
//
//==================================================================================================
class RimInputReservoir : public RimReservoir
class RimInputCase : public RimCase
{
CAF_PDM_HEADER_INIT;
public:
RimInputReservoir();
virtual ~RimInputReservoir();
RimInputCase();
virtual ~RimInputCase();
// Fields
caf::PdmField<RimInputPropertyCollection*> m_inputPropertyCollection;
// File open methods
void openDataFileSet(const QStringList& filenames);
void loadAndSyncronizeInputProperties();
void removeProperty(RimInputProperty* inputProperty);
// RimCase overrides
virtual bool openEclipseGridFile(); // Find grid file among file set. Read, Find read and validate property date. Syncronize child property sets.
// PdmObject overrides
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
// Overrides from RimCase
virtual QString locationOnDisc() const;
virtual QString gridFileName() const { return m_gridFileName();}
virtual void updateFilePathsFromProjectPath(const QString& projectPath, const QString& oldProjectPath);
private:
void addFiles(const QStringList& newFileNames);
void removeFiles(const QStringList& obsoleteFileNames);
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
// Fields
caf::PdmField<std::vector<QString> > m_additionalFileNames;
caf::PdmField<QString> m_gridFileName;
caf::PdmField<RimInputPropertyCollection*> m_inputPropertyCollection;
// File open methods
void openDataFileSet(const QStringList& filenames);
void loadAndSyncronizeInputProperties();
void removeProperty(RimInputProperty* inputProperty);
// RimReservoir overrides
virtual bool openEclipseGridFile(); // Find grid file among file set. Read, Find read and validate property date. Syncronize child property sets.
// PdmObject overrides
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual QString locationOnDisc() const;
private:
void addFiles(const QStringList& newFileNames);
void removeFiles(const QStringList& obsoleteFileNames);
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
};

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimInputProperty.h"

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimInputPropertyCollection.h"

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimLegendConfig.h"
#include "RimReservoirView.h"
@ -405,13 +405,13 @@ void RimLegendConfig::recreateLegend()
//--------------------------------------------------------------------------------------------------
double RimLegendConfig::adjust(double domainValue, double precision)
{
double decadeValue = cvf::Math::abs(domainValue);
double threshold = 1e-6;
if (decadeValue < threshold)
double absDomainValue = cvf::Math::abs(domainValue);
if (absDomainValue == 0.0)
{
return 0.0;
}
double logDecValue = log10(decadeValue);
double logDecValue = log10(absDomainValue);
logDecValue = cvf::Math::ceil(logDecValue);
double factor = pow(10.0, precision - logDecValue);

View File

@ -92,7 +92,7 @@ private:
caf::PdmPointer<RimReservoirView> m_reservoirView;
cvf::ref<cvf::ScalarMapperDiscreteLinear> m_linDiscreteScalarMapper;
cvf::ref<cvf::ScalarMapperDiscreteLinear> m_logDiscreteScalarMapper;
cvf::ref<cvf::ScalarMapperDiscreteLog> m_logDiscreteScalarMapper;
cvf::ref<cvf::ScalarMapperContinuousLog> m_logSmoothScalarMapper;
cvf::ref<cvf::ScalarMapperContinuousLinear> m_linSmoothScalarMapper;
cvf::ref<cvf::ScalarMapper> m_currentScalarMapper;

View File

@ -16,12 +16,16 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimProject.h"
#include "RIApplication.h"
#include "RIVersionInfo.h"
#include "RimScriptCollection.h"
#include "RiaApplication.h"
#include "RiaVersionInfo.h"
#include "RigGridManager.h"
#include "RigCaseData.h"
#include "RimResultCase.h"
CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject");
//--------------------------------------------------------------------------------------------------
@ -33,11 +37,15 @@ RimProject::RimProject(void)
m_projectFileVersionString.setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&reservoirs, "Reservoirs", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&caseGroups, "CaseGroups", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&scriptCollection, "ScriptCollection", "Scripts", ":/Default.png", "", "");
scriptCollection = new RimScriptCollection();
scriptCollection->directory.setUiHidden(true);
m_gridCollection = new RigGridManager;
initAfterRead();
}
@ -46,6 +54,8 @@ RimProject::RimProject(void)
//--------------------------------------------------------------------------------------------------
RimProject::~RimProject(void)
{
close();
if (scriptCollection()) delete scriptCollection();
reservoirs.deleteAllChildObjects();
@ -56,7 +66,10 @@ RimProject::~RimProject(void)
//--------------------------------------------------------------------------------------------------
void RimProject::close()
{
m_gridCollection->clear();
reservoirs.deleteAllChildObjects();
caseGroups.deleteAllChildObjects();
fileName = "";
}
@ -69,7 +82,7 @@ void RimProject::initAfterRead()
//
// TODO : Must store content of scripts in project file and notify user if stored content is different from disk on execute and edit
//
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString scriptDirectory = app->scriptDirectory();
this->setUserScriptPath(scriptDirectory);
@ -113,3 +126,145 @@ QString RimProject::projectFileVersionString() const
{
return m_projectFileVersionString;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir)
{
CVF_ASSERT(rimReservoir);
RigCaseData* rigEclipseCase = rimReservoir->reservoirData();
RigMainGrid* equalGrid = registerCaseInGridCollection(rigEclipseCase);
CVF_ASSERT(equalGrid);
// Insert in identical grid group
bool foundGroup = false;
for (size_t i = 0; i < caseGroups.size(); i++)
{
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
if (cg->mainGrid() == equalGrid)
{
cg->addCase(rimReservoir);
foundGroup = true;
}
}
if (!foundGroup)
{
RimIdenticalGridCaseGroup* group = new RimIdenticalGridCaseGroup;
group->addCase(rimReservoir);
caseGroups().push_back(group);
}
// Remove reservoir from main container
reservoirs().removeChildObject(rimReservoir);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::removeCaseFromAllGroups(RimCase* reservoir)
{
m_gridCollection->removeCase(reservoir->reservoirData());
for (size_t i = 0; i < caseGroups.size(); i++)
{
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
cg->removeCase(reservoir);
}
reservoirs().removeChildObject(reservoir);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigMainGrid* RimProject::registerCaseInGridCollection(RigCaseData* rigEclipseCase)
{
CVF_ASSERT(rigEclipseCase);
RigMainGrid* equalGrid = m_gridCollection->findEqualGrid(rigEclipseCase->mainGrid());
if (equalGrid)
{
// Replace the grid with an already registered grid
rigEclipseCase->setMainGrid(equalGrid);
}
else
{
// This is the first insertion of this grid, compute cached data
rigEclipseCase->mainGrid()->computeCachedData();
std::vector<RigGridBase*> grids;
rigEclipseCase->allGrids(&grids);
size_t i;
for (i = 0; i < grids.size(); i++)
{
grids[i]->computeFaults();
}
equalGrid = rigEclipseCase->mainGrid();
}
m_gridCollection->addCase(rigEclipseCase);
return equalGrid;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::insertCaseInCaseGroup(RimIdenticalGridCaseGroup* caseGroup, RimCase* rimReservoir)
{
CVF_ASSERT(rimReservoir);
RigCaseData* rigEclipseCase = rimReservoir->reservoirData();
registerCaseInGridCollection(rigEclipseCase);
caseGroup->addCase(rimReservoir);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::setProjectFileNameAndUpdateDependencies(const QString& fileName)
{
// Extract the filename of the project file when it was saved
QString oldProjectFileName = this->fileName;
// Replace with the new actual filename
this->fileName = fileName;
// Loop over all reservoirs and update file path
QFileInfo fileInfo(fileName);
QString newProjectPath = fileInfo.path();
QFileInfo fileInfoOld(oldProjectFileName);
QString oldProjectPath = fileInfoOld.path();
for (size_t i = 0; i < reservoirs.size(); i++)
{
reservoirs[i]->updateFilePathsFromProjectPath(newProjectPath, oldProjectPath);
}
// Case groups : Loop over all reservoirs in and update file path
for (size_t i = 0; i < caseGroups.size(); i++)
{
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
for (size_t j = 0; j < cg->caseCollection()->reservoirs().size(); j++)
{
cg->caseCollection()->reservoirs()[j]->updateFilePathsFromProjectPath(newProjectPath, oldProjectPath);
}
}
}

View File

@ -20,8 +20,10 @@
#include "cafPdmDocument.h"
#include "RimScriptCollection.h"
#include "RimIdenticalGridCaseGroup.h"
class RimReservoir;
class RimCase;
class RigGridManager;
//==================================================================================================
///
@ -32,11 +34,11 @@ class RimProject : public caf::PdmDocument
CAF_PDM_HEADER_INIT;
public:
caf::PdmPointersField<RimReservoir*> reservoirs;
caf::PdmField<RimScriptCollection*> scriptCollection;
caf::PdmPointersField<RimCase*> reservoirs;
caf::PdmPointersField<RimIdenticalGridCaseGroup*> caseGroups;
caf::PdmField<RimScriptCollection*> scriptCollection;
void setUserScriptPath(const QString& path);
//void updateProjectScriptPath();
QString projectFileVersionString() const;
@ -45,11 +47,22 @@ public:
void close();
void insertCaseInCaseGroup(RimIdenticalGridCaseGroup* caseGroup, RimCase* rimReservoir);
void moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir);
void removeCaseFromAllGroups(RimCase* rimReservoir);
void setProjectFileNameAndUpdateDependencies(const QString& fileName);
private:
RigMainGrid* registerCaseInGridCollection(RigCaseData* rigEclipseCase);
protected:
// Overridden methods
virtual void initAfterRead();
virtual void setupBeforeSave();
private:
caf::PdmField<QString> m_projectFileVersionString;
caf::PdmField<QString> m_projectFileVersionString;
cvf::ref<RigGridManager> m_gridCollection;
};

View File

@ -1,228 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RifReaderEclipseOutput.h"
#include "RifReaderMockModel.h"
#include "RimReservoir.h"
#include "RimReservoirView.h"
#include "RigReservoir.h"
#include "RigMainGrid.h"
#include "RigReservoirCellResults.h"
#include "cvfAssert.h"
#include "cafPdmUiPushButtonEditor.h"
#include <QString>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoir::RimReservoir()
{
m_rigReservoir = NULL;
CAF_PDM_InitField(&caseName, "CaseName", QString(), "Case name", "", "" ,"");
// CAF_PDM_InitField(&releaseResultMemory, "ReleaseResultMemory", true, "Release result memory", "", "" ,"");
// releaseResultMemory.setIOReadable(false);
// releaseResultMemory.setIOWritable(false);
// releaseResultMemory.setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName());
CAF_PDM_InitFieldNoDefault(&reservoirViews, "ReservoirViews", "", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigReservoir* RimReservoir::reservoirData()
{
return m_rigReservoir.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigReservoir* RimReservoir::reservoirData() const
{
return m_rigReservoir.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoir::initAfterRead()
{
size_t j;
for (j = 0; j < reservoirViews().size(); j++)
{
RimReservoirView* riv = reservoirViews()[j];
CVF_ASSERT(riv);
riv->setEclipseCase(this);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoir::~RimReservoir()
{
reservoirViews.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirView* RimReservoir::createAndAddReservoirView()
{
RimReservoirView* riv = new RimReservoirView();
riv->setEclipseCase(this);
size_t i = reservoirViews().size();
riv->name = QString("View %1").arg(i + 1);
reservoirViews().push_back(riv);
return riv;
}
//--------------------------------------------------------------------------------------------------
/// TODO: Move this functionality to PdmPointersField
//--------------------------------------------------------------------------------------------------
void RimReservoir::removeReservoirView(RimReservoirView* reservoirView)
{
std::vector<size_t> indices;
size_t i;
for (i = 0; i < reservoirViews().size(); i++)
{
if (reservoirViews()[i] == reservoirView)
{
indices.push_back(i);
}
}
// NB! Make sure the ordering goes from large to low index
while (!indices.empty())
{
reservoirViews().erase(indices.back());
indices.pop_back();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoir::removeResult(const QString& resultName)
{
size_t i;
for (i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
RimResultSlot* result = reservoirView->cellResult;
CVF_ASSERT(result);
bool rebuildDisplayModel = false;
// Set cell result variable to none if displaying
if (result->resultVariable() == resultName)
{
result->resultVariable.v() = RimDefines::undefinedResultName();
result->loadResult();
rebuildDisplayModel = true;
}
std::list< caf::PdmPointer< RimCellPropertyFilter > >::iterator it;
RimCellPropertyFilterCollection* propFilterCollection = reservoirView->propertyFilterCollection();
for (it = propFilterCollection->propertyFilters.v().begin(); it != propFilterCollection->propertyFilters.v().end(); ++it)
{
RimCellPropertyFilter* propertyFilter = *it;
if (propertyFilter->resultDefinition->resultVariable.v() == resultName)
{
propertyFilter->resultDefinition->resultVariable.v() = RimDefines::undefinedResultName();
propertyFilter->resultDefinition->loadResult();
propertyFilter->setDefaultValues();
rebuildDisplayModel = true;
}
}
if (rebuildDisplayModel)
{
reservoirViews()[i]->createDisplayModelAndRedraw();
}
// TODO
// CellEdgeResults are not considered, as they do not support display of input properties yet
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (changedField == &releaseResultMemory)
{
if (m_rigReservoir.notNull())
{
for (size_t i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
RimResultSlot* result = reservoirView->cellResult;
CVF_ASSERT(result);
result->resultVariable.v() = RimDefines::undefinedResultName();
result->loadResult();
RimCellEdgeResultSlot* cellEdgeResult = reservoirView->cellEdgeResult;
CVF_ASSERT(cellEdgeResult);
cellEdgeResult->resultVariable.v() = RimDefines::undefinedResultName();
cellEdgeResult->loadResult();
reservoirView->createDisplayModelAndRedraw();
}
RigReservoirCellResults* matrixModelResults = m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS);
if (matrixModelResults)
{
matrixModelResults->clearAllResults();
}
RigReservoirCellResults* fractureModelResults = m_rigReservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS);
if (fractureModelResults)
{
fractureModelResults->clearAllResults();
}
}
releaseResultMemory = oldValue.toBool();
}
}

View File

@ -1,76 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
class QString;
class RigReservoir;
class RigGridBase;
class RimReservoirView;
//==================================================================================================
//
// Interface for reservoirs.
// As this is a pure virtual class, the factory macros are not relevant (nor possible) to use
// CAF_PDM_HEADER_INIT and CAF_PDM_SOURCE_INIT
//
//==================================================================================================
class RimReservoir : public caf::PdmObject
{
public:
RimReservoir();
virtual ~RimReservoir();
virtual bool openEclipseGridFile() = 0;
RigReservoir* reservoirData();
const RigReservoir* reservoirData() const;
RimReservoirView* createAndAddReservoirView();
void removeReservoirView(RimReservoirView* reservoirView);
void removeResult(const QString& resultName);
// Fields:
caf::PdmField<QString> caseName;
caf::PdmField<bool> releaseResultMemory;
caf::PdmPointersField<RimReservoirView*> reservoirViews;
virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; }
virtual QString locationOnDisc() const { return QString(); }
protected:
// Overridden methods
virtual void initAfterRead();
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
protected:
cvf::ref<RigReservoir> m_rigReservoir;
};

View File

@ -0,0 +1,731 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimReservoirCellResultsCacher.h"
#include "RigCaseCellResultsData.h"
#include "RiaApplication.h"
#include "RigMainGrid.h"
#include "RigCell.h"
#include "cafProgressInfo.h"
CAF_PDM_SOURCE_INIT(RimReservoirCellResultsStorage, "ReservoirCellResultStorage");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorage::RimReservoirCellResultsStorage()
: m_cellResults(NULL),
m_ownerMainGrid(NULL)
{
CAF_PDM_InitObject("Cacher", "", "", "");
CAF_PDM_InitField(&m_resultCacheFileName, "ResultCacheFileName", QString(), "UiDummyname", "", "" ,"");
m_resultCacheFileName.setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_resultCacheMetaData, "ResultCacheEntries", "UiDummyname", "", "", "");
m_resultCacheMetaData.setUiHidden(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorage::~RimReservoirCellResultsStorage()
{
m_resultCacheMetaData.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
/// This override populates the metainfo regarding the cell results data in the RigCaseCellResultsData
/// object. This metainfo will then be written to the project file when saving, and thus read on project file open.
/// This method then writes the actual double arrays to the data file in a simple format:
/// MagicNumber<uint32>, Version<uint32>, ResultVariables< Array < TimeStep< CellDataArraySize<uint64>, CellData< Array<double > > > >
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::setupBeforeSave()
{
m_resultCacheMetaData.deleteAllChildObjects();
QString newValidCacheFileName = getValidCacheFileName();
// Delete the storage file
QFileInfo storageFileInfo(newValidCacheFileName);
if (storageFileInfo.exists())
{
QDir storageDir = storageFileInfo.dir();
storageDir.remove(storageFileInfo.fileName());
}
if (!m_cellResults) return;
const std::vector<RigCaseCellResultsData::ResultInfo>& resInfo = m_cellResults->infoForEachResultIndex();
bool hasResultsToStore = false;
for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx)
{
if (resInfo[rIdx].m_needsToBeStored)
{
hasResultsToStore = true;
break;
}
}
if(resInfo.size() && hasResultsToStore)
{
QDir::root().mkpath(getCacheDirectoryPath());
QFile cacheFile(newValidCacheFileName);
if (!cacheFile.open(QIODevice::WriteOnly))
{
qWarning() << "Saving project: Can't open the cache file : " + newValidCacheFileName;
return;
}
m_resultCacheFileName = newValidCacheFileName;
QDataStream stream(&cacheFile);
stream.setVersion(QDataStream::Qt_4_6);
stream << (quint32)0xCEECAC4E; // magic number
stream << (quint32)1; // Version number. Increment if needing to extend the format in ways that can not be handled generically by the reader
caf::ProgressInfo progInfo(resInfo.size(), "Saving generated and imported properties");
for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx)
{
// If there is no data, we do not store anything for the current result variable
// (Even not the metadata, of cause)
size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size();
if (timestepCount && resInfo[rIdx].m_needsToBeStored)
{
progInfo.setProgressDescription(resInfo[rIdx].m_resultName);
// Create and setup the cache information for this result
RimReservoirCellResultsStorageEntryInfo* cacheEntry = new RimReservoirCellResultsStorageEntryInfo;
m_resultCacheMetaData.push_back(cacheEntry);
cacheEntry->m_resultType = resInfo[rIdx].m_resultType;
cacheEntry->m_resultName = resInfo[rIdx].m_resultName;
cacheEntry->m_timeStepDates = resInfo[rIdx].m_timeStepDates;
// Take note of the file position for fast lookup later
cacheEntry->m_filePosition = cacheFile.pos();
// Write all the scalar values for each time step to the stream,
// starting with the number of values
for (size_t tsIdx = 0; tsIdx < resInfo[rIdx].m_timeStepDates.size() ; ++tsIdx)
{
const std::vector<double>* data = NULL;
if (tsIdx < timestepCount)
{
data = &(m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex, tsIdx));
}
if (data && data->size())
{
stream << (quint64)(data->size());
for (size_t cIdx = 0; cIdx < data->size(); ++cIdx)
{
stream << (*data)[cIdx];
}
}
else
{
stream << (quint64)0;
}
}
}
progInfo.incrementProgress();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimReservoirCellResultsStorage::getValidCacheFileName()
{
QString cacheFileName;
if (m_resultCacheFileName().isEmpty())
{
QString newCacheDirPath = getCacheDirectoryPath();
QUuid guid = QUuid::createUuid();
cacheFileName = newCacheDirPath + "/" + guid.toString();
}
else
{
// Make the path correct related to the possibly new project filename
QString newCacheDirPath = getCacheDirectoryPath();
QFileInfo oldCacheFile(m_resultCacheFileName());
cacheFileName = newCacheDirPath + "/" + oldCacheFile.fileName();
}
return cacheFileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimReservoirCellResultsStorage::getCacheDirectoryPath()
{
QString cacheDirPath;
QString projectFileName = RiaApplication::instance()->project()->fileName();
QFileInfo fileInfo(projectFileName);
cacheDirPath = fileInfo.canonicalPath();
cacheDirPath += "/" + fileInfo.completeBaseName() + "_cache";
return cacheDirPath;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::setReaderInterface(RifReaderInterface* readerInterface)
{
m_readerInterface = readerInterface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifReaderInterface* RimReservoirCellResultsStorage::readerInterface()
{
return m_readerInterface.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimReservoirCellResultsStorage::findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex)
{
if (!m_cellResults) return cvf::UNDEFINED_SIZE_T;
// Special handling for SOIL
if (type == RimDefines::DYNAMIC_NATIVE && resultName.toUpper() == "SOIL")
{
size_t soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName);
// If SOIL is not found, try to compute and return computed scalar index
// Will return cvf::UNDEFINED_SIZE_T if no SGAS/SWAT is found
if (soilScalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
computeSOILForTimeStep(timeStepIndex);
soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName);
return soilScalarResultIndex;
}
// If we have found SOIL and SOIL must be calculated, calculate and return
if (soilScalarResultIndex != cvf::UNDEFINED_SIZE_T && m_cellResults->mustBeCalculated(soilScalarResultIndex))
{
computeSOILForTimeStep(timeStepIndex);
return soilScalarResultIndex;
}
}
size_t scalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T;
if (type == RimDefines::GENERATED)
{
return cvf::UNDEFINED_SIZE_T;
}
if (m_readerInterface.notNull())
{
size_t timeStepCount = m_cellResults->infoForEachResultIndex()[scalarResultIndex].m_timeStepDates.size();
bool resultLoadingSucess = true;
if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0)
{
m_cellResults->cellScalarResults(scalarResultIndex).resize(timeStepCount);
std::vector<double>& values = m_cellResults->cellScalarResults(scalarResultIndex)[timeStepIndex];
if (values.size() == 0)
{
if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, timeStepIndex, &values))
{
resultLoadingSucess = false;
}
}
}
else if (type == RimDefines::STATIC_NATIVE)
{
m_cellResults->cellScalarResults(scalarResultIndex).resize(1);
std::vector<double>& values = m_cellResults->cellScalarResults(scalarResultIndex)[0];
if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values))
{
resultLoadingSucess = false;
}
}
if (!resultLoadingSucess)
{
// Error logging
CVF_ASSERT(false);
}
}
return scalarResultIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimReservoirCellResultsStorage::findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName)
{
if (!m_cellResults) return cvf::UNDEFINED_SIZE_T;
size_t resultGridIndex = m_cellResults->findScalarResultIndex(type, resultName);
if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T;
// If we have any results on any timestep, assume we have loaded results already
for (size_t tsIdx = 0; tsIdx < m_cellResults->timeStepCount(resultGridIndex); ++tsIdx)
{
if (m_cellResults->cellScalarResults(resultGridIndex, tsIdx).size())
{
return resultGridIndex;
}
}
if (type == RimDefines::GENERATED)
{
return cvf::UNDEFINED_SIZE_T;
}
if (m_readerInterface.notNull())
{
// Add one more result to result container
size_t timeStepCount = m_cellResults->infoForEachResultIndex()[resultGridIndex].m_timeStepDates.size();
bool resultLoadingSucess = true;
if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0)
{
m_cellResults->cellScalarResults(resultGridIndex).resize(timeStepCount);
size_t i;
for (i = 0; i < timeStepCount; i++)
{
std::vector<double>& values = m_cellResults->cellScalarResults(resultGridIndex)[i];
if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, i, &values))
{
resultLoadingSucess = false;
}
}
}
else if (type == RimDefines::STATIC_NATIVE)
{
m_cellResults->cellScalarResults(resultGridIndex).resize(1);
std::vector<double>& values = m_cellResults->cellScalarResults(resultGridIndex)[0];
if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values))
{
resultLoadingSucess = false;
}
}
if (!resultLoadingSucess)
{
// Remove last scalar result because loading of result failed
m_cellResults->cellScalarResults(resultGridIndex).clear();
}
}
return resultGridIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::loadOrComputeSOIL()
{
size_t scalarIndexSOIL = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL");
if (scalarIndexSOIL != cvf::UNDEFINED_SIZE_T)
{
return;
}
for (size_t timeStepIdx = 0; timeStepIdx < m_cellResults->maxTimeStepCount(); timeStepIdx++)
{
computeSOILForTimeStep(timeStepIdx);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::computeSOILForTimeStep(size_t timeStepIndex)
{
size_t scalarIndexSWAT = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SWAT", timeStepIndex);
size_t scalarIndexSGAS = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SGAS", timeStepIndex);
// Early exit if none of SWAT or SGAS is present
if (scalarIndexSWAT == cvf::UNDEFINED_SIZE_T && scalarIndexSGAS == cvf::UNDEFINED_SIZE_T)
{
return;
}
CVF_ASSERT(m_cellResults);
size_t soilResultValueCount = 0;
size_t soilTimeStepCount = 0;
std::vector<double>* swatForTimeStep = NULL;
std::vector<double>* sgasForTimeStep = NULL;
if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T)
{
swatForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSWAT, timeStepIndex));
if (swatForTimeStep->size() == 0)
{
swatForTimeStep = NULL;
}
else
{
soilResultValueCount = swatForTimeStep->size();
soilTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepDates.size();
}
}
if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T)
{
sgasForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSGAS, timeStepIndex));
if (sgasForTimeStep->size() == 0)
{
sgasForTimeStep = NULL;
}
else
{
soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep->size());
size_t sgasTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSGAS].m_timeStepDates.size();
soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount);
}
}
size_t soilResultGridIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL");
if (soilResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
soilResultGridIndex = m_cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL", false);
CVF_ASSERT(soilResultGridIndex != cvf::UNDEFINED_SIZE_T);
// Set this result to be calculated
m_cellResults->setMustBeCalculated(soilResultGridIndex);
m_cellResults->cellScalarResults(soilResultGridIndex).resize(soilTimeStepCount);
for (size_t timeStepIdx = 0; timeStepIdx < soilTimeStepCount; timeStepIdx++)
{
m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIdx).resize(soilResultValueCount);
}
}
std::vector<double>& soilForTimeStep = m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIndex);
#pragma omp parallel for
for (int idx = 0; idx < static_cast<int>(soilResultValueCount); idx++)
{
double soilValue = 1.0;
if (sgasForTimeStep)
{
soilValue -= sgasForTimeStep->at(idx);
}
if (swatForTimeStep)
{
soilValue -= swatForTimeStep->at(idx);
}
soilForTimeStep[idx] = soilValue;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::computeDepthRelatedResults()
{
if (!m_cellResults) return;
size_t depthResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DEPTH");
size_t dxResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DX");
size_t dyResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DY");
size_t dzResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DZ");
size_t topsResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "TOPS");
size_t bottomResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM");
bool computeDepth = false;
bool computeDx = false;
bool computeDy = false;
bool computeDz = false;
bool computeTops = false;
bool computeBottom = false;
size_t resultValueCount = m_ownerMainGrid->cells().size();
if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
depthResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", false, resultValueCount);
computeDepth = true;
}
if (dxResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
dxResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DX", false, resultValueCount);
computeDx = true;
}
if (dyResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
dyResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DY", false, resultValueCount);
computeDy = true;
}
if (dzResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
dzResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DZ", false, resultValueCount);
computeDz = true;
}
if (topsResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
topsResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "TOPS", false, resultValueCount);
computeTops = true;
}
if (bottomResultGridIndex == cvf::UNDEFINED_SIZE_T)
{
bottomResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM", false, resultValueCount);
computeBottom = true;
}
std::vector< std::vector<double> >& depth = m_cellResults->cellScalarResults(depthResultGridIndex);
std::vector< std::vector<double> >& dx = m_cellResults->cellScalarResults(dxResultGridIndex);
std::vector< std::vector<double> >& dy = m_cellResults->cellScalarResults(dyResultGridIndex);
std::vector< std::vector<double> >& dz = m_cellResults->cellScalarResults(dzResultGridIndex);
std::vector< std::vector<double> >& tops = m_cellResults->cellScalarResults(topsResultGridIndex);
std::vector< std::vector<double> >& bottom = m_cellResults->cellScalarResults(bottomResultGridIndex);
size_t cellIdx = 0;
for (cellIdx = 0; cellIdx < m_ownerMainGrid->cells().size(); cellIdx++)
{
const RigCell& cell = m_ownerMainGrid->cells()[cellIdx];
if (computeDepth)
{
depth[0][cellIdx] = cvf::Math::abs(cell.center().z());
}
if (computeDx)
{
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_I) - cell.faceCenter(cvf::StructGridInterface::POS_I);
dx[0][cellIdx] = cvf::Math::abs(cellWidth.x());
}
if (computeDy)
{
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_J) - cell.faceCenter(cvf::StructGridInterface::POS_J);
dy[0][cellIdx] = cvf::Math::abs(cellWidth.y());
}
if (computeDz)
{
cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_K) - cell.faceCenter(cvf::StructGridInterface::POS_K);
dz[0][cellIdx] = cvf::Math::abs(cellWidth.z());
}
if (computeTops)
{
tops[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::NEG_K).z());
}
if (computeBottom)
{
bottom[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::POS_K).z());
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimReservoirCellResultsStorage::findOrLoadScalarResult(const QString& resultName)
{
if (!m_cellResults) return cvf::UNDEFINED_SIZE_T;
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
scalarResultIndex = this->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, resultName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
scalarResultIndex = this->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, resultName);
}
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
scalarResultIndex = m_cellResults->findScalarResultIndex(RimDefines::GENERATED, resultName);
}
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
scalarResultIndex = m_cellResults->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName);
}
return scalarResultIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::setCellResults(RigCaseCellResultsData* cellResults)
{
m_cellResults = cellResults;
if (m_cellResults == NULL)
return;
// Now that we have got the results container, we can finally
// Read data from the internal storage and populate it
if (m_resultCacheFileName().isEmpty())
return;
// Get the name of the cache name relative to the current project file position
QString newValidCacheFileName = getValidCacheFileName();
QFile storageFile(newValidCacheFileName);
// Warn if we thought we were to find some data on the storage file
if (!storageFile.exists() && m_resultCacheMetaData.size())
{
qWarning() << "Reading stored results: Missing the storage file : " + newValidCacheFileName;
return;
}
if (!storageFile.open(QIODevice::ReadOnly))
{
qWarning() << "Reading stored results: Can't open the file : " + newValidCacheFileName;
return;
}
QDataStream stream(&storageFile);
stream.setVersion(QDataStream::Qt_4_6);
quint32 magicNumber = 0;
quint32 versionNumber = 0;
stream >> magicNumber;
if (magicNumber != 0xCEECAC4E)
{
qWarning() << "Reading stored results: The storage file has wrong type ";
return;
}
stream >> versionNumber;
if (versionNumber > 1 )
{
qWarning() << "Reading stored results: The storage file has been written by a newer version of ResInsight";
return;
}
caf::ProgressInfo progress(m_resultCacheMetaData.size(), "Reading internally stored results");
// Fill the object with data from the storage
for (size_t rIdx = 0; rIdx < m_resultCacheMetaData.size(); ++rIdx)
{
RimReservoirCellResultsStorageEntryInfo* resInfo = m_resultCacheMetaData[rIdx];
size_t resultIndex = m_cellResults->addEmptyScalarResult(resInfo->m_resultType(), resInfo->m_resultName(), true);
m_cellResults->setTimeStepDates(resultIndex, resInfo->m_timeStepDates());
progress.setProgressDescription(resInfo->m_resultName);
for (size_t tsIdx = 0; tsIdx < resInfo->m_timeStepDates().size(); ++tsIdx)
{
std::vector<double>* data = NULL;
data = &(m_cellResults->cellScalarResults(rIdx, tsIdx));
quint64 cellCount = 0;
stream >> cellCount;
data->resize(cellCount, HUGE_VAL);
for (size_t cIdx = 0; cIdx < cellCount; ++cIdx)
{
stream >> (*data)[cIdx];
}
}
progress.incrementProgress();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirCellResultsStorage::setMainGrid(RigMainGrid* mainGrid)
{
m_ownerMainGrid = mainGrid;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RimReservoirCellResultsStorage::storedResultsCount()
{
return m_resultCacheMetaData.size();
}
CAF_PDM_SOURCE_INIT(RimReservoirCellResultsStorageEntryInfo, "ResultStorageEntryInfo");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorageEntryInfo::RimReservoirCellResultsStorageEntryInfo()
{
CAF_PDM_InitObject("Cache Entry", "", "", "");
CAF_PDM_InitField(&m_resultType, "ResultType", caf::AppEnum<RimDefines::ResultCatType>(RimDefines::REMOVED), "ResultType", "", "" ,"");
CAF_PDM_InitField(&m_resultName, "ResultName", QString(), "ResultName", "", "" ,"");
CAF_PDM_InitFieldNoDefault(&m_timeStepDates, "TimeSteps", "TimeSteps", "", "" ,"");
CAF_PDM_InitField(&m_filePosition, "FilePositionDataStart", qint64(-1), "FilePositionDataStart", "", "" ,"");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorageEntryInfo::~RimReservoirCellResultsStorageEntryInfo()
{
}

View File

@ -0,0 +1,89 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QDateTime>
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafAppEnum.h"
#include "RimDefines.h"
class RimReservoirCellResultsStorageEntryInfo;
class RigCaseCellResultsData;
class RifReaderInterface;
class RigMainGrid;
class RimReservoirCellResultsStorage : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimReservoirCellResultsStorage();
virtual ~RimReservoirCellResultsStorage();
void setCellResults(RigCaseCellResultsData* cellResults);
RigCaseCellResultsData* cellResults() { return m_cellResults; }
const RigCaseCellResultsData* cellResults() const { return m_cellResults; }
size_t storedResultsCount();
void setMainGrid(RigMainGrid* mainGrid);
void setReaderInterface(RifReaderInterface* readerInterface);
RifReaderInterface* readerInterface();
void loadOrComputeSOIL();
void computeDepthRelatedResults();
size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex);
size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName);
size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types.
protected:
// Overridden methods from PdmObject
virtual void setupBeforeSave();
private:
void computeSOILForTimeStep(size_t timeStepIndex);
QString getValidCacheFileName();
QString getCacheDirectoryPath();
// Fields
caf::PdmField<QString> m_resultCacheFileName;
caf::PdmPointersField<RimReservoirCellResultsStorageEntryInfo*>
m_resultCacheMetaData;
cvf::ref<RifReaderInterface> m_readerInterface;
RigCaseCellResultsData* m_cellResults;
RigMainGrid* m_ownerMainGrid;
};
class RimReservoirCellResultsStorageEntryInfo : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimReservoirCellResultsStorageEntryInfo();
virtual ~RimReservoirCellResultsStorageEntryInfo();
caf::PdmField<caf::AppEnum< RimDefines::ResultCatType> > m_resultType;
caf::PdmField<QString> m_resultName;
caf::PdmField< std::vector <QDateTime> > m_timeStepDates;
caf::PdmField<qint64> m_filePosition;
};

View File

@ -16,15 +16,15 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RIViewer.h"
#include "RiaStdInclude.h"
#include "RiuViewer.h"
#include "RimReservoirView.h"
#include "RIMainWindow.h"
#include "RiuMainWindow.h"
#include "RigGridBase.h"
#include "RigReservoir.h"
#include "RIApplication.h"
#include "RIPreferences.h"
#include "RigCaseData.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "cafEffectGenerator.h"
#include "cafFrameAnimationControl.h"
@ -32,7 +32,7 @@
#include "RimCellRangeFilterCollection.h"
#include "cvfStructGridGeometryGenerator.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RivCellEdgeEffectGenerator.h"
#include "RimCellEdgeResultSlot.h"
#include "cvfqtUtils.h"
@ -41,7 +41,7 @@
#include "cafCadNavigation.h"
#include "cafCeetronNavigation.h"
#include "RimReservoir.h"
#include "RimCase.h"
#include "Rim3dOverlayInfoConfig.h"
#include "RigGridScalarDataAccess.h"
@ -82,8 +82,8 @@ CAF_PDM_SOURCE_INIT(RimReservoirView, "ReservoirView");
//--------------------------------------------------------------------------------------------------
RimReservoirView::RimReservoirView()
{
RIApplication* app = RIApplication::instance();
RIPreferences* preferences = app->preferences();
RiaApplication* app = RiaApplication::instance();
RiaPreferences* preferences = app->preferences();
CVF_ASSERT(preferences);
CAF_PDM_InitObject("Reservoir View", ":/ReservoirView.png", "", "");
@ -137,6 +137,9 @@ RimReservoirView::RimReservoirView()
CAF_PDM_InitField(&showInactiveCells, "ShowInactiveCells", false, "Show Inactive Cells", "", "", "");
CAF_PDM_InitField(&showInvalidCells, "ShowInvalidCells", false, "Show Invalid Cells", "", "", "");
CAF_PDM_InitField(&backgroundColor, "ViewBackgroundColor", cvf::Color3f(0.69f, 0.77f, 0.87f), "Viewer Background", "", "", "");
CAF_PDM_InitField(&cameraPosition, "CameraPosition", cvf::Mat4d::IDENTITY, "", "", "", "");
@ -169,7 +172,7 @@ RimReservoirView::~RimReservoirView()
if (m_viewer)
{
RIMainWindow::instance()->removeViewer(m_viewer);
RiuMainWindow::instance()->removeViewer(m_viewer);
}
m_geometry->clearGeometryCache();
@ -189,19 +192,19 @@ void RimReservoirView::updateViewerWidget()
if (!m_viewer)
{
QGLFormat glFormat;
glFormat.setDirectRendering(RIApplication::instance()->useShaders());
glFormat.setDirectRendering(RiaApplication::instance()->useShaders());
m_viewer = new RIViewer(glFormat, NULL);
m_viewer = new RiuViewer(glFormat, NULL);
m_viewer->setOwnerReservoirView(this);
RIMainWindow::instance()->addViewer(m_viewer);
RiuMainWindow::instance()->addViewer(m_viewer);
m_viewer->setMinNearPlaneDistance(10);
this->cellResult()->legendConfig->recreateLegend();
this->cellEdgeResult()->legendConfig->recreateLegend();
m_viewer->setColorLegend1(this->cellResult()->legendConfig->legend());
m_viewer->setColorLegend2(this->cellEdgeResult()->legendConfig->legend());
if (RIApplication::instance()->navigationPolicy() == RIApplication::NAVIGATION_POLICY_CEETRON)
if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_CEETRON)
{
m_viewer->setNavigationPolicy(new caf::CeetronNavigation);
}
@ -210,16 +213,18 @@ void RimReservoirView::updateViewerWidget()
m_viewer->setNavigationPolicy(new caf::CadNavigation);
}
m_viewer->enablePerfInfoHud(RIApplication::instance()->showPerformanceInfo());
m_viewer->enablePerfInfoHud(RiaApplication::instance()->showPerformanceInfo());
//m_viewer->layoutWidget()->showMaximized();
isViewerCreated = true;
}
RIMainWindow::instance()->setActiveViewer(m_viewer);
RiuMainWindow::instance()->setActiveViewer(m_viewer);
if (isViewerCreated) m_viewer->mainCamera()->setViewMatrix(cameraPosition);
m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor()));
m_viewer->update();
}
else
@ -250,7 +255,7 @@ void RimReservoirView::updateViewerWidgetWindowTitle()
QString windowTitle;
if (m_reservoir.notNull())
{
windowTitle = QString("%1 - %2").arg(m_reservoir->caseName()).arg(name);
windowTitle = QString("%1 - %2").arg(m_reservoir->caseUserDescription()).arg(name);
}
else
{
@ -267,11 +272,11 @@ void RimReservoirView::updateViewerWidgetWindowTitle()
void RimReservoirView::clampCurrentTimestep()
{
// Clamp the current timestep to actual possibilities
if (this->gridCellResults())
if (this->currentGridCellResults()->cellResults())
{
if (m_currentTimeStep() > this->gridCellResults()->maxTimeStepCount())
if (m_currentTimeStep() >= static_cast<int>(this->currentGridCellResults()->cellResults()->maxTimeStepCount()))
{
m_currentTimeStep = static_cast<int>(this->gridCellResults()->maxTimeStepCount()) -1;
m_currentTimeStep = static_cast<int>(this->currentGridCellResults()->cellResults()->maxTimeStepCount()) -1;
}
}
@ -298,7 +303,7 @@ void RimReservoirView::createDisplayModelAndRedraw()
}
}
RIMainWindow::instance()->refreshAnimationActions();
RiuMainWindow::instance()->refreshAnimationActions();
}
//--------------------------------------------------------------------------------------------------
@ -358,6 +363,13 @@ void RimReservoirView::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
createDisplayModelAndRedraw();
}
}
else if (changedField == &backgroundColor )
{
if (viewer() != NULL)
{
updateViewerWidget();
}
}
else if (changedField == &m_currentTimeStep)
{
if (m_viewer)
@ -448,10 +460,10 @@ void RimReservoirView::createDisplayModel()
|| this->propertyFilterCollection()->hasActiveDynamicFilters()
|| this->wellCollection->hasVisibleWellPipes())
{
CVF_ASSERT(gridCellResults());
CVF_ASSERT(currentGridCellResults());
size_t i;
for (i = 0; i < gridCellResults()->maxTimeStepCount(); i++)
for (i = 0; i < currentGridCellResults()->cellResults()->maxTimeStepCount(); i++)
{
timeStepIndices.push_back(i);
}
@ -690,16 +702,18 @@ void RimReservoirView::loadDataAndUpdate()
{
if (!m_reservoir->openEclipseGridFile())
{
QMessageBox::warning(RIMainWindow::instance(), "Error when opening project file", "Could not open the Eclipse Grid file (EGRID/GRID): \n"+ m_reservoir->caseName());
QMessageBox::warning(RiuMainWindow::instance(),
"Error when opening project file",
"Could not open the Eclipse Grid file: \n"+ m_reservoir->gridFileName());
m_reservoir = NULL;
return;
}
else
{
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
if (app->preferences()->autocomputeSOIL)
{
RigReservoirCellResults* results = gridCellResults();
RimReservoirCellResultsStorage* results = currentGridCellResults();
CVF_ASSERT(results);
results->loadOrComputeSOIL();
}
@ -709,7 +723,7 @@ void RimReservoirView::loadDataAndUpdate()
CVF_ASSERT(this->cellResult() != NULL);
this->cellResult()->loadResult();
if (m_reservoir->reservoirData()->mainGrid()->globalFractureModelActiveCellCount() == 0)
if (m_reservoir->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->globalActiveCellCount() == 0)
{
this->cellResult->porosityModel.setUiHidden(true);
}
@ -820,7 +834,7 @@ void RimReservoirView::updateStaticCellColors(unsigned short geometryType)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RIViewer* RimReservoirView::viewer()
RiuViewer* RimReservoirView::viewer()
{
return m_viewer;
}
@ -835,20 +849,20 @@ bool RimReservoirView::pickInfo(size_t gridIndex, size_t cellIndex, const cvf::V
if (m_reservoir)
{
const RigReservoir* reservoir = m_reservoir->reservoirData();
if (reservoir)
const RigCaseData* eclipseCase = m_reservoir->reservoirData();
if (eclipseCase)
{
size_t i = 0;
size_t j = 0;
size_t k = 0;
if (reservoir->grid(gridIndex)->ijkFromCellIndex(cellIndex, &i, &j, &k))
if (eclipseCase->grid(gridIndex)->ijkFromCellIndex(cellIndex, &i, &j, &k))
{
// Adjust to 1-based Eclipse indexing
i++;
j++;
k++;
cvf::Vec3d domainCoord = point + reservoir->grid(gridIndex)->displayModelOffset();
cvf::Vec3d domainCoord = point + eclipseCase->grid(gridIndex)->displayModelOffset();
pickInfoText->sprintf("Hit grid %u, cell [%u, %u, %u], intersection point: [E: %.2f, N: %.2f, Depth: %.2f]", static_cast<unsigned int>(gridIndex), static_cast<unsigned int>(i), static_cast<unsigned int>(j), static_cast<unsigned int>(k), domainCoord.x(), domainCoord.y(), -domainCoord.z());
return true;
@ -862,18 +876,19 @@ bool RimReservoirView::pickInfo(size_t gridIndex, size_t cellIndex, const cvf::V
//--------------------------------------------------------------------------------------------------
/// Get the current scalar value for the display face at the given index
//--------------------------------------------------------------------------------------------------
void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex, QString* resultInfoText) const
void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex, QString* resultInfoText)
{
CVF_ASSERT(resultInfoText);
if (m_reservoir && m_reservoir->reservoirData())
{
const RigReservoir* reservoir = m_reservoir->reservoirData();
const RigGridBase* grid = reservoir->grid(gridIndex);
RigCaseData* eclipseCase = m_reservoir->reservoirData();
RigGridBase* grid = eclipseCase->grid(gridIndex);
if (this->cellResult()->hasResult())
{
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
cvf::ref<RigGridScalarDataAccess> dataAccessObject = grid->dataAccessObject(porosityModel, m_currentTimeStep, this->cellResult()->gridScalarIndex());
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->dataAccessObject(grid, porosityModel, m_currentTimeStep, this->cellResult()->gridScalarIndex());
if (dataAccessObject.notNull())
{
double scalarValue = dataAccessObject->cellScalar(cellIndex);
@ -893,8 +908,8 @@ void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex,
if (resultIndices[idx] == cvf::UNDEFINED_SIZE_T) continue;
// Cell edge results are static, results are loaded for first time step only
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
cvf::ref<RigGridScalarDataAccess> dataAccessObject = grid->dataAccessObject(porosityModel, 0, resultIndices[idx]);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->dataAccessObject(grid, porosityModel, 0, resultIndices[idx]);
if (dataAccessObject.notNull())
{
double scalarValue = dataAccessObject->cellScalar(cellIndex);
@ -957,16 +972,30 @@ void RimReservoirView::setupBeforeSave()
//--------------------------------------------------------------------------------------------------
/// Convenience for quick access to results
//--------------------------------------------------------------------------------------------------
RigReservoirCellResults* RimReservoirView::gridCellResults()
RimReservoirCellResultsStorage* RimReservoirView::currentGridCellResults()
{
if (m_reservoir)
{
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResult->porosityModel());
return m_reservoir->results(porosityModel);
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigActiveCellInfo* RimReservoirView::currentActiveCellInfo()
{
if (m_reservoir &&
m_reservoir->reservoirData() &&
m_reservoir->reservoirData()->mainGrid()
m_reservoir->reservoirData()
)
{
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult->porosityModel());
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResult->porosityModel());
return m_reservoir->reservoirData()->mainGrid()->results(porosityModel);
return m_reservoir->reservoirData()->activeCellInfo(porosityModel);
}
return NULL;
@ -1032,11 +1061,11 @@ void RimReservoirView::updateLegends()
return;
}
RigReservoir* reservoir = m_reservoir->reservoirData();
CVF_ASSERT(reservoir);
RigCaseData* eclipseCase = m_reservoir->reservoirData();
CVF_ASSERT(eclipseCase);
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
RigReservoirCellResults* results = reservoir->mainGrid()->results(porosityModel);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResult()->porosityModel());
RigCaseCellResultsData* results = eclipseCase->results(porosityModel);
CVF_ASSERT(results);
if (this->cellResult()->hasResult())
@ -1085,7 +1114,7 @@ void RimReservoirView::updateLegends()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::setEclipseCase(RimReservoir* reservoir)
void RimReservoirView::setEclipseCase(RimCase* reservoir)
{
m_reservoir = reservoir;
}
@ -1093,7 +1122,7 @@ void RimReservoirView::setEclipseCase(RimReservoir* reservoir)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimReservoir* RimReservoirView::eclipseCase()
RimCase* RimReservoirView::eclipseCase()
{
return m_reservoir;
}
@ -1115,7 +1144,7 @@ void RimReservoirView::syncronizeWellsWithResults()
{
if (!(m_reservoir && m_reservoir->reservoirData()) ) return;
cvf::Collection<RigWellResults> wellResults = m_reservoir->reservoirData()->wellResults();
cvf::Collection<RigSingleWellResultsData> wellResults = m_reservoir->reservoirData()->wellResults();
// Find corresponding well from well result, or create a new
size_t wIdx;
@ -1137,7 +1166,7 @@ void RimReservoirView::syncronizeWellsWithResults()
for (wIdx = 0; wIdx < this->wellCollection()->wells().size(); ++wIdx)
{
RimWell* well = this->wellCollection()->wells()[wIdx];
RigWellResults* wellRes = well->wellResults();
RigSingleWellResultsData* wellRes = well->wellResults();
if (wellRes == NULL)
{
delete well;
@ -1171,13 +1200,17 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl
// If all wells are forced off, return
if (this->wellCollection()->wellCellVisibility() == RimWellCollection::FORCE_ALL_OFF) return;
RigActiveCellInfo* activeCellInfo = this->currentActiveCellInfo();
CVF_ASSERT(activeCellInfo);
// Loop over the wells and find their contribution
for (size_t wIdx = 0; wIdx < this->wellCollection()->wells().size(); ++wIdx)
{
RimWell* well = this->wellCollection()->wells()[wIdx];
if (this->wellCollection()->wellCellVisibility() == RimWellCollection::FORCE_ALL_ON || well->showWellCells())
{
RigWellResults* wres = well->wellResults();
RigSingleWellResultsData* wres = well->wellResults();
if (!wres) continue;
const std::vector< RigWellResultFrame >& wellResFrames = wres->m_wellCellsTimeSteps;
@ -1235,7 +1268,9 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl
for ( fIdx = 0; fIdx < cellCountFenceDirection; ++fIdx)
{
size_t fenceCellIndex = grid->cellIndexFromIJK(*pI,*pJ,*pK);
if (grid->cell(fenceCellIndex).isActiveInMatrixModel())
size_t globalGridCellIndex = grid->globalGridCellIndex(fenceCellIndex);
if (activeCellInfo && activeCellInfo->isActive(globalGridCellIndex))
{
(*visibleCells)[fenceCellIndex] = true;
}
@ -1249,3 +1284,24 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimReservoirView::updateDisplayModelForWellResults()
{
m_geometry->clearGeometryCache();
m_pipesPartManager->clearGeometryCache();
syncronizeWellsWithResults();
createDisplayModel();
updateDisplayModelVisibility();
overlayInfoConfig()->update3DInfo();
if (animationMode && m_viewer)
{
m_viewer->slotSetCurrentFrame(m_currentTimeStep);
}
}

View File

@ -23,7 +23,7 @@
#include <QPointer>
#include <QString>
#include "RimReservoir.h"
#include "RimCase.h"
#include "RimResultSlot.h"
#include "RimCellEdgeResultSlot.h"
#include "RimCellRangeFilter.h"
@ -39,7 +39,7 @@
#include "RivReservoirViewPartMgr.h"
#include "RivReservoirPipesPartMgr.h"
class RIViewer;
class RiuViewer;
class RigGridBase;
class RigGridCellFaceVisibilityFilter;
class RivReservoirViewPartMgr;
@ -51,7 +51,6 @@ namespace cvf
class ModelBasicList;
}
enum ViewState
{
GEOMETRY_ONLY,
@ -85,97 +84,103 @@ public:
NO_SURFACE
};
// Public fields:
// Fields containing child objects :
caf::PdmField<RimResultSlot*> cellResult;
caf::PdmField<RimCellEdgeResultSlot*> cellEdgeResult;
caf::PdmField<Rim3dOverlayInfoConfig*> overlayInfoConfig;
caf::PdmField<RimResultSlot*> cellResult;
caf::PdmField<RimCellEdgeResultSlot*> cellEdgeResult;
caf::PdmField<double> scaleZ;
caf::PdmField<bool> showWindow;
caf::PdmField<QString> name;
caf::PdmField<RimCellRangeFilterCollection*> rangeFilterCollection;
caf::PdmField<RimCellPropertyFilterCollection*> propertyFilterCollection;
// Visibility
caf::PdmField<bool> showInvalidCells;
caf::PdmField<bool> showInactiveCells;
caf::PdmField<bool> showMainGrid;
caf::PdmField<RimWellCollection*> wellCollection;
caf::PdmField<RimWellCollection*> wellCollection;
caf::PdmField<Rim3dOverlayInfoConfig*> overlayInfoConfig;
caf::PdmField<RimCellRangeFilterCollection*> rangeFilterCollection;
caf::PdmField<RimCellPropertyFilterCollection*> propertyFilterCollection;
// Visualization setup fields
caf::PdmField< caf::AppEnum< MeshModeType > > meshMode;
caf::PdmField< caf::AppEnum< SurfaceModeType > > surfaceMode;
caf::PdmField<QString> name;
caf::PdmField<double> scaleZ;
caf::PdmField<bool> showWindow;
caf::PdmField<bool> showInvalidCells;
caf::PdmField<bool> showInactiveCells;
caf::PdmField<bool> showMainGrid;
caf::PdmField< caf::AppEnum< MeshModeType > > meshMode;
caf::PdmField< caf::AppEnum< SurfaceModeType > > surfaceMode;
caf::PdmField< cvf::Color3f > backgroundColor;
caf::PdmField<cvf::Mat4d> cameraPosition;
caf::PdmField<int> maximumFrameRate;
caf::PdmField<bool> animationMode;
// Access internal objects
RimReservoirCellResultsStorage* currentGridCellResults();
RigActiveCellInfo* currentActiveCellInfo();
void setEclipseCase(RimCase* reservoir);
RimCase* eclipseCase();
// Animation
caf::PdmField<int> maximumFrameRate;
caf::PdmField<bool> animationMode;
int currentTimeStep() { return m_currentTimeStep;}
void setCurrentTimeStep(int frameIdx);
void updateCurrentTimeStepAndRedraw();
void endAnimation();
int currentTimeStep() { return m_currentTimeStep;}
void setCurrentTimeStep(int frameIdx);
void updateCurrentTimeStepAndRedraw();
void endAnimation();
// 3D Viewer
// Cam pos should be a field, but is not yet supported bu caf::Pdm
caf::PdmField<cvf::Mat4d> cameraPosition;
void setDefaultView();
RIViewer* viewer();
void updateViewerWidget();
void updateViewerWidgetWindowTitle();
RiuViewer* viewer();
void updateViewerWidget();
void updateViewerWidgetWindowTitle();
void setDefaultView();
// Picking info
bool pickInfo(size_t gridIndex, size_t cellIndex, const cvf::Vec3d& point, QString* pickInfoText) const;
void appendCellResultInfo(size_t gridIndex, size_t cellIndex, QString* resultInfoText) const;
RigReservoirCellResults* gridCellResults();
void setEclipseCase(RimReservoir* reservoir);
RimReservoir* eclipseCase();
void calculateVisibleWellCellsIncFence(cvf::UByteArray* visibleCells, RigGridBase * grid);
bool pickInfo(size_t gridIndex, size_t cellIndex, const cvf::Vec3d& point, QString* pickInfoText) const;
void appendCellResultInfo(size_t gridIndex, size_t cellIndex, QString* resultInfoText) ;
// Does this belong here, really ?
void calculateVisibleWellCellsIncFence(cvf::UByteArray* visibleCells, RigGridBase * grid);
// Display model generation
public:
void loadDataAndUpdate();
void createDisplayModelAndRedraw();
void scheduleGeometryRegen(unsigned short geometryType);
void schedulePipeGeometryRegen();
void loadDataAndUpdate();
void createDisplayModelAndRedraw();
void scheduleGeometryRegen(unsigned short geometryType);
void schedulePipeGeometryRegen();
void updateDisplayModelForWellResults();
// Display model generation
private:
void createDisplayModel();
void updateDisplayModelVisibility();
void updateCurrentTimeStep();
void indicesToVisibleGrids(std::vector<size_t>* gridIndices);
void updateScaleTransform();
void updateStaticCellColors();
void updateStaticCellColors(unsigned short geometryType);
void updateLegends();
cvf::ref<RivReservoirViewPartMgr> m_geometry;
cvf::ref<RivReservoirPipesPartMgr> m_pipesPartManager;
// Overridden PDM methods:
public:
virtual caf::PdmFieldHandle* userDescriptionField() { return &name;}
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual caf::PdmFieldHandle* userDescriptionField() { return &name;}
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
protected:
virtual void initAfterRead();
virtual void setupBeforeSave();
virtual void initAfterRead();
virtual void setupBeforeSave();
// Really private
private:
void syncronizeWellsWithResults();
void clampCurrentTimestep();
private:
void syncronizeWellsWithResults();
void clampCurrentTimestep();
private:
caf::PdmField<int> m_currentTimeStep;
QPointer<RIViewer> m_viewer;
caf::PdmPointer<RimReservoir> m_reservoir;
// Display model generation
private:
void createDisplayModel();
void updateDisplayModelVisibility();
void updateCurrentTimeStep();
void indicesToVisibleGrids(std::vector<size_t>* gridIndices);
void updateScaleTransform();
void updateStaticCellColors();
void updateStaticCellColors(unsigned short geometryType);
void updateLegends();
cvf::ref<RivReservoirViewPartMgr> m_geometry;
cvf::ref<RivReservoirPipesPartMgr> m_pipesPartManager;
caf::PdmField<int> m_currentTimeStep;
QPointer<RiuViewer> m_viewer;
caf::PdmPointer<RimCase> m_reservoir;
};

View File

@ -0,0 +1,307 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimResultCase.h"
#include "RigCaseData.h"
#include "RifReaderEclipseOutput.h"
#include "RigCaseCellResultsData.h"
#include "RimReservoirView.h"
#include "RifReaderMockModel.h"
#include "RifReaderEclipseInput.h"
#include "cafProgressInfo.h"
#include "RimProject.h"
#include "RifEclipseOutputFileTools.h"
#include "RiaApplication.h"
CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimResultCase::RimResultCase()
: RimCase()
{
CAF_PDM_InitObject("Eclipse Case", ":/AppLogo48x48.png", "", "");
CAF_PDM_InitField(&caseFileName, "CaseFileName", QString(), "Case file name", "", "" ,"");
caseFileName.setUiReadOnly(true);
// Obsolete, unused field
CAF_PDM_InitField(&caseDirectory, "CaseFolder", QString(), "Directory", "", "" ,"");
caseDirectory.setIOWritable(false);
caseDirectory.setUiHidden(true);
m_activeCellInfoIsReadFromFile = false;
m_gridAndWellDataIsReadFromFile = false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimResultCase::openEclipseGridFile()
{
caf::ProgressInfo progInfo(50, "Reading Eclipse Grid File");
progInfo.setProgressDescription("Open Grid File");
progInfo.setNextProgressIncrement(48);
// Early exit if data is already read
if (m_gridAndWellDataIsReadFromFile) return true;
cvf::ref<RifReaderInterface> readerInterface;
if (caseFileName().contains("Result Mock Debug Model"))
{
readerInterface = this->createMockModel(this->caseFileName());
}
else
{
if (!QFile::exists(caseFileName()))
{
return false;
}
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
readerInterface = new RifReaderEclipseOutput;
if (!readerInterface->open(caseFileName(), eclipseCase.p()))
{
return false;
}
this->setReservoirData( eclipseCase.p() );
}
results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
progInfo.incrementProgress();
CVF_ASSERT(this->reservoirData());
CVF_ASSERT(readerInterface.notNull());
progInfo.setProgressDescription("Computing Case Cache");
computeCachedData();
m_gridAndWellDataIsReadFromFile = true;
m_activeCellInfoIsReadFromFile = true;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimResultCase::openAndReadActiveCellData(RigCaseData* mainEclipseCase)
{
// Early exit if data is already read
if (m_activeCellInfoIsReadFromFile) return true;
cvf::ref<RifReaderInterface> readerInterface;
if (caseFileName().contains("Result Mock Debug Model"))
{
readerInterface = this->createMockModel(this->caseFileName());
}
else
{
if (!QFile::exists(caseFileName()))
{
return false;
}
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
CVF_ASSERT(mainEclipseCase && mainEclipseCase->mainGrid());
eclipseCase->setMainGrid(mainEclipseCase->mainGrid());
size_t scalarIndexWithMaxTimeStepCount = cvf::UNDEFINED_SIZE_T;
mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&scalarIndexWithMaxTimeStepCount);
if (scalarIndexWithMaxTimeStepCount == cvf::UNDEFINED_SIZE_T)
{
return false;
}
std::vector<QDateTime> timeStepDates = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(scalarIndexWithMaxTimeStepCount);
cvf::ref<RifReaderEclipseOutput> readerEclipseOutput = new RifReaderEclipseOutput;
if (!readerEclipseOutput->openAndReadActiveCellData(caseFileName(), timeStepDates, eclipseCase.p()))
{
return false;
}
readerEclipseOutput->close();
this->setReservoirData( eclipseCase.p() );
readerInterface = readerEclipseOutput;
}
results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
CVF_ASSERT(this->reservoirData());
CVF_ASSERT(readerInterface.notNull());
reservoirData()->computeActiveCellBoundingBoxes();
m_activeCellInfoIsReadFromFile = true;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RifReaderInterface> RimResultCase::createMockModel(QString modelName)
{
cvf::ref<RifReaderMockModel> mockFileInterface = new RifReaderMockModel;
cvf::ref<RigCaseData> reservoir = new RigCaseData;
if (modelName == "Result Mock Debug Model Simple")
{
// Create the mock file interface and and RigSerervoir and set them up.
mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 2, 2), cvf::Vec3st(0, 2, 2), cvf::Vec3st(3, 3, 3));
mockFileInterface->open("", reservoir.p());
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4);
//TODO: Rewrite active cell info in mock models
//reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3);
//TODO: Rewrite active cell info in mock models
//reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
}
else if (modelName == "Result Mock Debug Model With Results")
{
mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 3, 3), cvf::Vec3st(1, 4, 9), cvf::Vec3st(2, 2, 2));
mockFileInterface->setResultInfo(3, 10);
mockFileInterface->open("", reservoir.p());
// Make a fault
cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1];
tmp += cvf::Vec3d(1, 0, 0);
}
else if (modelName =="Result Mock Debug Model Large With Results")
{
double startX = 0;
double startY = 0;
double startZ = 0;
double widthX = 6000;
double widthY = 12000;
double widthZ = 500;
double offsetX = 0;
double offsetY = 0;
double offsetZ = 0;
// Test code to simulate UTM coordinates
offsetX = 400000;
offsetY = 6000000;
offsetZ = 0;
mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(50, 100, 200));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 30, 30), cvf::Vec3st(1, 40, 90), cvf::Vec3st(2, 2, 2));
mockFileInterface->setResultInfo(3, 10);
mockFileInterface->open("", reservoir.p());
}
this->setReservoirData( reservoir.p() );
return mockFileInterface.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimResultCase::~RimResultCase()
{
reservoirViews.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimResultCase::locationOnDisc() const
{
QFileInfo fi(caseFileName());
return fi.absolutePath();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimResultCase::readGridDimensions(std::vector< std::vector<int> >& gridDimensions)
{
RifEclipseOutputFileTools::readGridDimensions(caseFileName(), gridDimensions);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimResultCase::updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath)
{
bool foundFile = false;
std::vector<QString> searchedPaths;
// Update filename and folder paths when opening project from a different file location
caseFileName = relocateFile(caseFileName(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimResultCase::setCaseInfo(const QString& userDescription, const QString& caseFileName)
{
this->caseUserDescription = userDescription;
this->caseFileName = caseFileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimResultCase::initAfterRead()
{
RimCase::initAfterRead();
// Convert from old (9.0.2) way of storing the case file
if (caseFileName().isEmpty())
{
if (!this->caseName().isEmpty() && !caseDirectory().isEmpty())
{
caseFileName = QDir::fromNativeSeparators(caseDirectory()) + "/" + caseName() + ".EGRID";
}
}
}

View File

@ -0,0 +1,67 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimCase.h"
class RifReaderInterface;
class RigMainGrid;
//==================================================================================================
//
//
//
//==================================================================================================
class RimResultCase : public RimCase
{
CAF_PDM_HEADER_INIT;
public:
RimResultCase();
virtual ~RimResultCase();
void setCaseInfo(const QString& userDescription, const QString& caseFileName);
virtual bool openEclipseGridFile();
bool openAndReadActiveCellData(RigCaseData* mainEclipseCase);
void readGridDimensions(std::vector< std::vector<int> >& gridDimensions);
// Overrides from RimCase
virtual QString locationOnDisc() const;
virtual QString gridFileName() const { return caseFileName();}
virtual void updateFilePathsFromProjectPath(const QString& newProjectPath, const QString& oldProjectPath);
private:
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
virtual void initAfterRead();
// Fields:
caf::PdmField<QString> caseFileName;
// Obsolete field
caf::PdmField<QString> caseDirectory;
bool m_gridAndWellDataIsReadFromFile;
bool m_activeCellInfoIsReadFromFile;
};

View File

@ -16,14 +16,14 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimResultDefinition.h"
#include "RimReservoirView.h"
#include "RimReservoir.h"
#include "RigReservoirCellResults.h"
#include "RigReservoir.h"
#include "RimCase.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigMainGrid.h"
#include "cafPdmUiListEditor.h"
@ -63,9 +63,9 @@ void RimResultDefinition::setReservoirView(RimReservoirView* ownerReservoirView)
// TODO: This code is executed before reservoir is read, and then porosity model is never set to zero
if (m_reservoirView->eclipseCase() &&
m_reservoirView->eclipseCase()->reservoirData() &&
m_reservoirView->eclipseCase()->reservoirData()->mainGrid() )
m_reservoirView->eclipseCase()->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS) )
{
if (m_reservoirView->eclipseCase()->reservoirData()->mainGrid()->globalFractureModelActiveCellCount() == 0)
if (m_reservoirView->eclipseCase()->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->globalActiveCellCount() == 0)
{
porosityModel.setUiHidden(true);
}
@ -92,9 +92,9 @@ QList<caf::PdmOptionItemInfo> RimResultDefinition::calculateValueOptions(const c
{
if (fieldNeedingOptions == &resultVariable)
{
if (m_reservoirView && m_reservoirView->gridCellResults())
if (m_reservoirView && m_reservoirView->currentGridCellResults())
{
QStringList varList = m_reservoirView->gridCellResults()->resultNames(resultType());
QStringList varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(resultType());
QList<caf::PdmOptionItemInfo> optionList;
int i;
for (i = 0; i < varList.size(); ++i)
@ -119,8 +119,8 @@ size_t RimResultDefinition::gridScalarIndex() const
{
if (m_gridScalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults();
if (gridCellResults) m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable());
const RimReservoirCellResultsStorage* gridCellResults = m_reservoirView->currentGridCellResults();
if (gridCellResults) m_gridScalarResultIndex = gridCellResults->cellResults()->findScalarResultIndex(resultType(), resultVariable());
}
return m_gridScalarResultIndex;
}
@ -130,7 +130,7 @@ size_t RimResultDefinition::gridScalarIndex() const
//--------------------------------------------------------------------------------------------------
void RimResultDefinition::loadResult()
{
RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults();
RimReservoirCellResultsStorage* gridCellResults = m_reservoirView->currentGridCellResults();
if (gridCellResults)
{
m_gridScalarResultIndex = gridCellResults->findOrLoadScalarResult(resultType(), resultVariable);
@ -148,8 +148,8 @@ void RimResultDefinition::loadResult()
//--------------------------------------------------------------------------------------------------
bool RimResultDefinition::hasStaticResult() const
{
const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults();
if (hasResult() && gridCellResults->timeStepCount(m_gridScalarResultIndex) == 1 )
const RimReservoirCellResultsStorage* gridCellResults = m_reservoirView->currentGridCellResults();
if (hasResult() && gridCellResults->cellResults()->timeStepCount(m_gridScalarResultIndex) == 1 )
{
return true;
}
@ -166,7 +166,7 @@ bool RimResultDefinition::hasResult() const
{
if (m_gridScalarResultIndex != cvf::UNDEFINED_SIZE_T) return true;
const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults();
const RigCaseCellResultsData* gridCellResults = m_reservoirView->currentGridCellResults()->cellResults();
if (gridCellResults)
{
m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable());
@ -182,11 +182,22 @@ bool RimResultDefinition::hasResult() const
//--------------------------------------------------------------------------------------------------
bool RimResultDefinition::hasDynamicResult() const
{
const RigReservoirCellResults* gridCellResults = m_reservoirView->gridCellResults();
if (hasResult() && gridCellResults->timeStepCount(m_gridScalarResultIndex) > 1 )
return true;
else
return false;
const RigCaseCellResultsData* gridCellResults = m_reservoirView->currentGridCellResults()->cellResults();
if (hasResult())
{
if (resultType() == RimDefines::DYNAMIC_NATIVE)
{
return true;
}
if (gridCellResults->timeStepCount(m_gridScalarResultIndex) > 1 )
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------

View File

@ -26,7 +26,7 @@
class RimReservoirView;
class RigReservoirCellResults;
class RigCaseCellResultsData;
//==================================================================================================
///

View File

@ -1,248 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RimResultReservoir.h"
#include "RigReservoir.h"
#include "RifReaderEclipseOutput.h"
#include "RigReservoirCellResults.h"
#include "RimReservoirView.h"
#include "RifReaderMockModel.h"
#include "RifReaderEclipseInput.h"
#include "cafProgressInfo.h"
#include "RimProject.h"
CAF_PDM_SOURCE_INIT(RimResultReservoir, "EclipseCase");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimResultReservoir::RimResultReservoir()
: RimReservoir()
{
CAF_PDM_InitField(&caseFileName, "CaseFileName", QString(), "Case file name", "", "" ,"");
CAF_PDM_InitField(&caseDirectory, "CaseFolder", QString(), "Directory", "", "" ,"");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimResultReservoir::openEclipseGridFile()
{
caf::ProgressInfo progInfo(50, "Reading Eclipse Grid File");
progInfo.setProgressDescription("Open Grid File");
progInfo.setNextProgressIncrement(48);
// Early exit if reservoir data is created
if (m_rigReservoir.notNull()) return true;
cvf::ref<RifReaderInterface> readerInterface;
if (caseName().contains("Result Mock Debug Model"))
{
readerInterface = this->createMockModel(this->caseName());
size_t matrixActiveCellCount = 0;
size_t fractureActiveCellCount = 0;
for (size_t cellIdx = 0; cellIdx < m_rigReservoir->mainGrid()->cells().size(); cellIdx++)
{
const RigCell& cell = m_rigReservoir->mainGrid()->cells()[cellIdx];
if (cell.isActiveInMatrixModel())
{
matrixActiveCellCount++;
}
if (cell.isActiveInFractureModel())
{
fractureActiveCellCount++;
}
}
m_rigReservoir->mainGrid()->setGlobalMatrixModelActiveCellCount(matrixActiveCellCount);
m_rigReservoir->mainGrid()->setGlobalFractureModelActiveCellCount(fractureActiveCellCount);
m_rigReservoir->mainGrid()->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p());
m_rigReservoir->mainGrid()->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p());
}
else
{
QString fname = createAbsoluteFilenameFromCase(caseName);
if (fname.isEmpty())
{
return false;
}
RigReservoir* reservoir = new RigReservoir;
readerInterface = new RifReaderEclipseOutput;
if (!readerInterface->open(fname, reservoir))
{
delete reservoir;
return false;
}
m_rigReservoir = reservoir;
}
progInfo.incrementProgress();
CVF_ASSERT(m_rigReservoir.notNull());
CVF_ASSERT(readerInterface.notNull());
progInfo.setProgressDescription("Computing Faults");
m_rigReservoir->computeFaults();
progInfo.incrementProgress();
progInfo.setProgressDescription("Computing Cache");
m_rigReservoir->mainGrid()->computeCachedData();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RifReaderInterface> RimResultReservoir::createMockModel(QString modelName)
{
cvf::ref<RifReaderMockModel> mockFileInterface = new RifReaderMockModel;
cvf::ref<RigReservoir> reservoir = new RigReservoir;
if (modelName == "Result Mock Debug Model Simple")
{
// Create the mock file interface and and RigSerervoir and set them up.
mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(4, 5, 6));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 2, 2), cvf::Vec3st(0, 2, 2), cvf::Vec3st(3, 3, 3));
mockFileInterface->open("", reservoir.p());
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(1, 3, 4);
reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
{
size_t idx = reservoir->mainGrid()->cellIndexFromIJK(2, 2, 3);
reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T);
}
}
else if (modelName == "Result Mock Debug Model With Results")
{
mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 3, 3), cvf::Vec3st(1, 4, 9), cvf::Vec3st(2, 2, 2));
mockFileInterface->setResultInfo(3, 10);
mockFileInterface->open("", reservoir.p());
// Make a fault
cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1];
tmp += cvf::Vec3d(1, 0, 0);
}
else if (modelName =="Result Mock Debug Model Large With Results")
{
double startX = 0;
double startY = 0;
double startZ = 0;
double widthX = 6000;
double widthY = 12000;
double widthZ = 500;
double offsetX = 0;
double offsetY = 0;
double offsetZ = 0;
// Test code to simulate UTM coordinates
offsetX = 400000;
offsetY = 6000000;
offsetZ = 0;
mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ));
mockFileInterface->setGridPointDimensions(cvf::Vec3st(50, 100, 200));
mockFileInterface->addLocalGridRefinement(cvf::Vec3st(0, 30, 30), cvf::Vec3st(1, 40, 90), cvf::Vec3st(2, 2, 2));
mockFileInterface->setResultInfo(3, 10);
mockFileInterface->open("", reservoir.p());
}
m_rigReservoir = reservoir;
return mockFileInterface.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimResultReservoir::~RimResultReservoir()
{
reservoirViews.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimResultReservoir::locationOnDisc() const
{
return caseDirectory;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimResultReservoir::createAbsoluteFilenameFromCase(const QString& caseName)
{
QString candidate;
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".EGRID");
if (QFile::exists(candidate)) return candidate;
candidate = QDir::fromNativeSeparators(caseDirectory.v() + QDir::separator() + caseName + ".GRID");
if (QFile::exists(candidate)) return candidate;
std::vector<caf::PdmObject*> parentObjects;
this->parentObjects(parentObjects);
QString projectPath;
for (size_t i = 0; i < parentObjects.size(); i++)
{
caf::PdmObject* obj = parentObjects[i];
RimProject* proj = dynamic_cast<RimProject*>(obj);
if (proj)
{
QFileInfo fi(proj->fileName);
projectPath = fi.path();
}
}
if (!projectPath.isEmpty())
{
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".EGRID");
if (QFile::exists(candidate)) return candidate;
candidate = QDir::fromNativeSeparators(projectPath + QDir::separator() + caseName + ".GRID");
if (QFile::exists(candidate)) return candidate;
}
return QString();
}

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimResultSlot.h"
#include "RimLegendConfig.h"
#include "RimReservoirView.h"
#include "RimReservoir.h"
#include "RIMainWindow.h"
#include "RimCase.h"
#include "RiuMainWindow.h"
#include "RimUiTreeModelPdm.h"
@ -91,7 +91,7 @@ void RimResultSlot::changeLegendConfig(QString resultVarNameOfNewLegend)
m_legendConfigData.v().erase(it);
m_legendConfigData.v().push_back(this->legendConfig());
this->legendConfig = newLegend;
RIMainWindow::instance()->uiPdmModel()->rebuildUiSubTree(this);
RiuMainWindow::instance()->uiPdmModel()->rebuildUiSubTree(this);
found = true;
break;
}
@ -105,7 +105,7 @@ void RimResultSlot::changeLegendConfig(QString resultVarNameOfNewLegend)
newLegend->resultVariableName = resultVarNameOfNewLegend;
m_legendConfigData.v().push_back(this->legendConfig());
this->legendConfig = newLegend;
RIMainWindow::instance()->uiPdmModel()->rebuildUiSubTree(this);
RiuMainWindow::instance()->uiPdmModel()->rebuildUiSubTree(this);
}
}

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimScriptCollection.h"
#include "cafPdmField.h"
#include "cafUtils.h"
#include "RIMainWindow.h"
#include "RiuMainWindow.h"
#include "RimUiTreeModelPdm.h"
#include "cafPdmUiFilePathEditor.h"
@ -161,7 +161,7 @@ void RimScriptCollection::fieldChangedByUi(const caf::PdmFieldHandle *changedFie
QFileInfo fi(directory);
this->setUiName(fi.baseName());
this->readContentFromDisc();
RimUiTreeModelPdm* treeModel = RIMainWindow::instance()->uiPdmModel();
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
if (treeModel) treeModel->rebuildUiSubTree(this);
}
}

View File

@ -0,0 +1,681 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimStatisticsCase.h"
#include "RimReservoirView.h"
#include "cafPdmUiOrdering.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RigCaseData.h"
#include "RigCaseCellResultsData.h"
#include "RimStatisticsCaseEvaluator.h"
#include "RigMainGrid.h"
#include "cafPdmUiTextEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "RiuMainWindow.h"
#include "RimUiTreeModelPdm.h"
#include "cafProgressInfo.h"
namespace caf {
template<>
void caf::AppEnum<RimStatisticsCase::PercentileCalcType>::setUp()
{
addItem(RimStatisticsCase::NEAREST_OBSERVATION, "NearestObservationPercentile", "Nearest Observation");
addItem(RimStatisticsCase::HISTOGRAM_ESTIMATED, "HistogramEstimatedPercentile", "Histogram based estimate");
setDefault(RimStatisticsCase::NEAREST_OBSERVATION);
}
}
CAF_PDM_SOURCE_INIT(RimStatisticsCase, "RimStatisticalCalculation");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCase::RimStatisticsCase()
: RimCase()
{
CAF_PDM_InitObject("Case Group Statistics", ":/Histogram16x16.png", "", "");
CAF_PDM_InitFieldNoDefault(&m_calculateEditCommand, "m_editingAllowed", "", "", "", "");
m_calculateEditCommand.setIOWritable(false);
m_calculateEditCommand.setIOReadable(false);
m_calculateEditCommand.setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName());
m_calculateEditCommand.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_calculateEditCommand = false;
CAF_PDM_InitField(&m_selectionSummary, "SelectionSummary", QString(""), "Summary of calculation setup", "", "", "");
m_selectionSummary.setIOWritable(false);
m_selectionSummary.setIOReadable(false);
m_selectionSummary.setUiReadOnly(true);
m_selectionSummary.setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
m_selectionSummary.setUiLabelPosition(caf::PdmUiItemInfo::TOP);
CAF_PDM_InitFieldNoDefault(&m_resultType, "ResultType", "Result Type", "", "", "");
m_resultType.setIOWritable(false);
CAF_PDM_InitFieldNoDefault(&m_porosityModel, "PorosityModel", "Porosity Model", "", "", "");
m_porosityModel.setIOWritable(false);
CAF_PDM_InitFieldNoDefault(&m_selectedDynamicProperties, "DynamicPropertiesToCalculate", "Dyn Prop", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedStaticProperties, "StaticPropertiesToCalculate", "Stat Prop", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedGeneratedProperties, "GeneratedPropertiesToCalculate", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedInputProperties, "InputPropertiesToCalculate", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedFractureDynamicProperties, "FractureDynamicPropertiesToCalculate", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedFractureStaticProperties, "FractureStaticPropertiesToCalculate", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedFractureGeneratedProperties, "FractureGeneratedPropertiesToCalculate", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedFractureInputProperties, "FractureInputPropertiesToCalculate", "", "", "", "");
m_selectedDynamicProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedStaticProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedGeneratedProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedInputProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedFractureDynamicProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedFractureStaticProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedFractureGeneratedProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_selectedFractureInputProperties.setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
CAF_PDM_InitField(&m_calculatePercentiles, "CalculatePercentiles", true, "Calculate Percentiles", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_percentileCalculationType, "PercentileCalculationType", "Method", "", "", "");
CAF_PDM_InitField(&m_lowPercentile, "LowPercentile", 10.0, "Low", "", "", "");
CAF_PDM_InitField(&m_midPercentile, "MidPercentile", 50.0, "Mid", "", "", "");
CAF_PDM_InitField(&m_highPercentile, "HighPercentile", 90.0, "High", "", "", "");
CAF_PDM_InitField(&m_wellDataSourceCase, "WellDataSourceCase", RimDefines::undefinedResultName(), "Well Data Source Case", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCase::~RimStatisticsCase()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::setMainGrid(RigMainGrid* mainGrid)
{
CVF_ASSERT(mainGrid);
CVF_ASSERT(this->reservoirData());
reservoirData()->setMainGrid(mainGrid);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimStatisticsCase::openEclipseGridFile()
{
if (this->reservoirData()) return true;
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
CVF_ASSERT(parentStatisticsCaseCollection());
RimIdenticalGridCaseGroup* gridCaseGroup = parentStatisticsCaseCollection()->parentCaseGroup();
CVF_ASSERT(gridCaseGroup);
RigMainGrid* mainGrid = gridCaseGroup->mainGrid();
eclipseCase->setMainGrid(mainGrid);
eclipseCase->setActiveCellInfo(RifReaderInterface::MATRIX_RESULTS, gridCaseGroup->unionOfActiveCells(RifReaderInterface::MATRIX_RESULTS));
eclipseCase->setActiveCellInfo(RifReaderInterface::FRACTURE_RESULTS, gridCaseGroup->unionOfActiveCells(RifReaderInterface::FRACTURE_RESULTS));
this->setReservoirData( eclipseCase.p() );
this->populateWithDefaultsIfNeeded();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCaseCollection* RimStatisticsCase::parentStatisticsCaseCollection()
{
std::vector<RimCaseCollection*> parentObjects;
this->parentObjectsOfType(parentObjects);
if (parentObjects.size() > 0)
{
return parentObjects[0];
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::computeStatistics()
{
if (this->reservoirData() == NULL)
{
openEclipseGridFile();
}
RimIdenticalGridCaseGroup* gridCaseGroup = caseGroup();
CVF_ASSERT(gridCaseGroup);
gridCaseGroup->computeUnionOfActiveCells();
std::vector<RimCase*> sourceCases;
getSourceCases(sourceCases);
if (sourceCases.size() == 0)
{
return;
}
// The first source has been read completely from disk, and contains grid and meta data
// Use this information for all cases in the case group
size_t timeStepCount = sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->maxTimeStepCount();
RimStatisticsConfig statisticsConfig;
statisticsConfig.m_calculatePercentiles = m_calculatePercentiles();
statisticsConfig.m_pMaxPos = m_highPercentile();
statisticsConfig.m_pMidPos = m_midPercentile();
statisticsConfig.m_pMinPos = m_lowPercentile();
statisticsConfig.m_pValMethod = m_percentileCalculationType();
std::vector<size_t> timeStepIndices;
for (size_t i = 0; i < timeStepCount; i++)
{
timeStepIndices.push_back(i);
}
RigCaseData* resultCase = reservoirData();
QList<RimStatisticsCaseEvaluator::ResSpec > resultSpecification;
for(size_t pIdx = 0; pIdx < m_selectedDynamicProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::MATRIX_RESULTS, RimDefines::DYNAMIC_NATIVE, m_selectedDynamicProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedStaticProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::MATRIX_RESULTS, RimDefines::STATIC_NATIVE, m_selectedStaticProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedGeneratedProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::MATRIX_RESULTS, RimDefines::GENERATED, m_selectedGeneratedProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedInputProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::MATRIX_RESULTS, RimDefines::INPUT_PROPERTY, m_selectedInputProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedFractureDynamicProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::FRACTURE_RESULTS, RimDefines::DYNAMIC_NATIVE, m_selectedFractureDynamicProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedFractureStaticProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::FRACTURE_RESULTS, RimDefines::STATIC_NATIVE, m_selectedFractureStaticProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedFractureGeneratedProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::FRACTURE_RESULTS, RimDefines::GENERATED, m_selectedFractureGeneratedProperties()[pIdx]));
}
for(size_t pIdx = 0; pIdx < m_selectedFractureInputProperties().size(); ++pIdx)
{
resultSpecification.append(RimStatisticsCaseEvaluator::ResSpec(RifReaderInterface::FRACTURE_RESULTS, RimDefines::INPUT_PROPERTY, m_selectedFractureInputProperties()[pIdx]));
}
RimStatisticsCaseEvaluator stat(sourceCases, timeStepIndices, statisticsConfig, resultCase);
stat.evaluateForResults(resultSpecification);
// Todo: Is this really the time and place to do the following ? JJS
for (size_t i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
reservoirView->scheduleGeometryRegen(RivReservoirViewPartMgr::ACTIVE);
reservoirView->createDisplayModelAndRedraw();
}
this->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::getSourceCases(std::vector<RimCase*>& sourceCases)
{
RimIdenticalGridCaseGroup* gridCaseGroup = caseGroup();
if (gridCaseGroup)
{
size_t caseCount = gridCaseGroup->caseCollection->reservoirs.size();
for (size_t i = 0; i < caseCount; i++)
{
CVF_ASSERT(gridCaseGroup->caseCollection);
CVF_ASSERT(gridCaseGroup->caseCollection->reservoirs[i]);
CVF_ASSERT(gridCaseGroup->caseCollection->reservoirs[i]->reservoirData());
RimCase* sourceCase = gridCaseGroup->caseCollection->reservoirs[i];
sourceCases.push_back(sourceCase);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimStatisticsCase::caseGroup()
{
RimCaseCollection* parentCollection = parentStatisticsCaseCollection();
if (parentCollection)
{
return parentCollection->parentCaseGroup();
}
return NULL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
updateSelectionSummaryLabel();
updateSelectionListVisibilities();
updatePercentileUiVisibility();
uiOrdering.add(&caseUserDescription);
uiOrdering.add(&m_calculateEditCommand);
uiOrdering.add(&m_selectionSummary);
caf::PdmUiGroup * group = uiOrdering.addNewGroup("Properties to consider");
group->setUiHidden(hasComputedStatistics());
group->add(&m_resultType);
group->add(&m_porosityModel);
group->add(&m_selectedDynamicProperties);
group->add(&m_selectedStaticProperties);
group->add(&m_selectedGeneratedProperties);
group->add(&m_selectedInputProperties);
group->add(&m_selectedFractureDynamicProperties);
group->add(&m_selectedFractureStaticProperties);
group->add(&m_selectedFractureGeneratedProperties);
group->add(&m_selectedFractureInputProperties);
group = uiOrdering.addNewGroup("Percentile setup");
group->setUiHidden(hasComputedStatistics());
group->add(&m_calculatePercentiles);
group->add(&m_percentileCalculationType);
group->add(&m_lowPercentile);
group->add(&m_midPercentile);
group->add(&m_highPercentile);
}
QList<caf::PdmOptionItemInfo> toOptionList(const QStringList& varList)
{
QList<caf::PdmOptionItemInfo> optionList;
int i;
for (i = 0; i < varList.size(); ++i)
{
optionList.push_back(caf::PdmOptionItemInfo( varList[i], varList[i]));
}
return optionList;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimStatisticsCase::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> options;
if (useOptionsOnly) *useOptionsOnly = true;
RimIdenticalGridCaseGroup* idgcg = caseGroup();
if (!(caseGroup() && caseGroup()->mainCase() && caseGroup()->mainCase()->reservoirData()))
{
return options;
}
RigCaseData* caseData = idgcg->mainCase()->reservoirData();
if (&m_selectedDynamicProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::DYNAMIC_NATIVE);
return toOptionList(varList);
}
else if (&m_selectedStaticProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::STATIC_NATIVE);
return toOptionList(varList);
}
else if (&m_selectedGeneratedProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::GENERATED);
return toOptionList(varList);
}
else if (&m_selectedInputProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::INPUT_PROPERTY);
return toOptionList(varList);
}
else if (&m_selectedFractureDynamicProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::DYNAMIC_NATIVE);
return toOptionList(varList);
}
else if (&m_selectedFractureStaticProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::STATIC_NATIVE);
return toOptionList(varList);
}
else if (&m_selectedFractureGeneratedProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::GENERATED);
return toOptionList(varList);
}
else if (&m_selectedFractureInputProperties == fieldNeedingOptions)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::INPUT_PROPERTY);
return toOptionList(varList);
}
else if (&m_wellDataSourceCase == fieldNeedingOptions)
{
QStringList sourceCaseNames;
sourceCaseNames += RimDefines::undefinedResultName();
for (size_t i = 0; i < caseGroup()->caseCollection()->reservoirs().size(); i++)
{
sourceCaseNames += caseGroup()->caseCollection()->reservoirs()[i]->caseUserDescription();
}
return toOptionList(sourceCaseNames);
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (&m_resultType == changedField || &m_porosityModel == changedField)
{
}
if (&m_calculateEditCommand == changedField)
{
if (hasComputedStatistics())
{
clearComputedStatistics();
}
else
{
computeStatistics();
}
m_calculateEditCommand = false;
}
if (&m_wellDataSourceCase == changedField)
{
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
// Find or load well data for given case
RimCase* sourceResultCase = caseGroup()->caseCollection()->findByDescription(m_wellDataSourceCase);
if (sourceResultCase)
{
sourceResultCase->openEclipseGridFile();
// Propagate well info to statistics case
if (sourceResultCase->reservoirData())
{
const cvf::Collection<RigSingleWellResultsData>& sourceCaseWellResults = sourceResultCase->reservoirData()->wellResults();
setWellResultsAndUpdateViews(sourceCaseWellResults);
}
}
else
{
cvf::Collection<RigSingleWellResultsData> sourceCaseWellResults;
setWellResultsAndUpdateViews(sourceCaseWellResults);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::setWellResultsAndUpdateViews(const cvf::Collection<RigSingleWellResultsData>& sourceCaseWellResults)
{
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
this->reservoirData()->setWellResults(sourceCaseWellResults);
caf::ProgressInfo progInfo(reservoirViews().size() + 1, "Updating Well Data for Views");
// Update views
for (size_t i = 0; i < reservoirViews().size(); i++)
{
RimReservoirView* reservoirView = reservoirViews()[i];
CVF_ASSERT(reservoirView);
reservoirView->wellCollection()->wells.deleteAllChildObjects();
reservoirView->updateDisplayModelForWellResults();
treeModel->rebuildUiSubTree(reservoirView->wellCollection());
progInfo.incrementProgress();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void addPropertySetToHtmlText(QString& html, const QString& heading, const std::vector<QString>& varNames)
{
if (varNames.size())
{
html += "<p><b>" + heading + "</b></p>";
html += "<p class=indent>";
for (size_t pIdx = 0; pIdx < varNames.size(); ++pIdx)
{
html += varNames[pIdx];
if ( (pIdx+1)%6 == 0 ) html += "<br>";
else if (pIdx != varNames.size() -1) html += ", ";
}
html += "</p>";
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::updateSelectionSummaryLabel()
{
QString html;
html += "<style> "
"p{ margin-top:0px; margin-bottom:0px;} "
"p.indent{margin-left:20px; margin-top:0px;} "
"p.indent2{margin-left:40px; margin-top:0px;} "
"</style>";
html += "<p><b>Statistical variables to compute:</b></p>";
html += "<p class=indent>";
html += "Min, Max, Range, Mean, Std.dev"; ;
if (m_calculatePercentiles())
{
html += "<br>";
html += "Percentiles for : "
+ QString::number(m_lowPercentile()) + ", "
+ QString::number(m_midPercentile()) + ", "
+ QString::number(m_highPercentile());
}
html += "</p>";
addPropertySetToHtmlText(html, "Dynamic properties", m_selectedDynamicProperties());
addPropertySetToHtmlText(html, "Static properties", m_selectedStaticProperties());
addPropertySetToHtmlText(html, "Generated properties", m_selectedGeneratedProperties());
addPropertySetToHtmlText(html, "Input properties", m_selectedInputProperties());
addPropertySetToHtmlText(html, "Dynamic properties, fracture model" , m_selectedFractureDynamicProperties());
addPropertySetToHtmlText(html, "Static properties, fracture model" , m_selectedFractureStaticProperties());
addPropertySetToHtmlText(html, "Generated properties, fracture model", m_selectedFractureGeneratedProperties());
addPropertySetToHtmlText(html, "Input properties, fracture model" , m_selectedFractureInputProperties());
m_selectionSummary = html;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
{
if (&m_selectionSummary == field)
{
caf::PdmUiTextEditorAttribute* textEditAttrib = dynamic_cast<caf::PdmUiTextEditorAttribute*> (attribute);
textEditAttrib->textMode = caf::PdmUiTextEditorAttribute::HTML;
}
if (&m_calculateEditCommand == field)
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*> (attribute);
attrib->m_buttonText = hasComputedStatistics() ? "Edit (Will DELETE current results)": "Compute";
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::updateSelectionListVisibilities()
{
bool isLocked = hasComputedStatistics();
m_resultType.setUiHidden(isLocked);
m_porosityModel.setUiHidden(isLocked ); // || !caseGroup()->mainCase()->reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS)->resultCount()
m_selectedDynamicProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::MATRIX_MODEL && m_resultType() == RimDefines::DYNAMIC_NATIVE));
m_selectedStaticProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::MATRIX_MODEL && m_resultType() == RimDefines::STATIC_NATIVE));
m_selectedGeneratedProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::MATRIX_MODEL && m_resultType() == RimDefines::GENERATED));
m_selectedInputProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::MATRIX_MODEL && m_resultType() == RimDefines::INPUT_PROPERTY));
m_selectedFractureDynamicProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::FRACTURE_MODEL && m_resultType() == RimDefines::DYNAMIC_NATIVE));
m_selectedFractureStaticProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::FRACTURE_MODEL && m_resultType() == RimDefines::STATIC_NATIVE));
m_selectedFractureGeneratedProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::FRACTURE_MODEL && m_resultType() == RimDefines::GENERATED));
m_selectedFractureInputProperties.setUiHidden( isLocked || !(m_porosityModel() == RimDefines::FRACTURE_MODEL && m_resultType() == RimDefines::INPUT_PROPERTY));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::updatePercentileUiVisibility()
{
bool isLocked = hasComputedStatistics();
m_calculatePercentiles.setUiHidden(isLocked);
m_percentileCalculationType.setUiHidden( isLocked || !m_calculatePercentiles());
m_lowPercentile .setUiHidden(isLocked || !m_calculatePercentiles());
m_midPercentile .setUiHidden(isLocked || !m_calculatePercentiles());
m_highPercentile.setUiHidden(isLocked || !m_calculatePercentiles());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimStatisticsCase::hasComputedStatistics() const
{
if ( reservoirData()
&& ( reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->resultCount()
|| reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS)->resultCount()))
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::clearComputedStatistics()
{
reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->clearAllResults();
reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS)->clearAllResults();
this->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCase::populateWithDefaultsIfNeeded()
{
RimIdenticalGridCaseGroup* idgcg = caseGroup();
if (!(caseGroup() && caseGroup()->mainCase() && caseGroup()->mainCase()->reservoirData()))
{
return ;
}
RigCaseData* caseData = idgcg->mainCase()->reservoirData();
if (m_selectedDynamicProperties().size() == 0)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::DYNAMIC_NATIVE);
if (varList.contains("SOIL")) m_selectedDynamicProperties.v().push_back("SOIL");
if (varList.contains("PRESSURE")) m_selectedDynamicProperties.v().push_back("PRESSURE");
}
if (m_selectedStaticProperties().size() == 0)
{
QStringList varList = caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultNames(RimDefines::STATIC_NATIVE);
if (varList.contains("PERMX")) m_selectedStaticProperties.v().push_back("PERMX");
if (varList.contains("PORO")) m_selectedStaticProperties.v().push_back("PORO");
}
if (m_selectedFractureDynamicProperties().size() == 0)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::DYNAMIC_NATIVE);
if (varList.contains("SOIL")) m_selectedFractureDynamicProperties.v().push_back("SOIL");
if (varList.contains("PRESSURE")) m_selectedFractureDynamicProperties.v().push_back("PRESSURE");
}
if (m_selectedFractureStaticProperties().size() == 0)
{
QStringList varList = caseData->results(RifReaderInterface::FRACTURE_RESULTS)->resultNames(RimDefines::STATIC_NATIVE);
if (varList.contains("PERMX")) m_selectedFractureStaticProperties.v().push_back("PERMX");
if (varList.contains("PORO")) m_selectedFractureStaticProperties.v().push_back("PORO");
}
}

View File

@ -0,0 +1,111 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimCase.h"
class RimIdenticalGridCaseGroup;
class RimResultDefinition;
class RimStatisticsCaseCollection;
class RigMainGrid;
class RigSingleWellResultsData;
//==================================================================================================
//
//
//
//==================================================================================================
class RimStatisticsCase : public RimCase
{
CAF_PDM_HEADER_INIT;
public:
RimStatisticsCase();
virtual ~RimStatisticsCase();
void setMainGrid(RigMainGrid* mainGrid);
void computeStatistics();
bool hasComputedStatistics() const;
void clearComputedStatistics();
virtual bool openEclipseGridFile();
RimCaseCollection* parentStatisticsCaseCollection();
enum PercentileCalcType
{
NEAREST_OBSERVATION,
HISTOGRAM_ESTIMATED
};
private:
RimIdenticalGridCaseGroup* caseGroup();
void getSourceCases(std::vector<RimCase*>& sourceCases);
void populateWithDefaultsIfNeeded();
void updateSelectionListVisibilities();
void updateSelectionSummaryLabel();
void updatePercentileUiVisibility();
void setWellResultsAndUpdateViews(const cvf::Collection<RigSingleWellResultsData>& sourceCaseWellResults);
// Pdm system overrides
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) ;
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly );
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute );
// Fields
caf::PdmField< bool > m_calculateEditCommand;
caf::PdmField< caf::AppEnum< RimDefines::ResultCatType > > m_resultType;
caf::PdmField< caf::AppEnum< RimDefines::PorosityModelType > > m_porosityModel;
caf::PdmField<QString> m_selectionSummary;
caf::PdmField<std::vector<QString> > m_selectedDynamicProperties;
caf::PdmField<std::vector<QString> > m_selectedStaticProperties;
caf::PdmField<std::vector<QString> > m_selectedGeneratedProperties;
caf::PdmField<std::vector<QString> > m_selectedInputProperties;
caf::PdmField<std::vector<QString> > m_selectedFractureDynamicProperties;
caf::PdmField<std::vector<QString> > m_selectedFractureStaticProperties;
caf::PdmField<std::vector<QString> > m_selectedFractureGeneratedProperties;
caf::PdmField<std::vector<QString> > m_selectedFractureInputProperties;
caf::PdmField< bool > m_calculatePercentiles;
caf::PdmField< caf::AppEnum< PercentileCalcType > > m_percentileCalculationType;
caf::PdmField<double > m_lowPercentile;
caf::PdmField<double > m_midPercentile;
caf::PdmField<double > m_highPercentile;
caf::PdmField<QString> m_wellDataSourceCase;
};

View File

@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimReservoirView.h"
#include "RimStatisticsCaseCollection.h"
#include "RimIdenticalGridCaseGroup.h"
CAF_PDM_SOURCE_INIT(RimStatisticsCaseCollection, "RimStatisticalCollection");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCaseCollection::RimStatisticsCaseCollection()
: PdmObject()
{
CAF_PDM_InitObject("Derived Statistics", "", "", "");
CAF_PDM_InitFieldNoDefault(&cases, "Reservoirs", "", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCaseCollection::~RimStatisticsCaseCollection()
{
cases.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimStatisticsCaseCollection::parentCaseGroup()
{
std::vector<RimIdenticalGridCaseGroup*> parentObjects;
this->parentObjectsOfType(parentObjects);
if (parentObjects.size() > 0)
{
return parentObjects[0];
}
return NULL;
}

View File

@ -22,37 +22,28 @@
#include "cvfObject.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "RimReservoir.h"
class RifReaderInterface;
#include "RimStatisticsCase.h"
//==================================================================================================
//
//
//
//==================================================================================================
class RimResultReservoir : public RimReservoir
class RimStatisticsCaseCollection : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimResultReservoir();
virtual ~RimResultReservoir();
RimStatisticsCaseCollection();
virtual ~RimStatisticsCaseCollection();
caf::PdmPointersField<RimStatisticsCase*> cases;
// Fields:
caf::PdmField<QString> caseFileName;
caf::PdmField<QString> caseDirectory;
virtual bool openEclipseGridFile();
//virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName;}
virtual QString locationOnDisc() const;
RimIdenticalGridCaseGroup* parentCaseGroup();
private:
cvf::ref<RifReaderInterface> createMockModel(QString modelName);
QString createAbsoluteFilenameFromCase(const QString& caseName);
};

View File

@ -0,0 +1,360 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RimStatisticsCaseEvaluator.h"
#include "RigCaseCellResultsData.h"
#include "RimReservoirView.h"
#include "RimCase.h"
#include "RigCaseData.h"
#include "RigStatisticsMath.h"
//#include "RigCaseData.h"
#include <QDebug>
#include "cafProgressInfo.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCaseEvaluator::addNamedResult(RigCaseCellResultsData* destinationCellResults, RimDefines::ResultCatType resultType, const QString& resultName, size_t activeUnionCellCount)
{
// Use time step dates from first result in first source case
CVF_ASSERT(m_sourceCases.size() > 0);
std::vector<QDateTime> sourceTimeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->timeStepDates(0);
size_t destinationScalarResultIndex = destinationCellResults->addEmptyScalarResult(resultType, resultName, true);
CVF_ASSERT(destinationScalarResultIndex != cvf::UNDEFINED_SIZE_T);
destinationCellResults->setTimeStepDates(destinationScalarResultIndex, sourceTimeStepDates);
std::vector< std::vector<double> >& dataValues = destinationCellResults->cellScalarResults(destinationScalarResultIndex);
dataValues.resize(sourceTimeStepDates.size());
// Initializes the size of the destination dataset to active union cell count
for (size_t i = 0; i < sourceTimeStepDates.size(); i++)
{
dataValues[i].resize(activeUnionCellCount, HUGE_VAL);
}
}
QString createResultNameMin(const QString& resultName) { return resultName + "_MIN"; }
QString createResultNameMax(const QString& resultName) { return resultName + "_MAX"; }
QString createResultNameMean(const QString& resultName) { return resultName + "_MEAN"; }
QString createResultNameDev(const QString& resultName) { return resultName + "_DEV"; }
QString createResultNameRange(const QString& resultName) { return resultName + "_RANGE"; }
QString createResultNamePVal(const QString& resultName, double pValPos) { return resultName + "_P_" + QString::number(pValPos); }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCaseEvaluator::buildSourceMetaData(RifReaderInterface::PorosityModelResultType poroModel, RimDefines::ResultCatType resultType, const QString& resultName)
{
if (m_sourceCases.size() == 0) return;
std::vector<QDateTime> timeStepDates = m_sourceCases[0]->results(poroModel)->cellResults()->timeStepDates(0);
for (size_t caseIdx = 1; caseIdx < m_sourceCases.size(); caseIdx++)
{
RimReservoirCellResultsStorage* cellResultsStorage = m_sourceCases[caseIdx]->results(poroModel);
size_t scalarResultIndex = cellResultsStorage->findOrLoadScalarResult(resultType, resultName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
size_t scalarResultIndex = cellResultsStorage->cellResults()->addEmptyScalarResult(resultType, resultName, false);
cellResultsStorage->cellResults()->setTimeStepDates(scalarResultIndex, timeStepDates);
std::vector< std::vector<double> >& dataValues = cellResultsStorage->cellResults()->cellScalarResults(scalarResultIndex);
dataValues.resize(timeStepDates.size());
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCaseEvaluator::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)->globalActiveCellCount();
RigCaseCellResultsData* destCellResultsData = m_destinationCase->results(poroModel);
// Special handling if SOIL is asked for
// Build SGAS/SWAT meta data, SOIL is automatically generated as part of RigCaseCellResultsData::findOrLoadScalarResultForTimeStep
if (resultName.toUpper() == "SOIL")
{
size_t swatIndex = m_sourceCases.at(0)->results(poroModel)->cellResults()->findScalarResultIndex(resultType, "SWAT");
if (swatIndex != cvf::UNDEFINED_SIZE_T)
{
buildSourceMetaData(poroModel, resultType, "SWAT");
}
size_t sgasIndex = m_sourceCases.at(0)->results(poroModel)->cellResults()->findScalarResultIndex(resultType, "SGAS");
if (sgasIndex != cvf::UNDEFINED_SIZE_T)
{
buildSourceMetaData(poroModel, resultType, "SGAS");
}
}
else
{
// Meta info is loaded from disk for first case only
// Build metadata for all other source cases
buildSourceMetaData(poroModel, resultType, resultName);
}
// 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 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)->globalActiveCellCount();
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<cvf::StructGridScalarDataAccess> sourceDataAccessList;
for (size_t caseIdx = 0; caseIdx < m_sourceCases.size(); caseIdx++)
{
RimCase* eclipseCase = m_sourceCases.at(caseIdx);
size_t scalarResultIndex = eclipseCase->results(poroModel)->findOrLoadScalarResultForTimeStep(resultType, resultName, dataAccessTimeStepIndex);
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = eclipseCase->reservoirData()->dataAccessObject(grid, poroModel, dataAccessTimeStepIndex, scalarResultIndex);
if (dataAccessObject.notNull())
{
sourceDataAccessList.push_back(dataAccessObject.p());
}
}
// Build data access objects for destination scalar results
// Find the created result container, if any, and put its dataAccessObject into the enum indexed destination collection
cvf::Collection<cvf::StructGridScalarDataAccess> 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]);
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{
destinationDataAccessList.push_back(m_destinationCase->dataAccessObject(grid, poroModel, dataAccessTimeStepIndex, scalarResultIndex).p());
}
else
{
destinationDataAccessList.push_back(NULL);
}
}
// Loop over the cells in the grid, get the case values, and calculate the cell statistics
for (size_t cellIdx = 0; cellIdx < grid->cellCount(); cellIdx++)
{
size_t globalGridCellIdx = grid->globalGridCellIndex(cellIdx);
if (m_destinationCase->activeCellInfo(poroModel)->isActive(globalGridCellIdx))
{
// Extract the cell values from each of the cases and assemble them into one vector
std::vector<double> values(sourceDataAccessList.size(), HUGE_VAL);
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
std::vector<double> statParams(STAT_PARAM_COUNT, HUGE_VAL);
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 == RimStatisticsCase::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 == RimStatisticsCase::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
{
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, close all result files.
// 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++)
{
RimCase* eclipseCase = m_sourceCases.at(caseIdx);
eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->close();
eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->readerInterface()->close();
}
progressInfo.setProgress(timeIndicesIdx);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStatisticsCaseEvaluator::debugOutput(RimDefines::ResultCatType resultType, const QString& resultName, size_t timeStepIdx)
{
CVF_ASSERT(m_destinationCase);
qDebug() << resultName << "timeIdx : " << timeStepIdx;
size_t scalarResultIndex = m_destinationCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultType, resultName);
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObject = m_destinationCase->dataAccessObject(m_destinationCase->mainGrid(), RifReaderInterface::MATRIX_RESULTS, timeStepIdx, scalarResultIndex);
if (dataAccessObject.isNull()) return;
for (size_t cellIdx = 0; cellIdx < m_globalCellCount; cellIdx++)
{
qDebug() << dataAccessObject->cellScalar(cellIdx);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCaseEvaluator::RimStatisticsCaseEvaluator(const std::vector<RimCase*>& sourceCases, const std::vector<size_t>& timeStepIndices, const RimStatisticsConfig& statisticsConfig, RigCaseData* destinationCase)
: m_sourceCases(sourceCases),
m_statisticsConfig(statisticsConfig),
m_destinationCase(destinationCase),
m_globalCellCount(0),
m_timeStepIndices(timeStepIndices)
{
if (sourceCases.size() > 0)
{
m_globalCellCount = sourceCases[0]->reservoirData()->mainGrid()->cells().size();
}
CVF_ASSERT(m_destinationCase);
}

View File

@ -0,0 +1,95 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfCollection.h"
#include <vector>
#include <math.h>
#include <QPair>
#include "RimDefines.h"
#include "RimStatisticsCase.h"
class RimCase;
class RigCaseData;
class RigCaseCellResultsData;
class RimStatisticsConfig
{
public:
RimStatisticsConfig()
: m_calculatePercentiles(true),
m_pMinPos(10.0),
m_pMidPos(50.0),
m_pMaxPos(90.0),
m_pValMethod(RimStatisticsCase::NEAREST_OBSERVATION)
{
}
public:
bool m_calculatePercentiles;
double m_pMinPos;
double m_pMidPos;
double m_pMaxPos;
RimStatisticsCase::PercentileCalcType m_pValMethod;
};
class RimStatisticsCaseEvaluator
{
public:
RimStatisticsCaseEvaluator(const std::vector<RimCase*>& sourceCases,
const std::vector<size_t>& timeStepIndices,
const RimStatisticsConfig& statisticsConfig,
RigCaseData* destinationCase);
struct ResSpec
{
ResSpec() : m_resType(RimDefines::DYNAMIC_NATIVE), m_poroModel(RifReaderInterface::MATRIX_RESULTS) {}
ResSpec( RifReaderInterface::PorosityModelResultType poroModel,
RimDefines::ResultCatType resType,
QString resVarName) : m_poroModel(poroModel), m_resType(resType), m_resVarName(resVarName) {}
RifReaderInterface::PorosityModelResultType m_poroModel;
RimDefines::ResultCatType m_resType;
QString m_resVarName;
};
void evaluateForResults(const QList<ResSpec >& resultSpecification);
void debugOutput(RimDefines::ResultCatType resultType, const QString& resultName, size_t timeStepIdx);
private:
void addNamedResult(RigCaseCellResultsData* cellResults, RimDefines::ResultCatType resultType, const QString& resultName, size_t activeCellCount);
void buildSourceMetaData(RifReaderInterface::PorosityModelResultType poroModel, RimDefines::ResultCatType resultType, const QString& resultName);
enum StatisticsParamType { MIN, MAX, RANGE, MEAN, STDEV, PMIN, PMID, PMAX, STAT_PARAM_COUNT };
private:
std::vector<RimCase*> m_sourceCases;
std::vector<size_t> m_timeStepIndices;
size_t m_globalCellCount;
RimStatisticsConfig m_statisticsConfig;
RigCaseData* m_destinationCase;
};

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "RimUiTreeModelPdm.h"
#include "RimCellRangeFilter.h"
@ -27,14 +27,19 @@
#include "RimCellPropertyFilterCollection.h"
#include "RimReservoirView.h"
#include "RIViewer.h"
#include "RiuViewer.h"
#include "RimCalcScript.h"
#include "RIApplication.h"
#include "RIMainWindow.h"
#include "RiaApplication.h"
#include "RiuMainWindow.h"
#include "RimInputProperty.h"
#include "RimInputPropertyCollection.h"
#include "cafPdmField.h"
#include "RimInputReservoir.h"
#include "RimInputCase.h"
#include "RimStatisticsCase.h"
#include "RimResultCase.h"
#include "RigGridManager.h"
#include "RimCase.h"
#include "RigCaseData.h"
//--------------------------------------------------------------------------------------------------
///
@ -49,9 +54,9 @@ RimUiTreeModelPdm::RimUiTreeModelPdm(QObject* parent)
}
//--------------------------------------------------------------------------------------------------
///
/// TO BE DELETED
//--------------------------------------------------------------------------------------------------
bool RimUiTreeModelPdm::insertRows(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
bool RimUiTreeModelPdm::insertRows_special(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
{
caf::PdmUiTreeItem* parentItem = getTreeItemFromIndex(parent);
@ -124,7 +129,7 @@ bool RimUiTreeModelPdm::deletePropertyFilter(const QModelIndex& itemIndex)
bool wasSomeFilterActive = propertyFilterCollection->hasActiveFilters();
// Remove Ui items pointing at the pdm object to delete
removeRow(itemIndex.row(), itemIndex.parent());
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
propertyFilterCollection->remove(propertyFilter);
delete propertyFilter;
@ -138,6 +143,9 @@ bool RimUiTreeModelPdm::deletePropertyFilter(const QModelIndex& itemIndex)
{
propertyFilterCollection->reservoirView()->createDisplayModelAndRedraw();
}
clearClipboard();
return true;
}
@ -161,7 +169,7 @@ bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex)
bool wasSomeFilterActive = rangeFilterCollection->hasActiveFilters();
// Remove Ui items pointing at the pdm object to delete
removeRow(itemIndex.row(), itemIndex.parent());
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
rangeFilterCollection->remove(rangeFilter);
delete rangeFilter;
@ -176,6 +184,8 @@ bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex)
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
}
clearClipboard();
return true;
}
@ -193,34 +203,69 @@ bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex)
CVF_ASSERT(reservoirView);
// Remove Ui items pointing at the pdm object to delete
removeRow(itemIndex.row(), itemIndex.parent());
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
reservoirView->eclipseCase()->removeReservoirView(reservoirView);
delete reservoirView;
clearClipboard();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::deleteReservoir(const QModelIndex& itemIndex)
void RimUiTreeModelPdm::deleteReservoir(RimCase* reservoir)
{
CVF_ASSERT(itemIndex.isValid());
if (reservoir->parentCaseCollection())
{
RimCaseCollection* caseCollection = reservoir->parentCaseCollection();
QModelIndex caseCollectionModelIndex = getModelIndexFromPdmObject(caseCollection);
if (!caseCollectionModelIndex.isValid()) return;
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
CVF_ASSERT(uiItem);
QModelIndex mi = getModelIndexFromPdmObjectRecursive(caseCollectionModelIndex, reservoir);
if (mi.isValid())
{
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
CVF_ASSERT(uiItem);
RimReservoir* reservoir = dynamic_cast<RimReservoir*>(uiItem->dataObject().p());
CVF_ASSERT(reservoir);
// Remove Ui items pointing at the pdm object to delete
removeRows_special(mi.row(), 1, mi.parent());
}
// Remove Ui items pointing at the pdm object to delete
removeRow(itemIndex.row(), itemIndex.parent());
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
{
RimIdenticalGridCaseGroup* caseGroup = caseCollection->parentCaseGroup();
CVF_ASSERT(caseGroup);
RimProject* proj = RIApplication::instance()->project();
proj->reservoirs().removeChildObject(reservoir);
caseGroup->statisticsCaseCollection()->reservoirs.removeChildObject(reservoir);
}
else
{
RimProject* proj = RiaApplication::instance()->project();
proj->removeCaseFromAllGroups(reservoir);
}
}
else
{
RimProject* proj = RiaApplication::instance()->project();
QModelIndex mi = getModelIndexFromPdmObject(reservoir);
if (mi.isValid())
{
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
CVF_ASSERT(uiItem);
// Remove Ui items pointing at the pdm object to delete
removeRows_special(mi.row(), 1, mi.parent());
}
proj->removeCaseFromAllGroups(reservoir);
}
delete reservoir;
clearClipboard();
}
//--------------------------------------------------------------------------------------------------
@ -322,24 +367,43 @@ RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemInd
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
if (!currentItem) return NULL;
RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(currentItem->dataObject().p());
if (!reservoirView) return NULL;
caf::PdmUiTreeItem* collectionItem = NULL;
RimReservoirView* insertedView = reservoirView->eclipseCase()->createAndAddReservoirView();
caf::PdmUiTreeItem* collectionItem = currentItem->parent();
bool itemIndexIsCollection = false;
QModelIndex collectionIndex;
if (dynamic_cast<RimReservoirView*>(currentItem->dataObject().p()))
{
collectionItem = currentItem->parent();
collectionIndex = itemIndex.parent();
}
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
{
collectionItem = currentItem;
collectionIndex = itemIndex;
}
int viewCount = rowCount(itemIndex.parent());
beginInsertRows(itemIndex.parent(), viewCount, viewCount);
if (collectionItem)
{
RimCase* rimReservoir = dynamic_cast<RimCase*>(collectionItem->dataObject().p());
rimReservoir->openEclipseGridFile();
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(collectionItem, viewCount, insertedView);
RimReservoirView* insertedView = rimReservoir->createAndAddReservoirView();
endInsertRows();
// Must be run before buildViewItems, as wells are created in this function
insertedView->loadDataAndUpdate();
insertedView->loadDataAndUpdate();
int viewCount = rowCount(collectionIndex);
beginInsertRows(collectionIndex, viewCount, viewCount);
rebuildUiSubTree(insertedView);
// NOTE: -1 as second argument indicates append
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, -1, insertedView);
return insertedView;
endInsertRows();
return insertedView;
}
return NULL;
}
@ -348,7 +412,7 @@ RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemInd
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::updateScriptPaths()
{
RimProject* proj = RIApplication::instance()->project();
RimProject* proj = RiaApplication::instance()->project();
if (!proj || !proj->scriptCollection()) return;
@ -368,7 +432,7 @@ void RimUiTreeModelPdm::updateScriptPaths()
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::slotRefreshScriptTree(QString path)
{
RimProject* proj = RIApplication::instance()->project();
RimProject* proj = RiaApplication::instance()->project();
if (!proj || !proj->scriptCollection()) return;
@ -390,13 +454,11 @@ void RimUiTreeModelPdm::addInputProperty(const QModelIndex& itemIndex, const QSt
RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(currentItem->dataObject().p());
CVF_ASSERT(inputPropertyCollection);
std::vector<caf::PdmObject*> parentObjects;
inputPropertyCollection->parentObjects(parentObjects);
std::vector<RimInputCase*> parentObjects;
inputPropertyCollection->parentObjectsOfType(parentObjects);
CVF_ASSERT(parentObjects.size() == 1);
RimInputReservoir* inputReservoir = dynamic_cast<RimInputReservoir*>(parentObjects[0]);
RimInputCase* inputReservoir = parentObjects[0];
CVF_ASSERT(inputReservoir);
if (inputReservoir)
{
@ -421,24 +483,398 @@ void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex)
if (!inputProperty) return;
// Remove item from UI tree model before delete of project data structure
removeRow(itemIndex.row(), itemIndex.parent());
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
std::vector<caf::PdmObject*> parentObjects;
object->parentObjects(parentObjects);
std::vector<RimInputPropertyCollection*> parentObjects;
object->parentObjectsOfType(parentObjects);
CVF_ASSERT(parentObjects.size() == 1);
RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(parentObjects[0]);
RimInputPropertyCollection* inputPropertyCollection = parentObjects[0];
if (!inputPropertyCollection) return;
std::vector<caf::PdmObject*> parentObjects2;
inputPropertyCollection->parentObjects(parentObjects2);
std::vector<RimInputCase*> parentObjects2;
inputPropertyCollection->parentObjectsOfType(parentObjects2);
CVF_ASSERT(parentObjects2.size() == 1);
RimInputReservoir* inputReservoir = dynamic_cast<RimInputReservoir*>(parentObjects2[0]);
RimInputCase* inputReservoir = parentObjects2[0];
if (!inputReservoir) return;
inputReservoir->removeProperty(inputProperty);
delete inputProperty;
clearClipboard();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStatisticsCase* RimUiTreeModelPdm::addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
{
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
QModelIndex collectionIndex;
RimIdenticalGridCaseGroup* caseGroup = NULL;
caf::PdmUiTreeItem* parentCollectionItem = NULL;
int position = 0;
if (dynamic_cast<RimStatisticsCase*>(currentItem->dataObject().p()))
{
RimStatisticsCase* currentObject = dynamic_cast<RimStatisticsCase*>(currentItem->dataObject().p());
caseGroup = currentObject->parentStatisticsCaseCollection()->parentCaseGroup();
parentCollectionItem = currentItem->parent();
position = itemIndex.row();
collectionIndex = itemIndex.parent();
}
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
{
RimCaseCollection* statColl = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
caseGroup = statColl->parentCaseGroup();
parentCollectionItem = currentItem;
position = parentCollectionItem->childCount();
collectionIndex = itemIndex;
}
if (parentCollectionItem && caseGroup)
{
beginInsertRows(collectionIndex, position, position);
RimStatisticsCase* createdObject = caseGroup->createAndAppendStatisticsCase();
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentCollectionItem, position, createdObject);
endInsertRows();
insertedModelIndex = index(position, 0, collectionIndex);
return createdObject;
}
else
{
return NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(QModelIndex& insertedModelIndex)
{
RimProject* proj = RiaApplication::instance()->project();
CVF_ASSERT(proj);
QModelIndex scriptModelIndex = getModelIndexFromPdmObject(proj->scriptCollection());
if (!scriptModelIndex.isValid()) return NULL;
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(scriptModelIndex);
if (!currentItem) return NULL;
QModelIndex rootIndex = scriptModelIndex.parent();
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
// New case group is inserted before the last item, the script item
int position = rootTreeItem->childCount() - 1;
beginInsertRows(rootIndex, position, position);
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup;
createdObject->createAndAppendStatisticsCase();
createdObject->name = QString("Grid Case Group %1").arg(position + 1);
proj->caseGroups().push_back(createdObject);
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject);
endInsertRows();
insertedModelIndex = index(position, 0, rootIndex);
return createdObject;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects)
{
RimProject* proj = RiaApplication::instance()->project();
CVF_ASSERT(proj);
RimIdenticalGridCaseGroup* gridCaseGroup = gridCaseGroupFromItemIndex(itemIndex);
if (gridCaseGroup)
{
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
pdmObjects.createCopyByType(&typedObjects);
if (typedObjects.size() == 0)
{
return;
}
RimResultCase* mainResultCase = NULL;
std::vector< std::vector<int> > mainCaseGridDimensions;
// Read out main grid and main grid dimensions if present in case group
if (gridCaseGroup->mainCase())
{
mainResultCase = dynamic_cast<RimResultCase*>(gridCaseGroup->mainCase());
CVF_ASSERT(mainResultCase);
mainResultCase->readGridDimensions(mainCaseGridDimensions);
}
// Add cases to case group
for (size_t i = 0; i < typedObjects.size(); i++)
{
RimResultCase* rimResultReservoir = typedObjects[i];
if (gridCaseGroup->contains(rimResultReservoir))
{
continue;
}
if (!mainResultCase)
{
rimResultReservoir->openEclipseGridFile();
rimResultReservoir->readGridDimensions(mainCaseGridDimensions);
mainResultCase = rimResultReservoir;
}
else
{
std::vector< std::vector<int> > caseGridDimensions;
rimResultReservoir->readGridDimensions(caseGridDimensions);
bool identicalGrid = RigGridManager::isGridDimensionsEqual(mainCaseGridDimensions, caseGridDimensions);
if (!identicalGrid)
{
continue;
}
if (!rimResultReservoir->openAndReadActiveCellData(mainResultCase->reservoirData()))
{
CVF_ASSERT(false);
}
}
proj->insertCaseInCaseGroup(gridCaseGroup, rimResultReservoir);
caf::PdmObjectGroup::initAfterReadTraversal(rimResultReservoir);
{
QModelIndex rootIndex = getModelIndexFromPdmObject(gridCaseGroup->caseCollection());
caf::PdmUiTreeItem* caseCollectionUiItem = getTreeItemFromIndex(rootIndex);
int position = rowCount(rootIndex);
beginInsertRows(rootIndex, position, position);
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(caseCollectionUiItem, -1, rimResultReservoir);
endInsertRows();
}
for (size_t i = 0; i < rimResultReservoir->reservoirViews.size(); i++)
{
RimReservoirView* riv = rimResultReservoir->reservoirViews()[i];
riv->loadDataAndUpdate();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects)
{
addObjects(itemIndex, pdmObjects);
// Delete objects from original container
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
pdmObjects.objectsByType(&typedObjects);
for (size_t i = 0; i < typedObjects.size(); i++)
{
RimCase* rimReservoir = typedObjects[i];
deleteReservoir(rimReservoir);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimUiTreeModelPdm::deleteObjectFromPdmPointersField(const QModelIndex& itemIndex)
{
if (!itemIndex.isValid())
{
return false;
}
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
CVF_ASSERT(currentItem);
caf::PdmObject* currentPdmObject = currentItem->dataObject().p();
CVF_ASSERT(currentPdmObject);
std::vector<caf::PdmFieldHandle*> parentFields;
currentPdmObject->parentFields(parentFields);
if (parentFields.size() == 1)
{
beginRemoveRows(itemIndex.parent(), itemIndex.row(), itemIndex.row());
if (currentItem->parent())
{
currentItem->parent()->removeChildren(itemIndex.row(), 1);
}
endRemoveRows();
caf::PdmPointersField<RimIdenticalGridCaseGroup*>* caseGroup = dynamic_cast<caf::PdmPointersField<RimIdenticalGridCaseGroup*> *>(parentFields[0]);
if (caseGroup)
{
caseGroup->removeChildObject(currentPdmObject);
delete currentPdmObject;
}
}
clearClipboard();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeModelPdm::clearClipboard()
{
// We use QModelIndex to identify a selection on the clipboard
// When we delete or move an entity, the clipboard data might be invalid
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
if (dynamic_cast<const MimeDataWithIndexes*>(clipboard->mimeData()))
{
clipboard->clear();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::DropActions RimUiTreeModelPdm::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Qt::ItemFlags RimUiTreeModelPdm::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = caf::UiTreeModelPdm::flags(index);
if (index.isValid())
{
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(index);
CVF_ASSERT(currentItem);
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()) ||
dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
{
return Qt::ItemIsDropEnabled | defaultFlags;
}
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
{
// TODO: Remember to handle reservoir holding the main grid
return Qt::ItemIsDragEnabled | defaultFlags;
}
}
return defaultFlags;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimUiTreeModelPdm::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
const MimeDataWithIndexes* myMimeData = qobject_cast<const MimeDataWithIndexes*>(data);
if (myMimeData && parent.isValid())
{
caf::PdmObjectGroup pog;
for (int i = 0; i < myMimeData->indexes().size(); i++)
{
QModelIndex mi = myMimeData->indexes().at(i);
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(mi);
caf::PdmObject* pdmObj = currentItem->dataObject().p();
pog.objects().push_back(pdmObj);
}
if (action == Qt::CopyAction)
{
addObjects(parent, pog);
}
else if (action == Qt::MoveAction)
{
moveObjects(parent, pog);
}
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QMimeData* RimUiTreeModelPdm::mimeData(const QModelIndexList &indexes) const
{
MimeDataWithIndexes* myObj = new MimeDataWithIndexes();
myObj->setIndexes(indexes);
return myObj;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RimUiTreeModelPdm::mimeTypes() const
{
QStringList types;
types << MimeDataWithIndexes::formatName();
return types;
}
//--------------------------------------------------------------------------------------------------
/// Return grid case group when QModelIndex points to grid case group, case collection or case in a grid case group
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::gridCaseGroupFromItemIndex(const QModelIndex& itemIndex)
{
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
{
gridCaseGroup = dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p());
}
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
{
RimCaseCollection* caseCollection = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
CVF_ASSERT(caseCollection);
gridCaseGroup = caseCollection->parentCaseGroup();
}
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
{
RimCase* rimReservoir = dynamic_cast<RimCase*>(currentItem->dataObject().p());
CVF_ASSERT(rimReservoir);
RimCaseCollection* caseCollection = rimReservoir->parentCaseCollection();
if (caseCollection)
{
gridCaseGroup = caseCollection->parentCaseGroup();
}
}
return gridCaseGroup;
}

View File

@ -20,14 +20,70 @@
#include "cafPdmObject.h"
#include "cafPdmPointer.h"
#include "cafPdmDocument.h"
#include "cafUiTreeModelPdm.h"
#include <QMimeData>
class QFileSystemWatcher;
class RimCellPropertyFilter;
class RimCellRangeFilter;
class RimCase;
class RimReservoirView;
class RimInputProperty;
class RimStatisticsCase;
class RimIdenticalGridCaseGroup;
//--------------------------------------------------------------------------------------------------
/// MimeData class used to carry a QModelIndexList
//--------------------------------------------------------------------------------------------------
class MimeDataWithIndexes : public QMimeData
{
Q_OBJECT
public:
MimeDataWithIndexes()
{
}
MimeDataWithIndexes(const MimeDataWithIndexes & other) : QMimeData()
{
setIndexes(other.indexes());
}
void setIndexes(const QModelIndexList & indexes)
{
m_indexes = indexes;
}
const QModelIndexList& indexes() const { return m_indexes; }
virtual bool hasFormat( const QString &mimetype ) const
{
return (mimetype == formatName());
}
virtual QStringList formats() const
{
QStringList supportedFormats = QMimeData::formats();
supportedFormats << formatName();
return supportedFormats;
}
static QString formatName()
{
return "MimeDataWithIndexes";
}
private:
QModelIndexList m_indexes;
};
Q_DECLARE_METATYPE(MimeDataWithIndexes)
//==================================================================================================
///
@ -40,31 +96,47 @@ class RimUiTreeModelPdm : public caf::UiTreeModelPdm
public:
RimUiTreeModelPdm(QObject* parent);
// Overrides
virtual bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
// TO BE DELETED, NOT USED
virtual bool insertRows_special(int position, int rows, const QModelIndex &parent = QModelIndex());
// Special edit methods
bool deleteRangeFilter(const QModelIndex& itemIndex);
bool deletePropertyFilter(const QModelIndex& itemIndex);
bool deleteReservoirView(const QModelIndex& itemIndex);
void deleteInputProperty(const QModelIndex& itemIndex);
void deleteReservoir(const QModelIndex& itemIndex);
bool deleteRangeFilter(const QModelIndex& itemIndex);
bool deletePropertyFilter(const QModelIndex& itemIndex);
bool deleteReservoirView(const QModelIndex& itemIndex);
void deleteInputProperty(const QModelIndex& itemIndex);
void deleteReservoir(RimCase* reservoir);
RimCellPropertyFilter* addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimReservoirView* addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
void addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames);
RimCellPropertyFilter* addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimReservoirView* addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
void addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames);
void updateScriptPaths();
void addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
RimStatisticsCase* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimIdenticalGridCaseGroup* addCaseGroup(QModelIndex& insertedModelIndex);
bool deleteObjectFromPdmPointersField(const QModelIndex& itemIndex);
void updateScriptPaths();
virtual Qt::DropActions supportedDropActions() const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
virtual QMimeData* mimeData(const QModelIndexList &indexes) const;
virtual QStringList mimeTypes() const;
RimIdenticalGridCaseGroup* gridCaseGroupFromItemIndex(const QModelIndex& itemIndex);
private slots:
void slotRefreshScriptTree(QString path);
void slotRefreshScriptTree(QString path);
private:
QFileSystemWatcher* m_scriptChangeDetector;
void clearClipboard();
private:
QFileSystemWatcher* m_scriptChangeDetector;
};

View File

@ -16,21 +16,25 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafPdmDocument.h"
#include "RimUiTreeView.h"
#include "RimUiTreeModelPdm.h"
#include "RimReservoirView.h"
#include "RimCalcScript.h"
#include "RIApplication.h"
#include "RIMainWindow.h"
#include "RiaApplication.h"
#include "RiuMainWindow.h"
#include "RimInputPropertyCollection.h"
#include "RimExportInputPropertySettings.h"
#include "RIPreferencesDialog.h"
#include "RiuPreferencesDialog.h"
#include "RifEclipseInputFileTools.h"
#include "RimInputReservoir.h"
#include "RimInputCase.h"
#include "RimBinaryExportSettings.h"
#include "RigReservoirCellResults.h"
#include "RigCaseCellResultsData.h"
#include "RimStatisticsCase.h"
#include "RimResultCase.h"
//--------------------------------------------------------------------------------------------------
///
@ -39,6 +43,16 @@ RimUiTreeView::RimUiTreeView(QWidget *parent /*= 0*/)
: QTreeView(parent)
{
setHeaderHidden(true);
m_pasteAction = new QAction(QString("Paste"), this);
connect(m_pasteAction, SIGNAL(triggered()), SLOT(slotPastePdmObjects()));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimUiTreeView::~RimUiTreeView()
{
}
//--------------------------------------------------------------------------------------------------
@ -46,12 +60,25 @@ RimUiTreeView::RimUiTreeView(QWidget *parent /*= 0*/)
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
{
m_pasteAction->setEnabled(hasClipboardValidData());
if (selectionModel() && selectionModel()->selection().size() == 0)
{
// Clicking in blank space in tree view
QMenu menu;
menu.addAction(QString("New Grid Case Group"), this, SLOT(slotAddCaseGroup()));
menu.exec(event->globalPos());
return;
}
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
if (uiItem && uiItem->dataObject())
{
// Range filters
if (dynamic_cast<RimReservoirView*>(uiItem->dataObject().p()))
{
@ -100,7 +127,7 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
}
else if (dynamic_cast<RimCalcScript*>(uiItem->dataObject().p()))
{
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QMenu menu;
{
@ -143,12 +170,52 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
menu.addAction(QString("Save Property To File"), this, SLOT(slotWriteBinaryResultAsInputProperty()));
menu.exec(event->globalPos());
}
else if (dynamic_cast<RimReservoir*>(uiItem->dataObject().p()))
else if (dynamic_cast<RimStatisticsCaseCollection*>(uiItem->dataObject().p()))
{
QMenu menu;
menu.addAction(QString("New Statistcs Case"), this, SLOT(slotNewStatisticsCase()));
menu.exec(event->globalPos());
}
else if (dynamic_cast<RimStatisticsCase*>(uiItem->dataObject().p()))
{
QMenu menu;
menu.addAction(QString("New View"), this, SLOT(slotAddView()));
menu.addAction(QString("Compute"), this, SLOT(slotComputeStatistics()));
menu.addAction(QString("Close"), this, SLOT(slotCloseCase()));
menu.exec(event->globalPos());
}
else if (dynamic_cast<RimCase*>(uiItem->dataObject().p()))
{
QMenu menu;
menu.addAction(QString("Copy"), this, SLOT(slotCopyPdmObjectToClipboard()));
menu.addAction(m_pasteAction);
menu.addAction(QString("Close"), this, SLOT(slotCloseCase()));
menu.addAction(QString("New View"), this, SLOT(slotAddView()));
menu.addAction(QString("New Grid Case Group"), this, SLOT(slotAddCaseGroup()));
menu.exec(event->globalPos());
}
else if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem->dataObject().p()))
{
QMenu menu;
menu.addAction(QString("New Grid Case Group"), this, SLOT(slotAddCaseGroup()));
menu.addAction(m_pasteAction);
menu.addAction(QString("Close"), this, SLOT(slotDeleteObjectFromPdmPointersField()));
menu.exec(event->globalPos());
}
else if (dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p()))
{
QMenu menu;
menu.addAction(m_pasteAction);
// Check if parent field is a StatisticsCaseCollection
RimCaseCollection* rimCaseCollection = dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p());
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(rimCaseCollection))
{
menu.addAction(QString("New Statistics Case"), this, SLOT(slotNewStatisticsCase()));
}
menu.exec(event->globalPos());
}
}
}
}
@ -368,7 +435,7 @@ void RimUiTreeView::slotEditScript()
{
RimCalcScript* calcScript = dynamic_cast<RimCalcScript*>(uiItem->dataObject().p());
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString scriptEditor = app->scriptEditorPath();
if (!scriptEditor.isEmpty())
{
@ -380,7 +447,7 @@ void RimUiTreeView::slotEditScript()
if (!myProcess->waitForStarted(1000))
{
QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor);
QMessageBox::warning(RiuMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor);
}
}
}
@ -425,7 +492,7 @@ void RimUiTreeView::slotNewScript()
num++;
}
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString scriptEditor = app->scriptEditorPath();
if (!scriptEditor.isEmpty())
{
@ -437,7 +504,7 @@ void RimUiTreeView::slotNewScript()
if (!myProcess->waitForStarted(1000))
{
QMessageBox::warning(RIMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor);
QMessageBox::warning(RiuMainWindow::instance(), "Script editor", "Failed to start script editor executable\n" + scriptEditor);
}
}
}
@ -455,7 +522,7 @@ void RimUiTreeView::slotExecuteScript()
{
RimCalcScript* calcScript = dynamic_cast<RimCalcScript*>(uiItem->dataObject().p());
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString octavePath = app->octavePath();
if (!octavePath.isEmpty())
{
@ -482,7 +549,7 @@ void RimUiTreeView::slotExecuteScript()
arguments.append("-q");
arguments << calcScript->absolutePath();
RIApplication::instance()->launchProcess(octavePath, arguments);
RiaApplication::instance()->launchProcess(octavePath, arguments);
}
}
}
@ -496,12 +563,8 @@ void RimUiTreeView::slotAddView()
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
RimReservoirView* rimView = dynamic_cast<RimReservoirView*>(uiItem->dataObject().p());
if (rimView)
{
QModelIndex insertedIndex;
myModel->addReservoirView(index, insertedIndex);
}
QModelIndex insertedIndex;
myModel->addReservoirView(index, insertedIndex);
}
@ -515,7 +578,7 @@ void RimUiTreeView::slotDeleteView()
{
myModel->deleteReservoirView(currentIndex());
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
app->setActiveReservoirView(NULL);
}
}
@ -565,7 +628,7 @@ void RimUiTreeView::setModel(QAbstractItemModel* model)
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotAddInputProperty()
{
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->defaultFileDialogDirectory("INPUT_FILES");
QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Eclipse Input Property Files", defaultDir, "All Files (*.* *)");
@ -623,7 +686,7 @@ void RimUiTreeView::slotWriteInputProperty()
if (!isResolved)
{
QMessageBox::warning(RIMainWindow::instance(), "Export failure", "Property is not resolved, and then it is not possible to export the property.");
QMessageBox::warning(RiuMainWindow::instance(), "Export failure", "Property is not resolved, and then it is not possible to export the property.");
return;
}
@ -633,20 +696,20 @@ void RimUiTreeView::slotWriteInputProperty()
exportSettings.eclipseKeyword = inputProperty->eclipseKeyword;
// Find input reservoir for this property
RimInputReservoir* inputReservoir = NULL;
RimInputCase* inputReservoir = NULL;
{
std::vector<caf::PdmObject*> parentObjects;
inputProperty->parentObjects(parentObjects);
std::vector<RimInputPropertyCollection*> parentObjects;
inputProperty->parentObjectsOfType(parentObjects);
CVF_ASSERT(parentObjects.size() == 1);
RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(parentObjects[0]);
RimInputPropertyCollection* inputPropertyCollection = parentObjects[0];
if (!inputPropertyCollection) return;
std::vector<caf::PdmObject*> parentObjects2;
inputPropertyCollection->parentObjects(parentObjects2);
std::vector<RimInputCase*> parentObjects2;
inputPropertyCollection->parentObjectsOfType(parentObjects2);
CVF_ASSERT(parentObjects2.size() == 1);
inputReservoir = dynamic_cast<RimInputReservoir*>(parentObjects2[0]);
inputReservoir = parentObjects2[0];
}
if (!inputReservoir) return;
@ -654,7 +717,7 @@ void RimUiTreeView::slotWriteInputProperty()
{
QString projectFolder;
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString projectFileName = app->currentProjectFileName();
if (!projectFileName.isEmpty())
{
@ -671,7 +734,7 @@ void RimUiTreeView::slotWriteInputProperty()
exportSettings.fileName = outputFileName;
}
RIPreferencesDialog preferencesDialog(this, &exportSettings, "Export Eclipse Property to Text File");
RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Eclipse Property to Text File");
if (preferencesDialog.exec() == QDialog::Accepted)
{
bool isOk = RifEclipseInputFileTools::writePropertyToTextFile(exportSettings.fileName, inputReservoir->reservoirData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword);
@ -707,7 +770,7 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty()
{
QString projectFolder;
RIApplication* app = RIApplication::instance();
RiaApplication* app = RiaApplication::instance();
QString projectFileName = app->currentProjectFileName();
if (!projectFileName.isEmpty())
{
@ -724,11 +787,11 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty()
exportSettings.fileName = outputFileName;
}
RIPreferencesDialog preferencesDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File");
RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File");
if (preferencesDialog.exec() == QDialog::Accepted)
{
size_t timeStep = resultSlot->reservoirView()->currentTimeStep();
RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(resultSlot->porosityModel());
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(resultSlot->porosityModel());
bool isOk = RifEclipseInputFileTools::writeBinaryResultToTextFile(exportSettings.fileName, resultSlot->reservoirView()->eclipseCase()->reservoirData(), porosityModel, timeStep, resultSlot->resultVariable, exportSettings.eclipseKeyword, exportSettings.undefinedValue);
if (!isOk)
@ -743,10 +806,340 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty()
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotCloseCase()
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
QModelIndexList miList;
miList << currentIndex();
if (userConfirmedGridCaseGroupChange(miList))
{
myModel->deleteReservoir(currentIndex());
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
QItemSelectionModel* m = selectionModel();
CVF_ASSERT(m);
caf::PdmObjectGroup group;
QModelIndexList mil = m->selectedRows();
for (int i = 0; i < mil.size(); i++)
{
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(mil.at(i));
group.addObject(uiItem->dataObject().p());
}
std::vector<caf::PdmPointer<RimCase> > typedObjects;
group.objectsByType(&typedObjects);
for (size_t i = 0; i < typedObjects.size(); i++)
{
RimCase* rimReservoir = typedObjects[i];
myModel->deleteReservoir(rimReservoir);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotNewStatisticsCase()
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
QModelIndex insertedIndex;
RimStatisticsCase* newObject = myModel->addStatisticalCalculation(currentIndex(), insertedIndex);
setCurrentIndex(insertedIndex);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotComputeStatistics()
{
QModelIndex index = currentIndex();
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
RimStatisticsCase* statisticsCase = dynamic_cast<RimStatisticsCase*>(uiItem->dataObject().p());
if (!statisticsCase) return;
statisticsCase->computeStatistics();
if (statisticsCase->reservoirViews.size() == 0)
{
slotAddView();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotAddCaseGroup()
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
QModelIndex insertedIndex;
myModel->addCaseGroup(insertedIndex);
setCurrentIndex(insertedIndex);
setExpanded(insertedIndex, true);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotDeleteObjectFromPdmPointersField()
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
myModel->deleteObjectFromPdmPointersField(currentIndex());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotCopyPdmObjectToClipboard()
{
QItemSelectionModel* m = selectionModel();
QModelIndexList mil = m->selectedRows();
if (mil.size() == 0)
{
return;
}
MimeDataWithIndexes* myObject = new MimeDataWithIndexes;
myObject->setIndexes(mil);
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
clipboard->setMimeData(myObject);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::slotPastePdmObjects()
{
if (!currentIndex().isValid()) return;
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (!myModel) return;
QModelIndexList miList;
miList << currentIndex();
if (userConfirmedGridCaseGroupChange(miList))
{
caf::PdmObjectGroup objectGroup;
createPdmObjectsFromClipboard(&objectGroup);
if (objectGroup.objects().size() == 0) return;
myModel->addObjects(currentIndex(), objectGroup);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::createPdmObjectsFromClipboard(caf::PdmObjectGroup* objectGroup)
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (!myModel) return;
QClipboard* clipboard = QApplication::clipboard();
if (!clipboard) return;
const MimeDataWithIndexes* mdWithIndexes = dynamic_cast<const MimeDataWithIndexes*>(clipboard->mimeData());
if (!mdWithIndexes) return;
QModelIndexList indexList = mdWithIndexes->indexes();
for (int i = 0; i < indexList.size(); i++)
{
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(indexList.at(i));
objectGroup->addObject(uiItem->dataObject().p());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::keyPressEvent(QKeyEvent* keyEvent)
{
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
if (dynamic_cast<RimCase*>(uiItem->dataObject().p()))
{
if (keyEvent->matches(QKeySequence::Copy))
{
slotCopyPdmObjectToClipboard();
keyEvent->setAccepted(true);
return;
}
}
if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem->dataObject().p())
|| dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p())
|| dynamic_cast<RimCase*>(uiItem->dataObject().p()))
{
if (keyEvent->matches(QKeySequence::Paste))
{
slotPastePdmObjects();
keyEvent->setAccepted(true);
return;
}
}
QTreeView::keyPressEvent(keyEvent);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimUiTreeView::hasClipboardValidData()
{
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
if (dynamic_cast<const MimeDataWithIndexes*>(clipboard->mimeData()))
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUiTreeView::dropEvent(QDropEvent* dropEvent)
{
QModelIndexList affectedModels;
if (dropEvent->dropAction() == Qt::MoveAction)
{
const MimeDataWithIndexes* myMimeData = qobject_cast<const MimeDataWithIndexes*>(dropEvent->mimeData());
if (myMimeData)
{
affectedModels = myMimeData->indexes();
}
}
QModelIndex dropIndex = indexAt(dropEvent->pos());
if (dropIndex.isValid())
{
affectedModels.push_back(dropIndex);
}
if (userConfirmedGridCaseGroupChange(affectedModels))
{
QTreeView::dropEvent(dropEvent);
}
}
//--------------------------------------------------------------------------------------------------
/// Displays a question to the user when a grid case group with statistical results is about to change
//--------------------------------------------------------------------------------------------------
bool RimUiTreeView::userConfirmedGridCaseGroupChange(const QModelIndexList& itemIndexList)
{
if (itemIndexList.size() == 0) return true;
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
if (myModel)
{
caf::PdmObjectGroup pog;
for (int i = 0; i < itemIndexList.size(); i++)
{
QModelIndex itemIndex = itemIndexList.at(i);
if (!itemIndex.isValid()) continue;
RimIdenticalGridCaseGroup* gridCaseGroup = myModel->gridCaseGroupFromItemIndex(itemIndex);
if (gridCaseGroup)
{
if (hasAnyStatisticsResults(gridCaseGroup))
{
if (pog.objects().count(gridCaseGroup) == 0)
{
pog.addObject(gridCaseGroup);
}
}
}
}
std::vector<caf::PdmPointer<RimIdenticalGridCaseGroup> > typedObjects;
pog.objectsByType(&typedObjects);
if (typedObjects.size() > 0)
{
RiuMainWindow* mainWnd = RiuMainWindow::instance();
QMessageBox msgBox(mainWnd);
msgBox.setIcon(QMessageBox::Question);
QString questionText;
if (typedObjects.size() == 1)
{
questionText = QString("This operation will invalidate statistics results in grid case group\n\"%1\".\n").arg(typedObjects[0]->name());
questionText += "Computed results in this group will be deleted if you continue.";
}
else
{
questionText = "This operation will invalidate statistics results in grid case groups\n";
for (int i = 0; i < typedObjects.size(); i++)
{
questionText += QString("\"%1\"\n").arg(typedObjects[i]->name());
}
questionText += "Computed results in these groups will be deleted if you continue.";
}
msgBox.setText(questionText);
msgBox.setInformativeText("Do you want to continue?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
int ret = msgBox.exec();
if (ret == QMessageBox::No)
{
return false;
}
}
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimUiTreeView::hasAnyStatisticsResults(RimIdenticalGridCaseGroup* gridCaseGroup)
{
CVF_ASSERT(gridCaseGroup);
for (size_t i = 0; i < gridCaseGroup->statisticsCaseCollection()->reservoirs().size(); i++)
{
RimStatisticsCase* rimStaticsCase = dynamic_cast<RimStatisticsCase*>(gridCaseGroup->statisticsCaseCollection()->reservoirs[i]);
if (rimStaticsCase)
{
if (rimStaticsCase->hasComputedStatistics())
{
return true;
}
}
}
return false;
}

View File

@ -23,6 +23,11 @@
#include <QTreeView>
class QItemSelection;
class RimIdenticalGridCaseGroup;
namespace caf {
class PdmObjectGroup;
}
//==================================================================================================
///
@ -34,6 +39,7 @@ class RimUiTreeView : public QTreeView
public:
RimUiTreeView(QWidget *parent = 0);
~RimUiTreeView();
virtual void setModel(QAbstractItemModel* model);
@ -69,11 +75,32 @@ private slots:
void slotCloseCase();
void slotNewStatisticsCase();
void slotComputeStatistics();
void slotAddCaseGroup();
void slotDeleteObjectFromPdmPointersField();
void slotCopyPdmObjectToClipboard();
void slotPastePdmObjects();
void slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
signals:
void selectedObjectChanged( caf::PdmObject* pdmObject );
private:
bool userConfirmedGridCaseGroupChange(const QModelIndexList& itemIndexList);
bool hasAnyStatisticsResults(RimIdenticalGridCaseGroup* gridCaseGroup);
void createPdmObjectsFromClipboard(caf::PdmObjectGroup* objectGroup);
bool hasClipboardValidData();
virtual void keyPressEvent(QKeyEvent* keyEvent);
virtual void dropEvent(QDropEvent* dropEvent);
private:
QAction* m_pasteAction;
};

View File

@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafAppEnum.h"

View File

@ -24,7 +24,7 @@
#include "cafAppEnum.h"
#include "cafPdmFieldCvfColor.h"
#include "RigWellResults.h"
#include "RigSingleWellResultsData.h"
class RimReservoirView;
//==================================================================================================
@ -41,8 +41,8 @@ public:
void setReservoirView(RimReservoirView* ownerReservoirView);
void setWellResults(RigWellResults* wellResults) { m_wellResults = wellResults;}
RigWellResults* wellResults() { return m_wellResults.p();}
void setWellResults(RigSingleWellResultsData* wellResults) { m_wellResults = wellResults;}
RigSingleWellResultsData* wellResults() { return m_wellResults.p();}
virtual caf::PdmFieldHandle* userDescriptionField();
@ -61,7 +61,7 @@ public:
caf::PdmField<double> pipeRadiusScaleFactor;
private:
cvf::ref<RigWellResults> m_wellResults;
cvf::ref<RigSingleWellResultsData> m_wellResults;
RimReservoirView* m_reservoirView;
};

View File

@ -16,13 +16,13 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "cafAppEnum.h"
#include "cafPdmFieldCvfColor.h"
#include "RigWellResults.h"
#include "RigSingleWellResultsData.h"
#include "RimWellCollection.h"
#include "RimWell.h"
#include "RimReservoirView.h"

View File

@ -0,0 +1,39 @@
# Use this workaround until we're on 2.8.3 on all platforms and can use CMAKE_CURRENT_LIST_DIR directly
if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
set(CEE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/)
endif()
list(APPEND CODE_HEADER_FILES
${CEE_CURRENT_LIST_DIR}RigActiveCellInfo.h
${CEE_CURRENT_LIST_DIR}RigCell.h
${CEE_CURRENT_LIST_DIR}RigCaseData.h
${CEE_CURRENT_LIST_DIR}RigGridBase.h
${CEE_CURRENT_LIST_DIR}RigGridManager.h
${CEE_CURRENT_LIST_DIR}RigGridScalarDataAccess.h
${CEE_CURRENT_LIST_DIR}RigLocalGrid.h
${CEE_CURRENT_LIST_DIR}RigMainGrid.h
${CEE_CURRENT_LIST_DIR}RigReservoirBuilderMock.h
${CEE_CURRENT_LIST_DIR}RigCaseCellResultsData.h
${CEE_CURRENT_LIST_DIR}RigSingleWellResultsData.h
${CEE_CURRENT_LIST_DIR}RigStatisticsMath.h
)
list(APPEND CODE_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RigActiveCellInfo.cpp
${CEE_CURRENT_LIST_DIR}RigCell.cpp
${CEE_CURRENT_LIST_DIR}RigCaseData.cpp
${CEE_CURRENT_LIST_DIR}RigGridBase.cpp
${CEE_CURRENT_LIST_DIR}RigGridManager.cpp
${CEE_CURRENT_LIST_DIR}RigGridScalarDataAccess.cpp
${CEE_CURRENT_LIST_DIR}RigLocalGrid.cpp
${CEE_CURRENT_LIST_DIR}RigMainGrid.cpp
${CEE_CURRENT_LIST_DIR}RigReservoirBuilderMock.cpp
${CEE_CURRENT_LIST_DIR}RigCaseCellResultsData.cpp
${CEE_CURRENT_LIST_DIR}RigSingleWellResultsData.cpp
${CEE_CURRENT_LIST_DIR}RigStatisticsMath.cpp
)

View File

@ -22,10 +22,31 @@ include_directories(
${ResInsight_SOURCE_DIR}/cafProjectDataModel
${ResInsight_SOURCE_DIR}/CommonCode
#Remove when RigStatistics is out
#${ResInsight_SOURCE_DIR}/ApplicationCode/ModelVisualization
)
file( GLOB CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../*.cpp )
file( GLOB UNIT_TEST_CPP_SOURCES *.cpp )
# Populate the filenames into variable lists
include ("${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists_files.cmake")
set( UNIT_TEST_CPP_SOURCES
${ResInsight_SOURCE_DIR}/cafUserInterface/cafProgressInfo.cpp
main.cpp
RigActiveCellInfo-Test.cpp
RigReservoir-Test.cpp
RigStatisticsMath-Test.cpp
)
#############################################################################
# Adds folders for Visual Studio solution explorer (and for Xcode explorer)
#############################################################################
source_group( "UnitTests" FILES ${UNIT_TEST_CPP_SOURCES} )
set( LINK_LIBRARIES
@ -45,8 +66,9 @@ set( LINK_LIBRARIES
add_executable( ${ProjectName}
${CPP_SOURCES}
${CODE_SOURCE_FILES}
${UNIT_TEST_CPP_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists_files.cmake
${ResInsight_SOURCE_DIR}/ThirdParty/gtest/gtest-all.cc
)

View File

@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "RigActiveCellInfo.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigActiveCellInfo, BasicTest)
{
RigActiveCellInfo rigActiveCellInfo;
size_t globalActiveCellCount = 10;
rigActiveCellInfo.setGlobalCellCount(globalActiveCellCount);
for (size_t i = 0; i < globalActiveCellCount; i++)
{
EXPECT_TRUE(rigActiveCellInfo.cellResultIndex(i) == cvf::UNDEFINED_SIZE_T);
EXPECT_FALSE(rigActiveCellInfo.isActive(i));
}
rigActiveCellInfo.setCellResultIndex(3, 1);
EXPECT_TRUE(rigActiveCellInfo.cellResultIndex(3) == 1);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigActiveCellInfo, GridCellCounts)
{
{
RigActiveCellInfo rigActiveCellInfo;
rigActiveCellInfo.setGridCount(3);
rigActiveCellInfo.setGridActiveCellCounts(0, 0);
rigActiveCellInfo.setGridActiveCellCounts(1, 1);
rigActiveCellInfo.setGridActiveCellCounts(2, 2);
rigActiveCellInfo.computeDerivedData();
EXPECT_TRUE(rigActiveCellInfo.globalActiveCellCount() == 3);
}
{
RigActiveCellInfo rigActiveCellInfo;
rigActiveCellInfo.setGridCount(3);
rigActiveCellInfo.setGridActiveCellCounts(0, 3 );
rigActiveCellInfo.setGridActiveCellCounts(1, 4 );
rigActiveCellInfo.setGridActiveCellCounts(2, 5 );
rigActiveCellInfo.computeDerivedData();
EXPECT_TRUE(rigActiveCellInfo.globalActiveCellCount() == 12);
}
}

View File

@ -18,19 +18,85 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RIStdInclude.h"
#include "RiaStdInclude.h"
#include "gtest/gtest.h"
#include "RigReservoir.h"
#include "RigCaseData.h"
#include "RigGridManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigGridManager, BasicTest)
{
cvf::ref<RigMainGrid> mainGridA = new RigMainGrid;
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
eclipseCase->setMainGrid(mainGridA.p());
int count = mainGridA->refCount();
EXPECT_EQ(mainGridA->refCount(), 2);
RigGridManager gridCollection;
gridCollection.addCase(eclipseCase.p());
EXPECT_EQ(mainGridA->refCount(), 2);
cvf::ref<RigMainGrid> mainGridB = mainGridA;
EXPECT_EQ(mainGridA->refCount(), 3);
cvf::ref<RigMainGrid> existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.notNull());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigGridManager, EqualTests)
{
cvf::ref<RigMainGrid> mainGridA = new RigMainGrid;
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 0));
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 1));
mainGridA->nodes().push_back(cvf::Vec3d(0, 0, 2));
cvf::ref<RigCaseData> eclipseCase = new RigCaseData;
eclipseCase->setMainGrid(mainGridA.p());
RigGridManager gridCollection;
gridCollection.addCase(eclipseCase.p());
cvf::ref<RigMainGrid> mainGridB = new RigMainGrid;
cvf::ref<RigMainGrid> existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 0));
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
// Insert nodes in opposite direction
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 2));
mainGridB->nodes().push_back(cvf::Vec3d(0, 0, 1));
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.isNull());
// Overwrite to match the node structure of mainGridA
mainGridB->nodes()[1] = cvf::Vec3d(0, 0, 1);
mainGridB->nodes()[2] = cvf::Vec3d(0, 0, 2);
existingGrid = gridCollection.findEqualGrid(mainGridB.p());
EXPECT_TRUE(existingGrid.notNull());
}
/*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigReservoirTest, BasicTest)
{
cvf::ref<RigWellResults> wellCellTimeHistory = new RigWellResults;
cvf::ref<RigSingleWellResultsData> wellCellTimeHistory = new RigSingleWellResultsData;
QDateTime wellStartTime = QDateTime::currentDateTime();
@ -44,7 +110,7 @@ TEST(RigReservoirTest, BasicTest)
}
int resultTimeStepCount = 2 * wellTimeStepCount;
QList<QDateTime> resultTimes;
std::vector<QDateTime> resultTimes;
for (i = 0; i < resultTimeStepCount; i++)
{
resultTimes.push_back(QDateTime(wellStartTime).addMonths(i * 6));
@ -62,3 +128,5 @@ TEST(RigReservoirTest, BasicTest)
}
*/

View File

@ -0,0 +1,143 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "gtest/gtest.h"
#include "RigStatisticsMath.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, BasicTest)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
double min, max, range, mean, stdev;
RigStatisticsMath::calculateBasicStatistics(values, &min, &max, &range, &mean, &stdev);
EXPECT_DOUBLE_EQ(-98649.8109937874000, min );
EXPECT_DOUBLE_EQ(99372.9362079615000 , max );
EXPECT_DOUBLE_EQ(198022.7472017490000, range );
EXPECT_DOUBLE_EQ(16313.8051759152000 , mean );
EXPECT_DOUBLE_EQ(66104.391542887200 , stdev );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, RankPercentiles)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
std::vector<double> pValPos;
pValPos.push_back(10);
pValPos.push_back(40);
pValPos.push_back(50);
pValPos.push_back(90);
std::vector<double> pVals = RigStatisticsMath::calculateNearestRankPercentiles(values, pValPos);
EXPECT_DOUBLE_EQ( -76092.8157632591000, pVals[0]);
EXPECT_DOUBLE_EQ( 2788.2723335651900 , pVals[1]);
EXPECT_DOUBLE_EQ( 6391.979999097290 , pVals[2]);
EXPECT_DOUBLE_EQ( 96161.7546348456000 , pVals[3]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RigStatisticsMath, HistogramPercentiles)
{
std::vector<double> values;
values.push_back(HUGE_VAL);
values.push_back(2788.2723335651900);
values.push_back(-22481.0927881701000);
values.push_back(68778.6851686236000);
values.push_back(-76092.8157632591000);
values.push_back(6391.97999909729003);
values.push_back(65930.1200169780000);
values.push_back(-27696.2320267235000);
values.push_back(HUGE_VAL);
values.push_back(HUGE_VAL);
values.push_back(96161.7546348456000);
values.push_back(73875.6716288563000);
values.push_back(80720.4378655615000);
values.push_back(-98649.8109937874000);
values.push_back(99372.9362079615000);
values.push_back(HUGE_VAL);
values.push_back(-57020.4389966513000);
double min, max, range, mean, stdev;
RigStatisticsMath::calculateBasicStatistics(values, &min, &max, &range, &mean, &stdev);
std::vector<size_t> histogram;
RigHistogramCalculator histCalc(min, max, 100, &histogram);
histCalc.addData(values);
std::vector<double> pVals;
double p10, p50, p90;
p10 = histCalc.calculatePercentil(0.1);
p50 = histCalc.calculatePercentil(0.5);
p90 = histCalc.calculatePercentil(0.9);
EXPECT_DOUBLE_EQ( -76273.240559989776, p10);
EXPECT_DOUBLE_EQ( 5312.1312871307755 , p50);
EXPECT_DOUBLE_EQ( 94818.413022321271 , p90);
}

Some files were not shown because too many files have changed in this diff Show More