Merge pull request #764 from joakim-hove/restart-test

Restart test
This commit is contained in:
Atgeirr Flø Rasmussen 2016-08-02 12:10:38 +02:00 committed by GitHub
commit 73a4d42918
3 changed files with 45 additions and 112 deletions

View File

@ -127,34 +127,21 @@ 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_SPE1CASE2 COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2.DATA )
add_test( NAME flow_SPE1CASE2_restart COMMAND flow ${OPM_DATA_ROOT}/spe1/SPE1CASE2_RESTART.DATA )
add_test( NAME flow_sequential_SPE1 COMMAND flow_sequential ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA )
add_test( NAME flow_MSW2DH__ COMMAND flow_multisegment ${OPM_DATA_ROOT}/wells_test_suite/MSW/2D_H__/2D_H__.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 opmsimulators ${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
add_test( NAME flow_sequential_SPE1 COMMAND flow_sequential ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA )
if (ERT_PYTHON_PATH)
include(OpmPythonTest)
opm_add_python_test( check_INIT_SPE1 ${PROJECT_SOURCE_DIR}/tests/compare_INIT.py $<TARGET_FILE:flow> ${OPM_DATA_ROOT}/spe1/SPE1CASE1.DATA ${OPM_DATA_ROOT}/spe1/eclipse-simulation/SPE1CASE1.INIT
TRANX TRANY TRANZ PORO PORV PERMX DX DY DZ DEPTH PVTNUM SATNUM EQLNUM FIPNUM )
opm_add_python_test( check_INIT_NORNE ${PROJECT_SOURCE_DIR}/tests/compare_INIT.py $<TARGET_FILE:flow> ${OPM_DATA_ROOT}/norne/NORNE_ATW2013.DATA ${OPM_DATA_ROOT}/norne/ECL.2014.2/NORNE_ATW2013.INIT PORO PORV PERMX )
opm_add_python_test( check_RESTART_SPE1CASE2
${PROJECT_SOURCE_DIR}/tests/check_RESTART.py
$<TARGET_FILE:flow> ${OPM_DATA_ROOT}/spe1/SPE1CASE2.DATA ${OPM_DATA_ROOT}/spe1/SPE1CASE2_RESTART.DATA )
endif()
include (${CMAKE_CURRENT_SOURCE_DIR}/compareECLFiles.cmake)

40
tests/check_RESTART.py Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import subprocess
import sys
import os.path
from ert.ecl import EclFile
from ert.test import TestAreaContext
def compare_files( flow_file , ref_file):
flow = EclFile( flow_file )
ref = EclFile( ref_file )
for kw in ["PRESSURE" , "SWAT" , "SGAS" , "RS" , "RV"]:
flow_kw = flow[kw][-1]
ref_kw = ref[kw][-1]
if not flow_kw.equal_numeric( ref_kw , abs_epsilon = 0, rel_epsilon = 1e-3 ):
first_different = flow_kw.firstDifferent( ref_kw , abs_epsilon = 0, rel_epsilon = 1e-3 )
sys.exit("Keyword:%s was different in flow simulation and reference. First difference in index:%d" % (kw , first_different))
#-----------------------------------------------------------------
# Small script running flow twice, once with restart and normal run
# from step 0. The final state of the two runs is compared.
flow = sys.argv[1]
full_deck = sys.argv[2]
restart_deck = sys.argv[3]
with TestAreaContext("flow_init") as ta:
ta.copy_file( full_deck )
ta.copy_file( restart_deck )
subprocess.check_call( [flow , os.path.basename( full_deck ) ] )
subprocess.check_call( [flow , os.path.basename( restart_deck ) ] )
compare_files( os.path.splitext( os.path.basename( full_deck ) )[0] + ".UNRST" , os.path.splitext( os.path.basename( restart_deck ) )[0] + ".UNRST")

View File

@ -1,94 +0,0 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MODULE RestartTests
#include <iostream>
#include <map>
#include <cstdlib>
#include <ert/ecl/ecl_rst_file.h>
#include <ert/ecl/ecl_kw.h>
#include <boost/test/unit_test.hpp>
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]);
const double abs_diff = 0; // An absoulute value of 0 means that *only* the relative difference is used in the comparison.
std::map<std::string, double> relative_diffs;
relative_diffs["SWAT"] = 0.0005; //0.05 %
relative_diffs["SGAS"] = 0.0010;
relative_diffs["RS"] = 0.0001; //0.01 %
relative_diffs["RV"] = 0.0001;
relative_diffs["PRESSURE"] = 0.0001;
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);
if (!file1) {
std::cerr << "Failed to open restart file: " << filename1 << std::endl;
BOOST_REQUIRE( false );
}
if (!file2) {
std::cerr << "Failed to open restart file: " << filename2 << std::endl;
BOOST_REQUIRE( false );
}
for (const char * key : {"PRESSURE", "SWAT", "SGAS", "RS", "RV"}) {
if ((ecl_file_has_kw( file1 , key)) && (ecl_file_has_kw( file2 , key))) {
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, abs_diff , relative_diffs[key]);
if (numeric_equal) {
std::cout << " Restart results for " << key << " compared ok" << std::endl;
} else {
float max_value,min_value;
ecl_kw_inplace_sub(kw_1, kw_2);
ecl_kw_max_min(kw_1,&max_value, &min_value);
std::cout << " Restart results for " << key << " is not ok, failing test: " << std::endl
<< " Relative difference allowed is " << relative_diffs[key] << std::endl
<< " Actual absolute difference minimum value, maximum value is: " << min_value << ", " << max_value << std::endl;
}
BOOST_CHECK(numeric_equal);
} else {
std::cerr << "Could not find keyword: " << key << " in restart files" << std::endl;
BOOST_REQUIRE( false );
}
}
ecl_file_close(file1);
ecl_file_close(file2);
}