From 7cd29ea7d7958ceff1f9e4e7cb4029f8bf48f9e5 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 9 Sep 2018 10:20:23 +0200 Subject: [PATCH] Add option to ignore extra keywords in the regresstion testing --- examples/test_util/EclRegressionTest.cpp | 23 +++++++++++++---------- examples/test_util/EclRegressionTest.hpp | 9 +++++++++ examples/test_util/compareECL.cpp | 7 ++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/examples/test_util/EclRegressionTest.cpp b/examples/test_util/EclRegressionTest.cpp index 035433ab6..d98fa6efc 100644 --- a/examples/test_util/EclRegressionTest.cpp +++ b/examples/test_util/EclRegressionTest.cpp @@ -231,20 +231,23 @@ void ECLRegressionTest::gridCompare(const bool volumecheck) const { void ECLRegressionTest::results() { - if (keywords1.size() != keywords2.size()) { - std::set keys(keywords1.begin() , keywords1.end()); - for (const auto& key2: keywords2) - keys.insert( key2 ); + if (!this->acceptExtraKeywords) { + if (keywords1.size() != keywords2.size()) { + std::set keys(keywords1.begin() , keywords1.end()); + for (const auto& key2: keywords2) + keys.insert( key2 ); - for (const auto& key : keys) - fprintf(stderr," %8s:%3d %8s:%3d \n",key.c_str() , ecl_file_get_num_named_kw( ecl_file1 , key.c_str()), - key.c_str() , ecl_file_get_num_named_kw( ecl_file2 , key.c_str())); + for (const auto& key : keys) + fprintf(stderr," %8s:%3d %8s:%3d \n",key.c_str() , ecl_file_get_num_named_kw( ecl_file1 , key.c_str()), + key.c_str() , ecl_file_get_num_named_kw( ecl_file2 , key.c_str())); - OPM_THROW(std::runtime_error, "\nKeywords in first file: " << keywords1.size() - << "\nKeywords in second file: " << keywords2.size() - << "\nThe number of keywords differ."); + OPM_THROW(std::runtime_error, "\nKeywords in first file: " << keywords1.size() + << "\nKeywords in second file: " << keywords2.size() + << "\nThe number of keywords differ."); + } } + for (const auto& it : keywords1) resultsForKeyword(it); diff --git a/examples/test_util/EclRegressionTest.hpp b/examples/test_util/EclRegressionTest.hpp index fe329baf9..9265b6e5c 100644 --- a/examples/test_util/EclRegressionTest.hpp +++ b/examples/test_util/EclRegressionTest.hpp @@ -40,6 +40,10 @@ class ECLRegressionTest: public ECLFilesComparator { // Only compare last occurrence bool onlyLastOccurrence = false; + // Accept extra keywords in the restart file of the 'new' simulation. + bool acceptExtraKeywords = false; + + // Prints results stored in absDeviation and relDeviation. void printResultsForKeyword(const std::string& keyword) const; @@ -69,6 +73,11 @@ class ECLRegressionTest: public ECLFilesComparator { //! \brief Option to only compare last occurrence void setOnlyLastOccurrence(bool onlyLastOccurrenceArg) {this->onlyLastOccurrence = onlyLastOccurrenceArg;} + // Accept extra keywords: If this switch is set to true the comparison + // of restart files will ignore extra keywords which are only present + // in the new simulation. + void setAcceptExtraKeywords(bool acceptExtraKeywords) { this->acceptExtraKeywords = acceptExtraKeywords; } + //! \brief Compares grid properties of the two cases. // gridCompare() checks if both the number of active and global cells in the two cases are the same. If they are, and volumecheck is true, all cells are looped over to calculate the cell volume deviation for the two cases. If the both the relative and absolute deviation exceeds the tolerances, an exception is thrown. void gridCompare(const bool volumecheck) const; diff --git a/examples/test_util/compareECL.cpp b/examples/test_util/compareECL.cpp index b25164159..b497da188 100644 --- a/examples/test_util/compareECL.cpp +++ b/examples/test_util/compareECL.cpp @@ -132,6 +132,7 @@ int main(int argc, char** argv) { bool allowSpikes = false; bool throwOnError = true; bool throwTooGreatErrorRatio = true; + bool acceptExtraKeywords = false; bool analysis = false; bool volumecheck = true; char* keyword = nullptr; @@ -140,7 +141,7 @@ int main(int argc, char** argv) { int c = 0; int spikeLimit = -1; - while ((c = getopt(argc, argv, "hiIk:alnpPt:VRgs:m:vK")) != -1) { + while ((c = getopt(argc, argv, "hiIk:alnpPt:VRgs:m:vKx")) != -1) { switch (c) { case 'a': analysis = true; @@ -198,6 +199,9 @@ int main(int argc, char** argv) { case 'V': volumecheck = false; break; + case 'x': + acceptExtraKeywords = true; + break; case '?': if (optopt == 'k' || optopt == 'm' || optopt == 's') { std::cerr << "Option " << optopt << " requires a keyword as argument, see manual (-h) for more information." << std::endl; @@ -344,6 +348,7 @@ int main(int argc, char** argv) { ECLRegressionTest comparator(file_type, basename1, basename2, absTolerance, relTolerance); comparator.throwOnErrors(throwOnError); comparator.doAnalysis(analysis); + comparator.setAcceptExtraKeywords(acceptExtraKeywords); if (printKeywords) { comparator.printKeywords(); return 0;