diff --git a/CMakeLists.txt b/CMakeLists.txt index 8af981a26..c1952fdb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,5 +124,24 @@ endif (NOT EIGEN3_FOUND) if (HAVE_OPM_DATA) - add_test( NAME flow_SPE1 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA ) + add_test( NAME flow_SPE1 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA ) + + add_test( NAME flow_SPE1CASE2 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2.DATA ) + add_test( NAME flow_SPE1CASE2_restart COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2_RESTART.DATA ) + + set_tests_properties(flow_SPE1CASE2_restart PROPERTIES DEPENDS flow_SPE1CASE2) # Dependes on the restart file from test flow_SPE1CASE2 + + add_executable( test_restart tests/test_restart.cpp ) + target_link_libraries( test_restart opmautodiff ${Boost_LIBRARIES}) + + add_test( compare_restart_files + ${CMAKE_BINARY_DIR}/bin/test_restart + SPE1CASE2.UNRST + SPE1CASE2_RESTART.UNRST # Restart from step 60 + 120 + ) + + set_tests_properties(compare_restart_files PROPERTIES DEPENDS flow_SPE1CASE2_restart) # Compares the restart files from tests flow_SPE1CASE2_restart and flow_SPE1CASE2 + + endif() diff --git a/tests/test_restart.cpp b/tests/test_restart.cpp new file mode 100644 index 000000000..250300a80 --- /dev/null +++ b/tests/test_restart.cpp @@ -0,0 +1,73 @@ +/* + Copyright 2014 SINTEF ICT, Applied Mathematics. + Copyright 2015 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 + +#if HAVE_DYNAMIC_BOOST_TEST +#define BOOST_TEST_DYN_LINK +#endif + +#define BOOST_TEST_MODULE RestartTests + +#include +#include + +#include +#include + +#include + + +BOOST_AUTO_TEST_CASE(CompareRestartFileResults) +{ + const std::string& filename1 = boost::unit_test::framework::master_test_suite().argv[1]; + const std::string& filename2 = boost::unit_test::framework::master_test_suite().argv[2]; + int last_report_step = std::atoi(boost::unit_test::framework::master_test_suite().argv[3]); + + std::map relative_diffs; + relative_diffs["SWAT"] = 0.000200; //0.02 % + relative_diffs["SGAS"] = 0.000200; + + relative_diffs["RS"] = 0.000010; //0.001 % + relative_diffs["RV"] = 0.000010; + relative_diffs["PRESSURE"] = 0.000010; + + ecl_file_type* file1 = ecl_file_open_rstblock_report_step( filename1.c_str() , last_report_step, 1); + ecl_file_type* file2 = ecl_file_open_rstblock_report_step( filename2.c_str() , last_report_step, 1); + + for (auto key : {"PRESSURE", "SWAT", "SGAS", "RS", "RV"}) { + ecl_kw_type * kw_1 = ecl_file_iget_named_kw( file1 , key, 0); + ecl_kw_type * kw_2 = ecl_file_iget_named_kw( file2 , key, 0); + + bool numeric_equal = ecl_kw_numeric_equal(kw_1, kw_2, relative_diffs[key]); + if (numeric_equal) { + std::cout << " Restart results for " << key << " compared ok" << std::endl; + } else { + std::cout << " Restart results for " << key << " not ok, failing test " << std::endl; + } + + BOOST_CHECK_EQUAL(numeric_equal, true); + } + + ecl_file_close(file1); + ecl_file_close(file2); +} + +