diff --git a/examples/test_util/initRegressionTest.cpp b/examples/test_util/initRegressionTest.cpp new file mode 100644 index 000000000..8f3e5457a --- /dev/null +++ b/examples/test_util/initRegressionTest.cpp @@ -0,0 +1,102 @@ +/* + 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 . + */ + +#include + +#include +#include +#include + +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; +} diff --git a/examples/test_util/restartRegressionTest.cpp b/examples/test_util/restartRegressionTest.cpp new file mode 100644 index 000000000..b1f4a3544 --- /dev/null +++ b/examples/test_util/restartRegressionTest.cpp @@ -0,0 +1,102 @@ +/* + 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 . + */ + +#include + +#include +#include +#include + +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; +} diff --git a/examples/test_util/rftRegressionTest.cpp b/examples/test_util/rftRegressionTest.cpp new file mode 100644 index 000000000..5d936d1a9 --- /dev/null +++ b/examples/test_util/rftRegressionTest.cpp @@ -0,0 +1,104 @@ +/* + 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 . + */ + +#include + +#include +#include +#include + +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; +} diff --git a/examples/test_util/summaryRegressionTest.cpp b/examples/test_util/summaryRegressionTest.cpp new file mode 100644 index 000000000..995c785d5 --- /dev/null +++ b/examples/test_util/summaryRegressionTest.cpp @@ -0,0 +1,85 @@ +/* + 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 . + */ + +#include +#include +#include +void printHelp(){ + std::cout << "The program takes four arguments" << std::endl; + std::cout << "1) /" << std::endl; + std::cout << "2) /" << 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; +}