From 0e2c61856f0d4c125edd0c2cd95c47d95f0ea731 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 30 Apr 2021 09:48:15 +0200 Subject: [PATCH] RelpermDiagnostics: make templates private use explicit template instantation. to avoid rebuilding this code over and over (minor), and to avoid includes in headers. --- CMakeLists_files.cmake | 1 - opm/core/props/satfunc/RelpermDiagnostics.cpp | 69 ++++++++++++ opm/core/props/satfunc/RelpermDiagnostics.hpp | 18 ++-- .../props/satfunc/RelpermDiagnostics_impl.hpp | 100 ------------------ 4 files changed, 76 insertions(+), 112 deletions(-) delete mode 100644 opm/core/props/satfunc/RelpermDiagnostics_impl.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 6e9fc77cd..cc1e9bbaf 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -185,7 +185,6 @@ list (APPEND PUBLIC_HEADER_FILES opm/core/props/BlackoilPhases.hpp opm/core/props/phaseUsageFromDeck.hpp opm/core/props/satfunc/RelpermDiagnostics.hpp - opm/core/props/satfunc/RelpermDiagnostics_impl.hpp opm/simulators/timestepping/SimulatorReport.hpp opm/simulators/wells/WellState.hpp opm/simulators/aquifers/AquiferInterface.hpp diff --git a/opm/core/props/satfunc/RelpermDiagnostics.cpp b/opm/core/props/satfunc/RelpermDiagnostics.cpp index 8278509a7..d154eda84 100644 --- a/opm/core/props/satfunc/RelpermDiagnostics.cpp +++ b/opm/core/props/satfunc/RelpermDiagnostics.cpp @@ -32,9 +32,13 @@ #include #include #include +#include #include #include +#include +#include + namespace Opm{ bool RelpermDiagnostics::phaseCheck_(const EclipseState& es) @@ -725,9 +729,74 @@ namespace Opm{ } } + template + void RelpermDiagnostics::diagnosis(const Opm::EclipseState& eclState, + const CartesianIndexMapper& cartesianIndexMapper) + { + OpmLog::info("\n===============Saturation Functions Diagnostics===============\n"); + bool doDiagnostics = phaseCheck_(eclState); + if (!doDiagnostics) // no diagnostics needed for single phase problems + return; + satFamilyCheck_(eclState); + tableCheck_(eclState); + unscaledEndPointsCheck_(eclState); + scaledEndPointsCheck_(eclState, cartesianIndexMapper); + } + template + void RelpermDiagnostics::scaledEndPointsCheck_(const EclipseState& eclState, + 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 = cartesianIndexMapper.compressedSize(); + const bool threepoint = eclState.runspec().endpointScaling().threepoint(); + scaledEpsInfo_.resize(nc); + EclEpsGridProperties epsGridProperties(eclState, false); + const std::string tag = "Scaled endpoints"; + for (int c = 0; c < nc; ++c) { + const std::string satnumIdx = std::to_string(epsGridProperties.satRegion(c)); + std::string cellIdx; + { + std::array ijk; + cartesianIndexMapper.cartesianCoordinate(c, ijk); + cellIdx = "(" + std::to_string(ijk[0]) + ", " + + std::to_string(ijk[1]) + ", " + + std::to_string(ijk[2]) + ")"; + } + scaledEpsInfo_[c].extractScaled(eclState, epsGridProperties, c); + // SGU <= 1.0 - SWL + if (scaledEpsInfo_[c].Sgu > (1.0 - scaledEpsInfo_[c].Swl + tolerance)) { + const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SGU exceed 1.0 - SWL"; + OpmLog::warning(tag, msg); + } + // SGL <= 1.0 - SWU + if (scaledEpsInfo_[c].Sgl > (1.0 - scaledEpsInfo_[c].Swu + tolerance)) { + const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SGL exceed 1.0 - SWU"; + OpmLog::warning(tag, msg); + } + if (threepoint && fluidSystem_ == FluidSystem::BlackOil) { + // Mobilility check. + if ((scaledEpsInfo_[c].Sowcr + scaledEpsInfo_[c].Swcr) >= (1.0 + tolerance)) { + const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SOWCR + SWCR exceed 1.0"; + OpmLog::warning(tag, msg); + } + if ((scaledEpsInfo_[c].Sogcr + scaledEpsInfo_[c].Sgcr + scaledEpsInfo_[c].Swl) >= (1.0 + tolerance)) { + const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SOGCR + SGCR + SWL exceed 1.0"; + OpmLog::warning(tag, msg); + } + } + } + } + +#define INSTANCE_DIAGNOSIS(...) \ + template void RelpermDiagnostics::diagnosis>(const EclipseState&, const Dune::CartesianIndexMapper<__VA_ARGS__>&); \ + template void RelpermDiagnostics::scaledEndPointsCheck_>(const EclipseState&, const Dune::CartesianIndexMapper<__VA_ARGS__>&); + + INSTANCE_DIAGNOSIS(Dune::CpGrid) + INSTANCE_DIAGNOSIS(Dune::PolyhedralGrid<3,3>) } //namespace Opm diff --git a/opm/core/props/satfunc/RelpermDiagnostics.hpp b/opm/core/props/satfunc/RelpermDiagnostics.hpp index 0b83ba01d..578a00412 100644 --- a/opm/core/props/satfunc/RelpermDiagnostics.hpp +++ b/opm/core/props/satfunc/RelpermDiagnostics.hpp @@ -27,22 +27,20 @@ #include "config.h" #endif // HAVE_CONFIG_H -#include -#include -#include -#include -#include -#include -#include -#include #include namespace Opm { + class EclipseState; + class MiscTable; + class MsfnTable; + class SgcwimTable; class Sof2Table; + class SorwmisTable; + class SsfnTable; class SgwfnTable; - ///This class is intend to be a relpmer diganostics, to detect + ///This class is intend to be a relperm diagnostics, to detect ///wrong input of relperm table and endpoints. class RelpermDiagnostics { @@ -128,6 +126,4 @@ namespace Opm { } //namespace Opm -#include - #endif // OPM_RELPERMDIAGNOSTICS_HEADER_INCLUDED diff --git a/opm/core/props/satfunc/RelpermDiagnostics_impl.hpp b/opm/core/props/satfunc/RelpermDiagnostics_impl.hpp deleted file mode 100644 index dfb3baab0..000000000 --- a/opm/core/props/satfunc/RelpermDiagnostics_impl.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - 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 . -*/ - -#ifndef OPM_RELPERMDIAGNOSTICS_IMPL_HEADER_INCLUDED -#define OPM_RELPERMDIAGNOSTICS_IMPL_HEADER_INCLUDED - -#include -#include - -#include -#include -#include -#include - - -namespace Opm { - - template - void RelpermDiagnostics::diagnosis(const Opm::EclipseState& eclState, - const CartesianIndexMapper& cartesianIndexMapper) - { - OpmLog::info("\n===============Saturation Functions Diagnostics===============\n"); - bool doDiagnostics = phaseCheck_(eclState); - if (!doDiagnostics) // no diagnostics needed for single phase problems - return; - satFamilyCheck_(eclState); - tableCheck_(eclState); - unscaledEndPointsCheck_(eclState); - scaledEndPointsCheck_(eclState, cartesianIndexMapper); - } - - template - void RelpermDiagnostics::scaledEndPointsCheck_(const EclipseState& eclState, - 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 = cartesianIndexMapper.compressedSize(); - const bool threepoint = eclState.runspec().endpointScaling().threepoint(); - scaledEpsInfo_.resize(nc); - EclEpsGridProperties epsGridProperties(eclState, false); - const std::string tag = "Scaled endpoints"; - for (int c = 0; c < nc; ++c) { - const std::string satnumIdx = std::to_string(epsGridProperties.satRegion(c)); - std::string cellIdx; - { - std::array ijk; - cartesianIndexMapper.cartesianCoordinate(c, ijk); - cellIdx = "(" + std::to_string(ijk[0]) + ", " + - std::to_string(ijk[1]) + ", " + - std::to_string(ijk[2]) + ")"; - } - scaledEpsInfo_[c].extractScaled(eclState, epsGridProperties, c); - - // SGU <= 1.0 - SWL - if (scaledEpsInfo_[c].Sgu > (1.0 - scaledEpsInfo_[c].Swl + tolerance)) { - const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SGU exceed 1.0 - SWL"; - OpmLog::warning(tag, msg); - } - - // SGL <= 1.0 - SWU - if (scaledEpsInfo_[c].Sgl > (1.0 - scaledEpsInfo_[c].Swu + tolerance)) { - const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SGL exceed 1.0 - SWU"; - OpmLog::warning(tag, msg); - } - - if (threepoint && fluidSystem_ == FluidSystem::BlackOil) { - // Mobilility check. - if ((scaledEpsInfo_[c].Sowcr + scaledEpsInfo_[c].Swcr) >= (1.0 + tolerance)) { - const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SOWCR + SWCR exceed 1.0"; - OpmLog::warning(tag, msg); - } - - if ((scaledEpsInfo_[c].Sogcr + scaledEpsInfo_[c].Sgcr + scaledEpsInfo_[c].Swl) >= (1.0 + tolerance)) { - const std::string msg = "For scaled endpoints input, cell" + cellIdx + " SATNUM = " + satnumIdx + ", SOGCR + SGCR + SWL exceed 1.0"; - OpmLog::warning(tag, msg); - } - } - } - } - -} //namespace Opm - -#endif // OPM_RELPERMDIAGNOSTICS_IMPL_HEADER_INCLUDED