Fixes test for WellStateFullyImplicitBlackoil

This commit is contained in:
Markus Blatt 2020-11-30 16:52:12 +01:00
parent fd4db9b933
commit 562f9ffd03
2 changed files with 92 additions and 6 deletions

76
tests/MpiFixture.hpp Normal file
View File

@ -0,0 +1,76 @@
/*
Copyright 2020 OPM-OP AS
Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services.
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/>.
*/
#ifndef OPM_SIMULATOR_TEST_MPIFIXTURE_HPP
#define OPM_SIMULATOR_TEST_MPIFIXTURE_HPP
#include <dune/common/parallel/mpihelper.hh>
#include <boost/test/unit_test.hpp>
class MPIError {
public:
/** @brief Constructor. */
MPIError(std::string s, int e) : errorstring(s), errorcode(e){}
/** @brief The error string. */
std::string errorstring;
/** @brief The mpi error code. */
int errorcode;
};
#ifdef HAVE_MPI
void MPI_err_handler(MPI_Comm *, int *err_code, ...){
char *err_string=new char[MPI_MAX_ERROR_STRING];
int err_length;
MPI_Error_string(*err_code, err_string, &err_length);
std::string s(err_string, err_length);
std::cerr << "An MPI Error ocurred:"<<std::endl<<s<<std::endl;
delete[] err_string;
throw MPIError(s, *err_code);
}
#endif
struct MPIFixture
{
MPIFixture()
{
#if HAVE_MPI
int m_argc = boost::unit_test::framework::master_test_suite().argc;
char** m_argv = boost::unit_test::framework::master_test_suite().argv;
helper = &Dune::MPIHelper::instance(m_argc, m_argv);
#ifdef MPI_2
MPI_Comm_create_errhandler(MPI_err_handler, &handler);
MPI_Comm_set_errhandler(MPI_COMM_WORLD, handler);
#else
MPI_Errhandler_create(MPI_err_handler, &handler);
MPI_Errhandler_set(MPI_COMM_WORLD, handler);
#endif
#endif
}
~MPIFixture()
{
#if HAVE_MPI
MPI_Finalize();
#endif
}
Dune::MPIHelper* helper;
#if HAVE_MPI
MPI_Errhandler handler;
#endif
};
#endif

View File

@ -21,6 +21,7 @@
#define BOOST_TEST_MODULE WellStateFIBOTest
#include "MpiFixture.hpp"
#include <opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp>
#include <opm/parser/eclipse/Python/Python.hpp>
@ -42,6 +43,8 @@
#include <cstddef>
#include <string>
BOOST_GLOBAL_FIXTURE(MPIFixture);
struct Setup
{
Setup(const std::string& filename)
@ -114,7 +117,8 @@ struct Setup
namespace {
Opm::WellStateFullyImplicitBlackoil
buildWellState(const Setup& setup, const std::size_t timeStep)
buildWellState(const Setup& setup, const std::size_t timeStep,
std::vector<Opm::ParallelWellInfo>& pinfos)
{
auto state = Opm::WellStateFullyImplicitBlackoil{};
@ -123,7 +127,7 @@ namespace {
100.0*Opm::unit::barsa);
auto wells = setup.sched.getWells(timeStep);
std::vector<Opm::ParallelWellInfo> pinfos(wells.size());
pinfos.resize(wells.size());
std::vector<Opm::ParallelWellInfo*> ppinfos(wells.size());
auto pw = pinfos.begin();
auto ppw = ppinfos.begin();
@ -132,6 +136,7 @@ namespace {
{
*pw = {well.name()};
*ppw = &(*pw);
pw->communicateFirstPerforation(true);
++pw;
++ppw;
}
@ -237,7 +242,8 @@ BOOST_AUTO_TEST_CASE(Linearisation)
const Setup setup{ "msw.data" };
const auto tstep = std::size_t{0};
const auto wstate = buildWellState(setup, tstep);
std::vector<Opm::ParallelWellInfo> pinfos;
const auto wstate = buildWellState(setup, tstep, pinfos);
BOOST_CHECK_EQUAL(wstate.numSegment(), 6 + 1);
@ -258,7 +264,8 @@ BOOST_AUTO_TEST_CASE(Pressure)
const Setup setup{ "msw.data" };
const auto tstep = std::size_t{0};
auto wstate = buildWellState(setup, tstep);
std::vector<Opm::ParallelWellInfo> pinfos;
auto wstate = buildWellState(setup, tstep, pinfos);
const auto& wells = setup.sched.getWells(tstep);
const auto prod01_first = wells[0].name() == "PROD01";
@ -304,7 +311,8 @@ BOOST_AUTO_TEST_CASE(Rates)
const Setup setup{ "msw.data" };
const auto tstep = std::size_t{0};
auto wstate = buildWellState(setup, tstep);
std::vector<Opm::ParallelWellInfo> pinfos;
auto wstate = buildWellState(setup, tstep, pinfos);
const auto wells = setup.sched.getWells(tstep);
const auto prod01_first = wells[0].name() == "PROD01";
@ -375,7 +383,9 @@ BOOST_AUTO_TEST_CASE(STOP_well)
also for wells in the STOP state.
*/
const Setup setup{ "wells_manager_data_wellSTOP.data" };
auto wstate = buildWellState(setup, 0);
std::vector<Opm::ParallelWellInfo> pinfos;
auto wstate = buildWellState(setup, 0, pinfos);
for (const auto& p : wstate.perfPress())
BOOST_CHECK(p > 0);
}