Changed to two applications for comparison
- restartRegressionTest, initRegressionTest was squashed to one application, which also supports integration test as well as test of restart files (non-unified) and .RFT files. - summaryRegressionTest was renamed compareSummary -- now it can execute an integration test as well as regression test. Also other improvements were made.
This commit is contained in:
parent
3bb1cda00c
commit
a403a8d21c
264
examples/test_util/compareECL.cpp
Normal file
264
examples/test_util/compareECL.cpp
Normal file
@ -0,0 +1,264 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/test_util/EclFilesComparator.hpp>
|
||||
|
||||
#include <ert/util/util.h>
|
||||
#include <ert/util/stringlist.h>
|
||||
#include <ert/ecl/ecl_endian_flip.h>
|
||||
#include <ert/ecl/ecl_file.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
static void printHelp() {
|
||||
std::cout << "\ncompareECL compares ECLIPSE files (restart (.RST), unified restart (.UNRST), initial (.INIT) or .RFT) and gridsizes (from .EGRID or .GRID file) from two simulations.\n"
|
||||
<< "The program takes four arguments:\n\n"
|
||||
<< "1. Case number 1 (full path without extension)\n"
|
||||
<< "2. Case number 2 (full path without extension)\n"
|
||||
<< "3. Absolute tolerance\n"
|
||||
<< "4. Relative tolerance (between 0 and 1)\n\n"
|
||||
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
|
||||
<< "-h Print help and exit.\n"
|
||||
<< "-i Execute integration test (regression test is default).\n"
|
||||
<< " The integration test compares SGAS, SWAT and PRESSURE in unified restart files, so this option can not be used in combination with -t.\n"
|
||||
<< "-I Same as -i, but throws an exception when the number of keywords in the two cases differ. Can not be used in combination with -t.\n"
|
||||
<< "-k Specify specific keyword to compare (capitalized), for example -k PRESSURE.\n"
|
||||
<< "-l Only do comparison for the last occurrence. This option is only for the regression test, and can therefore not be used in combination with -i or -I.\n"
|
||||
<< "-p Print keywords in both cases and exit. Can not be used in combination with -P.\n"
|
||||
<< "-P Print common and uncommon keywords in both cases and exit. Can not be used in combination with -p.\n"
|
||||
<< "-t Specify ECLIPSE filetype to compare (unified restart is default). Can not be used in combination with -i or -I. Different possible arguments are:\n"
|
||||
<< " -t UNRST \t Compare two unified restart files (.UNRST). This the default value, so it is the same as not passing option -t.\n"
|
||||
<< " -t INIT \t Compare two initial files (.INIT).\n"
|
||||
<< " -t RFT \t Compare two RFT files (.RFT).\n"
|
||||
<< " -t RST \t Compare two cases consisting of restart files (.Xnnnn).\n"
|
||||
<< " -t RST1 \t Compare two cases where the first case consists of restart files (.Xnnnn), and the second case consists of a unified restart file (.UNRST).\n"
|
||||
<< " -t RST2 \t Compare two cases where the first case consists of a unified restart file (.UNRST), and the second case consists of restart files (.Xnnnn).\n"
|
||||
<< " Note that when dealing with restart files (.Xnnnn), the program concatenates all of them into one unified restart file, which is used for comparison and stored in the same directory as the restart files.\n"
|
||||
<< " This will overwrite any existing unified restart file in that directory.\n\n"
|
||||
<< "Example usage of the program: \n\n"
|
||||
<< "compareECL -k PRESSURE <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
|
||||
<< "compareECL -t INIT -k PORO <path to first casefile> <path to second casefile> 1e-3 1e-5\n"
|
||||
<< "compareECL -i <path to first casefile> <path to second casefile> 0.01 1e-6\n\n"
|
||||
<< "Exceptions are thrown (and hence program exits) when deviations are larger than the specified "
|
||||
<< "tolerances, or when the number of cells does not match -- either in the grid file or for a "
|
||||
<< "specific keyword. Information about the keyword, keyword occurrence (zero based) and cell "
|
||||
<< "coordinate is printed when an exception is thrown. For more information about how the cases "
|
||||
<< "are compared, see the documentation of the EclFilesComparator class.\n\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void splitBasename(const std::string& basename, std::string& path, std::string& filename) {
|
||||
const size_t lastSlashIndex = basename.find_last_of("/\\");
|
||||
path = basename.substr(0,lastSlashIndex);
|
||||
filename = basename.substr(lastSlashIndex+1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Inspired by the ecl_pack application in the ERT library
|
||||
void concatenateRestart(const std::string& basename) {
|
||||
std::string inputPath, inputBase;
|
||||
splitBasename(basename, inputPath, inputBase);
|
||||
stringlist_type* inputFiles = stringlist_alloc_new();
|
||||
const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles);
|
||||
|
||||
const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1);
|
||||
fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP);
|
||||
int dummy;
|
||||
ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT_TYPE, &dummy);
|
||||
|
||||
int reportStep = 0;
|
||||
for (int i = 0; i < numFiles; ++i) {
|
||||
ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep);
|
||||
ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0);
|
||||
ecl_kw_iset_int(seqnum_kw, 0, reportStep);
|
||||
ecl_kw_fwrite(seqnum_kw, target);
|
||||
ecl_file_fwrite_fortio(src_file, target, 0);
|
||||
ecl_file_close(src_file);
|
||||
}
|
||||
fortio_fclose(target);
|
||||
stringlist_free(inputFiles);
|
||||
}
|
||||
|
||||
//------------------------------------------------//
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Restart is default
|
||||
ecl_file_enum file_type = ECL_UNIFIED_RESTART_FILE;
|
||||
// RegressionTest is default
|
||||
bool integrationTest = false;
|
||||
bool checkNumKeywords = false;
|
||||
bool onlyLastOccurrence = false;
|
||||
bool printKeywords = false;
|
||||
bool printKeywordsDifference = false;
|
||||
bool specificKeyword = false;
|
||||
bool specificFileType = false;
|
||||
char* keyword = nullptr;
|
||||
char* fileTypeCstr = nullptr;
|
||||
int c = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "hiIk:lpPt:")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'i':
|
||||
integrationTest = true;
|
||||
break;
|
||||
case 'I':
|
||||
integrationTest = true;
|
||||
checkNumKeywords = true;
|
||||
break;
|
||||
case 'k':
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
onlyLastOccurrence = true;
|
||||
break;
|
||||
case 'p':
|
||||
printKeywords = true;
|
||||
break;
|
||||
case 'P':
|
||||
printKeywordsDifference = true;
|
||||
break;
|
||||
case 't':
|
||||
specificFileType = true;
|
||||
fileTypeCstr = optarg;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k') {
|
||||
std::cerr << "Option k requires a keyword as argument, see manual (-h) for more information." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if (optopt == 't') {
|
||||
std::cerr << "Option t requires an ECLIPSE filetype as argument, see manual (-h) for more information." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
int argOffset = optind;
|
||||
if ((printKeywords && printKeywordsDifference) ||
|
||||
(integrationTest && specificFileType) ||
|
||||
(integrationTest && onlyLastOccurrence)) {
|
||||
std::cerr << "Error: Options given which can not be combined. "
|
||||
<< "Please see the manual (-h) for more information." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != argOffset + 4) {
|
||||
std::cerr << "Error: The number of options and arguments given is not correct. "
|
||||
<< "Please run compareECL -h to see manual." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::string basename1 = argv[argOffset];
|
||||
std::string basename2 = argv[argOffset + 1];
|
||||
double absTolerance = strtod(argv[argOffset + 2], nullptr);
|
||||
double relTolerance = strtod(argv[argOffset + 3], nullptr);
|
||||
|
||||
if (specificFileType) {
|
||||
std::string fileTypeString(fileTypeCstr);
|
||||
for (auto& c: fileTypeString) c = toupper(c);
|
||||
if (fileTypeString== "UNRST") {} //Do nothing
|
||||
else if (fileTypeString == "RST") {
|
||||
concatenateRestart(basename1);
|
||||
concatenateRestart(basename2);
|
||||
}
|
||||
else if (fileTypeString == "RST1") {
|
||||
concatenateRestart(basename1);
|
||||
}
|
||||
else if (fileTypeString == "RST2") {
|
||||
concatenateRestart(basename2);
|
||||
}
|
||||
else if (fileTypeString == "INIT") {
|
||||
file_type = ECL_INIT_FILE;
|
||||
}
|
||||
else if (fileTypeString == "RFT") {
|
||||
file_type = ECL_RFT_FILE;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Unknown ECLIPSE filetype specified with option -t. Please run compareECL -h to see manual." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
std::cout << "Comparing '" << basename1 << "' to '" << basename2 << "'." << std::endl;
|
||||
try {
|
||||
if (integrationTest) {
|
||||
IntegrationTest comparator(basename1, basename2, absTolerance, relTolerance);
|
||||
if (printKeywords) {
|
||||
comparator.printKeywords();
|
||||
return 0;
|
||||
}
|
||||
if (printKeywordsDifference) {
|
||||
comparator.printKeywordsDifference();
|
||||
return 0;
|
||||
}
|
||||
if (checkNumKeywords) {
|
||||
comparator.equalNumKeywords();
|
||||
}
|
||||
if (specificKeyword) {
|
||||
if (comparator.elementInWhitelist(keyword)) {
|
||||
comparator.resultsForKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
std::cerr << "Keyword " << keyword << " is not supported for the integration test. Use SGAS, SWAT or PRESSURE." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
comparator.results();
|
||||
}
|
||||
}
|
||||
else {
|
||||
RegressionTest comparator(file_type, basename1, basename2, absTolerance, relTolerance);
|
||||
if (printKeywords) {
|
||||
comparator.printKeywords();
|
||||
return 0;
|
||||
}
|
||||
if (printKeywordsDifference) {
|
||||
comparator.printKeywordsDifference();
|
||||
return 0;
|
||||
}
|
||||
if (onlyLastOccurrence) {
|
||||
comparator.setOnlyLastOccurrence(true);
|
||||
}
|
||||
if (specificKeyword) {
|
||||
comparator.gridCompare();
|
||||
comparator.resultsForKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
comparator.gridCompare();
|
||||
comparator.results();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
215
examples/test_util/compareSummary.cpp
Normal file
215
examples/test_util/compareSummary.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <opm/test_util/summaryRegressionTest.hpp>
|
||||
#include <opm/test_util/summaryIntegrationTest.hpp>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <getopt.h>
|
||||
|
||||
void printHelp(){
|
||||
std::cout << "\n\nThe program can handle both unified and non-unified summary files."<< std::endl;
|
||||
std::cout <<"In the case of non-unified summary files all the files must be located in the same directory. Only the basename (full path without extension) is needed as input." << std::endl << std::endl;
|
||||
std::cout << "\nThe program takes four arguments" << std::endl;
|
||||
std::cout << "1) <path to file1>/<base_name>, basename without extension" << std::endl;
|
||||
std::cout << "2) <path to file2>/<base_name>, basename without extension" << std::endl;
|
||||
std::cout << "3) absolute tolerance" << std::endl;
|
||||
std::cout << "4) relative tolerance (between 0 and 1)" << std::endl;
|
||||
std::cout << "The program will only throw an exception when both the absolute and relative tolerance are exceeded." << std::endl;
|
||||
std::cout << "The program is capable of performing both a regression test and an integration test, \nhowever only one type of test at a time. ";
|
||||
std::cout << "By default the program will run a regression test."<< std::endl;
|
||||
std::cout << "\nThe program have command line options:" << std::endl;
|
||||
std::cout << "-h \t\tPrint help message." << std::endl << std::endl;
|
||||
std::cout << "For the regression test: " << std::endl;
|
||||
std::cout << "-r \t\tChoosing regression test (this is default)."<< std::endl;
|
||||
std::cout << "-k keyword \tSpecify a specific keyword to compare, for example - k WOPR:PRODU1."<< std::endl;
|
||||
std::cout << "-p \t\tWill print the keywords of the files." << std::endl;
|
||||
std::cout << "-R \t\tWill allow comparison between a restarted simulation and a normal simulation. The files must end at the same time." << std::endl << std::endl;
|
||||
std::cout << "For the integration test:"<< std::endl;
|
||||
std::cout << "-i \t\tChoosing integration test." << std::endl;
|
||||
std::cout << "-d \t\tThe program will not throw an exception when the volume error ratio exceeds the limit." << std::endl;
|
||||
std::cout << "-g \t\tWill print the vector with the greatest error ratio." << std::endl;
|
||||
std::cout << "-k keyword \tSpecify a specific keyword to compare, for example - k WOPR:PRODU1."<< std::endl;
|
||||
std::cout << "-K \t\tWill not allow different amount of keywords in the two files. Throws an exception if the amount are different." << std::endl;
|
||||
std::cout << "-m mainVar \tWill calculate the error ratio for one main variable. Valid input is WOPR, WWPR, WGPR or WBHP." << std::endl;
|
||||
std::cout << "-p \t\tWill print the keywords of the files." << std::endl;
|
||||
std::cout << "-P keyword \tWill print the summary vectors of a specified kewyord, for example -P WOPR:B-3H." << std::endl;
|
||||
std::cout << "-s int \t\tSets the number of spikes that are allowed for each keyword, for example: -s 5." << std::endl;
|
||||
std::cout << "-v \t\tFor the rate keywords WOPR, WGPR, WWPR and WBHP. Calculates the error volume of \n\t\tthe two summary files. This is printed to screen." << std::endl;
|
||||
std::cout << "-V keyword \tWill calculate the error rate for a specific keyword." << std::endl << std::endl;
|
||||
std::cout << "Suggested combination of command line options:"<< std::endl;
|
||||
std::cout << " -i -g -m mainVariable, will print the vector which have the greatest error ratio of the main variable of interest.\n"<< std::endl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
int main (int argc, char ** argv){
|
||||
|
||||
//------------------------------------------------
|
||||
//Defines some constants
|
||||
bool specificKeyword = false;
|
||||
bool allowSpikes = false;
|
||||
bool findVolumeError = false;
|
||||
bool integrationTest = false;
|
||||
bool regressionTest = true;
|
||||
bool allowDifferentAmountOfKeywords = true;
|
||||
bool printKeywords = false;
|
||||
bool printSpecificKeyword = false;
|
||||
bool findVectorWithGreatestErrorRatio = false;
|
||||
bool oneOfTheMainVariables = false;
|
||||
bool throwExceptionForTooGreatErrorRatio = true;
|
||||
bool isRestartFile = false;
|
||||
const char* keyword = nullptr;
|
||||
const char* mainVariable = nullptr;
|
||||
int c = 0;
|
||||
int limit = -1;
|
||||
//------------------------------------------------
|
||||
|
||||
//------------------------------------------------
|
||||
//For setting the options selected
|
||||
while ((c = getopt(argc, argv, "dghik:Km:pP:rRs:vV:")) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
throwExceptionForTooGreatErrorRatio = false;
|
||||
break;
|
||||
case 'g':
|
||||
findVectorWithGreatestErrorRatio = true;
|
||||
throwExceptionForTooGreatErrorRatio = false;
|
||||
break;
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'i':
|
||||
integrationTest = true;
|
||||
regressionTest = false;
|
||||
break;
|
||||
case 'k':
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 'K':
|
||||
allowDifferentAmountOfKeywords = false;
|
||||
break;
|
||||
case 'm':
|
||||
oneOfTheMainVariables = true;
|
||||
mainVariable = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
printKeywords = true;
|
||||
break;
|
||||
case 'P':
|
||||
specificKeyword = true;
|
||||
printSpecificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
integrationTest = false;
|
||||
regressionTest = true;
|
||||
break;
|
||||
case 'R':
|
||||
isRestartFile = true;
|
||||
break;
|
||||
case 's':
|
||||
allowSpikes = true;
|
||||
limit = atof(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
findVolumeError = true;
|
||||
break;
|
||||
case 'V':
|
||||
findVolumeError = true;
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k' || optopt == 'm' || optopt == 's') {
|
||||
std::cout << "Option requires an keyword." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------
|
||||
|
||||
int argOffset = optind;
|
||||
if (argc != argOffset + 4) {
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char * basename1 = argv[argOffset];
|
||||
const char * basename2 = argv[argOffset+1];
|
||||
double absoluteTolerance = strtod(argv[argOffset+2], nullptr);
|
||||
double relativeTolerance = strtod(argv[argOffset+3], nullptr);
|
||||
|
||||
std::cout << "Comparing '" << basename1 << "' to '" << basename2 << "'." << std::endl;
|
||||
|
||||
try {
|
||||
if(regressionTest){
|
||||
RegressionTest compare(basename1,basename2, absoluteTolerance, relativeTolerance);
|
||||
if(printKeywords){compare.setPrintKeywords(true);}
|
||||
if(isRestartFile){compare.setIsRestartFile(true);}
|
||||
if(specificKeyword){
|
||||
compare.getRegressionTest(keyword);
|
||||
}
|
||||
else{
|
||||
if(printKeywords){compare.setPrintKeywords(true);}
|
||||
compare.getRegressionTest();
|
||||
}
|
||||
}
|
||||
if(integrationTest){
|
||||
IntegrationTest compare(basename1,basename2, absoluteTolerance, relativeTolerance);
|
||||
if(findVectorWithGreatestErrorRatio){compare.setFindVectorWithGreatestErrorRatio(true);}
|
||||
if(allowSpikes){compare.setAllowSpikes(true);}
|
||||
if(oneOfTheMainVariables){
|
||||
compare.setOneOfTheMainVariables(true);
|
||||
std::string str(mainVariable);
|
||||
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
|
||||
if(str == "WOPR" ||str=="WWPR" ||str=="WGPR" || str == "WBHP"){
|
||||
compare.setMainVariable(str);
|
||||
}else{
|
||||
throw std::invalid_argument("The input is not a main variable. -m option requires a valid main variable.");
|
||||
}
|
||||
}
|
||||
if(findVolumeError){compare.setFindVolumeError(true);}
|
||||
if(limit != -1){compare.setSpikeLimit(limit);}
|
||||
if(!allowDifferentAmountOfKeywords){compare.setAllowDifferentAmountOfKeywords(false);}
|
||||
if(printKeywords){compare.setPrintKeywords(true);}
|
||||
if(!throwExceptionForTooGreatErrorRatio){compare.setThrowExceptionForTooGreatErrorRatio(false);}
|
||||
if(specificKeyword){
|
||||
if(printSpecificKeyword){compare.setPrintSpecificKeyword(true);}
|
||||
compare.getIntegrationTest(keyword);
|
||||
return 0;
|
||||
}
|
||||
compare.getIntegrationTest();
|
||||
}
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/test_util/EclFilesComparator.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
static void printHelp() {
|
||||
std::cout << "compareRestart compares restartfiles and gridsizes from two simulations.\n"
|
||||
<< "The program takes four arguments:\n\n"
|
||||
<< "1. File number 1 (full path without extension)\n"
|
||||
<< "2. File number 2 (full path without extension)\n"
|
||||
<< "3. Absolute tolerance\n"
|
||||
<< "4. Relative tolerance (between 0 and 1)\n\n"
|
||||
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
|
||||
<< "-h Print help.\n"
|
||||
<< "-k Specify specific keyword to compare, for example -k PRESSURE.\n"
|
||||
<< "-s Print all values side by side from the specified files.\n\n";
|
||||
}
|
||||
|
||||
//------------------------------------------------//
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool showValues = false;
|
||||
bool specificKeyword = false;
|
||||
char* keyword = nullptr;
|
||||
int c = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "hk:s")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'k':
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 's':
|
||||
showValues = true;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k') {
|
||||
std::cout << "Option k requires an argument." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int argOffset = optind;
|
||||
if (argc != argOffset + 4) {
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const std::string basename1 = argv[argOffset];
|
||||
const std::string basename2 = argv[argOffset + 1];
|
||||
const double absTolerance = atof(argv[argOffset + 2]);
|
||||
const double relTolerance = atof(argv[argOffset + 3]);
|
||||
|
||||
try {
|
||||
ECLFilesComparator comparator(INITFILE, basename1, basename2, absTolerance, relTolerance);
|
||||
if (showValues) {
|
||||
comparator.setShowValues(true);
|
||||
}
|
||||
if (specificKeyword) {
|
||||
comparator.gridCompare();
|
||||
comparator.resultsForKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
comparator.gridCompare();
|
||||
comparator.results();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/test_util/EclFilesComparator.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
static void printHelp() {
|
||||
std::cout << "compareRestart compares restartfiles and gridsizes from two simulations.\n"
|
||||
<< "The program takes four arguments:\n\n"
|
||||
<< "1. File number 1 (full path without extension)\n"
|
||||
<< "2. File number 2 (full path without extension)\n"
|
||||
<< "3. Absolute tolerance\n"
|
||||
<< "4. Relative tolerance (between 0 and 1)\n\n"
|
||||
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
|
||||
<< "-h Print help.\n"
|
||||
<< "-k Specify specific keyword to compare, for example -k PRESSURE.\n"
|
||||
<< "-s Print all values side by side from the specified files.\n\n";
|
||||
}
|
||||
|
||||
//------------------------------------------------//
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool showValues = false;
|
||||
bool specificKeyword = false;
|
||||
char* keyword = nullptr;
|
||||
int c = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "hk:s")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'k':
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 's':
|
||||
showValues = true;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k') {
|
||||
std::cout << "Option k requires an argument." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int argOffset = optind;
|
||||
if (argc != argOffset + 4) {
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const std::string basename1 = argv[argOffset];
|
||||
const std::string basename2 = argv[argOffset + 1];
|
||||
const double absTolerance = atof(argv[argOffset + 2]);
|
||||
const double relTolerance = atof(argv[argOffset + 3]);
|
||||
|
||||
try {
|
||||
ECLFilesComparator comparator(RESTARTFILE, basename1, basename2, absTolerance, relTolerance);
|
||||
if (showValues) {
|
||||
comparator.setShowValues(true);
|
||||
}
|
||||
if (specificKeyword) {
|
||||
comparator.gridCompare();
|
||||
comparator.resultsForKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
comparator.gridCompare();
|
||||
comparator.results();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/test_util/EclFilesComparator.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
static void printHelp() {
|
||||
std::cout << "compareRestart compares restartfiles and gridsizes from two simulations.\n"
|
||||
<< "The program takes four arguments:\n\n"
|
||||
<< "1. File number 1 (full path without extension)\n"
|
||||
<< "2. File number 2 (full path without extension)\n"
|
||||
<< "3. Absolute tolerance\n"
|
||||
<< "4. Relative tolerance (between 0 and 1)\n\n"
|
||||
<< "In addition, the program takes these options (which must be given before the arguments):\n\n"
|
||||
<< "-h Print help.\n"
|
||||
<< "-k Specify specific keyword to compare, for example -k PRESSURE.\n"
|
||||
<< "-s Print all values side by side from the specified files.\n\n";
|
||||
}
|
||||
|
||||
//------------------------------------------------//
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool showValues = false;
|
||||
bool specificKeyword = false;
|
||||
char* keyword = nullptr;
|
||||
int c = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "hk:s")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'k':
|
||||
specificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case 's':
|
||||
showValues = true;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k') {
|
||||
std::cout << "Option k requires an argument." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int argOffset = optind;
|
||||
if (argc != argOffset + 4) {
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const std::string basename1 = argv[argOffset];
|
||||
const std::string basename2 = argv[argOffset + 1];
|
||||
const double absTolerance = atof(argv[argOffset + 2]);
|
||||
const double relTolerance = atof(argv[argOffset + 3]);
|
||||
|
||||
try {
|
||||
std::cout << "\nUsing absolute deviation tolerance of " << absTolerance
|
||||
<< " and relative tolerance of " << relTolerance << ".\n";
|
||||
ECLFilesComparator comparator(RFTFILE, basename1, basename2, absTolerance, relTolerance);
|
||||
if (showValues) {
|
||||
comparator.setShowValues(true);
|
||||
}
|
||||
if (specificKeyword) {
|
||||
comparator.gridCompare();
|
||||
comparator.resultsForKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
comparator.gridCompare();
|
||||
comparator.results();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
char* unit = getUnit(keyword);
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <opm/test_util/summaryRegressionTest.hpp>
|
||||
#include <string>
|
||||
#include <getopt.h>
|
||||
|
||||
void printHelp(); //< Declare global function which prints help text
|
||||
void printHelp(){
|
||||
std::cout << "The program takes four arguments" << std::endl;
|
||||
std::cout << "1) <path to file1>/<base_name>" << std::endl;
|
||||
std::cout << "2) <path to file2>/<base_name>" << std::endl;
|
||||
std::cout << "the basename should be without ectension." << std::endl;
|
||||
std::cout << "3) relative tolerance (between 0 and 1)" << std::endl;
|
||||
std::cout << "4) absolute tolerance" << std::endl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
int main (int argc, char ** argv){
|
||||
bool spesificKeyword = false;
|
||||
const char* keyword = nullptr;
|
||||
int c = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "hk:")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
printHelp();
|
||||
return 0;
|
||||
case 'k':
|
||||
spesificKeyword = true;
|
||||
keyword = optarg;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt == 'k') {
|
||||
std::cout << "Option k requires an keyword." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown option." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
int argOffset = optind;
|
||||
|
||||
if (argc != argOffset + 4) {
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char * basename1 = argv[argOffset];
|
||||
const char * basename2 = argv[argOffset+1];
|
||||
double absoluteTolerance = atof(argv[argOffset+2]);
|
||||
double relativeTolerance = atof(argv[argOffset+3]);
|
||||
try {
|
||||
RegressionTest read(basename1,basename2, absoluteTolerance, relativeTolerance);
|
||||
if(spesificKeyword){
|
||||
read.getRegressionTest(keyword);
|
||||
}
|
||||
else{
|
||||
read.getRegressionTest();
|
||||
}
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Program threw an exception: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,24 +1,25 @@
|
||||
/*
|
||||
Copyright 2016 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
+ Copyright 2016 Statoil ASA.
|
||||
+
|
||||
+ This file is part of the Open Porous Media project (OPM).
|
||||
+
|
||||
+ OPM 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.
|
||||
+
|
||||
+ OPM 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 for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU General Public License
|
||||
+ along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include <opm/test_util/summaryComparator.hpp>
|
||||
#include <opm/test_util/summaryIntegrationTest.hpp>
|
||||
|
||||
|
||||
#if HAVE_DYNAMIC_BOOST_TEST
|
||||
@ -40,35 +41,59 @@ BOOST_AUTO_TEST_CASE(deviation){
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(median){
|
||||
std::vector<double> vec = {8.6, 0.6 ,0 , 3.0, 7.2};
|
||||
BOOST_CHECK_EQUAL(3,SummaryComparator::median(vec));
|
||||
vec.pop_back();
|
||||
BOOST_CHECK_EQUAL(1.8, SummaryComparator::median(vec));
|
||||
BOOST_AUTO_TEST_CASE(area) {
|
||||
double width1 = 0;
|
||||
double width2 = 2;
|
||||
double width3 = 10;
|
||||
|
||||
}
|
||||
double area1 = IntegrationTest::getRectangleArea(1,width2);
|
||||
double area2 = IntegrationTest::getRectangleArea(10,width1);
|
||||
double area3 = IntegrationTest::getRectangleArea(4,width3);
|
||||
|
||||
BOOST_AUTO_TEST_CASE(interpolation){
|
||||
double timeArray[3] = {6,1,2};
|
||||
double linearCheckValues[2] = {6,11};
|
||||
double linearCheckValues_2[2] = {2,12};
|
||||
double constCheckValues[2] = {3,3};
|
||||
|
||||
double linearLP = SummaryComparator::interpolation(linearCheckValues[1],linearCheckValues[0], timeArray);
|
||||
double constLP = SummaryComparator::interpolation(constCheckValues[1], constCheckValues[0], timeArray);
|
||||
double linearLP_2 = SummaryComparator::interpolation(linearCheckValues_2[1], linearCheckValues_2[0], timeArray);
|
||||
BOOST_CHECK_EQUAL(linearLP,7);
|
||||
BOOST_CHECK_EQUAL(constLP,3);
|
||||
BOOST_CHECK_EQUAL(linearLP_2,4);
|
||||
BOOST_CHECK_EQUAL(area1,2);
|
||||
BOOST_CHECK_EQUAL(area2,0);
|
||||
BOOST_CHECK_EQUAL(area3,40);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(average) {
|
||||
BOOST_AUTO_TEST_CASE(operatorOverload) {
|
||||
WellProductionVolume volumeA;
|
||||
WellProductionVolume volumeB;
|
||||
volumeA.total = 2;
|
||||
volumeA.error = 2;
|
||||
volumeB.total = 3;
|
||||
volumeB.error = 1;
|
||||
volumeA += volumeB;
|
||||
|
||||
std::vector<double> vec = {1,2,3,4,5,6};
|
||||
const double tol = 1.0e-14;
|
||||
|
||||
double avg = SummaryComparator::average(vec);
|
||||
|
||||
BOOST_CHECK_CLOSE(avg, 21.0/6, tol);
|
||||
BOOST_CHECK_EQUAL(volumeA.total,5);
|
||||
BOOST_CHECK_EQUAL(volumeA.error,3);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(integration) {
|
||||
std::vector<double> data1 = {2,2,2,2,2,2};
|
||||
std::vector<double> time1 = {0,1,2,3,4,5};
|
||||
|
||||
double val1 = IntegrationTest::integrate(time1, data1);
|
||||
|
||||
std::vector<double> data2 = {3, 3, 4, 3, 2, 1, 0, 4};
|
||||
std::vector<double> time2 = {0, 0.5, 1, 2, 3, 3.5, 4.5, 5};
|
||||
|
||||
std::vector<double> data3 = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
std::vector<double> data4 = {0, 1, 4, 1, 2, 4, 0, 2, 5, 6, 3};
|
||||
std::vector<double> time4 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10};
|
||||
|
||||
std::vector<double> data5 = {0, 4, 3, 2, 5, 6, 3, 1, 0, 4, 2, 1};
|
||||
std::vector<double> time5 = {0, 0.5, 1, 2.5, 3, 4, 4.5, 6, 7.5,8, 9.5 ,10};
|
||||
|
||||
double val2 = IntegrationTest::integrateError(time1, data1, time2, data2);
|
||||
double val3 = IntegrationTest::integrateError(time1, data1, time2, data3);
|
||||
double val4 = IntegrationTest::integrateError(time1, data1, time1, data1);
|
||||
double val5 = IntegrationTest::integrateError(time4, data4, time5, data5);
|
||||
BOOST_CHECK_EQUAL(val1,10);
|
||||
BOOST_CHECK_EQUAL(val2,6);
|
||||
BOOST_CHECK_EQUAL(val3,10);
|
||||
BOOST_CHECK_EQUAL(val4,0);
|
||||
BOOST_CHECK_EQUAL(val5,24.5);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user