#1035 Connected the Flow Diag solver, and added the statistics needed for legend. Now many things work .

This commit is contained in:
Jacob Støren
2016-12-20 11:41:05 +01:00
parent 3c55a86650
commit 003271ff54
15 changed files with 962 additions and 23 deletions

View File

@@ -18,11 +18,21 @@
#include "RigFlowDiagSolverInterface.h"
#include "RimFlowDiagSolution.h"
#include "RimEclipseResultCase.h"
#include "RigCaseCellResultsData.h"
#include "RigFlowDiagInterfaceTools.h"
#include "RifEclipseOutputFileTools.h"
#include "RigCaseData.h"
#include "RimEclipseCase.h"
#include "RifReaderInterface.h"
#include <QMessageBox>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagTimeStepResult::RigFlowDiagTimeStepResult(size_t activeCellCount)
: m_activeCellCount(activeCellCount)
{
}
@@ -31,10 +41,70 @@ RigFlowDiagTimeStepResult::RigFlowDiagTimeStepResult(size_t activeCellCount)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagSolverInterface::RigFlowDiagSolverInterface(RimFlowDiagSolution* flowSol)
: m_flowDiagSolution(flowSol)
void RigFlowDiagTimeStepResult::setInjectorTracerTOF(const std::string& tracerName, const std::map<int, double>& cellValues)
{
std::set<std::string> tracers;
tracers.insert(tracerName);
this->addResult(RigFlowDiagResultAddress(RIG_FLD_TOF_RESNAME, tracers), cellValues);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFlowDiagTimeStepResult::setInjectorTracerFraction(const std::string& tracerName, const std::map<int, double>& cellValues)
{
std::set<std::string> tracers;
tracers.insert(tracerName);
this->addResult(RigFlowDiagResultAddress(RIG_FLD_CELL_FRACTION_RESNAME, tracers), cellValues);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFlowDiagTimeStepResult::setProducerTracerTOF(const std::string& tracerName, const std::map<int, double>& cellValues)
{
std::set<std::string> tracers;
tracers.insert(tracerName);
this->addResult(RigFlowDiagResultAddress(RIG_FLD_TOF_RESNAME, tracers), cellValues);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFlowDiagTimeStepResult::setProducerTracerFraction(const std::string& tracerName, const std::map<int, double>& cellValues)
{
std::set<std::string> tracers;
tracers.insert(tracerName);
this->addResult(RigFlowDiagResultAddress(RIG_FLD_CELL_FRACTION_RESNAME, tracers), cellValues);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFlowDiagTimeStepResult::addResult(const RigFlowDiagResultAddress& resAddr, const std::map<int, double>& cellValues)
{
std::vector<double>& activeCellValues = m_nativeResults[resAddr];
activeCellValues.resize(m_activeCellCount, HUGE_VAL);
for (const auto& pairIt : cellValues)
{
activeCellValues[pairIt.first] = pairIt.second;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagSolverInterface::RigFlowDiagSolverInterface(RimEclipseResultCase * eclipseCase)
: m_eclipseCase(eclipseCase)
{
}
//--------------------------------------------------------------------------------------------------
@@ -48,10 +118,92 @@ RigFlowDiagSolverInterface::~RigFlowDiagSolverInterface()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timestep)
RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepIndex,
std::map<std::string, std::vector<int> > injectorTracers,
std::map<std::string, std::vector<int> > producerTracers)
{
std::vector<RigTracerCells > allTracerData;
using namespace Opm::FlowDiagnostics;
return RigFlowDiagTimeStepResult(0); // Relying on implicit move constructor
RigFlowDiagTimeStepResult result(m_eclipseCase->reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->reservoirActiveCellCount());
// Get set of files
QString gridFileName = m_eclipseCase->gridFileName();
QStringList m_filesWithSameBaseName;
if ( !RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(gridFileName, &m_filesWithSameBaseName) ) return result;
QString initFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_INIT_FILE);
Opm::ECLGraph graph = Opm::ECLGraph::load(gridFileName.toStdString(),
initFileName.toStdString());
// Look for unified restart file
QString restartFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_UNIFIED_RESTART_FILE);
if ( restartFileName.isEmpty() )
{
// Look for set of restart files (one file per time step)
QStringList restartFileNames;
restartFileNames = RifEclipseOutputFileTools::filterFileNamesOfType(m_filesWithSameBaseName, ECL_RESTART_FILE);
if (restartFileNames.size() <= timeStepIndex && restartFileNames.size() != m_eclipseCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount() )
{
QMessageBox::critical(nullptr, "ResInsight", "Flow Diagnostics: Could not find all the restart files. Results will not be loaded.");
return result;
}
restartFileNames.sort(); // To make sure they are sorted in increasing *.X000N order. Hack. Should probably be actual time stored on file.
restartFileName = restartFileNames[static_cast<int>(timeStepIndex)];
}
std::string casePath;
graph.assignFluxDataSource(restartFileName.toStdString());
if ( ! graph.selectReportStep(static_cast<int>(timeStepIndex)) )
{
QMessageBox::critical(nullptr, "ResInsight", "Flow Diagnostics: Could not find the requested timestep in the result file. Results will not be loaded.");
return result;
}
{
Toolbox fdTool = RigFlowDiagInterfaceTools::initialiseFlowDiagnostics(graph);
{
std::vector<CellSet> injectorCellSet;
for ( const auto& tIt: injectorTracers )
{
injectorCellSet.push_back(CellSet(CellSetID(tIt.first), tIt.second));
}
Solution injSol = fdTool.computeInjectionDiagnostics(injectorCellSet).fd;
for ( const CellSetID& tracerId: injSol.startPoints() )
{
CellSetValues tofVals = injSol.timeOfFlight(tracerId);
result.setInjectorTracerTOF(tracerId.to_string(), tofVals);
CellSetValues fracVals = injSol.concentration(tracerId);
result.setInjectorTracerFraction(tracerId.to_string(), fracVals);
}
}
{
std::vector<CellSet> prodjCellSet;
for ( const auto& tIt: producerTracers )
{
prodjCellSet.push_back(CellSet(CellSetID(tIt.first), tIt.second));
}
Solution prodSol = fdTool.computeProductionDiagnostics(prodjCellSet).fd;
for ( const CellSetID& tracerId: prodSol.startPoints() )
{
CellSetValues tofVals = prodSol.timeOfFlight(tracerId);
result.setProducerTracerTOF(tracerId.to_string(), tofVals);
CellSetValues fracVals = prodSol.concentration(tracerId);
result.setInjectorTracerFraction(tracerId.to_string(), fracVals);
}
}
}
return result; // Relying on implicit move constructor
}