mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#2042 Well import. Match wells, well paths and sim wells. Set 'master' well path name
This commit is contained in:
parent
9f9fb21cbe
commit
1abc5e0e27
@ -18,6 +18,7 @@ ${CEE_CURRENT_LIST_DIR}RiaRegressionTest.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaImportEclipseCaseTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaQDateTimeTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaSummaryTools.h
|
||||
${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@ -33,6 +34,7 @@ ${CEE_CURRENT_LIST_DIR}RiaRegressionTest.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaImportEclipseCaseTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaQDateTimeTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaSummaryTools.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
117
ApplicationCode/Application/Tools/RiaWellNameComparer.cpp
Normal file
117
ApplicationCode/Application/Tools/RiaWellNameComparer.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "../RiaApplication.h"
|
||||
#include "RiaWellNameComparer.h"
|
||||
#include "../../ProjectDataModel/RimProject.h"
|
||||
#include "../../ProjectDataModel/RimWellPath.h"
|
||||
#include <regex>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
QString RiaWellNameComparer::tryFindMatchingSimWellName(QString searchName)
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
const std::vector<QString>& simWellNames = proj->simulationWellNames();
|
||||
|
||||
if (searchName.isEmpty() || simWellNames.empty()) return QString();
|
||||
|
||||
searchName = removeWellNamePrefix(searchName);
|
||||
return tryMatchNameInList(searchName, simWellNames);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaWellNameComparer::tryFindMatchingWellPath(QString wellName)
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
const std::vector<RimWellPath*>& wellPaths = proj->allWellPaths();
|
||||
|
||||
if (wellName.isEmpty() || wellPaths.empty()) return QString();
|
||||
|
||||
std::vector<QString> wellPathNames;
|
||||
for (const RimWellPath* wellPath : wellPaths)
|
||||
{
|
||||
wellPathNames.push_back(wellPath->name());
|
||||
}
|
||||
|
||||
wellName = removeWellNamePrefix(wellName);
|
||||
return tryMatchNameInList(wellName, wellPathNames);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaWellNameComparer::tryMatchNameInList(QString searchName, const std::vector<QString>& nameList)
|
||||
{
|
||||
// Try exact name match
|
||||
QString matchedName = tryMatchName(searchName, nameList);
|
||||
if (!matchedName.isEmpty())
|
||||
{
|
||||
return matchedName;
|
||||
}
|
||||
|
||||
// Try matching ignoring spaces, dashes and underscores
|
||||
return tryMatchName(searchName, nameList, [](const QString& str) {
|
||||
QString s = str;
|
||||
s = removeWellNamePrefix(s);
|
||||
return s.remove(' ').remove('-').remove('_');
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaWellNameComparer::tryMatchName(QString searchName,
|
||||
const std::vector<QString>& simWellNames,
|
||||
std::function<QString(QString)> stringFormatter)
|
||||
{
|
||||
if (searchName.isEmpty()) return QString();
|
||||
|
||||
if (stringFormatter != nullptr)
|
||||
{
|
||||
searchName = stringFormatter(searchName);
|
||||
}
|
||||
|
||||
for (const auto& simWellName : simWellNames)
|
||||
{
|
||||
QString simWn = simWellName;
|
||||
if (stringFormatter != nullptr)
|
||||
{
|
||||
simWn = stringFormatter(simWn);
|
||||
}
|
||||
if (QString::compare(simWn, searchName, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
return simWellName;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaWellNameComparer::removeWellNamePrefix(const QString& name)
|
||||
{
|
||||
// Try to remove prefix on the format 'xx xxxx/xx-'
|
||||
std::regex pattern("^.*\\d*[/]\\d*[-_]");
|
||||
|
||||
return QString::fromStdString(std::regex_replace(name.toStdString(), pattern, ""));
|
||||
}
|
45
ApplicationCode/Application/Tools/RiaWellNameComparer.h
Normal file
45
ApplicationCode/Application/Tools/RiaWellNameComparer.h
Normal file
@ -0,0 +1,45 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaWellNameComparer
|
||||
{
|
||||
public:
|
||||
static QString tryFindMatchingSimWellName(QString searchName);
|
||||
static QString tryFindMatchingWellPath(QString wellName);
|
||||
|
||||
private:
|
||||
static QString tryMatchNameInList(QString searchName,
|
||||
const std::vector<QString>& nameList);
|
||||
static QString tryMatchName(QString searchName,
|
||||
const std::vector<QString>& nameList,
|
||||
std::function<QString(QString)> stringFormatter = nullptr);
|
||||
|
||||
static QString removeWellNamePrefix(const QString& name);
|
||||
};
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "RivWellPathPartMgr.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaWellNameComparer.h"
|
||||
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
#include "cafUtils.h"
|
||||
@ -632,6 +633,7 @@ RiaEclipseUnitTools::UnitSystem RimWellPath::unitSystem() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellPath::addWellLogFile(RimWellLogFile* logFileInfo)
|
||||
{
|
||||
// Prevent the same file from being loaded more than once
|
||||
auto itr = std::find_if(m_wellLogFiles.begin(), m_wellLogFiles.end(), [&](const RimWellLogFile* file)
|
||||
{
|
||||
return QString::compare(file->fileName(), logFileInfo->fileName(), Qt::CaseInsensitive) == 0;
|
||||
@ -702,27 +704,16 @@ int RimWellPath::associatedSimulationWellBranch() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimWellPath::tryAssociateWithSimulationWell()
|
||||
{
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
const std::vector<QString>& simWellNames = proj->simulationWellNames();
|
||||
|
||||
if (!m_simWellName().isEmpty()) return false;
|
||||
if (simWellNames.empty()) return false;
|
||||
|
||||
QString wellPathName = QString(m_name);
|
||||
|
||||
// Try to remove prefix on the format 'xx xxxx/xx-'
|
||||
std::regex pattern("^.*\\d*[/]\\d*[-_]");
|
||||
|
||||
wellPathName = QString::fromStdString(std::regex_replace(wellPathName.toStdString(), pattern, ""));
|
||||
|
||||
// Try exact name match
|
||||
if (tryMatchName(wellPathName, simWellNames)) return true;
|
||||
|
||||
// Try matching ignoring spaces, dashes and underscores
|
||||
return tryMatchName(wellPathName, simWellNames, [](const QString& str) {
|
||||
QString s = str;
|
||||
return s.remove(' ').remove('-').remove('_');
|
||||
});
|
||||
QString matchedSimWell = RiaWellNameComparer::tryFindMatchingSimWellName(m_name);
|
||||
|
||||
if (!matchedSimWell.isEmpty())
|
||||
{
|
||||
m_simWellName = matchedSimWell;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -732,31 +723,3 @@ bool RimWellPath::isAssociatedWithSimulationWell() const
|
||||
{
|
||||
return !m_simWellName().isEmpty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimWellPath::tryMatchName(QString wellPathName, const std::vector<QString>& simWellNames, std::function<QString (QString)> stringFormatter)
|
||||
{
|
||||
if (wellPathName.isEmpty()) return false;
|
||||
|
||||
if (stringFormatter != nullptr)
|
||||
{
|
||||
wellPathName = stringFormatter(wellPathName);
|
||||
}
|
||||
|
||||
for (const auto& simWellName : simWellNames)
|
||||
{
|
||||
QString simWn = simWellName;
|
||||
if (stringFormatter != nullptr)
|
||||
{
|
||||
simWn = stringFormatter(simWn);
|
||||
}
|
||||
if (QString::compare(simWn, wellPathName, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
m_simWellName = simWellName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaWellNameComparer.h"
|
||||
|
||||
#include "RigWellPath.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
@ -250,13 +251,16 @@ void RimWellPathCollection::readAndAddWellPaths(std::vector<RimWellPath*>& wellP
|
||||
progress.setProgressDescription(QString("Reading file %1").arg(wellPath->name()));
|
||||
|
||||
// If a well path with this name exists already, make it read the well path file
|
||||
RimWellPath* existingWellPath = wellPathByName(wellPath->name());
|
||||
RimWellPath* existingWellPath = tryFindMatchingWellPath(wellPath->name());
|
||||
if (existingWellPath)
|
||||
{
|
||||
existingWellPath->filepath = wellPath->filepath;
|
||||
existingWellPath->wellPathIndexInFile = wellPath->wellPathIndexInFile;
|
||||
existingWellPath->readWellPathFile(NULL, m_wellPathImporter);
|
||||
|
||||
// Let name from well path file override name from well log file
|
||||
existingWellPath->setName(wellPath->name());
|
||||
|
||||
delete wellPath;
|
||||
}
|
||||
else
|
||||
@ -296,7 +300,7 @@ RimWellLogFile* RimWellPathCollection::addWellLogs(const QStringList& filePaths)
|
||||
logFileInfo = RimWellLogFile::readWellLogFile(filePath);
|
||||
if (logFileInfo)
|
||||
{
|
||||
RimWellPath* wellPath = wellPathByName(logFileInfo->wellName());
|
||||
RimWellPath* wellPath = tryFindMatchingWellPath(logFileInfo->wellName());
|
||||
if (!wellPath)
|
||||
{
|
||||
wellPath = new RimWellPath();
|
||||
@ -428,7 +432,17 @@ RimWellPath* RimWellPathCollection::wellPathByName(const QString& wellPathName)
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellPath* RimWellPathCollection::tryFindMatchingWellPath(const QString& wellName) const
|
||||
{
|
||||
QString matchedWellPath = RiaWellNameComparer::tryFindMatchingWellPath(wellName);
|
||||
|
||||
return !matchedWellPath.isEmpty() ? wellPathByName(matchedWellPath) : nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
void deleteAllWellPaths();
|
||||
|
||||
RimWellPath* wellPathByName(const QString& wellPathName) const;
|
||||
RimWellPath* tryFindMatchingWellPath(const QString& wellName) const;
|
||||
void addWellPaths(const std::vector<RimWellPath*> wellPaths);
|
||||
RimWellLogFile* addWellLogs(const QStringList& filePaths);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user