mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#14683 Share OPM parser for keyword lookups
This commit is contained in:
1 parent
275b120688
commit
2462170647
4 files changed
+19
-31
No files matched your search
@@ -25,6 +25,7 @@
|
|||||||
#include "RimWellEventKeywordItem.h"
|
#include "RimWellEventKeywordItem.h"
|
||||||
|
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
|
#include "RiaOpmKeywordTools.h"
|
||||||
#include "RiaQStringFormatter.h"
|
#include "RiaQStringFormatter.h"
|
||||||
|
|
||||||
#include "cafAppEnum.h"
|
#include "cafAppEnum.h"
|
||||||
@@ -46,16 +47,6 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Constructing an Opm::Parser builds the complete keyword database (several thousand keywords) and
|
|
||||||
// costs milliseconds. The parser is stateless once constructed, so a single shared instance is used
|
|
||||||
// for all keyword lookups. Building one per keyword made schedule generation scale linearly in the
|
|
||||||
// number of events with a very large constant (see issue: GenerateSchedule does not scale).
|
|
||||||
const Opm::Parser& sharedParser()
|
|
||||||
{
|
|
||||||
static const Opm::Parser parser;
|
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString keywordToString( const Opm::DeckKeyword& kw )
|
QString keywordToString( const Opm::DeckKeyword& kw )
|
||||||
{
|
{
|
||||||
if ( kw.name().empty() ) return {};
|
if ( kw.name().empty() ) return {};
|
||||||
@@ -73,7 +64,7 @@ bool RifEventKeywordFormatter::isRecordlessKeyword( const Opm::DeckKeyword& keyw
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto& parserKeyword = sharedParser().getKeyword( keyword.name() );
|
const auto& parserKeyword = RiaOpmKeywordTools::defaultParser().getKeyword( keyword.name() );
|
||||||
return parserKeyword.begin() == parserKeyword.end();
|
return parserKeyword.begin() == parserKeyword.end();
|
||||||
}
|
}
|
||||||
catch ( const std::exception& )
|
catch ( const std::exception& )
|
||||||
@@ -94,7 +85,7 @@ std::optional<Opm::DeckKeyword> RifEventKeywordFormatter::buildKeyword( const QS
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const Opm::ParserKeyword& parserKw = sharedParser().getKeyword( kwName );
|
const Opm::ParserKeyword& parserKw = RiaOpmKeywordTools::defaultParser().getKeyword( kwName );
|
||||||
Opm::DeckKeyword kw( parserKw );
|
Opm::DeckKeyword kw( parserKw );
|
||||||
|
|
||||||
const size_t numRecords = static_cast<size_t>( std::distance( parserKw.begin(), parserKw.end() ) );
|
const size_t numRecords = static_cast<size_t>( std::distance( parserKw.begin(), parserKw.end() ) );
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.h"
|
#include "Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.h"
|
||||||
|
|
||||||
|
#include "RiaOpmKeywordTools.h"
|
||||||
#include "RiaResultNames.h"
|
#include "RiaResultNames.h"
|
||||||
|
|
||||||
#include "RifEclipseInputFileTools.h"
|
#include "RifEclipseInputFileTools.h"
|
||||||
@@ -64,18 +65,6 @@
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// A single shared parser instance is used for all keyword schema lookups. Constructing an
|
|
||||||
// Opm::Parser populates the complete keyword database and costs milliseconds, which is far too
|
|
||||||
// expensive to repeat for every keyword being serialised.
|
|
||||||
const Opm::Parser& sharedParser()
|
|
||||||
{
|
|
||||||
static const Opm::Parser parser;
|
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace RimKeywordFactory
|
namespace RimKeywordFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -944,7 +933,7 @@ QString deckKeywordToAlignedString( const Opm::DeckKeyword& keyword )
|
|||||||
std::vector<std::string> canonicalItemOrder;
|
std::vector<std::string> canonicalItemOrder;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const Opm::ParserKeyword& parserKeyword = sharedParser().getKeyword( keyword.name() );
|
const Opm::ParserKeyword& parserKeyword = RiaOpmKeywordTools::defaultParser().getKeyword( keyword.name() );
|
||||||
if ( std::distance( parserKeyword.begin(), parserKeyword.end() ) == 1 )
|
if ( std::distance( parserKeyword.begin(), parserKeyword.end() ) == 1 )
|
||||||
{
|
{
|
||||||
const Opm::ParserRecord& parserRecord = parserKeyword.getRecord( 0 );
|
const Opm::ParserRecord& parserRecord = parserKeyword.getRecord( 0 );
|
||||||
@@ -1089,7 +1078,7 @@ QString deckKeywordToAlignedString( const Opm::DeckKeyword& keyword )
|
|||||||
bool slashTerminated = true;
|
bool slashTerminated = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
slashTerminated = !sharedParser().getKeyword( keyword.name() ).hasFixedSize();
|
slashTerminated = !RiaOpmKeywordTools::defaultParser().getKeyword( keyword.name() ).hasFixedSize();
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,14 +26,16 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace
|
//--------------------------------------------------------------------------------------------------
|
||||||
{
|
///
|
||||||
const Opm::Parser& sharedParser()
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
const Opm::Parser& RiaOpmKeywordTools::defaultParser()
|
||||||
{
|
{
|
||||||
|
// Constructing an Opm::Parser builds the complete keyword database. Keep one shared instance
|
||||||
|
// for all keyword schema lookups.
|
||||||
static const Opm::Parser parser( true );
|
static const Opm::Parser parser( true );
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
} // namespace
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@@ -41,7 +43,7 @@ const Opm::Parser& sharedParser()
|
|||||||
std::optional<RiaOpmKeywordInfo> RiaOpmKeywordTools::keywordInfo( const QString& keywordName )
|
std::optional<RiaOpmKeywordInfo> RiaOpmKeywordTools::keywordInfo( const QString& keywordName )
|
||||||
{
|
{
|
||||||
const QString keyword = keywordName.toUpper();
|
const QString keyword = keywordName.toUpper();
|
||||||
const auto& parser = sharedParser();
|
const auto& parser = defaultParser();
|
||||||
const auto deckName = keyword.toStdString();
|
const auto deckName = keyword.toStdString();
|
||||||
|
|
||||||
if ( !parser.isRecognizedKeyword( deckName ) ) return std::nullopt;
|
if ( !parser.isRecognizedKeyword( deckName ) ) return std::nullopt;
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Opm
|
||||||
|
{
|
||||||
|
class Parser;
|
||||||
|
}
|
||||||
|
|
||||||
struct RiaOpmKeywordInfo
|
struct RiaOpmKeywordInfo
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
@@ -32,5 +37,6 @@ struct RiaOpmKeywordInfo
|
|||||||
|
|
||||||
namespace RiaOpmKeywordTools
|
namespace RiaOpmKeywordTools
|
||||||
{
|
{
|
||||||
|
const Opm::Parser& defaultParser();
|
||||||
std::optional<RiaOpmKeywordInfo> keywordInfo( const QString& keywordName );
|
std::optional<RiaOpmKeywordInfo> keywordInfo( const QString& keywordName );
|
||||||
} // namespace RiaOpmKeywordTools
|
} // namespace RiaOpmKeywordTools
|
||||||
Reference in new issue
Block a user