Merge branch 'dev' into fishbones

This commit is contained in:
Magne Sjaastad 2017-05-15 13:37:09 +02:00
commit 25e6aec94a
319 changed files with 3791 additions and 2178 deletions

View File

@ -348,7 +348,7 @@ bool RiaApplication::loadProject(const QString& projectFileName, ProjectLoadActi
// Open the project file and read the serialized data.
// Will initialize itself.
if (!QFile::exists(projectFileName))
if (!caf::Utils::fileExists(projectFileName))
{
RiaLogging::info(QString("File does not exist : '%1'").arg(projectFileName));
return false;
@ -714,7 +714,7 @@ bool RiaApplication::saveProject()
{
CVF_ASSERT(m_project.notNull());
if (!QFile::exists(m_project->fileName()))
if (!caf::Utils::fileExists(m_project->fileName()))
{
return saveProjectPromptForFileName();
}
@ -940,7 +940,7 @@ QString RiaApplication::createAbsolutePathFromProjectRelativePath(QString projec
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openEclipseCaseFromFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
QFileInfo gridFileName(fileName);
QString caseName = gridFileName.completeBaseName();
@ -1113,7 +1113,7 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openOdbCaseFromFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
QFileInfo gridFileName(fileName);
QString caseName = gridFileName.completeBaseName();
@ -1479,14 +1479,14 @@ bool RiaApplication::parseArguments()
foreach (QString caseName, caseNames)
{
QString caseFileNameWithExt = caseName + ".EGRID";
if (QFile::exists(caseFileNameWithExt))
if (!caf::Utils::fileExists(caseFileNameWithExt))
{
openEclipseCaseFromFile(caseFileNameWithExt);
}
else
{
caseFileNameWithExt = caseName + ".GRID";
if (QFile::exists(caseFileNameWithExt))
if (!caf::Utils::fileExists(caseFileNameWithExt))
{
openEclipseCaseFromFile(caseFileNameWithExt);
}
@ -2135,7 +2135,7 @@ void RiaApplication::setLastUsedDialogDirectory(const QString& dialogName, const
//--------------------------------------------------------------------------------------------------
bool RiaApplication::openFile(const QString& fileName)
{
if (!QFile::exists(fileName)) return false;
if (!caf::Utils::fileExists(fileName)) return false;
bool loadingSucceded = false;

View File

@ -29,6 +29,8 @@
#include "RiuMainWindow.h"
#include "cafUtils.h"
#include <QAction>
#include <QFileInfo>
#include <QInputDialog>
@ -76,7 +78,7 @@ void RicNewScriptFeature::onActionTriggered(bool isChecked)
fullPathFilenameNewScript = fullPathNewScript + "/untitled.m";
int num= 1;
while (QFileInfo(fullPathFilenameNewScript).exists())
while (caf::Utils::fileExists(fullPathFilenameNewScript))
{
fullPathFilenameNewScript = fullPathNewScript + "/untitled" + QString::number(num) + ".m";
num++;

View File

@ -216,6 +216,15 @@ bool RicNewGridTimeHistoryCurveFeature::isCommandEnabled()
if (items.size() > 0)
{
const RiuEclipseSelectionItem* eclSelectionItem = dynamic_cast<const RiuEclipseSelectionItem*>(items[0]);
if (eclSelectionItem)
{
if (eclSelectionItem->m_view->cellResult()->resultType() == RimDefines::FLOW_DIAGNOSTICS)
{
return false;
}
}
return true;
}

View File

@ -27,6 +27,8 @@
#include "RiuMainWindow.h"
#include "RiuWellImportWizard.h"
#include "cafUtils.h"
#include <QAction>
#include <QDir>
#include <QFile>
@ -47,7 +49,7 @@ bool RicWellPathsImportSsihubFeature::isCommandEnabled()
return false;
}
if (!QFile::exists(app->project()->fileName()))
if (!caf::Utils::fileExists(app->project()->fileName()))
{
return false;
}
@ -66,7 +68,7 @@ void RicWellPathsImportSsihubFeature::onActionTriggered(bool isChecked)
return;
}
if (!QFile::exists(app->project()->fileName()))
if (!caf::Utils::fileExists(app->project()->fileName()))
{
return;
}

View File

@ -969,8 +969,17 @@ RigWellResultPoint RifReaderEclipseOutput::createWellResultPoint(const RigGridBa
resultPoint.m_ertSegmentId = ertSegmentId;
resultPoint.m_flowRate = volumeRate;
resultPoint.m_oilRate = oilRate;
resultPoint.m_gasRate = gasRate;
resultPoint.m_waterRate = waterRate;
// If field unit, the Gas is in Mega ft^3 while the others are in [stb] (barrel)
// we convert gas to stb as well. Based on
// 1 [stb] = 0.15898729492800007 [m^3]
// 1 [ft] = 0.3048 [m]
// megaFt3ToStbFactor = 1.0 / (1.0e-6 * 0.15898729492800007 * ( 1.0 / 0.3048 )^3 )
double megaFt3ToStbFactor = 178107.60668;
if (m_eclipseCase->unitsType() == RigEclipseCaseData::UNITS_FIELD) gasRate = megaFt3ToStbFactor * gasRate;
resultPoint.m_gasRate = gasRate;
}
return resultPoint;

View File

@ -69,7 +69,7 @@ private:
std::string ertGridName( size_t gridNr );
static RigWellResultPoint createWellResultPoint(const RigGridBase* grid, const well_conn_type* ert_connection, int ertBranchId, int ertSegmentId, const char* wellName);
RigWellResultPoint createWellResultPoint(const RigGridBase* grid, const well_conn_type* ert_connection, int ertBranchId, int ertSegmentId, const char* wellName);
void importFaults(const QStringList& fileSet, cvf::Collection<RigFault>* faults);

View File

@ -26,6 +26,8 @@
#include "RiuFlowCharacteristicsPlot.h"
#include "cafPdmUiCheckBoxEditor.h"
#include <cmath> // Needed for HUGE_VAL on Linux
@ -57,6 +59,8 @@ RimFlowCharacteristicsPlot::RimFlowCharacteristicsPlot()
CAF_PDM_InitFieldNoDefault(&m_timeStepSelectionType, "TimeSelectionType", "Time Steps", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedTimeSteps, "SelectedTimeSteps", "", "", "", "");
CAF_PDM_InitField(&m_showLegend, "ShowLegend", true, "Legend", "", "", "");
this->m_showWindow = false;
setAsPlotMdiWindow();
}
@ -167,11 +171,11 @@ QList<caf::PdmOptionItemInfo> RimFlowCharacteristicsPlot::calculateValueOptions(
RigFlowDiagResults* flowResult = m_flowDiagSolution->flowDiagResults();
std::vector<int> calculatedTimesteps = flowResult->calculatedTimeSteps();
std::vector<QDateTime> timeStepDates = m_case->timeStepDates();
QStringList timeStepDates = m_case->timeStepStrings();
for ( int tsIdx : calculatedTimesteps )
{
options.push_back(caf::PdmOptionItemInfo(timeStepDates[tsIdx].toString(), tsIdx));
options.push_back(caf::PdmOptionItemInfo(timeStepDates[tsIdx], tsIdx));
}
}
}
@ -191,6 +195,8 @@ void RimFlowCharacteristicsPlot::defineUiOrdering(QString uiConfigName, caf::Pdm
if (m_timeStepSelectionType == SELECT_AVAILABLE) uiOrdering.add(&m_selectedTimeSteps);
uiOrdering.add(&m_showLegend);
uiOrdering.skipRemainingFields();
}
@ -210,7 +216,6 @@ void RimFlowCharacteristicsPlot::zoomAll()
if (m_flowCharPlotWidget) m_flowCharPlotWidget->zoomAll();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -229,7 +234,6 @@ void RimFlowCharacteristicsPlot::fieldChangedByUi(const caf::PdmFieldHandle* cha
this->loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -246,8 +250,6 @@ QImage RimFlowCharacteristicsPlot::snapshotWindowContent()
return image;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -277,6 +279,7 @@ void RimFlowCharacteristicsPlot::loadDataAndUpdate()
m_currentlyPlottedTimeSteps = calculatedTimesteps;
std::vector<QDateTime> timeStepDates = m_case->timeStepDates();
QStringList timeStepStrings = m_case->timeStepStrings();
std::vector<double> lorenzVals(timeStepDates.size(), HUGE_VAL);
m_flowCharPlotWidget->removeAllCurves();
@ -285,7 +288,7 @@ void RimFlowCharacteristicsPlot::loadDataAndUpdate()
{
lorenzVals[timeStepIdx] = flowResult->flowCharacteristicsResults(timeStepIdx).m_lorenzCoefficient;
}
m_flowCharPlotWidget->setLorenzCurve(timeStepDates, lorenzVals);
m_flowCharPlotWidget->setLorenzCurve(timeStepStrings, timeStepDates, lorenzVals);
for ( int timeStepIdx: calculatedTimesteps )
{
@ -299,6 +302,7 @@ void RimFlowCharacteristicsPlot::loadDataAndUpdate()
flowCharResults.m_sweepEfficiencyCurve.second);
}
m_flowCharPlotWidget->showLegend(m_showLegend());
}
}

View File

@ -86,6 +86,7 @@ private:
caf::PdmPtrField<RimFlowDiagSolution*> m_flowDiagSolution;
caf::PdmField<caf::AppEnum<TimeSelectionType> > m_timeStepSelectionType;
caf::PdmField<std::vector<int> > m_selectedTimeSteps;
caf::PdmField<bool> m_showLegend;
std::vector<int> m_currentlyPlottedTimeSteps;

View File

@ -374,7 +374,14 @@ void RimWellAllocationPlot::updateWellFlowPlotXAxisTitle(RimWellLogTrack* plotTr
}
plotTrack->setXAxisTitle("Flow Rate " + unitText);
if (m_flowDiagSolution)
{
plotTrack->setXAxisTitle("Reservoir Flow Rate " + unitText);
}
else
{
plotTrack->setXAxisTitle("Surface Flow Rate " + unitText);
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -41,6 +41,7 @@
#include "cafPdmSettings.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafProgressInfo.h"
#include "cafUtils.h"
#include <QDir>
#include <QFile>
@ -100,7 +101,7 @@ bool RimEclipseResultCase::openEclipseGridFile()
}
else
{
if (!QFile::exists(caseFileName()))
if (!caf::Utils::fileExists(caseFileName()))
{
return false;
}
@ -174,7 +175,7 @@ bool RimEclipseResultCase::openAndReadActiveCellData(RigEclipseCaseData* mainEcl
}
else
{
if (!QFile::exists(caseFileName()))
if (!caf::Utils::fileExists(caseFileName()))
{
return false;
}

View File

@ -40,6 +40,8 @@
#include "RimGeoMechResultDefinition.h"
#include "RimGeoMechPropertyFilter.h"
#include "cafUtils.h"
#include <QFile>
CAF_PDM_SOURCE_INIT(RimGeoMechCase, "ResInsightGeoMechCase");
@ -110,7 +112,7 @@ bool RimGeoMechCase::openGeoMechCase(std::string* errorMessage)
// If read already, return
if (this->m_geoMechCaseData.notNull()) return true;
if (!QFile::exists(m_caseFileName()))
if (!caf::Utils::fileExists(m_caseFileName()))
{
return false;
}

View File

@ -29,6 +29,7 @@
#include "RimTools.h"
#include "cafProgressInfo.h"
#include "cafUtils.h"
#include "cvfGeometryTools.h"
@ -1394,16 +1395,15 @@ void RimReservoirCellResultsStorage::setCellResults(RigCaseCellResultsData* cell
// 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())
if (!caf::Utils::fileExists(newValidCacheFileName) && m_resultCacheMetaData.size())
{
qWarning() << "Reading stored results: Missing the storage file : " + newValidCacheFileName;
return;
}
QFile storageFile(newValidCacheFileName);
if (!storageFile.open(QIODevice::ReadOnly))
{
qWarning() << "Reading stored results: Can't open the file : " + newValidCacheFileName;

View File

@ -87,11 +87,12 @@ void RimScriptCollection::readContentFromDisc()
{
QString fileName = fileList.at(i);
QFileInfo fi(fileName);
if (fi.exists())
if (caf::Utils::fileExists(fileName))
{
RimCalcScript* calcScript = new RimCalcScript;
calcScript->absolutePath = fileName;
QFileInfo fi(fileName);
calcScript->setUiName(fi.baseName());
calcScripts.push_back(calcScript);

View File

@ -30,6 +30,7 @@
#include "RimWellPathCollection.h"
#include "cafPdmUiItem.h"
#include "cafUtils.h"
#include <QFileInfo>
#include <QDir>
@ -81,7 +82,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
bool isWindowsPath = false;
if (orgFileName.count("/")) isWindowsPath = false; // "/" are not allowed in a windows path
else if (orgFileName.count("\\")
&& !QFile::exists(orgFileName)) // To make sure we do not convert single linux files containing "\"
&& !caf::Utils::fileExists(orgFileName)) // To make sure we do not convert single linux files containing "\"
{
isWindowsPath = true;
}
@ -93,7 +94,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
}
if (searchedPaths) searchedPaths->push_back(fileName);
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
return fileName;
}
@ -104,7 +105,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
QString candidate = QDir::fromNativeSeparators(newProjectPath + QDir::separator() + fileNameWithoutPath);
if (searchedPaths) searchedPaths->push_back(candidate);
if (QFile::exists(candidate))
if (caf::Utils::fileExists(candidate))
{
return candidate;
}
@ -199,7 +200,7 @@ QString RimTools::relocateFile(const QString& orgFileName, const QString& orgNew
if (searchedPaths) searchedPaths->push_back(relocatedFileName);
if (QFile::exists(relocatedFileName))
if (caf::Utils::fileExists(relocatedFileName))
{
return relocatedFileName;
}

View File

@ -39,6 +39,8 @@
#include "RivWellPathPartMgr.h"
#include "cafUtils.h"
#include "cafPdmUiTreeOrdering.h"
#include <QDateTime>
@ -382,7 +384,7 @@ void RimWellPath::updateFilePathsFromProjectPath(const QString& newProjectPath,
{
QString newCacheFileName = getCacheFileName();
if (QFile::exists(newCacheFileName))
if (caf::Utils::fileExists(newCacheFileName))
{
filepath = newCacheFileName;
}

View File

@ -46,7 +46,7 @@ size_t RigEclCellIndexCalculator::resultCellIndex(size_t gridIndex, size_t gridC
///
//==================================================================================================
//#define USE_WELL_PHASE_RATES
#define USE_WELL_PHASE_RATES
//--------------------------------------------------------------------------------------------------
///
@ -105,6 +105,9 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
calculateAccumulatedFlowPrConnection(0, 1);
calculateFlowPrPseudoLength(0, 0.0);
#ifdef USE_WELL_PHASE_RATES
sortTracers();
#endif
}
//--------------------------------------------------------------------------------------------------

View File

@ -18,56 +18,83 @@
namespace RigFlowDiagInterfaceTools {
template <class FluxCalc>
inline Opm::FlowDiagnostics::ConnectionValues
extractFluxField(const Opm::ECLGraph& G, const bool compute_fluxes)
extractFluxField(const Opm::ECLGraph& G,
FluxCalc&& getFlux)
{
using ConnVals = Opm::FlowDiagnostics::ConnectionValues;
const auto actPh = G.activePhases();
auto flux = ConnVals(ConnVals::NumConnections{ G.numConnections() },
ConnVals::NumPhases{ 3 });
ConnVals::NumPhases{ actPh.size() });
auto phas = ConnVals::PhaseID{ 0 };
Opm::ECLFluxCalc calc(G);
const auto phases = { Opm::ECLGraph::PhaseIndex::Aqua ,
Opm::ECLGraph::PhaseIndex::Liquid ,
Opm::ECLGraph::PhaseIndex::Vapour };
for ( const auto& p : phases )
{
const auto pflux = compute_fluxes ? calc.flux(p) : G.flux(p);
if ( ! pflux.empty() )
{
assert (pflux.size() == flux.numConnections());
for (const auto& p : actPh) {
const auto pflux = getFlux(p);
if (!pflux.empty()) {
assert(pflux.size() == flux.numConnections());
auto conn = ConnVals::ConnID{ 0 };
for ( const auto& v : pflux )
{
for (const auto& v : pflux) {
flux(conn, phas) = v;
conn.id += 1;
}
}
phas.id += 1;
}
return flux;
}
inline Opm::FlowDiagnostics::ConnectionValues
extractFluxField(const Opm::ECLGraph& G,
const Opm::ECLRestartData& rstrt,
const bool compute_fluxes)
{
if (compute_fluxes) {
Opm::ECLFluxCalc calc(G);
auto getFlux = [&calc, &rstrt]
(const Opm::ECLGraph::PhaseIndex p)
{
return calc.flux(rstrt, p);
};
return extractFluxField(G, getFlux);
}
auto getFlux = [&G, &rstrt]
(const Opm::ECLGraph::PhaseIndex p)
{
return G.flux(rstrt, p);
};
return extractFluxField(G, getFlux);
}
template <class WellFluxes>
Opm::FlowDiagnostics::CellSetValues
extractWellFlows(const Opm::ECLGraph& G,
const WellFluxes& well_fluxes)
extractWellFlows(const Opm::ECLGraph& G,
const WellFluxes& well_fluxes)
{
Opm::FlowDiagnostics::CellSetValues inflow;
for (const auto& well : well_fluxes) {
for (const auto& completion : well.completions) {
const int grid_index = completion.grid_index;
const auto& gridName = completion.gridName;
const auto& ijk = completion.ijk;
const int cell_index = G.activeCell(ijk, grid_index);
const int cell_index = G.activeCell(ijk, gridName);
if (cell_index >= 0) {
auto iterIsInsertedPair = inflow.emplace(cell_index, completion.reservoir_inflow_rate);
if (!iterIsInsertedPair.second){ // Not inserted, We had something there already
iterIsInsertedPair.first->second += completion.reservoir_inflow_rate; // Accumulate the flow at this connection
}
// Since inflow is a std::map, if the key was not
// already present operator[] will insert a
// value-initialized value (as in T() for a type
// T), which is zero for built-in numerical types,
// including double.
inflow[cell_index] += completion.reservoir_inflow_rate;
}
}
}
@ -75,7 +102,6 @@ namespace RigFlowDiagInterfaceTools {
return inflow;
}
}

View File

@ -104,19 +104,25 @@ void RigFlowDiagTimeStepResult::addResult(const RigFlowDiagResultAddress& resAdd
}
class RigOpmFldStaticData : public cvf::Object
class RigOpmFlowDiagStaticData : public cvf::Object
{
public:
RigOpmFldStaticData(const std::string& grid, const std::string& init) : m_eclGraph(Opm::ECLGraph::load(grid, init)), m_hasUnifiedRestartFile(false)
RigOpmFlowDiagStaticData(const std::string& grid, const std::string& init)
{
m_poreVolume = m_eclGraph.poreVolume();
Opm::ECLInitFileData initData(init);
m_eclGraph.reset(new Opm::ECLGraph(Opm::ECLGraph::load(grid, initData)));
m_hasUnifiedRestartFile = false;
m_poreVolume = m_eclGraph->poreVolume();
}
Opm::ECLGraph m_eclGraph;
std::unique_ptr<Opm::ECLGraph> m_eclGraph;
std::vector<double> m_poreVolume;
std::unique_ptr<Opm::FlowDiagnostics::Toolbox> m_fldToolbox;
bool m_hasUnifiedRestartFile;
QStringList m_restartFileNames;
std::vector<Opm::ECLRestartData> m_singleRestartDataTimeSteps;
std::unique_ptr<Opm::ECLRestartData> m_unifiedRestartData;
};
@ -150,9 +156,8 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
RigFlowDiagTimeStepResult result(m_eclipseCase->eclipseCaseData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->reservoirActiveCellCount());
caf::ProgressInfo progressInfo(8, "Calculating Flow Diagnostics");
if ( m_opmFldData.isNull() )
if ( m_opmFlowDiagStaticData.isNull() )
{
progressInfo.setProgressDescription("Grid access");
@ -165,66 +170,77 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
QString initFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_INIT_FILE);
m_opmFldData = new RigOpmFldStaticData(gridFileName.toStdString(),
m_opmFlowDiagStaticData = new RigOpmFlowDiagStaticData(gridFileName.toStdString(),
initFileName.toStdString());
progressInfo.incrementProgress();
progressInfo.setProgressDescription("Calculating Connectivities");
const Opm::FlowDiagnostics::ConnectivityGraph connGraph =
Opm::FlowDiagnostics::ConnectivityGraph{ static_cast<int>(m_opmFldData->m_eclGraph.numCells()),
m_opmFldData->m_eclGraph.neighbours() };
Opm::FlowDiagnostics::ConnectivityGraph{ static_cast<int>(m_opmFlowDiagStaticData->m_eclGraph->numCells()),
m_opmFlowDiagStaticData->m_eclGraph->neighbours() };
progressInfo.incrementProgress();
progressInfo.setProgressDescription("Initialize Solver");
// Create the Toolbox.
m_opmFldData->m_fldToolbox.reset(new Opm::FlowDiagnostics::Toolbox{ connGraph });
m_opmFldData->m_fldToolbox->assignPoreVolume( m_opmFldData->m_poreVolume);
m_opmFlowDiagStaticData->m_fldToolbox.reset(new Opm::FlowDiagnostics::Toolbox{ connGraph });
m_opmFlowDiagStaticData->m_fldToolbox->assignPoreVolume( m_opmFlowDiagStaticData->m_poreVolume);
// Look for unified restart file
QString restartFileName = RifEclipseOutputFileTools::firstFileNameOfType(m_filesWithSameBaseName, ECL_UNIFIED_RESTART_FILE);
if ( !restartFileName.isEmpty() )
{
m_opmFldData->m_eclGraph.assignFluxDataSource(restartFileName.toStdString());
m_opmFldData->m_hasUnifiedRestartFile = true;
m_opmFlowDiagStaticData->m_unifiedRestartData.reset(new Opm::ECLRestartData(Opm::ECLRestartData(restartFileName.toStdString())));
m_opmFlowDiagStaticData->m_hasUnifiedRestartFile = true;
}
else
{
QStringList restartFileNames = RifEclipseOutputFileTools::filterFileNamesOfType(m_filesWithSameBaseName, ECL_RESTART_FILE);
m_opmFldData->m_restartFileNames = RifEclipseOutputFileTools::filterFileNamesOfType(m_filesWithSameBaseName, ECL_RESTART_FILE);
size_t restartFileCount = static_cast<size_t>(m_opmFldData->m_restartFileNames.size());
size_t restartFileCount = static_cast<size_t>(restartFileNames.size());
size_t maxTimeStepCount = m_eclipseCase->eclipseCaseData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount();
if (restartFileCount <= timeStepIndex && restartFileCount != maxTimeStepCount )
if (restartFileCount <= timeStepIndex && restartFileCount != maxTimeStepCount )
{
QMessageBox::critical(nullptr, "ResInsight", "Flow Diagnostics: Could not find all the restart files. Results will not be loaded.");
return result;
}
m_opmFldData->m_restartFileNames.sort(); // To make sure they are sorted in increasing *.X000N order. Hack. Should probably be actual time stored on file.
m_opmFldData->m_hasUnifiedRestartFile = false;
restartFileNames.sort(); // To make sure they are sorted in increasing *.X000N order. Hack. Should probably be actual time stored on file.
m_opmFlowDiagStaticData->m_hasUnifiedRestartFile = false;
for (auto restartFileName : restartFileNames)
{
m_opmFlowDiagStaticData->m_singleRestartDataTimeSteps.push_back(Opm::ECLRestartData(restartFileName.toStdString()));
}
}
}
progressInfo.setProgress(3);
progressInfo.setProgressDescription("Assigning Flux Field");
if ( ! m_opmFldData->m_hasUnifiedRestartFile )
Opm::ECLRestartData* currentRestartData = nullptr;
if ( ! m_opmFlowDiagStaticData->m_hasUnifiedRestartFile )
{
QString restartFileName = m_opmFldData->m_restartFileNames[static_cast<int>(timeStepIndex)];
m_opmFldData->m_eclGraph.assignFluxDataSource(restartFileName.toStdString());
currentRestartData = &(m_opmFlowDiagStaticData->m_singleRestartDataTimeSteps[timeStepIndex]);
}
else
{
currentRestartData = m_opmFlowDiagStaticData->m_unifiedRestartData.get();
}
CVF_ASSERT(currentRestartData);
size_t resultIndexWithMaxTimeSteps = cvf::UNDEFINED_SIZE_T;
m_eclipseCase->eclipseCaseData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(&resultIndexWithMaxTimeSteps);
int reportStepNumber = m_eclipseCase->eclipseCaseData()->results(RifReaderInterface::MATRIX_RESULTS)->reportStepNumber(resultIndexWithMaxTimeSteps, timeStepIndex);
if ( ! m_opmFldData->m_eclGraph.selectReportStep(reportStepNumber) )
if ( !currentRestartData->selectReportStep(reportStepNumber) )
{
QMessageBox::critical(nullptr, "ResInsight", "Flow Diagnostics: Could not find the requested timestep in the result file. Results will not be loaded.");
return result;
@ -235,22 +251,25 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
Opm::FlowDiagnostics::CellSetValues sumWellFluxPrCell;
{
Opm::FlowDiagnostics::ConnectionValues connectionsVals = RigFlowDiagInterfaceTools::extractFluxField(m_opmFldData->m_eclGraph, false);
Opm::FlowDiagnostics::ConnectionValues connectionsVals = RigFlowDiagInterfaceTools::extractFluxField(*(m_opmFlowDiagStaticData->m_eclGraph),
*currentRestartData,
false);
m_opmFldData->m_fldToolbox->assignConnectionFlux(connectionsVals);
m_opmFlowDiagStaticData->m_fldToolbox->assignConnectionFlux(connectionsVals);
progressInfo.incrementProgress();
Opm::ECLWellSolution wsol = Opm::ECLWellSolution{-1.0 , false};
const std::vector<Opm::ECLWellSolution::WellData> well_fluxes =
wsol.solution(m_opmFldData->m_eclGraph.rawResultData(), m_opmFldData->m_eclGraph.numGrids());
std::vector<std::string> gridNames = m_opmFlowDiagStaticData->m_eclGraph->activeGrids();
sumWellFluxPrCell = RigFlowDiagInterfaceTools::extractWellFlows(m_opmFldData->m_eclGraph, well_fluxes);
const std::vector<Opm::ECLWellSolution::WellData> well_fluxes = wsol.solution(*currentRestartData, gridNames);
m_opmFldData->m_fldToolbox->assignInflowFlux(sumWellFluxPrCell);
sumWellFluxPrCell = RigFlowDiagInterfaceTools::extractWellFlows(*(m_opmFlowDiagStaticData->m_eclGraph), well_fluxes);
// Filter connection cells with inconsistent well in flow direction (Hack, we should do something better)
m_opmFlowDiagStaticData->m_fldToolbox->assignInflowFlux(sumWellFluxPrCell);
// Start Hack: Filter connection cells with inconsistent well in flow direction (Hack, we should do something better)
for ( auto& tracerCellIdxsPair: injectorTracers )
{
@ -259,6 +278,8 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
for (int activeCellIdx : tracerCellIdxsPair.second)
{
auto activeCellIdxFluxPair = sumWellFluxPrCell.find(activeCellIdx);
CVF_TIGHT_ASSERT(activeCellIdxFluxPair != sumWellFluxPrCell.end());
if (activeCellIdxFluxPair->second > 0 )
{
filteredCellIndices.push_back(activeCellIdx);
@ -275,6 +296,8 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
for (int activeCellIdx : tracerCellIdxsPair.second)
{
auto activeCellIdxFluxPair = sumWellFluxPrCell.find(activeCellIdx);
CVF_TIGHT_ASSERT(activeCellIdxFluxPair != sumWellFluxPrCell.end());
if (activeCellIdxFluxPair->second < 0 )
{
filteredCellIndices.push_back(activeCellIdx);
@ -282,6 +305,8 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
}
if (tracerCellIdxsPair.second.size() != filteredCellIndices.size()) tracerCellIdxsPair.second = filteredCellIndices;
}
// End Hack
}
progressInfo.incrementProgress();
@ -299,7 +324,7 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
std::unique_ptr<Toolbox::Forward> injectorSolution;
try
{
injectorSolution.reset(new Toolbox::Forward( m_opmFldData->m_fldToolbox->computeInjectionDiagnostics(injectorCellSets)));
injectorSolution.reset(new Toolbox::Forward( m_opmFlowDiagStaticData->m_fldToolbox->computeInjectionDiagnostics(injectorCellSets)));
}
catch (const std::exception& e)
{
@ -329,7 +354,7 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
std::unique_ptr<Toolbox::Reverse> producerSolution;
try
{
producerSolution.reset(new Toolbox::Reverse(m_opmFldData->m_fldToolbox->computeProductionDiagnostics(prodjCellSets)));
producerSolution.reset(new Toolbox::Reverse(m_opmFlowDiagStaticData->m_fldToolbox->computeProductionDiagnostics(prodjCellSets)));
}
catch ( const std::exception& e )
{
@ -375,7 +400,7 @@ RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timeStepI
{
Graph flowCapStorCapCurve = flowCapacityStorageCapacityCurve(*(injectorSolution.get()),
*(producerSolution.get()),
m_opmFldData->m_poreVolume);
m_opmFlowDiagStaticData->m_poreVolume);
result.setFlowCapStorageCapCurve(flowCapStorCapCurve);
result.setSweepEfficiencyCurve(sweepEfficiency(flowCapStorCapCurve));

View File

@ -70,7 +70,7 @@ private:
class RigEclipseCaseData;
class RigOpmFldStaticData;
class RigOpmFlowDiagStaticData;
class RigFlowDiagSolverInterface : public cvf::Object
{
@ -85,7 +85,7 @@ public:
private:
RimEclipseResultCase * m_eclipseCase;
cvf::ref<RigOpmFldStaticData> m_opmFldData;
cvf::ref<RigOpmFlowDiagStaticData> m_opmFlowDiagStaticData;
};

View File

@ -25,6 +25,7 @@
#include "RimWellLogExtractionCurve.h"
#include "cafUtils.h"
#include "cvfAssert.h"
#include "laswell.hpp"
@ -390,7 +391,7 @@ bool RigLasFileExporter::writeToFolder(const QString& exportFolder)
QDir dir(exportFolder);
QString fileName = dir.absoluteFilePath(QString::fromStdString(lasFileDescr.generateFilename()));
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
QString txt = QString("File %1 exists.\n\nDo you want to overwrite the file?").arg(fileName);
int ret = QMessageBox::question(NULL, "LAS File Export",

View File

@ -128,10 +128,10 @@ struct RigWellResultPoint
int m_ertSegmentId;
cvf::Vec3d m_bottomPosition; //< The estimated bottom position of the well segment, when we have no grid cell connections for the segment.
double m_flowRate;
double m_oilRate;
double m_gasRate;
double m_waterRate;
double m_flowRate; //< Total reservoir rate
double m_oilRate; //< Surface oil rate
double m_gasRate; //< Surface gas rate For Field-unit, converted to [stb/day] to allign with oil and water.
double m_waterRate; //< Surface water rate
};
//==================================================================================================

View File

@ -2,6 +2,7 @@
const std::string casePath = "\\\\csfiles\\Store\\ProjectData\\StatoilReservoir\\ReferenceCases\\simple_FlowDiag_Model\\";
/*
#include "exampleSetup.hpp"
TEST(opm_flowdiagnostics_test, basic_construction)
@ -9,12 +10,14 @@ TEST(opm_flowdiagnostics_test, basic_construction)
try
{
Opm::ECLRestartData rstrt(casePath + "SIMPLE.UNRST");
Opm::ECLInitFileData initData(casePath + "SIMPLE.INIT");
Opm::ECLGraph graph = Opm::ECLGraph::load(casePath + "SIMPLE.EGRID",
casePath + "SIMPLE.INIT");
graph.assignFluxDataSource(casePath + "SIMPLE.UNRST");
initData);
int step = 2;
if ( ! graph.selectReportStep(step) )
if ( ! rstrt.selectReportStep(step) )
{
std::ostringstream os;
@ -44,3 +47,4 @@ TEST(opm_flowdiagnostics_test, basic_construction)
std::cerr << "Caught exception: " << e.what() << '\n';
}
}
*/

View File

@ -17,27 +17,31 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiuFlowCharacteristicsPlot.h"
#include "RimFlowCharacteristicsPlot.h"
#include "RiuResultQwtPlot.h"
#include "qwt_plot.h"
#include "RiaColorTables.h"
#include "RimFlowCharacteristicsPlot.h"
#include "RiuLineSegmentQwtPlotCurve.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuResultQwtPlot.h"
#include "RiuSummaryQwtPlot.h"
#include "cvfBase.h"
#include "cvfColor3.h"
#include "qwt_date.h"
#include "qwt_legend.h"
#include "qwt_plot.h"
#include "qwt_plot_zoomer.h"
#include "qwt_symbol.h"
#include <QBoxLayout>
#include <QContextMenuEvent>
#include <QDateTime>
#include <QLabel>
#include <QMenu>
#include "RiuLineSegmentQwtPlotCurve.h"
#include <QDateTime>
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "qwt_plot_zoomer.h"
#include "RiaColorTables.h"
#include "qwt_plot_zoneitem.h"
#include "qwt_date.h"
#include "RiuQwtPlotZoomer.h"
//--------------------------------------------------------------------------------------------------
@ -85,6 +89,9 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
m_flowCapVsStorageCapPlot->setTitle("Flow Capacity vs Storage Capacity");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::addWindowZoom(QwtPlot* plot)
{
auto zoomer = new RiuQwtPlotZoomer(plot->canvas());
@ -107,50 +114,58 @@ RiuFlowCharacteristicsPlot::~RiuFlowCharacteristicsPlot()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::setLorenzCurve(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
void RiuFlowCharacteristicsPlot::setLorenzCurve(const QStringList& dateTimeStrings, const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
{
initializeColors(dateTimes);
m_lorenzPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
auto curve = createEmptyCurve(m_lorenzPlot, "Lorenz Coefficient", QColor(0, 0, 0));
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
//curve->setSymbol(QwtSymbol )
//size_t tsIdx = 0;
//for ( const QDateTime& dateTime: dateTimes )
//{
// auto curve = createEmptyCurve(m_lorenzPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
// std::vector<QDateTime> timeStep;
// timeStep.push_back(dateTime);
// std::vector<double> lorCoeff;
// lorCoeff.push_back(timeHistoryValues[tsIdx]);
//
// curve->setSamplesFromDateAndValues(timeStep, lorCoeff, false);
//
// ++tsIdx;
//}
//double milliSecSinceEpoch = QwtDate::toDouble(filteredDateTimes[i]);
for ( size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx )
for (size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx)
{
double currentTsValue = QwtDate::toDouble(dateTimes[tsIdx]);
if (timeHistoryValues[tsIdx] == HUGE_VAL) continue;
double minTsValue = currentTsValue;
if ( tsIdx > 0 ) minTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx-1]));
double maxTsValue = currentTsValue;
if ( tsIdx < dateTimes.size()-1 ) maxTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx+1]));
QDateTime dateTime = dateTimes[tsIdx];
double timeHistoryValue = timeHistoryValues[tsIdx];
auto plotZone = new QwtPlotZoneItem();
plotZone->setOrientation(Qt::Vertical);
plotZone->setInterval(minTsValue, maxTsValue);
plotZone->setBrush(QBrush(m_dateToColorMap[dateTimes[tsIdx]]));
plotZone->attach(m_lorenzPlot);
QString curveName = dateTimeStrings[static_cast<int>(tsIdx)];
RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(m_lorenzPlot, curveName, m_dateToColorMap[dateTime], dateTime, timeHistoryValue);
}
m_lorenzPlot->replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(QwtPlot* plot, const QString& curveName, const QColor& color, const QDateTime& dateTime, double timeHistoryValue)
{
auto curve = createEmptyCurve(plot, curveName, color);
QwtSymbol::Style style = QwtSymbol::Diamond;
QwtSymbol* symbol = new QwtSymbol(style);
symbol->setSize(15, 15);
symbol->setColor(color);
curve->setSymbol(symbol);
// Add date and value twice to avoid a cross as symbol generated by RiuLineSegmentQwtPlotCurve
std::vector<QDateTime> dateTimes;
dateTimes.push_back(dateTime);
dateTimes.push_back(dateTime);
std::vector<double> timeHistoryValues;
timeHistoryValues.push_back(timeHistoryValue);
timeHistoryValues.push_back(timeHistoryValue);
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuLineSegmentQwtPlotCurve* RiuFlowCharacteristicsPlot::createEmptyCurve(QwtPlot* plot, const QString& curveName, const QColor& curveColor )
{
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve(curveName);
@ -200,6 +215,9 @@ void RiuFlowCharacteristicsPlot::removeAllCurves()
m_dateToColorMap.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void zoomAllInPlot(QwtPlot * plot)
{
plot->setAxisAutoScale(QwtPlot::xBottom, true);
@ -217,6 +235,23 @@ void RiuFlowCharacteristicsPlot::zoomAll()
zoomAllInPlot(m_flowCapVsStorageCapPlot);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::showLegend(bool show)
{
if (show)
{
// Will be released in plot destructor or when a new legend is set
QwtLegend* legend = new QwtLegend(m_lorenzPlot);
m_lorenzPlot->insertLegend(legend, QwtPlot::BottomLegend);
}
else
{
m_lorenzPlot->insertLegend(nullptr);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -225,7 +260,6 @@ RimFlowCharacteristicsPlot* RiuFlowCharacteristicsPlot::ownerPlotDefinition()
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -242,7 +276,6 @@ QSize RiuFlowCharacteristicsPlot::minimumSizeHint() const
return QSize(0, 100);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -18,13 +18,14 @@
#pragma once
#include "qwt_plot.h"
#include "RiuInterfaceToViewWindow.h"
#include "cafPdmPointer.h"
#include <QPointer>
#include "qwt_plot.h"
#include <QFrame>
#include "RiuInterfaceToViewWindow.h"
#include <QPointer>
class RimFlowCharacteristicsPlot;
class RiuNightchartsWidget;
@ -49,13 +50,15 @@ public:
RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlot* plotDefinition, QWidget* parent = NULL);
virtual ~RiuFlowCharacteristicsPlot();
void setLorenzCurve(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues);
void setLorenzCurve(const QStringList& dateTimeStrings, const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues);
void addFlowCapStorageCapCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals);
void addSweepEfficiencyCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals);
void removeAllCurves();
void zoomAll();
void showLegend(bool show);
RimFlowCharacteristicsPlot* ownerPlotDefinition();
virtual RimViewWindow* ownerViewWindow() const override;
@ -68,9 +71,9 @@ protected:
private:
void setDefaults();
void initializeColors(const std::vector<QDateTime>& dateTimes);
void initializeColors(const std::vector<QDateTime>& dateTimes);
static void addCurveWithLargeSymbol(QwtPlot* plot, const QString& curveName, const QColor& color, const QDateTime& dateTime, double timeHistoryValue);
private:
caf::PdmPointer<RimFlowCharacteristicsPlot> m_plotDefinition;
@ -78,7 +81,6 @@ private:
QPointer<QwtPlot> m_flowCapVsStorageCapPlot;
QPointer<QwtPlot> m_sweepEffPlot;
std::map<QDateTime, QColor> m_dateToColorMap;
};

View File

@ -56,6 +56,7 @@
#include "cafPdmUiPropertyViewDialog.h"
#include "cafPdmUiTreeView.h"
#include "cafSelectionManager.h"
#include "cafUtils.h"
#include "cvfTimer.h"
@ -637,7 +638,7 @@ void RiuMainWindow::slotRefreshFileActions()
{
RiaApplication* app = RiaApplication::instance();
bool projectFileExists = QFile::exists(app->project()->fileName());
bool projectFileExists = caf::Utils::fileExists(app->project()->fileName());
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
CVF_ASSERT(cmdFeatureMgr);

View File

@ -32,6 +32,7 @@
#include "cafPdmUiPropertyView.h"
#include "cafPdmUiTreeView.h"
#include "cafPdmUiTreeViewEditor.h"
#include "cafUtils.h"
#include <QObject>
#include <QtGui>
@ -99,7 +100,7 @@ QString RiuWellImportWizard::jsonWellsFilePath()
void RiuWellImportWizard::downloadFields()
{
QString wellFileName = jsonWellsFilePath();
if (QFile::exists(wellFileName))
if (caf::Utils::fileExists(wellFileName))
{
QFile::remove(wellFileName);
}
@ -355,7 +356,7 @@ void RiuWellImportWizard::updateFieldsModel()
{
QString fileName = jsonFieldsFilePath();
if (QFile::exists(fileName))
if (caf::Utils::fileExists(fileName))
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);
@ -540,7 +541,7 @@ QStringList RiuWellImportWizard::absoluteFilePathsToWellPaths() const
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(downloadEntities[i].responseFilename))
if (caf::Utils::fileExists(downloadEntities[i].responseFilename))
{
filePaths.push_back(downloadEntities[i].responseFilename);
}
@ -582,7 +583,7 @@ void RiuWellImportWizard::parseWellsResponse(RimOilFieldEntry* oilFieldEntry)
QStringList surveyNames;
QStringList planNames;
if (QFile::exists(oilFieldEntry->wellsFilePath))
if (caf::Utils::fileExists(oilFieldEntry->wellsFilePath))
{
ResInsightInternalJson::JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(oilFieldEntry->wellsFilePath);
@ -1056,7 +1057,7 @@ void WellSummaryPage::updateSummaryPage()
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(downloadEntities[i].responseFilename))
if (caf::Utils::fileExists(downloadEntities[i].responseFilename))
{
wellPathCount++;
}

View File

@ -223,4 +223,22 @@ bool Utils::getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, st
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Utils::fileExists(const QString& fileName)
{
QFileInfo fi(fileName);
// QFileInfo::exists returns true for both files and folders
// Also check if the path points to a file
if (fi.exists() && fi.isFile())
{
return true;
}
return false;
}
} // namespace caf

View File

@ -63,6 +63,8 @@ public:
static QString indentString(int numSpacesToIndent, const QString& str);
static bool getSaveDirectoryAndCheckOverwriteFiles(const QString& defaultDir, std::vector<QString> fileNames, QString* saveDir);
static bool fileExists(const QString& fileName);
};
}

View File

@ -88,6 +88,13 @@ void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, q
{
error("riSetActiveCellProperty : ResInsight refused to accept the data. Maybe the dimensions or porosity model is wrong");
}
#ifdef WIN32
// TODO: Due to synchronization issues seen on Windows 10, it is required to do a sleep here to be able to catch disconnect
// signals from the socket. No sleep causes the server to hang.
Sleep(100);
#endif //WIN32
return;
}

View File

@ -110,6 +110,13 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName,
{
error("riSetGridProperty : ResInsight refused to accept the data. Maybe the dimensions or porosity model is wrong.\n");
}
#ifdef WIN32
// TODO: Due to synchronization issues seen on Windows 10, it is required to do a sleep here to be able to catch disconnect
// signals from the socket. No sleep causes the server to hang.
Sleep(100);
#endif //WIN32
return;
}

View File

@ -9,15 +9,15 @@ The main input data is *.GRID and *.EGRID files along with their *.INIT and rest
ResInsight has been co-developed by Statoil ASA, Ceetron Solutions AS, and Ceetron AS with the aim to provide a versatile tool for professionals who need to visualize and process reservoir models. The software is copyrighted by Ceetron and Statoil and licensed under GPL 3+. See COPYING for details.
### Dependencies
ResInsight uses the Ensambles/ert library to access Eclipse result files, and the two projects collaborates closely. The source code of the approved ert library version is embedded in the ResInsight source code tree, making downloading and building simple.
ResInsight uses the Statoil/libecl (formerly Ensambles/ert) library to access Eclipse result files, and the two projects collaborates closely. The source code of the approved libecl version is embedded in the ResInsight source code tree, making downloading and building simple.
ResInsight also features an interface to Octave for retrieval of data from ResInsight, processing using Octave, and communication of data back into ResInsight for further handling and visualization.
Octave : [http://www.gnu.org/software/octave/](http://www.gnu.org/software/octave/)
Ensembles/ert : [https://github.com/Ensembles/ert](https://github.com/Ensembles/ert)
Statoil/libecl : [https://github.com/Statoil/libecl](https://github.com/Statoil/libecl)
### Supported Platforms
ResInsight is designed cross-platform from the start. Efforts have been made to ensure that code will compile and run on Linux and Windows platforms. Tested platforms are currently 64 bit RHEL6 and Windows 7.
ResInsight is designed cross-platform from the start. Efforts have been made to ensure that code will compile and run on Linux and Windows platforms. Tested platforms are currently 64 bit RHEL6 and Windows 7/8/10, and we have also received reports on successful builds on Ubuntu based systems.
### Documentation
@ -38,4 +38,4 @@ Release branches that might pop up are dedicated bug fix branches for the releas
### Building ResInsight
See [ Build Instructions ] (http://resinsight.org/docs/buildinstructions/)
See [ Build Instructions ](http://resinsight.org/docs/buildinstructions/)

View File

@ -1,20 +1,20 @@
set(RESINSIGHT_MAJOR_VERSION 2016)
set(RESINSIGHT_MINOR_VERSION 11)
set(RESINSIGHT_INCREMENT_VERSION "flow.13")
set(RESINSIGHT_INCREMENT_VERSION "flow.14")
# https://github.com/CRAVA/crava/tree/master/libs/nrlib
set(NRLIB_GITHUB_SHA "ba35d4359882f1c6f5e9dc30eb95fe52af50fd6f")
# https://github.com/Statoil/libecl
set(ERT_GITHUB_SHA "f39d2e7fd196350ab1db86bb1bd5a3faca72d75d")
set(ERT_GITHUB_SHA "06a39878636af0bc52582430ad0431450e51139c")
# https://github.com/OPM/opm-flowdiagnostics
set(OPM_FLOWDIAGNOSTICS_SHA "a14dc4ba1302bcc1e0aeb35c5de6b4bd39bce98")
set(OPM_FLOWDIAGNOSTICS_SHA "2c5fb55db4c4ded49c14161dd16463e1207da049")
# https://github.com/OPM/opm-flowdiagnostics-applications
set(OPM_FLOWDIAGNOSTICS_APPLICATIONS_SHA "1b521494ce9c09a1286dd0a81a1333caa123c680")
set(OPM_FLOWDIAGNOSTICS_APPLICATIONS_SHA "570601718e7197b751bc3cba60c1e5fb7d842842")
# https://github.com/OPM/opm-parser/blob/master/opm/parser/eclipse/Units/Units.hpp
# This file was moved from opm-core to opm-parser october 2016

View File

@ -22,6 +22,5 @@ python/lib64
scratch.sparsebundle
*.iml
*.DS_Store
__ert_lib_path.py
__ert_lib_info.py
__ecl_lib_path.py
__ecl_lib_info.py

View File

@ -129,17 +129,6 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin)
if (BUILD_SHARED_LIBS)
set( LIBRARY_TYPE SHARED )
else()
set( LIBRARY_TYPE STATIC )
if (BUILD_ERT)
message(FATAL_ERROR "The full ERT application must be built with shared libraries")
endif()
if (BUILD_PYTHON)
message(FATAL_ERROR "The Python wrappers require shared libraries")
endif()
endif()
if (MSVC)
add_definitions( -D__func__="\\"????\\"")
@ -179,12 +168,14 @@ endif()
include_directories( ${PROJECT_SOURCE_DIR}/libecl_well/include )
add_subdirectory( libecl_well )
if (BUILD_PYTHON)
if (ERT_WINDOWS)
message(STATUS "Python is not supported on Windows")
message(WARNING "Python is not supported on Windows")
set( BUILD_PYTHON OFF )
else()
include(cmake/python.cmake2)
# If finding the Python interpreter and required packages
# fails in the python/CMakeLists.txt file the BUILD_PYTHON
# will be set to OFF.
add_subdirectory( python )
if(ERT_DOC)
@ -193,3 +184,16 @@ if (BUILD_PYTHON)
endif()
endif()
if (BUILD_PYTHON)
if (NOT ${BUILD_SHARED_LIBS})
message(FATAL_ERROR "The Python wrappers require shared libraries")
endif()
endif()
configure_file( cmake/libecl-config.cmake.in libecl-config.cmake @ONLY)
configure_file( cmake/libecl-config-version.cmake.in libecl-config-version.cmake @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libecl-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/libecl-config-version.cmake
DESTINATION lib/libecl )

View File

@ -131,6 +131,7 @@ filesystem. One level above the toplevel source directory is a practical choice.
ccmake <path/to/directory/containing/CMakeLists.txt>
```
Go through several 'configure' steps with CMake and generate native build files.
3. Exit ccmake and invoke the native build system, i.e. ordinarily 'make' on
Linux.
4. Subsequent builds can be performed using just the native make command, as in

View File

@ -1,35 +0,0 @@
#!/usr/bin/env python
import py_compile
import os
import os.path
import sys
# Small 'python compiler' used in the build system for ert. The
# commandline arguments should be:
#
# cmake_pyc.py src1.py src2.py src3.py /path/to/pyc/files
#
# The input source files can contain a path component like
# path/src1.py, but the path will not be recreated in the target
# domain.
def compile_file(src_file , target_file):
path = os.path.dirname( target_file )
if not os.path.exists( path ):
os.makedirs( path )
try:
py_compile.compile( src_file , cfile = target_file , doraise = True)
except Exception as error:
sys.exit(str(error))
target_path = sys.argv[-1]
for src_file in sys.argv[1:-1]:
compile_file( src_file , "%s/%sc" % (target_path , os.path.basename(src_file)))
sys.exit(0)

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
import py_compile
import os
import os.path
import sys
import shutil
src_file = sys.argv[1]
target_file = sys.argv[2]
(target_path , tail) = os.path.split( target_file )
if not os.path.exists( target_path ):
try:
os.makedirs( target_path )
except:
# When running with make -j 4 there might be a race to create this directory.
pass
shutil.copyfile( src_file , target_file )
shutil.copystat( src_file , target_file )
try:
py_compile.compile( target_file , doraise = True)
except Exception as error:
sys.exit("py_compile(%s) failed:%s" % (target_file , error))
sys.exit(0)

View File

@ -1,20 +0,0 @@
#!/usr/bin/env python
import py_compile
import os
import sys
import os.path
# Small 'python compiler' used in the build system for ert.
for file in sys.argv[1:]:
try:
py_compile.compile( file , doraise = True )
except Exception as error:
sys.exit("py_compile(%s) failed:%s" % (file , error))
sys.exit(0)

View File

@ -1,35 +0,0 @@
#!/usr/bin/env python
import py_compile
import os
import sys
import os.path
# Small 'python compiler' used in the build system for ert. The
# commandline argument should be the top level name of directory
# containing python source code. The 'compiler' will walk through the
# tree and in-place compile all the python files.
root_path = sys.argv[1]
for (root , dir_list , file_list) in os.walk( root_path ):
for file in file_list:
full_path = os.path.join( root , file )
(tmp , ext) = os.path.splitext( full_path )
if ext == ".py":
py_file = full_path
pyc_file = full_path + "c"
if os.path.exists( pyc_file ):
os.unlink( pyc_file )
try:
print "Compiling: %s" % py_file
py_compile.compile( py_file , doraise = True )
except Exception as error:
sys.exit("py_compile(%s) failed:%s" % (py_file , error))
sys.exit(0)

View File

@ -0,0 +1,14 @@
set(PACKAGE_VERSION @ERT_VERSION_MAJOR@.@ERT_VERSION_MINOR@.@ERT_VERSION_PATCH@)
set(PACKAGE_VERSION_MAJOR @ERT_VERSION_MAJOR@)
set(PACKAGE_VERSION_MINOR @ERT_VERSION_MINOR@)
set(PACKAGE_VERSION_PATCH @ERT_VERSION_MICRO@)
set(libecl_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include)
set(libecl_LIBRARIES -lecl_well -lecl -lert_geometry -lert_util)
link_directories( @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ )
include_directories( @CMAKE_INSTALL_PREFIX@/include )
set( CMAKE_MODULE_PATH @CMAKE_INSTALL_PREFIX@/share/cmake/Modules ${CMAKE_MODULE_PATH})
if (@BUILD_PYTHON@)
set(libecl_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ )
endif()

View File

@ -0,0 +1,10 @@
set(libecl_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include)
set(libecl_LIBRARIES -lecl_well -lecl -lert_geometry -lert_util)
set( CMAKE_MODULE_PATH @CMAKE_INSTALL_PREFIX@/share/cmake/Modules ${CMAKE_MODULE_PATH})
link_directories( @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ )
include_directories( @CMAKE_INSTALL_PREFIX@/include )
if (@BUILD_PYTHON@)
set(libecl_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ )
endif()

View File

@ -1,25 +0,0 @@
macro(add_python_target tgt PYTHON_INSTALL_PATH)
SET(OUT_FILES "")
foreach(file ${python_source_files})
set(OUT ${CMAKE_CURRENT_BINARY_DIR}/${file}.pyc)
list(APPEND OUT_FILES ${OUT})
#------------------------------------------------------
ADD_CUSTOM_COMMAND(
OUTPUT ${OUT}
COMMAND ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PATH}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py)
#------------------------------------------------------
if (INSTALL_ERT)
install(FILES ${PROJECT_BINARY_DIR}/${PYTHON}/${file}.pyc DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PATH})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file}.py DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PATH})
endif()
endforeach(file)
list(REMOVE_DUPLICATES OUT_FILES)
ADD_CUSTOM_TARGET(
${tgt} ALL DEPENDS ${OUT_FILES})
endmacro()

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
from ert.ecl import EclSum
from ecl.ecl import EclSum
def writeDiff(filename, vector1, vector2):
with open(filename, "w") as f:

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
from ert.ecl import EclSum
from ecl.ecl import EclSum
OIL_PRICES = {"2010-01-01": 78.33,
"2010-02-01": 76.39,

View File

@ -3,8 +3,8 @@ from datetime import datetime
import os
import sys
from ert.ecl import EclSum, EclSumTStep
from ert.test import ExtendedTestCase
from ecl.ecl import EclSum, EclSumTStep
from ecl.test import ExtendedTestCase
try:
from synthesizer import OilSimulator

View File

@ -40,8 +40,7 @@ extern "C" {
typedef enum {
ECL_KW_READ_OK = 0,
ECL_KW_READ_FAIL = 1,
ECL_KW_READ_SKIP = 2
ECL_KW_READ_FAIL = 1
} ecl_read_status_enum;
/*
@ -111,6 +110,8 @@ extern "C" {
void ecl_kw_iset(ecl_kw_type *ecl_kw , int i , const void *iptr);
void ecl_kw_iset_char_ptr( ecl_kw_type * ecl_kw , int index, const char * s);
void ecl_kw_iset_string8(ecl_kw_type * ecl_kw , int index , const char *s8);
void ecl_kw_iset_string_ptr(ecl_kw_type*, int, const char*);
const char * ecl_kw_iget_string_ptr(const ecl_kw_type *, int);
const char * ecl_kw_iget_char_ptr( const ecl_kw_type * ecl_kw , int i);
void * ecl_kw_iget_ptr(const ecl_kw_type *, int);
int ecl_kw_get_size(const ecl_kw_type *);

View File

@ -414,6 +414,7 @@ values (2e20) are denoted with '*'.
#define MINISTEP_KW "MINISTEP"
#define STARTDAT_KW "STARTDAT" /* Intgere keyword containing day,month,year. */
#define WGNAMES_KW "WGNAMES" /* The names of wells/groups for the summary vectors. */
#define NAMES_KW "NAMES" /* Alias for WGNAMES_KW. */
#define KEYWORDS_KW "KEYWORDS" /* The variable type for the various summary vectors. */
#define UNITS_KW "UNITS" /* The units, i.e SM^3/DAY the summary vectors. */
#define DIMENS_KW "DIMENS" /* The dimensions of the grid - also used in the GRID files. */

View File

@ -38,6 +38,8 @@ extern "C" {
different code paths for C and C++.
*/
#define ECL_STRING8_LENGTH 8
#define ECL_TYPE_LENGTH 4
typedef enum {
ECL_CHAR_TYPE = 0,
@ -46,7 +48,7 @@ typedef enum {
ECL_INT_TYPE = 3,
ECL_BOOL_TYPE = 4,
ECL_MESS_TYPE = 5,
ECL_C010_TYPE = 6 // See comment immediately above about the limited support of this type.
ECL_STRING_TYPE = 7
} ecl_type_enum;
#define ECL_TYPE_ENUM_DEFS {.value = 0 , .name = "ECL_CHAR_TYPE"}, \
@ -54,9 +56,10 @@ typedef enum {
{.value = 2 , .name = "ECL_DOUBLE_TYPE"}, \
{.value = 3 , .name = "ECL_INT_TYPE"}, \
{.value = 4 , .name = "ECL_BOOL_TYPE"}, \
{.value = 5 , .name = "ECL_MESS_TYPE"}
{.value = 5 , .name = "ECL_MESS_TYPE"}, \
{.value = 7 , .name = "ECL_STRING_TYPE"}
#define ECL_TYPE_ENUM_SIZE 6
#define ECL_TYPE_ENUM_SIZE 7
/*
Character data in ECLIPSE files comes as an array of fixed-length
@ -77,13 +80,13 @@ typedef enum {
#ifdef __cplusplus
struct ecl_type_struct {
const ecl_type_enum type;
const size_t element_size;
const ecl_type_enum type;
const size_t element_size;
ecl_type_struct( ecl_type_enum t, size_t es) :
type( t ),
element_size( es )
{}
ecl_type_struct( ecl_type_enum t, size_t es) :
type( t ),
element_size( es )
{}
};
#define ECL_INT ecl_data_type( ECL_INT_TYPE, sizeof(int))
@ -92,13 +95,13 @@ struct ecl_type_struct {
#define ECL_BOOL ecl_data_type( ECL_BOOL_TYPE, sizeof(int))
#define ECL_CHAR ecl_data_type( ECL_CHAR_TYPE, ECL_STRING8_LENGTH + 1)
#define ECL_MESS ecl_data_type( ECL_MESS_TYPE, 0)
#define ECL_C010 ecl_data_type( ECL_C010_TYPE . ECL_STRING10_LENGTH + 1)
#define ECL_STRING(size) ecl_data_type(ECL_STRING_TYPE, size + 1)
#else
struct ecl_type_struct {
const ecl_type_enum type;
const size_t element_size;
const ecl_type_enum type;
const size_t element_size;
};
#define ECL_CHAR (ecl_data_type) {.type = ECL_CHAR_TYPE, .element_size = ECL_STRING8_LENGTH + 1}
@ -107,26 +110,23 @@ struct ecl_type_struct {
#define ECL_DOUBLE (ecl_data_type) {.type = ECL_DOUBLE_TYPE, .element_size = sizeof(double)}
#define ECL_BOOL (ecl_data_type) {.type = ECL_BOOL_TYPE, .element_size = sizeof(int)}
#define ECL_MESS (ecl_data_type) {.type = ECL_MESS_TYPE, .element_size = 0}
#define ECL_C010 (ecl_data_type) {.type = ECL_C010_TYPE, .element_size = ECL_STRING10_LENGTH + 1}
#define ECL_STRING(size) (ecl_data_type) {.type = ECL_STRING_TYPE, .element_size = size + 1}
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ecl_type_struct ecl_data_type;
ecl_data_type ecl_type_create_from_name(const char *);
ecl_data_type ecl_type_create(const ecl_type_enum, const size_t);
ecl_data_type ecl_type_create_from_type(const ecl_type_enum);
ecl_type_enum ecl_type_get_type(const ecl_data_type);
const char * ecl_type_get_name(const ecl_data_type);
char * ecl_type_alloc_name(const ecl_data_type);
int ecl_type_get_sizeof_ctype(const ecl_data_type);
int ecl_type_get_sizeof_ctype_fortio(const ecl_data_type);
@ -134,14 +134,18 @@ int ecl_type_get_sizeof_ctype_fortio(const ecl_data_type);
bool ecl_type_is_equal(const ecl_data_type, const ecl_data_type);
bool ecl_type_is_numeric(const ecl_data_type);
bool ecl_type_is_alpha(const ecl_data_type);
bool ecl_type_is_char(const ecl_data_type);
bool ecl_type_is_int(const ecl_data_type);
bool ecl_type_is_float(const ecl_data_type);
bool ecl_type_is_double(const ecl_data_type);
bool ecl_type_is_mess(const ecl_data_type);
bool ecl_type_is_bool(const ecl_data_type);
bool ecl_type_is_C010(const ecl_data_type);
bool ecl_type_is_string(const ecl_data_type);
// Temporary fixup for OPM.
char * ecl_type_get_name(const ecl_data_type);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2017 Statoil ASA, Norway.
The file 'ecl_units.h' is part of ERT - Ensemble based Reservoir Tool.
ERT 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.
ERT 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.
*/
#ifndef ECL_UNITS_H
#define ECL_UNITS_H
#ifdef __cplusplus
extern "C" {
#endif
#define ECL_UNITS_CUBIC(x) ((x)*(x)*(x))
#define ECL_UNITS_MILLI(x) ((x)*0.001)
#define ECL_UNITS_MEGA(x) ((x)*1000000)
#define ECL_UNITS_LENGTH_INCH 0.0254
#define ECL_UNITS_LENGTH_FEET 12 * ECL_UNITS_LENGTH_INCH
#define ECL_UNITS_VOLUME_GALLON 231 * ECL_UNITS_CUBIC( ECL_UNITS_LENGTH_INCH )
#define ECL_UNITS_VOLUME_BARREL ECL_UNITS_VOLUME_GALLON * 42
#define ECL_UNITS_VOLUME_LITER 0.001
#define ECL_UNITS_VOLUME_MILLI_LITER ECL_UNITS_MILLI( ECL_UNITS_VOLUME_LITER )
#define ECL_UNITS_VOLUME_GAS_FIELD ECL_UNITS_MEGA( ECL_UNITS_CUBIC( ECL_UNITS_LENGTH_FEET ) )
#define ECL_UNITS_TIME_HOUR 3600
#define ECL_UNITS_TIME_DAY 24 * ECL_UNITS_TIME_HOUR
#ifdef __cplusplus
}
#endif
#endif

View File

@ -45,6 +45,7 @@ set( source_files
${ext_source})
set( header_files
ecl_units.h
ecl_rsthead.h
ecl_sum_tstep.h
ecl_rst_file.h
@ -95,7 +96,7 @@ if (ERT_USE_OPENMP)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}")
endif()
add_library( ecl ${LIBRARY_TYPE} ${source_files} )
add_library( ecl ${source_files} )
set_target_properties( ecl PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR})
if (USE_RUNPATH)
add_runpath( ecl )

View File

@ -539,13 +539,6 @@ static bool ecl_file_scan( ecl_file_type * ecl_file ) {
else
break;
}
if (read_status == ECL_KW_READ_SKIP) {
bool skip_ok = ecl_kw_fskip_data( work_kw , ecl_file->fortio );
fprintf(stderr,"** Warning: keyword %s is of type \'C010\' - will be skipped when loading file. skip_ok:%d\n" , ecl_kw_get_header( work_kw ) , skip_ok);
if (!skip_ok)
break;
}
}
}

View File

@ -358,10 +358,12 @@ void ecl_file_view_fprintf_kw_list(const ecl_file_view_type * ecl_file_view , FI
int i;
for (i=0; i < vector_get_size( ecl_file_view->kw_list ); i++) {
const ecl_file_kw_type * file_kw = vector_iget_const( ecl_file_view->kw_list , i );
char * type_name = ecl_type_alloc_name(ecl_file_kw_get_data_type(file_kw));
fprintf(stream , "%-8s %7d:%s\n",
ecl_file_kw_get_header( file_kw ) ,
ecl_file_kw_get_size( file_kw ) ,
ecl_type_get_name( ecl_file_kw_get_data_type( file_kw )));
type_name);
free(type_name);
}
}

View File

@ -5401,7 +5401,7 @@ static bool ecl_grid_get_property__(const ecl_grid_type * ecl_grid , const ecl_k
return false;
} else {
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_get_name( data_type ) , __func__);
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_alloc_name( data_type ) , __func__);
return false;
}
}
@ -5466,7 +5466,7 @@ double ecl_grid_get_property(const ecl_grid_type * ecl_grid , const ecl_kw_type
return -1; /* Tried to lookup an inactive cell. */
} else {
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_get_name( data_type ) , __func__);
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_alloc_name( data_type ) , __func__);
return -1;
}
}
@ -5517,7 +5517,7 @@ void ecl_grid_get_column_property(const ecl_grid_type * ecl_grid , const ecl_kw_
}
}
} else
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_get_name( data_type ) , __func__);
util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n",__func__ , ecl_type_alloc_name( data_type ) , __func__);
}

View File

@ -61,7 +61,6 @@ UTIL_IS_INSTANCE_FUNCTION(ecl_kw , ECL_KW_TYPE_ID )
#define BLOCKSIZE_NUMERIC 1000
#define BLOCKSIZE_CHAR 105
#define BLOCKSIZE_C010 105
@ -113,7 +112,6 @@ UTIL_IS_INSTANCE_FUNCTION(ecl_kw , ECL_KW_TYPE_ID )
*/
#define READ_FMT_CHAR "%8c"
#define READ_FMT_C010 "%10c"
#define READ_FMT_FLOAT "%gE"
#define READ_FMT_INT "%d"
#define READ_FMT_MESS "%8c"
@ -122,7 +120,6 @@ UTIL_IS_INSTANCE_FUNCTION(ecl_kw , ECL_KW_TYPE_ID )
#define WRITE_FMT_CHAR " '%-8s'"
#define WRITE_FMT_C010 " '%-10s'"
#define WRITE_FMT_INT " %11d"
#define WRITE_FMT_FLOAT " %11.8fE%+03d"
#define WRITE_FMT_DOUBLE " %17.14fD%+03d"
@ -161,75 +158,68 @@ UTIL_IS_INSTANCE_FUNCTION(ecl_kw , ECL_KW_TYPE_ID )
ecl_type_enum ecl_kw_get_type(const ecl_kw_type *);
void ecl_kw_set_data_type(ecl_kw_type * ecl_kw, ecl_data_type data_type);
static const char * get_read_fmt(const ecl_data_type data_type ) {
static char * alloc_read_fmt_string(const ecl_data_type ecl_type) {
return util_alloc_sprintf(
"%%%dc",
ecl_type_get_sizeof_ctype_fortio(ecl_type)
);
}
static char * alloc_read_fmt(const ecl_data_type data_type ) {
switch(ecl_type_get_type(data_type)) {
case(ECL_CHAR_TYPE):
return READ_FMT_CHAR;
break;
case(ECL_C010_TYPE):
return READ_FMT_C010;
break;
return util_alloc_string_copy(READ_FMT_CHAR);
case(ECL_INT_TYPE):
return READ_FMT_INT;
break;
return util_alloc_string_copy(READ_FMT_INT);
case(ECL_FLOAT_TYPE):
return READ_FMT_FLOAT;
break;
return util_alloc_string_copy(READ_FMT_FLOAT);
case(ECL_DOUBLE_TYPE):
return READ_FMT_DOUBLE;
break;
return util_alloc_string_copy(READ_FMT_DOUBLE);
case(ECL_BOOL_TYPE):
return READ_FMT_BOOL;
break;
return util_alloc_string_copy(READ_FMT_BOOL);
case(ECL_MESS_TYPE):
return READ_FMT_MESS;
break;
return util_alloc_string_copy(READ_FMT_MESS);
case(ECL_STRING_TYPE):
return alloc_read_fmt_string(data_type);
default:
util_abort("%s: invalid ecl_type:%d \n",__func__ , ecl_type_get_type(data_type));
util_abort("%s: invalid ecl_type:%s \n",__func__ , ecl_type_alloc_name(data_type));
return NULL;
}
}
static char * alloc_write_fmt_string(const ecl_data_type ecl_type) {
return util_alloc_sprintf(
" '%%-%ds'",
ecl_type_get_sizeof_ctype_fortio(ecl_type)
);
}
static const char * ecl_kw_get_write_fmt(const ecl_data_type data_type) {
static char * alloc_write_fmt(const ecl_data_type data_type) {
switch(ecl_type_get_type(data_type)) {
case(ECL_CHAR_TYPE):
return WRITE_FMT_CHAR;
break;
case(ECL_C010_TYPE):
return WRITE_FMT_C010;
break;
return util_alloc_string_copy(WRITE_FMT_CHAR);
case(ECL_INT_TYPE):
return WRITE_FMT_INT;
break;
return util_alloc_string_copy(WRITE_FMT_INT);
case(ECL_FLOAT_TYPE):
return WRITE_FMT_FLOAT;
break;
return util_alloc_string_copy(WRITE_FMT_FLOAT);
case(ECL_DOUBLE_TYPE):
return WRITE_FMT_DOUBLE;
break;
return util_alloc_string_copy(WRITE_FMT_DOUBLE);
case(ECL_BOOL_TYPE):
return WRITE_FMT_BOOL;
break;
return util_alloc_string_copy(WRITE_FMT_BOOL);
case(ECL_MESS_TYPE):
return WRITE_FMT_MESS;
break;
return util_alloc_string_copy(WRITE_FMT_MESS);
case(ECL_STRING_TYPE):
return alloc_write_fmt_string(data_type);
default:
util_abort("%s: invalid ecl_type:%d \n",__func__ , ecl_type_get_type(data_type));
util_abort("%s: invalid ecl_type: %s\n",__func__ , ecl_type_alloc_name(data_type));
return NULL;
}
}
static int get_blocksize( ecl_data_type data_type ) {
if (ecl_type_is_char(data_type))
if (ecl_type_is_alpha(data_type))
return BLOCKSIZE_CHAR;
if (ecl_type_is_mess(data_type))
return BLOCKSIZE_CHAR;
if (ecl_type_is_C010(data_type))
return BLOCKSIZE_C010;
return BLOCKSIZE_NUMERIC;
}
@ -238,24 +228,20 @@ static int get_columns(const ecl_data_type data_type) {
switch(ecl_type_get_type(data_type)) {
case(ECL_CHAR_TYPE):
return COLUMNS_CHAR;
break;
case(ECL_INT_TYPE):
return COLUMNS_INT;
break;
case(ECL_FLOAT_TYPE):
return COLUMNS_FLOAT;
break;
case(ECL_DOUBLE_TYPE):
return COLUMNS_DOUBLE;
break;
case(ECL_BOOL_TYPE):
return COLUMNS_BOOL;
break;
case(ECL_MESS_TYPE):
return COLUMNS_MESSAGE;
break;
case(ECL_STRING_TYPE):
return COLUMNS_CHAR; // TODO: Is this correct?
default:
util_abort("%s: invalid ecl_type:%d \n",__func__ , ecl_type_get_type(data_type));
util_abort("%s: invalid ecl_type: %s\n",__func__ , ecl_type_alloc_name(data_type));
return -1;
}
}
@ -535,17 +521,13 @@ ecl_kw_type * ecl_kw_alloc_new(const char * header , int size, ecl_data_type da
ecl_kw_type * ecl_kw_alloc( const char * header , int size , ecl_data_type data_type ) {
if (ecl_type_is_C010(data_type))
return NULL;
{
ecl_kw_type *ecl_kw;
ecl_kw_type *ecl_kw;
ecl_kw = ecl_kw_alloc_empty();
ecl_kw_initialize(ecl_kw , header , size , data_type);
ecl_kw_alloc_data(ecl_kw);
ecl_kw = ecl_kw_alloc_empty();
ecl_kw_initialize(ecl_kw , header , size , data_type);
ecl_kw_alloc_data(ecl_kw);
return ecl_kw;
}
return ecl_kw;
}
@ -812,6 +794,12 @@ const char * ecl_kw_iget_char_ptr( const ecl_kw_type * ecl_kw , int i) {
return ecl_kw_iget_ptr( ecl_kw , i );
}
const char * ecl_kw_iget_string_ptr( const ecl_kw_type * ecl_kw, int i) {
if (ecl_kw_get_type(ecl_kw) != ECL_STRING_TYPE)
util_abort("%s: Keyword: %s is wrong type - aborting \n",__func__ , ecl_kw_get_header8(ecl_kw));
return ecl_kw_iget_ptr( ecl_kw , i );
}
/**
This will set the elemnts of the ecl_kw data storage in index to
@ -864,6 +852,30 @@ void ecl_kw_iset_char_ptr( ecl_kw_type * ecl_kw , int index, const char * s) {
}
}
/**
* This function will verify that the given string is of approperiate length
* (0 <= lenght <= data_type.element_size). If so, the elements of @s will be
* written to the @ecl_kw string array starting at @index.
*/
void ecl_kw_iset_string_ptr( ecl_kw_type * ecl_kw, int index, const char * s) {
if(!ecl_type_is_alpha(ecl_kw_get_data_type(ecl_kw))) {
char * type_name = ecl_type_alloc_name(ecl_kw_get_data_type(ecl_kw));
util_abort("%s: Expected alphabetic data type (CHAR, CXXX or MESS), was %s\n", __func__, type_name);
}
size_t input_len = strlen(s);
size_t type_len = ecl_type_get_sizeof_ctype_fortio(ecl_kw_get_data_type(ecl_kw));
if(input_len > type_len)
util_abort("%s: String of length %d cannot hold input string of length %d\n", __func__, type_len, input_len);
char * ecl_string = (char *) ecl_kw_iget_ptr(ecl_kw, index);
for(int i = 0; i < input_len; ++i)
ecl_string[i] = s[i];
ecl_string[input_len] = '\0';
}
/**
This function will compare the string at position @index with the
@ -1078,7 +1090,7 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) {
const int blocksize = get_blocksize( ecl_kw->data_type );
if (fmt_file) {
const int blocks = ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1);
const char * read_fmt = get_read_fmt( ecl_kw->data_type );
char * read_fmt = alloc_read_fmt( ecl_kw->data_type );
FILE * stream = fortio_get_FILE(fortio);
int offset = 0;
int index = 0;
@ -1090,6 +1102,14 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) {
case(ECL_CHAR_TYPE):
ecl_kw_fscanf_qstring(&ecl_kw->data[offset] , read_fmt , 8, stream);
break;
case(ECL_STRING_TYPE):
ecl_kw_fscanf_qstring(
&ecl_kw->data[offset],
read_fmt,
ecl_type_get_sizeof_ctype_fortio(ecl_kw_get_data_type(ecl_kw)),
stream
);
break;
case(ECL_INT_TYPE):
{
int iread = fscanf(stream , read_fmt , (int *) &ecl_kw->data[offset]);
@ -1141,10 +1161,11 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) {
/* Skip the trailing newline */
fortio_fseek( fortio , 1 , SEEK_CUR);
free(read_fmt);
return true;
} else {
bool read_ok = true;
if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type)) {
if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type) || ecl_type_is_string(ecl_kw->data_type)) {
const int blocks = ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1);
int ib = 0;
while (true) {
@ -1157,9 +1178,11 @@ bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) {
int record_size = fortio_init_read(fortio);
if (record_size >= 0) {
int ir;
const int sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type);
const int sizeof_ctype_fortio = ecl_type_get_sizeof_ctype_fortio(ecl_kw->data_type);
for (ir = 0; ir < read_elm; ir++) {
util_fread( &ecl_kw->data[(ib * blocksize + ir) * ecl_kw_get_sizeof_ctype(ecl_kw)] , 1 , ECL_STRING8_LENGTH , stream , __func__);
ecl_kw->data[(ib * blocksize + ir) * ecl_kw_get_sizeof_ctype(ecl_kw) + ECL_STRING8_LENGTH] = null_char;
util_fread( &ecl_kw->data[(ib * blocksize + ir) * sizeof_ctype] , 1 , sizeof_ctype_fortio , stream , __func__);
ecl_kw->data[(ib * blocksize + ir) * sizeof_ctype + sizeof_ctype_fortio] = null_char;
}
read_ok = fortio_complete_read(fortio , record_size);
} else
@ -1228,31 +1251,27 @@ bool ecl_kw_fread_realloc_data(ecl_kw_type *ecl_kw, fortio_type *fortio) {
*/
bool ecl_kw_fskip_data__( ecl_data_type data_type , const int element_count , fortio_type * fortio) {
if (element_count <= 0)
return true;
bool fmt_file = fortio_fmt_file(fortio);
bool skip_ok = true;
if (element_count > 0) {
if (fmt_file) {
/* Formatted skipping actually involves reading the data - nice ??? */
ecl_kw_type * tmp_kw = ecl_kw_alloc_empty( );
ecl_kw_initialize( tmp_kw , "WORK" , element_count , data_type );
ecl_kw_alloc_data(tmp_kw);
ecl_kw_fread_data(tmp_kw , fortio);
ecl_kw_free( tmp_kw );
} else {
const int blocksize = get_blocksize( data_type );
const int block_count = element_count / blocksize + (element_count % blocksize == 0 ? 0 : 1);
if (fmt_file) {
/* Formatted skipping actually involves reading the data - nice ??? */
ecl_kw_type * tmp_kw = ecl_kw_alloc_empty( );
ecl_kw_initialize( tmp_kw , "WORK" , element_count , data_type );
ecl_kw_alloc_data(tmp_kw);
ecl_kw_fread_data(tmp_kw , fortio);
ecl_kw_free( tmp_kw );
} else {
const int blocksize = get_blocksize( data_type );
const int block_count = element_count / blocksize + (element_count % blocksize != 0);
int element_size = ecl_type_get_sizeof_ctype_fortio(data_type);
int element_size = ecl_type_get_sizeof_ctype(data_type);
if(ecl_type_is_char(data_type))
element_size = ECL_STRING8_LENGTH;
if(ecl_type_is_C010(data_type))
element_size = ECL_STRING10_LENGTH;
skip_ok = fortio_data_fskip(fortio, element_size, element_count, block_count);
}
if(!fortio_data_fskip(fortio, element_size, element_count, block_count))
return false;
}
return skip_ok;
return true;
}
@ -1289,51 +1308,47 @@ ecl_read_status_enum ecl_kw_fread_header(ecl_kw_type *ecl_kw , fortio_type * for
char ecl_type_str[ECL_TYPE_LENGTH + 1];
int record_size;
int size;
bool OK = true;
if (fmt_file) {
OK = ecl_kw_fscanf_qstring(header , "%8c" , 8 , stream);
if (OK) {
int read_count = fscanf(stream , "%d" , &size);
if (read_count == 1) {
ecl_kw_fscanf_qstring(ecl_type_str , "%4c" , 4 , stream);
fgetc(stream); /* Reading the trailing newline ... */
} else
util_abort("%s: reading failed - at end of file?\n",__func__);
}
} else {
header[ECL_STRING8_LENGTH] = null_char;
if(!ecl_kw_fscanf_qstring(header , "%8c" , 8 , stream))
return ECL_KW_READ_FAIL;
int read_count = fscanf(stream , "%d" , &size);
if (read_count != 1)
util_abort("%s: reading failed - at end of file?\n",__func__);
ecl_kw_fscanf_qstring(ecl_type_str , "%4c" , 4 , stream);
fgetc(stream); /* Reading the trailing newline ... */
}
else {
header[ECL_STRING8_LENGTH] = null_char;
ecl_type_str[ECL_TYPE_LENGTH] = null_char;
record_size = fortio_init_read(fortio);
if (record_size > 0) {
char buffer[ECL_KW_HEADER_DATA_SIZE];
size_t read_bytes = fread(buffer , 1 , ECL_KW_HEADER_DATA_SIZE , stream);
if (read_bytes == ECL_KW_HEADER_DATA_SIZE) {
memcpy( header , &buffer[0] , ECL_STRING8_LENGTH);
size = *( (int *) &buffer[ECL_STRING8_LENGTH] );
memcpy( ecl_type_str , &buffer[ECL_STRING8_LENGTH + sizeof(size)] , ECL_TYPE_LENGTH);
if (record_size <= 0)
return ECL_KW_READ_FAIL;
OK = fortio_complete_read(fortio , record_size);
} else
OK = false;
char buffer[ECL_KW_HEADER_DATA_SIZE];
size_t read_bytes = fread(buffer , 1 , ECL_KW_HEADER_DATA_SIZE , stream);
if (OK && ECL_ENDIAN_FLIP)
util_endian_flip_vector(&size , sizeof size , 1);
} else
OK = false;
if (read_bytes != ECL_KW_HEADER_DATA_SIZE)
return ECL_KW_READ_FAIL;
memcpy( header , &buffer[0] , ECL_STRING8_LENGTH);
size = *( (int *) &buffer[ECL_STRING8_LENGTH] );
memcpy( ecl_type_str , &buffer[ECL_STRING8_LENGTH + sizeof(size)] , ECL_TYPE_LENGTH);
if(!fortio_complete_read(fortio , record_size))
return ECL_KW_READ_FAIL;
if (ECL_ENDIAN_FLIP)
util_endian_flip_vector(&size , sizeof size , 1);
}
if (OK) {
ecl_data_type data_type = ecl_type_create_from_name( ecl_type_str );
ecl_kw_initialize( ecl_kw , header , size , data_type);
ecl_data_type data_type = ecl_type_create_from_name( ecl_type_str );
ecl_kw_initialize( ecl_kw , header , size , data_type);
if (ecl_type_is_C010(data_type))
return ECL_KW_READ_SKIP;
return ECL_KW_READ_OK;
} else
return ECL_KW_READ_FAIL;
return ECL_KW_READ_OK;
}
@ -1526,18 +1541,19 @@ static void ecl_kw_fwrite_data_unformatted( ecl_kw_type * ecl_kw , fortio_type *
for (block_nr = 0; block_nr < num_blocks; block_nr++) {
int this_blocksize = util_int_min((block_nr + 1)*blocksize , ecl_kw->size) - block_nr*blocksize;
if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type)) {
if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_mess(ecl_kw->data_type) || ecl_type_is_string(ecl_kw->data_type)) {
/*
Due to the terminating \0 characters there is not a
continous file/memory mapping - the \0 characters arel
skipped.
*/
FILE *stream = fortio_get_FILE(fortio);
int record_size = this_blocksize * ECL_STRING8_LENGTH; /* The total size in bytes of the record written by the fortio layer. */
int i;
FILE *stream = fortio_get_FILE(fortio);
int word_size = ecl_type_get_sizeof_ctype_fortio(ecl_kw->data_type);
int record_size = this_blocksize * word_size; /* The total size in bytes of the record written by the fortio layer. */
int i;
fortio_init_write(fortio , record_size );
for (i = 0; i < this_blocksize; i++)
fwrite(&ecl_kw->data[(block_nr * blocksize + i) * ecl_kw_get_sizeof_ctype(ecl_kw)] , 1 , ECL_STRING8_LENGTH , stream);
fwrite(&ecl_kw->data[(block_nr * blocksize + i) * ecl_kw_get_sizeof_ctype(ecl_kw)] , 1 , word_size , stream);
fortio_complete_write(fortio , record_size);
} else {
int record_size = this_blocksize * ecl_kw_get_sizeof_ctype(ecl_kw); /* The total size in bytes of the record written by the fortio layer. */
@ -1595,7 +1611,7 @@ static void ecl_kw_fwrite_data_formatted( ecl_kw_type * ecl_kw , fortio_type * f
FILE * stream = fortio_get_FILE( fortio );
const int blocksize = get_blocksize( ecl_kw->data_type );
const int columns = get_columns( ecl_kw->data_type );
const char * write_fmt = ecl_kw_get_write_fmt( ecl_kw->data_type );
char * write_fmt = alloc_write_fmt( ecl_kw->data_type );
const int num_blocks = ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1);
int block_nr;
@ -1613,7 +1629,7 @@ static void ecl_kw_fwrite_data_formatted( ecl_kw_type * ecl_kw , fortio_type * f
case(ECL_CHAR_TYPE):
fprintf(stream , write_fmt , data_ptr);
break;
case(ECL_C010_TYPE):
case(ECL_STRING_TYPE):
fprintf(stream , write_fmt , data_ptr);
break;
case(ECL_INT_TYPE):
@ -1651,6 +1667,8 @@ static void ecl_kw_fwrite_data_formatted( ecl_kw_type * ecl_kw , fortio_type * f
fprintf(stream , "\n");
}
}
free(write_fmt);
}
}
@ -1670,8 +1688,10 @@ void ecl_kw_fwrite_data(const ecl_kw_type *_ecl_kw , fortio_type *fortio) {
void ecl_kw_fwrite_header(const ecl_kw_type *ecl_kw , fortio_type *fortio) {
FILE *stream = fortio_get_FILE(fortio);
bool fmt_file = fortio_fmt_file(fortio);
char * type_name = ecl_type_alloc_name(ecl_kw->data_type);
if (fmt_file)
fprintf(stream , WRITE_HEADER_FMT , ecl_kw->header8 , ecl_kw->size , ecl_type_get_name( ecl_kw->data_type ));
fprintf(stream , WRITE_HEADER_FMT , ecl_kw->header8 , ecl_kw->size , type_name);
else {
int size = ecl_kw->size;
if (ECL_ENDIAN_FLIP)
@ -1681,11 +1701,13 @@ void ecl_kw_fwrite_header(const ecl_kw_type *ecl_kw , fortio_type *fortio) {
fwrite(ecl_kw->header8 , sizeof(char) , ECL_STRING8_LENGTH , stream);
fwrite(&size , sizeof(int) , 1 , stream);
fwrite(ecl_type_get_name( ecl_kw->data_type ) , sizeof(char) , ECL_TYPE_LENGTH , stream);
fwrite(type_name , sizeof(char) , ECL_TYPE_LENGTH , stream);
fortio_complete_write(fortio , ECL_KW_HEADER_DATA_SIZE);
}
free(type_name);
}
@ -1892,9 +1914,11 @@ void ecl_kw_fread_double_param(const char * filename , bool fmt_file , double *
void ecl_kw_summarize(const ecl_kw_type * ecl_kw) {
char * type_name = ecl_type_alloc_name(ecl_kw->data_type);
printf("%8s %10d:%4s \n",ecl_kw_get_header8(ecl_kw),
ecl_kw_get_size(ecl_kw),
ecl_type_get_name( ecl_kw->data_type));
type_name);
free(type_name);
}
@ -2109,7 +2133,7 @@ void ecl_kw_inplace_add_indexed( ecl_kw_type * target_kw , const int_vector_type
ecl_kw_inplace_add_indexed_int( target_kw , index_set , add_kw );
break;
default:
util_abort("%s: inplace add not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace add not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2147,7 +2171,7 @@ void ecl_kw_inplace_add( ecl_kw_type * target_kw , const ecl_kw_type * add_kw) {
ecl_kw_inplace_add_int( target_kw , add_kw );
break;
default:
util_abort("%s: inplace add not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace add not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2186,7 +2210,7 @@ void ecl_kw_inplace_sub( ecl_kw_type * target_kw , const ecl_kw_type * sub_kw) {
ecl_kw_inplace_sub_int( target_kw , sub_kw );
break;
default:
util_abort("%s: inplace sub not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace sub not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2226,7 +2250,7 @@ void ecl_kw_inplace_sub_indexed( ecl_kw_type * target_kw , const int_vector_type
ecl_kw_inplace_sub_indexed_int( target_kw , index_set , sub_kw );
break;
default:
util_abort("%s: inplace sub not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace sub not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2261,7 +2285,7 @@ void ecl_kw_inplace_abs( ecl_kw_type * kw ) {
ecl_kw_inplace_abs_int( kw );
break;
default:
util_abort("%s: inplace abs not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(kw) ));
util_abort("%s: inplace abs not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(kw) ));
}
}
@ -2298,7 +2322,7 @@ void ecl_kw_inplace_mul( ecl_kw_type * target_kw , const ecl_kw_type * mul_kw) {
ecl_kw_inplace_mul_int( target_kw , mul_kw );
break;
default:
util_abort("%s: inplace mul not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace mul not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2338,7 +2362,7 @@ void ecl_kw_inplace_mul_indexed( ecl_kw_type * target_kw , const int_vector_type
ecl_kw_inplace_mul_indexed_int( target_kw , index_set , mul_kw );
break;
default:
util_abort("%s: inplace mul not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace mul not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2376,7 +2400,7 @@ void ecl_kw_inplace_div( ecl_kw_type * target_kw , const ecl_kw_type * div_kw) {
ecl_kw_inplace_div_int( target_kw , div_kw );
break;
default:
util_abort("%s: inplace div not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace div not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2417,7 +2441,7 @@ void ecl_kw_inplace_div_indexed( ecl_kw_type * target_kw , const int_vector_type
ecl_kw_inplace_div_indexed_int( target_kw , index_set , div_kw );
break;
default:
util_abort("%s: inplace div not implemented for type:%s \n",__func__ , ecl_type_get_name( ecl_kw_get_data_type(target_kw) ));
util_abort("%s: inplace div not implemented for type:%s \n",__func__ , ecl_type_alloc_name( ecl_kw_get_data_type(target_kw) ));
}
}
@ -2673,7 +2697,7 @@ static void ecl_kw_fprintf_data_bool( const ecl_kw_type * ecl_kw , const char *
}
static void ecl_kw_fprintf_data_char( const ecl_kw_type * ecl_kw , const char * fmt , FILE * stream) {
static void ecl_kw_fprintf_data_string( const ecl_kw_type * ecl_kw , const char * fmt , FILE * stream) {
int i;
for (i=0; i < ecl_kw->size; i++)
fprintf(stream , fmt , &ecl_kw->data[ i * ecl_kw_get_sizeof_ctype(ecl_kw)]);
@ -2689,8 +2713,8 @@ void ecl_kw_fprintf_data( const ecl_kw_type * ecl_kw , const char * fmt , FILE *
ecl_kw_fprintf_data_int( ecl_kw , fmt , stream );
else if (ecl_type_is_bool(ecl_kw->data_type))
ecl_kw_fprintf_data_bool( ecl_kw , fmt , stream );
else if (ecl_type_is_char(ecl_kw->data_type))
ecl_kw_fprintf_data_char( ecl_kw , fmt , stream );
else if (ecl_type_is_char(ecl_kw->data_type) || ecl_type_is_string(ecl_kw->data_type))
ecl_kw_fprintf_data_string( ecl_kw , fmt , stream );
}

View File

@ -413,7 +413,7 @@ static char * fscanf_alloc_grdecl_data( const char * header , bool strict , ecl_
value_ptr = &value;
} else
util_abort("%s: sorry type:%s not supported \n",__func__ , ecl_type_get_name(data_type));
util_abort("%s: sorry type:%s not supported \n",__func__ , ecl_type_alloc_name(data_type));
/*
Removing this warning on user request:

View File

@ -233,3 +233,13 @@ void ecl_rsthead_fprintf_struct( const ecl_rsthead_type * header , FILE * stream
void ecl_rsthead_free( ecl_rsthead_type * rsthead ) {
free( rsthead );
}
int ecl_rsthead_get_nxconz( const ecl_rsthead_type * rsthead ) {
return rsthead->nxconz;
}
int ecl_rsthead_get_ncwmax( const ecl_rsthead_type * rsthead ) {
return rsthead->ncwmax;
}

View File

@ -234,11 +234,14 @@ static const char* special_vars[] = {"NEWTON",
this simple list.
*/
static const char* smspec_required_keywords[] = {WGNAMES_KW,
KEYWORDS_KW,
STARTDAT_KW,
UNITS_KW,
DIMENS_KW};
static const size_t num_req_keywords = 5;
static const char* smspec_required_keywords[] = {
WGNAMES_KW,
KEYWORDS_KW,
STARTDAT_KW,
UNITS_KW,
DIMENS_KW
};
/*****************************************************************/
@ -333,6 +336,21 @@ void ecl_smspec_lock( ecl_smspec_type * smspec ) {
smspec->locked = true;
}
/**
* Returns an ecl data type for which all names will fit. If the maximum name
* length is at most 8, an ECL_CHAR is returned and otherwise a large enough
* ECL_STRING.
*/
static ecl_data_type get_wgnames_type(const ecl_smspec_type * smspec) {
size_t max_len = 0;
for(int i = 0; i < ecl_smspec_num_nodes(smspec); ++i) {
const char * name = smspec_node_get_wgname(ecl_smspec_iget_node(smspec, i));
if(name != NULL)
max_len = util_size_t_max(max_len, strlen(name));
}
return max_len <= 8 ? ECL_CHAR : ECL_STRING(max_len);
}
// DIMENS
// KEYWORDS
@ -371,10 +389,18 @@ static void ecl_smspec_fortio_fwrite( const ecl_smspec_type * smspec , fortio_ty
{
ecl_kw_type * keywords_kw = ecl_kw_alloc( KEYWORDS_KW , num_nodes , ECL_CHAR );
ecl_kw_type * wgnames_kw = ecl_kw_alloc( WGNAMES_KW , num_nodes , ECL_CHAR );
ecl_kw_type * units_kw = ecl_kw_alloc( UNITS_KW , num_nodes , ECL_CHAR );
ecl_kw_type * nums_kw = NULL;
// If the names_type is an ECL_STRING we expect this to be an INTERSECT
// summary, otherwise an ECLIPSE summary.
ecl_data_type names_type = get_wgnames_type(smspec);
ecl_kw_type * wgnames_kw = ecl_kw_alloc(
ecl_type_is_char(names_type) ? WGNAMES_KW : NAMES_KW,
num_nodes,
names_type
);
if (smspec->need_nums)
nums_kw = ecl_kw_alloc( NUMS_KW , num_nodes , ECL_INT);
{
@ -403,7 +429,7 @@ static void ecl_smspec_fortio_fwrite( const ecl_smspec_type * smspec , fortio_ty
if (smspec_node_get_var_type( smspec_node ) == ECL_SMSPEC_INVALID_VAR) {
ecl_kw_iset_string8( keywords_kw , i , "WWCT" );
ecl_kw_iset_string8( units_kw , i , "????????");
ecl_kw_iset_string8( wgnames_kw , i , DUMMY_WELL);
ecl_kw_iset_string_ptr( wgnames_kw , i , DUMMY_WELL);
} else {
ecl_kw_iset_string8( keywords_kw , i , smspec_node_get_keyword( smspec_node ));
ecl_kw_iset_string8( units_kw , i , smspec_node_get_unit( smspec_node ));
@ -411,7 +437,7 @@ static void ecl_smspec_fortio_fwrite( const ecl_smspec_type * smspec , fortio_ty
const char * wgname = DUMMY_WELL;
if (smspec_node_get_wgname( smspec_node ) != NULL)
wgname = smspec_node_get_wgname( smspec_node );
ecl_kw_iset_string8( wgnames_kw , i , wgname);
ecl_kw_iset_string_ptr( wgnames_kw , i , wgname);
}
}
@ -958,7 +984,7 @@ bool ecl_smspec_equal( const ecl_smspec_type * self , const ecl_smspec_type * ot
static void ecl_smspec_load_restart( ecl_smspec_type * ecl_smspec , const ecl_file_type * header ) {
if (ecl_file_has_kw( header , RESTART_KW )) {
const ecl_kw_type * restart_kw = ecl_file_iget_kw( header , 0 );
const ecl_kw_type * restart_kw = ecl_file_iget_named_kw(header, RESTART_KW , 0);
char tmp_base[73]; /* To accomodate a maximum of 9 items which consist of 8 characters each. */
char * restart_base;
int i;
@ -1058,16 +1084,25 @@ const int_vector_type * ecl_smspec_get_index_map( const ecl_smspec_type * smspec
return smspec->index_map;
}
/**
* This function is to support the NAMES alias for WGNAMES. If similar
* situations occur in the future, this is a sane starting point for general
* support.
*/
static const char * get_active_keyword_alias(ecl_file_type * header, const char * keyword) {
if (strcmp(keyword, WGNAMES_KW) == 0 || strcmp(keyword, NAMES_KW) == 0)
return ecl_file_has_kw(header, WGNAMES_KW) ? WGNAMES_KW : NAMES_KW;
return keyword;
}
static bool ecl_smspec_check_header( ecl_file_type * header ) {
bool OK = true;
int num_required = sizeof( smspec_required_keywords ) / sizeof( smspec_required_keywords[0] );
int i;
for (i=0; i < num_required; i++) {
if (!ecl_file_has_kw( header , smspec_required_keywords[i])) {
OK = false;
break;
}
for (int i=0; i < num_req_keywords && OK; i++) {
OK &= ecl_file_has_kw(
header,
get_active_keyword_alias(header, smspec_required_keywords[i])
);
}
return OK;
@ -1077,16 +1112,18 @@ static bool ecl_smspec_check_header( ecl_file_type * header ) {
static bool ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * header_file , bool include_restart) {
ecl_file_type * header = ecl_file_open( header_file , 0);
if (header && ecl_smspec_check_header( header )) {
ecl_kw_type *wells = ecl_file_iget_named_kw(header, WGNAMES_KW , 0);
ecl_kw_type *keywords = ecl_file_iget_named_kw(header, KEYWORDS_KW , 0);
ecl_kw_type *startdat = ecl_file_iget_named_kw(header, STARTDAT_KW , 0);
ecl_kw_type *units = ecl_file_iget_named_kw(header, UNITS_KW , 0);
ecl_kw_type *dimens = ecl_file_iget_named_kw(header, DIMENS_KW , 0);
ecl_kw_type *nums = NULL;
ecl_kw_type *lgrs = NULL;
ecl_kw_type *numlx = NULL;
ecl_kw_type *numly = NULL;
ecl_kw_type *numlz = NULL;
const char * names_alias = get_active_keyword_alias(header, WGNAMES_KW);
ecl_kw_type *wells = ecl_file_iget_named_kw(header, names_alias , 0);
ecl_kw_type *keywords = ecl_file_iget_named_kw(header, KEYWORDS_KW , 0);
ecl_kw_type *startdat = ecl_file_iget_named_kw(header, STARTDAT_KW , 0);
ecl_kw_type *units = ecl_file_iget_named_kw(header, UNITS_KW , 0);
ecl_kw_type *dimens = ecl_file_iget_named_kw(header, DIMENS_KW , 0);
ecl_kw_type *nums = NULL;
ecl_kw_type *lgrs = NULL;
ecl_kw_type *numlx = NULL;
ecl_kw_type *numly = NULL;
ecl_kw_type *numlz = NULL;
int params_index;
ecl_smspec->num_regions = 0;
if (startdat == NULL)

View File

@ -18,6 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <ert/util/util.h>
#include <ert/ecl/ecl_type.h>
@ -27,71 +28,96 @@
types.
*/
#define ECL_TYPE_NAME_CHAR "CHAR"
#define ECL_TYPE_NAME_C010 "C010"
#define ECL_TYPE_NAME_FLOAT "REAL"
#define ECL_TYPE_NAME_INT "INTE"
#define ECL_TYPE_NAME_DOUBLE "DOUB"
#define ECL_TYPE_NAME_BOOL "LOGI"
#define ECL_TYPE_NAME_MESSAGE "MESS"
static char * alloc_string_name(const ecl_data_type ecl_type) {
return util_alloc_sprintf(
"C%03d",
ecl_type_get_sizeof_ctype_fortio(ecl_type)
);
}
static bool is_ecl_string_name(const char * type_name) {
return (type_name[0] == 'C' &&
isdigit(type_name[1]) &&
isdigit(type_name[2]) &&
isdigit(type_name[3])
);
}
static size_t get_ecl_string_length(const char * type_name) {
if(!is_ecl_string_name(type_name))
util_abort("%s: Expected eclipse string (CXXX), received %s\n",
__func__, type_name);
return atoi(type_name+1);
}
ecl_data_type ecl_type_create(const ecl_type_enum type, const size_t element_size) {
ecl_data_type ecl_type = ecl_type_create_from_type(type);
ecl_data_type ecl_type = (
type == ECL_STRING_TYPE ?
ECL_STRING(element_size) :
ecl_type_create_from_type(type)
);
if(ecl_type.element_size != element_size)
util_abort(
"%s: element_size mismatch for type %d, was: %d, expected: %d\n",
__func__, type, element_size, ecl_type.element_size);
if(ecl_type_get_sizeof_ctype_fortio(ecl_type) != element_size)
util_abort(
"%s: element_size mismatch for type %d, was: %d, expected: %d\n",
__func__, type,
element_size, ecl_type_get_sizeof_ctype_fortio(ecl_type)
);
return ecl_type;
return ecl_type;
}
ecl_data_type ecl_type_create_from_type(const ecl_type_enum type) {
switch(type) {
case(ECL_CHAR_TYPE):
return ECL_CHAR;
case(ECL_INT_TYPE):
return ECL_INT;
case(ECL_FLOAT_TYPE):
return ECL_FLOAT;
case(ECL_DOUBLE_TYPE):
return ECL_DOUBLE;
case(ECL_BOOL_TYPE):
return ECL_BOOL;
case(ECL_MESS_TYPE):
return ECL_MESS;
case(ECL_C010_TYPE):
return ECL_C010;
default:
util_abort("%s: invalid ecl_type: %d\n", __func__, type);
return ECL_INT; /* Dummy */
}
switch(type) {
case(ECL_CHAR_TYPE):
return ECL_CHAR;
case(ECL_INT_TYPE):
return ECL_INT;
case(ECL_FLOAT_TYPE):
return ECL_FLOAT;
case(ECL_DOUBLE_TYPE):
return ECL_DOUBLE;
case(ECL_BOOL_TYPE):
return ECL_BOOL;
case(ECL_MESS_TYPE):
return ECL_MESS;
case(ECL_STRING_TYPE):
util_abort("%s: Variable length string type cannot be created"
" from type alone!\n" , __func__);
return ECL_STRING(0); /* Dummy */
default:
util_abort("%s: invalid ecl_type: %d\n", __func__, type);
return ECL_INT; /* Dummy */
}
}
ecl_type_enum ecl_type_get_type(const ecl_data_type ecl_type) {
return ecl_type.type;
}
size_t ecl_type_get_element_size(const ecl_data_type ecl_type) {
return ecl_type.element_size;
}
const char * ecl_type_get_name(const ecl_data_type ecl_type) {
char * ecl_type_alloc_name(const ecl_data_type ecl_type) {
switch (ecl_type.type) {
case(ECL_CHAR_TYPE):
return ECL_TYPE_NAME_CHAR ;
case(ECL_C010_TYPE):
return ECL_TYPE_NAME_C010;
return util_alloc_string_copy(ECL_TYPE_NAME_CHAR);
case(ECL_STRING_TYPE):
return alloc_string_name(ecl_type);
case(ECL_FLOAT_TYPE):
return ECL_TYPE_NAME_FLOAT;
return util_alloc_string_copy(ECL_TYPE_NAME_FLOAT);
case(ECL_DOUBLE_TYPE):
return ECL_TYPE_NAME_DOUBLE;
return util_alloc_string_copy(ECL_TYPE_NAME_DOUBLE);
case(ECL_INT_TYPE):
return ECL_TYPE_NAME_INT;
return util_alloc_string_copy(ECL_TYPE_NAME_INT);
case(ECL_BOOL_TYPE):
return ECL_TYPE_NAME_BOOL;
return util_alloc_string_copy(ECL_TYPE_NAME_BOOL);
case(ECL_MESS_TYPE):
return ECL_TYPE_NAME_MESSAGE;
return util_alloc_string_copy(ECL_TYPE_NAME_MESSAGE);
default:
util_abort("Internal error in %s - internal eclipse_type: %d not recognized - aborting \n",__func__ , ecl_type.type);
return NULL; /* Dummy */
@ -107,8 +133,8 @@ ecl_data_type ecl_type_create_from_name( const char * type_name ) {
return ECL_DOUBLE;
else if (strncmp( type_name , ECL_TYPE_NAME_CHAR , ECL_TYPE_LENGTH) == 0)
return ECL_CHAR;
else if (strncmp( type_name , ECL_TYPE_NAME_C010 , ECL_TYPE_LENGTH) == 0)
return ECL_C010;
else if (is_ecl_string_name(type_name))
return ECL_STRING(get_ecl_string_length(type_name));
else if (strncmp( type_name , ECL_TYPE_NAME_MESSAGE , ECL_TYPE_LENGTH) == 0)
return ECL_MESS;
else if (strncmp( type_name , ECL_TYPE_NAME_BOOL , ECL_TYPE_LENGTH) == 0)
@ -121,52 +147,64 @@ ecl_data_type ecl_type_create_from_name( const char * type_name ) {
int ecl_type_get_sizeof_ctype_fortio(const ecl_data_type ecl_type) {
if(ecl_type_is_char(ecl_type) || ecl_type_is_C010(ecl_type))
if(ecl_type_is_char(ecl_type) || ecl_type_is_string(ecl_type))
return ecl_type.element_size - 1;
else
return ecl_type_get_sizeof_ctype(ecl_type);
}
int ecl_type_get_sizeof_ctype(const ecl_data_type ecl_type) {
return ecl_type.element_size;
return ecl_type.element_size;
}
bool ecl_type_is_numeric(const ecl_data_type ecl_type) {
return (ecl_type_is_int(ecl_type) ||
ecl_type_is_float(ecl_type) ||
ecl_type_is_double(ecl_type));
return (ecl_type_is_int(ecl_type) ||
ecl_type_is_float(ecl_type) ||
ecl_type_is_double(ecl_type));
}
bool ecl_type_is_alpha(const ecl_data_type ecl_type) {
return (ecl_type_is_char(ecl_type) ||
ecl_type_is_mess(ecl_type) ||
ecl_type_is_string(ecl_type));
}
bool ecl_type_is_equal(const ecl_data_type ecl_type1,
const ecl_data_type ecl_type2) {
return (ecl_type1.type == ecl_type2.type &&
ecl_type1.element_size == ecl_type2.element_size);
return (ecl_type1.type == ecl_type2.type &&
ecl_type1.element_size == ecl_type2.element_size);
}
bool ecl_type_is_char(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_CHAR_TYPE);
return (ecl_type.type == ECL_CHAR_TYPE);
}
bool ecl_type_is_int(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_INT_TYPE);
return (ecl_type.type == ECL_INT_TYPE);
}
bool ecl_type_is_float(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_FLOAT_TYPE);
return (ecl_type.type == ECL_FLOAT_TYPE);
}
bool ecl_type_is_double(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_DOUBLE_TYPE);
return (ecl_type.type == ECL_DOUBLE_TYPE);
}
bool ecl_type_is_mess(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_MESS_TYPE);
return (ecl_type.type == ECL_MESS_TYPE);
}
bool ecl_type_is_bool(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_BOOL_TYPE);
return (ecl_type.type == ECL_BOOL_TYPE);
}
bool ecl_type_is_C010(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_C010_TYPE);
bool ecl_type_is_string(const ecl_data_type ecl_type) {
return (ecl_type.type == ECL_STRING_TYPE);
}
// Temporary fixup for OPM.
char * ecl_type_get_name(const ecl_data_type ecl_type) {
return ecl_type_alloc_name( ecl_type );
}

View File

@ -36,8 +36,8 @@ ecl_type_enum ecl_type_get_type_python(const ecl_data_type * ecl_type) {
return ecl_type_get_type(*ecl_type);
}
const char * ecl_type_get_name_python(const ecl_data_type * ecl_type) {
return ecl_type_get_name(*ecl_type);
const char * ecl_type_alloc_name_python(const ecl_data_type * ecl_type) {
return ecl_type_alloc_name(*ecl_type);
}
int ecl_type_get_sizeof_ctype_fortio_python(const ecl_data_type * ecl_type) {
@ -81,8 +81,8 @@ bool ecl_type_is_bool_python(const ecl_data_type * ecl_type) {
return ecl_type_is_bool(*ecl_type);
}
bool ecl_type_is_C010_python(const ecl_data_type * ecl_type) {
return ecl_type_is_C010(*ecl_type);
bool ecl_type_is_string_python(const ecl_data_type * ecl_type) {
return ecl_type_is_string(*ecl_type);
}
/**

View File

@ -33,21 +33,6 @@
#include <ert/ecl/ecl_type.h>
/*****************************************************************/
/* The string names for the different ECLIPSE low-level
types.
*/
#define ECL_TYPE_NAME_CHAR "CHAR"
#define ECL_TYPE_NAME_C010 "C010"
#define ECL_TYPE_NAME_FLOAT "REAL"
#define ECL_TYPE_NAME_INT "INTE"
#define ECL_TYPE_NAME_DOUBLE "DOUB"
#define ECL_TYPE_NAME_BOOL "LOGI"
#define ECL_TYPE_NAME_MESSAGE "MESS"
#define ECL_PHASE_NAME_OIL "SOIL" // SHould match the keywords found in restart file
#define ECL_PHASE_NAME_WATER "SWAT"
#define ECL_PHASE_NAME_GAS "SGAS"
@ -700,7 +685,7 @@ void ecl_util_memcpy_typed_data(void *_target_data , const void * _src_data , ec
break;
}
default:
util_abort("%s con not convert %s -> %s \n",__func__ , ecl_type_get_name(src_type) , ecl_type_get_name(target_type));
util_abort("%s con not convert %s -> %s \n",__func__ , ecl_type_alloc_name(src_type) , ecl_type_alloc_name(target_type));
}
}
}

View File

@ -407,20 +407,12 @@ smspec_node_type * smspec_node_alloc_new(int params_index, float default_value)
}
/**
Observe that the wellname can have max 8 characters; anything
beyond that is silently dropped.
*/
static void smspec_node_set_wgname( smspec_node_type * index , const char * wgname ) {
if (wgname == NULL) {
util_safe_free( index->wgname );
index->wgname = NULL;
} else {
if (strlen(wgname) > 8)
index->wgname = util_realloc_substring_copy(index->wgname , wgname , 8);
else
index->wgname = util_realloc_string_copy(index->wgname , wgname );
index->wgname = util_realloc_string_copy(index->wgname , wgname );
}
}

View File

@ -1,41 +0,0 @@
/*
Copyright (C) 2017 Statoil ASA, Norway.
The file 'ecl_kw_ix_types.c' is part of ERT - Ensemble based Reservoir Tool.
ERT 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.
ERT 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 <stdlib.h>
#include <stdbool.h>
#include <ert/util/test_util.h>
#include <ert/ecl/ecl_util.h>
#include <ert/ecl/ecl_kw.h>
/*
The behaviour of the ECL_C010_TYPE is quite unclear; we therefor do
not alloaw instanstiation of keywords with this type.
*/
void test_create_ECL_C010_TYPE() {
ecl_kw_type * ecl_kw = ecl_kw_alloc("TEST" , 1000 , ECL_C010 );
test_assert_NULL( ecl_kw );
}
int main( int argc , char ** argv) {
test_create_ECL_C010_TYPE();
}

View File

@ -14,10 +14,6 @@ add_executable( ecl_kw_init ecl_kw_init.c )
target_link_libraries( ecl_kw_init ecl )
add_test( ecl_kw_init ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_init )
add_executable( ecl_kw_ix_types ecl_kw_ix_types.c )
target_link_libraries( ecl_kw_ix_types ecl )
add_test( ecl_kw_ix_types ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_ix_types )
add_executable( ecl_grid_init_fwrite ecl_grid_init_fwrite.c )
target_link_libraries( ecl_grid_init_fwrite ecl )
add_test( ecl_grid_init_fwrite ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_init_fwrite )

View File

@ -105,9 +105,9 @@ extern "C" {
#define SCON_CF_INDEX 0
#define XCON_WRAT_INDEX 46
#define XCON_GRAT_INDEX 47
#define XCON_ORAT_INDEX 48
#define XCON_ORAT_INDEX 0
#define XCON_WRAT_INDEX 1
#define XCON_GRAT_INDEX 2
#define XCON_QR_INDEX 49
#define RSEG_LENGTH_INDEX 0

View File

@ -82,6 +82,7 @@ extern "C" {
bool well_state_is_open( const well_state_type * well_state );
int well_state_get_well_nr( const well_state_type * well_state );
const well_conn_type * well_state_get_global_wellhead( const well_state_type * well_state );
const well_conn_type * well_state_iget_wellhead( const well_state_type * well_state , int grid_nr);
const well_conn_type * well_state_get_wellhead( const well_state_type * well_state , const char * grid_name);

View File

@ -32,7 +32,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
include_directories( ${libgeometry_src_path} )
add_library( ecl_well ${LIBRARY_TYPE} ${source_files} )
add_library( ecl_well ${source_files} )
set_target_properties( ecl_well PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR} )
target_link_libraries( ecl_well ecl )
if (USE_RUNPATH)

View File

@ -227,6 +227,7 @@ well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw ,
if (xcon_kw) {
const int xcon_offset = header->nxconz * (header->ncwmax * well_nr + conn_nr);
conn->water_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_WRAT_INDEX);
conn->gas_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_GRAT_INDEX);
conn->oil_rate = ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_ORAT_INDEX);

View File

@ -37,6 +37,8 @@
#include <ert/ecl/ecl_kw_magic.h>
#include <ert/ecl/ecl_util.h>
#include <ert/ecl/ecl_grid.h>
#include <ert/ecl/ecl_units.h>
#include <ert/ecl/ecl_util.h>
#include <ert/ecl_well/well_const.h>
#include <ert/ecl_well/well_conn.h>
@ -173,7 +175,7 @@ struct well_state_struct {
double gas_rate;
double water_rate;
double volume_rate;
ert_ecl_unit_enum unit_system;
hash_type * connections; // hash<grid_name,well_conn_collection>
well_segment_collection_type * segments;
@ -210,7 +212,7 @@ well_state_type * well_state_alloc(const char * well_name , int global_well_nr ,
well_state->gas_rate = 0;
well_state->water_rate = 0;
well_state->volume_rate = 0;
well_state->unit_system = ECL_METRIC_UNITS;
/* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */
if ((type == ECL_WELL_ZERO) && open)
@ -240,17 +242,44 @@ double well_state_get_volume_rate( const well_state_type * well_state) {
}
double well_state_get_oil_rate_si( const well_state_type * well_state ) {
return well_state->oil_rate;
double conversion_factor = 1;
if (well_state->unit_system == ECL_METRIC_UNITS)
conversion_factor = 1.0 / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_FIELD_UNITS)
conversion_factor = ECL_UNITS_VOLUME_BARREL / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_LAB_UNITS)
conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR;
return well_state->oil_rate * conversion_factor;
}
double well_state_get_gas_rate_si( const well_state_type * well_state ) {
return well_state->gas_rate;
double conversion_factor = 1;
if (well_state->unit_system == ECL_METRIC_UNITS)
conversion_factor = 1.0 / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_FIELD_UNITS)
conversion_factor = ECL_UNITS_VOLUME_GAS_FIELD / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_LAB_UNITS)
conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR;
return well_state->gas_rate * conversion_factor;
}
double well_state_get_water_rate_si( const well_state_type * well_state) {
return well_state->water_rate;
double conversion_factor = 1;
if (well_state->unit_system == ECL_METRIC_UNITS)
conversion_factor = 1.0 / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_FIELD_UNITS)
conversion_factor = ECL_UNITS_VOLUME_BARREL / ECL_UNITS_TIME_DAY;
else if (well_state->unit_system == ECL_LAB_UNITS)
conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR;
return well_state->water_rate * conversion_factor;
}
double well_state_get_volume_rate_si( const well_state_type * well_state) {
@ -278,6 +307,7 @@ static bool well_state_add_rates( well_state_type * well_state ,
ecl_rsthead_type *header = ecl_rsthead_alloc(rst_view, -1);
int offset = header->nxwelz * well_nr;
well_state->unit_system = header->unit_system;
well_state->oil_rate = ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_ORAT_ITEM);
well_state->gas_rate = ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_GRAT_ITEM);
well_state->water_rate = ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_WRAT_ITEM);
@ -611,6 +641,13 @@ const well_conn_type * well_state_get_wellhead( const well_state_type * well_sta
return NULL;
}
const well_conn_type * well_state_get_global_wellhead( const well_state_type * well_state ) {
if (hash_has_key( well_state->name_wellhead , ECL_GRID_GLOBAL_GRID))
return hash_get( well_state->name_wellhead , ECL_GRID_GLOBAL_GRID );
else
return NULL;
}
well_type_enum well_state_get_type( const well_state_type * well_state){
return well_state->type;

View File

@ -12,7 +12,7 @@ set( header_files
)
add_library( eclxx ${LIBRARY_TYPE} ${source_files} )
add_library( eclxx ${source_files} )
set_target_properties( eclxx PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR})
if (USE_RUNPATH)
add_runpath( eclxx )

View File

@ -161,7 +161,7 @@ if (ERT_BUILD_CXX)
list( APPEND header_files test_util.hpp )
endif()
add_library( ert_util ${LIBRARY_TYPE} ${source_files} )
add_library( ert_util ${source_files} )
message(STATUS "Linking with: ${ERT_EXTERNAL_UTIL_LIBS}")
set_target_properties( ert_util PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR} )

View File

@ -8,7 +8,7 @@ set( header_files
)
add_library( ert_utilxx ${LIBRARY_TYPE} ${source_files} )
add_library( ert_utilxx ${source_files} )
set_target_properties( ert_utilxx PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR})
if (USE_RUNPATH)
add_runpath( ert_utilxx )

View File

@ -1,7 +1,7 @@
set( source_files geo_surface.c geo_util.c geo_pointset.c geo_region.c geo_polygon.c geo_polygon_collection.c)
set( header_files geo_surface.h geo_util.h geo_pointset.h geo_region.h geo_polygon.h geo_polygon_collection.h)
add_library( ert_geometry ${LIBRARY_TYPE} ${source_files} )
add_library( ert_geometry ${source_files} )
set_target_properties( ert_geometry PROPERTIES VERSION ${ERT_VERSION_MAJOR}.${ERT_VERSION_MINOR} SOVERSION ${ERT_VERSION_MAJOR})
target_link_libraries( ert_geometry ert_util )
if (USE_RUNPATH)

View File

@ -1,28 +1,21 @@
include(cmake/find_python_module.cmake)
include(cmake/python_package_versions.cmake) # finds version
install( DIRECTORY cmake DESTINATION share )
FIND_PACKAGE(PythonInterp 2.7 EXACT)
if (NOT DEFINED PYTHON_EXECUTABLE)
message("Python2.7 interpreter not found - Python wrappers not enabled")
return()
endif()
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
include(init_python)
init_python( 2.7 )
python_package(numpy 1.7.1)
find_python_package(numpy 1.7.1 ${PYTHON_INSTALL_PREFIX})
if (NOT DEFINED PY_numpy)
message("numpy module not found - Python wrappers not enabled")
message(WARNING "numpy module not found - Python wrappers not enabled")
set( BUILD_PYTHON OFF PARENT_SCOPE )
return()
endif()
if (EXISTS "/etc/debian_version")
set( PYTHON_PACKAGE_PATH "dist-packages")
else()
set( PYTHON_PACKAGE_PATH "site-packages")
endif()
set(PYTHON_INSTALL_PREFIX "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_PACKAGE_PATH}" CACHE STRING "Subdirectory to install Python modules in")
if (BUILD_TESTS)
add_subdirectory( tests )
endif()
add_subdirectory( python )

View File

@ -4,4 +4,4 @@ Python.
More detailed documentation of the wrapping can be found in
docs/devel.txt.
doc/devel.txt.

View File

@ -1,6 +1,3 @@
if (NOT PYTHONINTERP_FOUND)
find_package (PythonInterp REQUIRED)
endif ()
function(add_python_package target package_path source_files install_package)
set(build_files "")
@ -27,14 +24,14 @@ function(add_python_package target package_path source_files install_package)
add_custom_command(
OUTPUT ${build_file}
COMMAND ${PYTHON_EXECUTABLE}
ARGS ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc2 ${source_file} ${build_file}
ARGS ${PROJECT_BINARY_DIR}/bin/cmake_pyc ${source_file} ${build_file}
${dependent_target})
list(APPEND build_files ${build_file} )
if (install_package)
install(FILES ${build_file} DESTINATION ${CMAKE_INSTALL_PREFIX}/${package_path})
install(CODE "execute_process(COMMAND ${PROJECT_SOURCE_DIR}/cmake/cmake_pyc_file ${install_file})")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/bin/cmake_pyc_file ${install_file})")
endif()
endforeach()

View File

@ -0,0 +1,38 @@
# This macro will create a ctest based on the supplied TEST_CLASS. The
# TEST_CLASS argument should correspond to a valid Python path, i.e.
#
# >> import ${TEST_CLASS}
#
# should work. The actual test is by running a small test script which
# will invoke normal Python test discovery functionality. This is a
# macro, and relevant variables must be crrectly set in calling scope
# before it is invoked:
#
# PYTHON_TEST_RUNNER: Path to executable which will load the testcase
# given by ${TEST_CLASS} and run it.
#
#
# CTEST_PYTHONPATH: Normal colon separated path variable, should at
# least include the binary root directory of the current python
# installation, but can in addition contain the path to
# additional packages. The PYTHON_TEST_RUNNER should inspect the
# $CTEST_PYTHONPATH environment variable and update sys.path
# accordingly.
macro( addPythonTest TEST_CLASS )
set(TEST_NAME ${TEST_CLASS})
add_test(NAME ${TEST_NAME}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}"
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/bin/ctest_run_python ${TEST_CLASS} )
set(oneValueArgs LABELS)
cmake_parse_arguments(TEST_OPTIONS "" "${oneValueArgs}" "" ${ARGN})
if(TEST_OPTIONS_LABELS)
set_property(TEST ${TEST_NAME} PROPERTY LABELS "Python:${TEST_OPTIONS_LABELS}")
else()
set_property(TEST ${TEST_NAME} PROPERTY LABELS "Python")
endif()
set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT "CTEST_PYTHONPATH=${CTEST_PYTHONPATH}")
endmacro( )

View File

@ -1,6 +1,6 @@
# try import python module, if success, check its version, store as PY_module.
# the module is imported as-is, hence the case (e.g. PyQt4) must be correct.
function(python_package_version package)
function(find_python_package_version package)
set(PY_VERSION_ACCESSOR "__version__")
set(PY_package_name ${package})
@ -30,8 +30,25 @@ endfunction()
# If we find the correct module and new enough version, set PY_package, where
# "package" is the given argument to the version we found else, display warning
# and do not set any variables.
function(python_package package version)
python_package_version(${package})
function(find_python_package package version python_prefix)
if (CMAKE_PREFIX_PATH)
set( ORG_PYTHONPATH $ENV{PYTHONPATH} )
foreach ( PREFIX_PATH ${CMAKE_PREFIX_PATH} )
set(THIS_PYTHONPATH "${PREFIX_PATH}/${python_prefix}")
set(ENV{PYTHONPATH} "${THIS_PYTHONPATH}:${ORG_PYTHONPATH}")
find_python_package_version(${package})
if (DEFINED PY_${package})
if (${PY_${package}_PATH} STREQUAL ${THIS_PYTHONPATH})
set(CTEST_PYTHONPATH "${PY_${package}_PATH}:${CTEST_PYTHONPATH}" PARENT_SCOPE)
endif()
break( )
endif()
endforeach()
set(ENV{PYTHONPATH} ${ORG_PYTHONPATH})
else()
find_python_package_version(${package})
endif()
if(NOT DEFINED PY_${package})
message("Could not find Python package " ${package})

View File

@ -0,0 +1,175 @@
# This macro will initialize the current cmake session for Python. The
# macro starts by looking for the Python interpreter of correct
# version. When a Python interepreter of the correct version has been
# located the macro will continue to set variables, load other cmake
# modules and generate scripts to be used in the remaining part of the
# cmake process.
#
# Variables which will be set:
# ----------------------------
#
# PYTHON_INSTALL_PREFIX: All python packages will be located in
# ${GLOBAL_PREFIX}/${PYTHON_INSTALL_PREFIX} - this applies both
# when searching for dependencies and when installing.
#
# CTEST_PYTHONPATH: Normal ':' separated path variables which is
# passed to the test runner. Should contain the PYTHONPATH to
# all third party packages which are not in the default search
# path. The CTEST_PYTHONPATH variable will be updated by the
# python_package( ) function when searching for third party
# packages.
#
#
# New functions/macros which will be available:
# ---------------------------------------------
#
# add_python_package( ): This function will copy python source files
# to the build directory, 'compile' them and set up installation.
#
#
# add_python_test( ): Set up a test based on invoking a Python test
# class with a small python executable front end.
#
# find_python_package( ): Will search for a python package.
#
#
# New scripts generated:
# ----------------------
#
#
# cmake_pyc: Small script which will run in-place Python compilation
# of a directory tree recursively.
#
# cmake_pyc_file: Small script which will compile one python file.
#
# ctest_run_python: Small script which will invoke one Python test class.
#
# All the generated scripts will be located in ${PROJECT_BINARY_DIR}/bin.
#
#
# Downstream projects should use this as:
#
# include( init_python )
# init_python( 2.7 )
# ...
macro(init_python target_version)
FIND_PACKAGE(PythonInterp)
if (NOT DEFINED PYTHON_EXECUTABLE)
message(WARNING "Python interpreter not found - Python wrappers not enabled")
set( BUILD_PYTHON OFF PARENT_SCOPE )
return()
endif()
if (NOT "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" STREQUAL "${target_version}")
message(WARNING "Need Python version ${target_version}, found version: ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} - Python wrappers not enabled")
set( BUILD_PYTHON OFF PARENT_SCOPE )
return()
endif()
if (EXISTS "/etc/debian_version")
set( PYTHON_PACKAGE_PATH "dist-packages")
else()
set( PYTHON_PACKAGE_PATH "site-packages")
endif()
set(PYTHON_INSTALL_PREFIX "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_PACKAGE_PATH}" CACHE STRING "Subdirectory to install Python modules in")
set(CTEST_PYTHONPATH ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX})
configure_python_env( )
include(add_python_test)
include(find_python_package)
include(add_python_package)
endmacro()
# The function configure_python_env( ) will generate three small
# Python scripts which will be located in ${PROJECT_BINARY_DIR}/bin
# and will be used when 'compiling' and testing Python code. The
# function will be called from the init_python() macro.
function( configure_python_env )
FILE(WRITE "${PROJECT_BINARY_DIR}/bin/ctest_run_python"
"import sys
import os
from unittest import TextTestRunner
def runTestCase(tests, verbosity=0):
test_result = TextTestRunner(verbosity=verbosity).run(tests)
if len(test_result.errors) or len(test_result.failures):
test_result.printErrors()
sys.exit(1)
def update_path():
for path in os.environ['CTEST_PYTHONPATH'].split(':'):
sys.path.insert(0 , path)
if __name__ == '__main__':
update_path( )
from ecl.test import ErtTestRunner
for test_class in sys.argv[1:]:
tests = ErtTestRunner.getTestsFromTestClass(test_class)
# Set verbosity to 2 to see which test method in a class that fails.
runTestCase(tests, verbosity=0)
")
#-----------------------------------------------------------------
FILE(WRITE "${PROJECT_BINARY_DIR}/bin/cmake_pyc"
"
import py_compile
import os
import os.path
import sys
import shutil
src_file = sys.argv[1]
target_file = sys.argv[2]
(target_path , tail) = os.path.split( target_file )
if not os.path.exists( target_path ):
try:
os.makedirs( target_path )
except:
# When running make with multiple processes there might be a
# race to create this directory.
pass
shutil.copyfile( src_file , target_file )
shutil.copystat( src_file , target_file )
try:
py_compile.compile( target_file , doraise = True)
except Exception as error:
sys.exit('py_compile(%s) failed:%s' % (target_file , error))
")
#-----------------------------------------------------------------
FILE(WRITE "${PROJECT_BINARY_DIR}/bin/cmake_pyc_file"
"
import py_compile
import os
import sys
import os.path
# Small 'python compiler' used in the build system for ert.
for file in sys.argv[1:]:
try:
py_compile.compile( file , doraise = True )
except Exception as error:
sys.exit('py_compile(%s) failed:%s' % (file , error))
")
endfunction()

View File

@ -1,27 +0,0 @@
# Found from: github user ivansafrin
#
# Find if a Python module is installed
# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
# To use do: find_python_module(PyQt4 REQUIRED)
function(find_python_module module)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _${module}_status)
set(PY_${module_upper} ${_${module}_location} CACHE STRING
"Location of Python module ${module}")
endif()
endif(NOT PY_${module_upper})
find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
endfunction(find_python_module)

View File

@ -1,5 +1,5 @@
configure_file(test_env.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/test_env.py )
add_subdirectory(cwrap)
add_subdirectory( ert )
add_subdirectory( ecl )
add_subdirectory( bin )

View File

@ -55,7 +55,7 @@ class CFILE(BaseCClass):
If the supplied argument is not of type py_file the function
will raise a TypeException.
Examples: ert.ecl.ecl_kw.EclKW.fprintf_grdecl()
Examples: ecl.ecl.ecl_kw.EclKW.fprintf_grdecl()
"""
c_ptr = self._as_file(py_file)
try:

View File

@ -17,13 +17,13 @@
Observe that to ensure that all libraries are loaded through the same
code path, all required libraries should be loaded explicitly through
the use of import statements; i.e. the ert.geo package requires the
the use of import statements; i.e. the ecl.geo package requires the
libert_util librarary, to ensure that the correct version of the
libert_util.so library file is loaded we should manually load that
first as:
import ert.util
GEO_LIB = ert.load("libert_geometry")
import ecl.util
GEO_LIB = ecl.load("libert_geometry")
Otherwise the standard operating system dependency resolve code will
be invoked when loading libert_geometry, and that could in principle

View File

@ -0,0 +1,14 @@
set(PYTHON_SOURCES
__init__.py
)
add_python_package("python.ecl" ${PYTHON_INSTALL_PREFIX}/ecl "${PYTHON_SOURCES}" True)
add_subdirectory(ecl)
add_subdirectory(geo)
add_subdirectory(test)
add_subdirectory(util)
add_subdirectory(well)
configure_file(ecl_lib_info_build.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl/__ecl_lib_info.py )
configure_file(ecl_lib_info_install.py.in ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py )
install(FILES ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/ecl_lib_info_install.py DESTINATION ${PYTHON_INSTALL_PREFIX}/ecl RENAME __ecl_lib_info.py)

View File

@ -18,12 +18,10 @@ ert - Ensemble Reservoir Tool - a package for reservoir modeling.
The ert package itself has no code, but contains several subpackages:
ert.ecl: Package for working with ECLIPSE files. The far most mature
ecl.ecl: Package for working with ECLIPSE files. The far most mature
package in ert.
ert.job_queue:
ert.util:
ecl.util:
The ert package is based on wrapping the libriaries from the ERT C
code with ctypes; an essential part of ctypes approach is to load the
@ -69,22 +67,22 @@ except ImportError:
pass
required_version_hex = 0x02060000
required_version_hex = 0x02070000
ert_lib_path = None
ecl_lib_path = None
ert_so_version = ""
__version__ = "0.0.0"
# 1. Try to load the __ert_lib_info module; this module has been
# 1. Try to load the __ecl_lib_info module; this module has been
# configured by cmake during the build configuration process. The
# module should contain the variable lib_path pointing to the
# directory with shared object files.
try:
import __ert_lib_info
ert_lib_path = __ert_lib_info.lib_path
ert_so_version = __ert_lib_info.so_version
__version__ = __ert_lib_info.__version__
import __ecl_lib_info
ecl_lib_path = __ecl_lib_info.lib_path
ert_so_version = __ecl_lib_info.so_version
__version__ = __ecl_lib_info.__version__
except ImportError:
pass
except AttributeError:
@ -105,23 +103,23 @@ if env_lib_path:
# Check that the final ert_lib_path setting corresponds to an existing
# directory.
if ert_lib_path:
if not os.path.isdir( ert_lib_path ):
ert_lib_path = None
if ecl_lib_path:
if not os.path.isdir( ecl_lib_path ):
ecl_lib_path = None
if sys.hexversion < required_version_hex:
raise Exception("ERT Python requires at least version 2.6 of Python")
raise Exception("ERT Python requires Python 2.7.")
# This load() function is *the* function actually loading shared
# libraries.
def load(name):
return cwrapload( name , path = ert_lib_path , so_version = ert_so_version)
return cwrapload(name, path=ecl_lib_path, so_version=ert_so_version)
from ert.util import Version
from ert.util import updateAbortSignals
from .util import Version
from .util import updateAbortSignals
updateAbortSignals( )

View File

@ -30,7 +30,7 @@ set(PYTHON_SOURCES
ecl_grid_generator.py
)
add_python_package("python.ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "${PYTHON_SOURCES}" True)
add_python_package("python.ecl.ecl" ${PYTHON_INSTALL_PREFIX}/ecl/ecl "${PYTHON_SOURCES}" True)
add_subdirectory(faults)
add_subdirectory(rft)

View File

@ -72,19 +72,19 @@ per module organization:
namespace 'ecl'.
"""
import ert.util
import ert.geo
import ecl.util
import ecl.geo
from cwrap import Prototype
class EclPrototype(Prototype):
lib = ert.load("libecl")
lib = ecl.load("libecl")
def __init__(self, prototype, bind=True):
super(EclPrototype, self).__init__(EclPrototype.lib, prototype, bind=bind)
ECL_LIB = ert.load("libecl")
ECL_LIB = ecl.load("libecl")
from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclUnitTypeEnum , EclUtil
from .ecl_type import EclTypeEnum, EclDataType

View File

@ -14,7 +14,7 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclFile, Ecl3DKW
from ecl.ecl import EclFile, Ecl3DKW
class Ecl3DFile(EclFile):

View File

@ -37,7 +37,7 @@ class Ecl3DKW(EclKW):
Usage example:
from ert.ecl import EclInitFile,EclGrid
from ecl.ecl import EclInitFile,EclGrid
grid = EclGrid("ECLIPSE.EGRID")
file = EclInitFile(grid , "ECLIPSE.INIT")
@ -168,7 +168,7 @@ class Ecl3DKW(EclKW):
2. Convert the keyword to a 3D keyword.
from ert.ecl import EclGrid,EclKW,Ecl3DKW
from ecl.ecl import EclGrid,EclKW,Ecl3DKW
grid = EclGrid("ECLIPSE.EGRID")
poro = EclKW.read_grdecl(open("poro.grdecl") , "PORO")

View File

@ -14,7 +14,7 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclSum
from ecl.ecl import EclSum
class EclCase(object):

View File

@ -41,8 +41,8 @@ import datetime
import ctypes
from cwrap import BaseCClass
from ert.ecl import EclPrototype, EclKW, EclFileEnum, EclFileView
from ert.util import CTime
from ecl.ecl import EclPrototype, EclKW, EclFileEnum, EclFileView
from ecl.util import CTime
class EclFile(BaseCClass):
@ -100,7 +100,7 @@ class EclFile(BaseCClass):
corresponding to @report_step can be found. Since this is a
classmethod it is invoked like this:
import ert.ecl.ecl as ecl
import ecl.ecl.ecl as ecl
....
if ecl.EclFile.contains_report_step("ECLIPSE.UNRST" , 20):
print "OK - file contains report step 20"
@ -124,7 +124,7 @@ class EclFile(BaseCClass):
time corresponding to @dtime can be found. Since this is a
classmethod it is invoked like this:
import ert.ecl.ecl as ecl
import ecl.ecl.ecl as ecl
....
if ecl.EclFile.contains_sim_time("ECLIPSE.UNRST" , datetime.datetime( 2007 , 10 , 10) ):
print "OK - file contains 10th of October 2007"
@ -669,7 +669,7 @@ class EclFile(BaseCClass):
This method will write the current EclFile instance to a
FortIO stream already opened for writing:
import ert.ecl.ecl as ecl
import ecl.ecl.ecl as ecl
...
fortio = ecl.FortIO( "FILE.XX" )
file.fwrite( fortio )

View File

@ -17,8 +17,8 @@
from __future__ import absolute_import, division, print_function, unicode_literals
from six import string_types
from cwrap import BaseCClass
from ert.ecl import EclPrototype
from ert.util import CTime
from ecl.ecl import EclPrototype
from ecl.util import CTime
class EclFileView(BaseCClass):
TYPE_NAME = "ecl_file_view"

View File

@ -22,7 +22,7 @@ different surveys. The implementation is a thin wrapper around the
ecl_grav.c implementation in the libecl library.
"""
from cwrap import BaseCClass
from ert.ecl import EclPhaseEnum, EclPrototype
from ecl.ecl import EclPhaseEnum, EclPrototype
class EclGrav(BaseCClass):
@ -84,7 +84,7 @@ class EclGrav(BaseCClass):
to load the @restart_view argument is:
import datetime
from ert.ecl import EclRestartFile
from ecl.ecl import EclRestartFile
...
...
date = datetime.datetime( year , month , day )

View File

@ -14,7 +14,7 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclPrototype
from ecl.ecl import EclPrototype
_phase_deltag = EclPrototype("double ecl_grav_phase_deltag( double, double ,double , ecl_grid , ecl_file , ecl_kw , ecl_kw , ecl_kw , ecl_kw , ecl_kw , ecl_kw")

View File

@ -32,8 +32,8 @@ import os.path
import math
import itertools
from cwrap import CFILE, BaseCClass
from ert.util import IntVector
from ert.ecl import EclPrototype, EclDataType, EclKW, FortIO, EclUnitTypeEnum
from ecl.util import IntVector
from ecl.ecl import EclPrototype, EclDataType, EclKW, FortIO, EclUnitTypeEnum
class EclGrid(BaseCClass):
@ -222,7 +222,7 @@ class EclGrid(BaseCClass):
super(EclGrid, self).__init__(c_ptr)
else:
raise IOError("Loading grid from:%s failed" % filename)
self.__str__ = self.__repr__
def free(self):
self._free( )

View File

@ -17,8 +17,8 @@
import itertools
import numpy
from ert.util import IntVector
from ert.ecl import EclGrid, EclKW, EclDataType, EclPrototype
from ecl.util import IntVector
from ecl.ecl import EclGrid, EclKW, EclDataType, EclPrototype
class EclGridGenerator:

View File

@ -14,7 +14,7 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.ecl import EclFileEnum , EclFile, Ecl3DKW , Ecl3DFile
from ecl.ecl import EclFileEnum , EclFile, Ecl3DKW , Ecl3DFile
class EclInitFile(Ecl3DFile):

View File

@ -45,8 +45,8 @@ import warnings
import numpy
from cwrap import CFILE, BaseCClass
from ert.ecl import EclDataType
from ert.ecl import EclTypeEnum, EclUtil, EclPrototype
from ecl.ecl import EclDataType
from ecl.ecl import EclTypeEnum, EclUtil, EclPrototype
def dump_type_deprecation_warning():
warnings.warn("EclTypeEnum is deprecated. " +
@ -109,6 +109,8 @@ class EclKW(BaseCClass):
_get_type = EclPrototype("ecl_type_enum ecl_kw_get_type( ecl_kw )")
_iget_char_ptr = EclPrototype("char* ecl_kw_iget_char_ptr( ecl_kw , int )")
_iset_char_ptr = EclPrototype("void ecl_kw_iset_char_ptr( ecl_kw , int , char*)")
_iget_string_ptr = EclPrototype("char* ecl_kw_iget_string_ptr( ecl_kw , int )")
_iset_string_ptr = EclPrototype("void ecl_kw_iset_string_ptr( ecl_kw , int, char*)")
_iget_bool = EclPrototype("bool ecl_kw_iget_bool( ecl_kw , int)")
_iset_bool = EclPrototype("bool ecl_kw_iset_bool( ecl_kw , int, bool)")
_iget_int = EclPrototype("int ecl_kw_iget_int( ecl_kw , int )")
@ -398,6 +400,8 @@ class EclKW(BaseCClass):
self.str_fmt = "%d"
elif self.data_type.is_mess():
self.str_fmt = "%s" #"Message type"
elif self.data_type.is_string():
self.str_fmt = "%" + str(self.data_type.element_size) + "s"
else:
raise ValueError("Unknown EclDataType (%s)!" % self.data_type.type_name)
@ -474,6 +478,8 @@ class EclKW(BaseCClass):
return self._iget_bool( index)
elif self.data_type.is_char():
return self._iget_char_ptr( index )
elif self.data_type.is_string():
return self._iget_string_ptr( index )
else:
raise TypeError("Internal implementation error ...")
elif isinstance( index , slice):
@ -502,6 +508,8 @@ class EclKW(BaseCClass):
self._iset_bool( index , value)
elif self.data_type.is_char():
return self._iset_char_ptr( index , value)
elif self.data_type.is_string():
return self._iset_string_ptr( index, value)
else:
raise SystemError("Internal implementation error ...")
elif isinstance( index , slice):
@ -1059,7 +1067,7 @@ class EclKW(BaseCClass):
existing GRDECL file, set all poro values below 0.05 to 0.00
and write back an updated GRDECL file.
poro = ecl.EclKW.load_grdecl( open("poro1.grdecl" , "r") , "PORO" )
poro = ecl.EclKW.read_grdecl( open("poro1.grdecl" , "r") , "PORO" )
grid = ecl.EclGrid( "ECLIPSE.EGRID" )
reg = ecl.EclRegion( grid , False )

View File

@ -17,7 +17,7 @@
import re
import datetime
import numbers
from ert.ecl import EclSum
from ecl.ecl import EclSum
class NPVParseKey(object):

View File

@ -28,10 +28,10 @@ queried for the corresponding list of indices.
import ctypes
from cwrap import BaseCClass
from ert.ecl.faults import Layer
from ert.ecl import EclKW, EclDataType, EclPrototype
from ert.geo import CPolyline
from ert.util import IntVector
from ecl.ecl.faults import Layer
from ecl.ecl import EclKW, EclDataType, EclPrototype
from ecl.geo import CPolyline
from ecl.util import IntVector
def select_method(select):
@ -825,7 +825,7 @@ class EclRegion(BaseCClass):
vertical coordinate @k.
The input @layer should be of type Layer - from the
ert.ecl.faults.layer module. The k value must in the range
ecl.ecl.faults.layer module. The k value must in the range
[0,grid.nz) and the dimensions of the layer must correspond
exactly to nx,ny of the grid.
"""

View File

@ -14,8 +14,8 @@
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
# for more details.
from ert.util import CTime
from ert.ecl import EclPrototype , EclFile, Ecl3DKW , Ecl3DFile, EclFileEnum
from ecl.util import CTime
from ecl.ecl import EclPrototype , EclFile, Ecl3DKW , Ecl3DFile, EclFileEnum
from cwrap import BaseCClass
class EclRestartHead(BaseCClass):
@ -26,7 +26,9 @@ class EclRestartHead(BaseCClass):
_get_report_step = EclPrototype("int ecl_rsthead_get_report_step(ecl_rsthead)")
_get_sim_time = EclPrototype("time_t ecl_rsthead_get_sim_time(ecl_rsthead)")
_get_sim_days = EclPrototype("double ecl_rsthead_get_sim_days(ecl_rsthead)")
_get_nxconz = EclPrototype("int ecl_rsthead_get_nxconz(ecl_rsthead)")
_get_ncwmax = EclPrototype("int ecl_rsthead_get_ncwmax(ecl_rsthead)")
def __init__(self , kw_arg = None , rst_view = None):
if kw_arg is None and rst_view is None:
raise ValueError('Cannot construct EclRestartHead without one of kw_arg and rst_view, both were None!')
@ -53,6 +55,11 @@ class EclRestartHead(BaseCClass):
def getSimDays(self):
return self._get_sim_days( )
def well_details(self):
return {"NXCONZ" : self._get_nxconz(),
"NCWMAX" : self._get_ncwmax()}
class EclRestartFile(Ecl3DFile):
@ -129,3 +136,13 @@ class EclRestartFile(Ecl3DFile):
time_list.append( (header.getReportStep() , header.getSimDate( ) , header.getSimDays( )) )
return time_list
def headers(self):
self.assertHeaders()
return self.rst_headers
def get_header(self, index):
self.assertHeaders()
return self.rst_headers[index]

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