pass CartesianIndexMapper instead of the grid to the RelpermDiagnositics

This commit is contained in:
Tor Harald Sandve 2021-01-26 14:59:22 +01:00
parent 3a0dbdc6e7
commit c145722798
6 changed files with 47 additions and 62 deletions

View File

@ -34,7 +34,6 @@
#include <opm/grid/CpGrid.hpp>
#include <opm/grid/cpgrid/GridHelpers.hpp>
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
#include <opm/parser/eclipse/Python/Python.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
@ -700,14 +699,6 @@ protected:
asImp_().filterConnections_();
asImp_().updateOutputDir_();
asImp_().finalizeInit_();
if (enableExperiments) {
if (asImp_().grid().size(0)) //grid not loadbalanced yet for ebos!
{
Opm::RelpermDiagnostics relpermDiagnostics;
relpermDiagnostics.diagnosis(*eclState_, asImp_().grid());
}
}
}
void updateCartesianToCompressedMapping_()
{

View File

@ -66,6 +66,8 @@
#include "ecltracermodel.hh"
#include "vtkecltracermodule.hh"
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
#include <opm/models/utils/pffgridvector.hh>
#include <opm/models/blackoil/blackoilmodel.hh>
#include <opm/models/discretization/ecfv/ecfvdiscretization.hh>
@ -839,6 +841,9 @@ public:
maxTimeStepAfterWellEvent_ = EWOMS_GET_PARAM(TypeTag, Scalar, EclMaxTimeStepSizeAfterWellEvent);
restartShrinkFactor_ = EWOMS_GET_PARAM(TypeTag, Scalar, EclRestartShrinkFactor);
maxFails_ = EWOMS_GET_PARAM(TypeTag, unsigned, MaxTimeStepDivisions);
Opm::RelpermDiagnostics relpermDiagnostics;
relpermDiagnostics.diagnosis(vanguard.eclState(), vanguard.cartesianIndexMapper());
}
/*!

View File

@ -52,9 +52,9 @@ namespace Opm {
///output if they're found.
///\param[in] eclState eclipse state.
///\param[in] grid unstructured grid.
template <class GridT>
template <class CartesianIndexMapper>
void diagnosis(const EclipseState& eclState,
const GridT& grid);
const CartesianIndexMapper& cartesianIndexMapper);
private:
enum FluidSystem {
@ -91,9 +91,9 @@ namespace Opm {
///Check endpoints in the saturation tables.
void unscaledEndPointsCheck_(const EclipseState& eclState);
template <class GridT>
template <class CartesianIndexMapper>
void scaledEndPointsCheck_(const EclipseState& eclState,
const GridT& grid);
const CartesianIndexMapper& cartesianIndexMapper);
///For every table, need to deal with case by case.
void swofTableCheck_(const Opm::SwofTable& swofTables,

View File

@ -31,28 +31,25 @@
namespace Opm {
template <class GridT>
template <class CartesianIndexMapper>
void RelpermDiagnostics::diagnosis(const Opm::EclipseState& eclState,
const GridT& grid)
const CartesianIndexMapper& cartesianIndexMapper)
{
OpmLog::info("\n===============Saturation Functions Diagnostics===============\n");
phaseCheck_(eclState);
satFamilyCheck_(eclState);
tableCheck_(eclState);
unscaledEndPointsCheck_(eclState);
scaledEndPointsCheck_(eclState, grid);
scaledEndPointsCheck_(eclState, cartesianIndexMapper);
}
template <class GridT>
template <class CartesianIndexMapper>
void RelpermDiagnostics::scaledEndPointsCheck_(const EclipseState& eclState,
const GridT& grid)
const CartesianIndexMapper& cartesianIndexMapper)
{
// All end points are subject to round-off errors, checks should account for it
const float tolerance = 1e-6;
const int nc = Opm::UgGridHelpers::numCells(grid);
const auto& global_cell = Opm::UgGridHelpers::globalCell(grid);
const auto dims = Opm::UgGridHelpers::cartDims(grid);
const auto& compressedToCartesianIdx = Opm::compressedToCartesian(nc, global_cell);
const int nc = cartesianIndexMapper.compressedSize();
const bool threepoint = eclState.runspec().endpointScaling().threepoint();
scaledEpsInfo_.resize(nc);
EclEpsGridProperties epsGridProperties(eclState, false);
@ -62,10 +59,7 @@ namespace Opm {
std::string cellIdx;
{
std::array<int, 3> ijk;
int cartIdx = compressedToCartesianIdx[c];
ijk[0] = cartIdx % dims[0]; cartIdx /= dims[0];
ijk[1] = cartIdx % dims[1];
ijk[2] = cartIdx / dims[1];
cartesianIndexMapper.cartesianCoordinate(c, ijk);
cellIdx = "(" + std::to_string(ijk[0]) + ", " +
std::to_string(ijk[1]) + ", " +
std::to_string(ijk[2]) + ")";

View File

@ -407,7 +407,6 @@ namespace Opm
setupParallelism();
setupEbosSimulator();
runDiagnostics();
createSimulator();
// if run, do the actual work, else just initialize
@ -545,35 +544,6 @@ namespace Opm
const Schedule& schedule() const
{ return ebosSimulator_->vanguard().schedule(); }
// Run diagnostics.
// Writes to:
// OpmLog singleton.
void runDiagnostics()
{
if (!this->output_cout_) {
return;
}
// Run relperm diagnostics if we have more than one phase.
if (FluidSystem::numActivePhases() > 1) {
RelpermDiagnostics diagnostic;
if (mpi_size_ > 1) {
#if HAVE_MPI
this->grid().switchToGlobalView();
static_cast<ParallelEclipseState&>(this->eclState()).switchToGlobalProps();
#endif
}
diagnostic.diagnosis(eclState(), this->grid());
if (mpi_size_ > 1) {
#if HAVE_MPI
this->grid().switchToDistributedView();
static_cast<ParallelEclipseState&>(this->eclState()).switchToDistributedProps();
#endif
}
}
}
// Run the simulator.
int runSimulator()
{

View File

@ -36,29 +36,54 @@
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/CounterLog.hpp>
#include <opm/grid/UnstructuredGrid.h>
#include <opm/grid/cart_grid.h>
#include <opm/grid/GridManager.hpp>
#include <opm/grid/CpGrid.hpp>
#include <dune/grid/common/mcmgmapper.hh>
#include <opm/core/props/satfunc/RelpermDiagnostics.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#if HAVE_DUNE_FEM
#include <dune/fem/misc/mpimanager.hh>
#else
#include <dune/common/parallel/mpihelper.hh>
#endif
BOOST_AUTO_TEST_SUITE ()
BOOST_AUTO_TEST_CASE(diagnosis)
{
// MPI setup.
int argcDummy = 1;
const char *tmp[] = {"test_relpermdiagnostic"};
char **argvDummy = const_cast<char**>(tmp);
#if HAVE_DUNE_FEM
Dune::Fem::MPIManager::initialize(argcDummy, argvDummy);
#else
Dune::MPIHelper::instance(argcDummy, argvDummy);
#endif
using namespace Opm;
Parser parser;
Opm::Deck deck = parser.parseFile("../tests/relpermDiagnostics.DATA");
EclipseState eclState(deck);
GridManager gm(eclState.getInputGrid());
const UnstructuredGrid& grid = *gm.c_grid();
typedef Dune::CpGrid Grid;
Grid grid = Grid();
grid.processEclipseFormat(&eclState.getInputGrid(),
/*isPeriodic=*/false,
/*flipNormals=*/false,
/*clipZ=*/false,
eclState.fieldProps().porv(true),
eclState.getInputNNC());
typedef Dune::CartesianIndexMapper<Grid> CartesianIndexMapper;
CartesianIndexMapper cartesianIndexMapper = CartesianIndexMapper(grid);
std::shared_ptr<CounterLog> counterLog = std::make_shared<CounterLog>(Log::DefaultMessageTypes);
OpmLog::addBackend( "COUNTERLOG" , counterLog );
RelpermDiagnostics diagnostics;
diagnostics.diagnosis(eclState, grid);
diagnostics.diagnosis(eclState, cartesianIndexMapper);
BOOST_CHECK_EQUAL(1, counterLog->numMessages(Log::MessageType::Warning));
}
BOOST_AUTO_TEST_SUITE_END()