Loading...
Searching...
No Matches
SatfuncConsistencyCheckManager.hpp
/*
Copyright 2024 Equinor AS
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 SATFUNC_CONSISTENCY_CHECK_MANAGER_HPP_INCLUDED
#define SATFUNC_CONSISTENCY_CHECK_MANAGER_HPP_INCLUDED
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp>
#include <opm/material/fluidmatrixinteractions/EclEpsGridProperties.hpp>
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <opm/simulators/utils/satfunc/SatfuncCheckPointInterface.hpp>
#include <opm/simulators/utils/satfunc/SatfuncConsistencyChecks.hpp>
#include <dune/grid/common/partitionset.hh>
#include <dune/grid/common/rangegenerators.hh>
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
namespace Opm::Satfunc::PhaseChecks {
template <typename Scalar>
class UnscaledSatfuncCheckPoint;
} // namespace Opm::Satfunc::PhaseChecks
namespace Opm::Satfunc::PhaseChecks {
template <typename Scalar>
class SatfuncConsistencyCheckManager
{
public:
using LocalToGlobal = std::function<std::size_t(int)>;
using ReportRecordOutput = typename
SatfuncConsistencyChecks<Scalar>::ReportRecordOutput;
using ViolationLevel = typename
SatfuncConsistencyChecks<Scalar>::ViolationLevel;
explicit SatfuncConsistencyCheckManager(const std::size_t numSamplePoints,
const EclipseState& eclipseState,
const LocalToGlobal& localToGlobal);
SatfuncConsistencyCheckManager& collectFailuresTo(const int root)
{
this->root_ = root;
return *this;
}
template <typename GridView, typename GetCellIndex>
void run(const GridView& gv, GetCellIndex&& getCellIndex)
{
this->isRoot_ = gv.comm().rank() == this->root_;
this->warnIfDirectionalOrIrreversibleEPS();
for (const auto& elem : elements(gv, Dune::Partitions::interior)) {
this->runCellChecks(getCellIndex(elem));
}
gv.comm().barrier();
this->collectFailures(gv.comm());
}
bool anyFailedStandardChecks() const;
bool anyFailedCriticalChecks() const;
void reportFailures(const ViolationLevel level,
const ReportRecordOutput& emitReportRecord) const;
private:
struct CurveCollection
{
explicit CurveCollection(std::unique_ptr<SatfuncCheckPointInterface<Scalar>> point,
std::string_view pointName,
const std::size_t numSamplePoints);
std::unique_ptr<SatfuncCheckPointInterface<Scalar>> point;
SatfuncConsistencyChecks<Scalar> checks;
};
std::reference_wrapper<const EclipseState> eclipseState_;
LocalToGlobal localToGlobal_;
satfunc::RawTableEndPoints rtep_{};
satfunc::RawFunctionValues rfunc_{};
std::vector<EclEpsGridProperties> gridProps_{};
std::vector<CurveCollection> curves_{};
int root_{0};
bool isRoot_{false};
void warnIfDirectionalOrIrreversibleEPS() const;
void runCellChecks(const int cellIdx);
void configureCurveChecks(const std::size_t numSamplePoints);
std::unique_ptr<UnscaledSatfuncCheckPoint<Scalar>>
configureUnscaledCurveChecks(const std::string& regionName,
const std::size_t numSamplePoints);
void configureScaledCurveChecks(const UnscaledSatfuncCheckPoint<Scalar>& unscaledChecks,
const bool useImbibition,
const std::size_t numSamplePoints);
void addChecks();
void collectFailures(const Parallel::Communication& comm);
template <typename Body>
void curveLoop(Body&& body);
template <typename Body>
void curveLoop(Body&& body) const;
};
} // namespace Opm::Satfunc::PhaseChecks
#endif // SATFUNC_CONSISTENCY_CHECK_MANAGER_HPP_INCLUDED
Opm::SatfuncConsistencyChecks
Platform for running sets of consistency checks against collection of saturation function end-points.
Definition SatfuncConsistencyChecks.hpp:46
Opm::SatfuncConsistencyChecks::ViolationLevel
ViolationLevel
Severity level for consistency condition violation.
Definition SatfuncConsistencyChecks.hpp:107
Opm::SatfuncConsistencyChecks::ReportRecordOutput
std::function< void(std::string_view)> ReportRecordOutput
Call-back function type for outputting a single record of a consistency condition violation report.
Definition SatfuncConsistencyChecks.hpp:122
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::collectFailuresTo
SatfuncConsistencyCheckManager & collectFailuresTo(const int root)
Set rank to which failure reports should be collected.
Definition SatfuncConsistencyCheckManager.hpp:99
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::anyFailedStandardChecks
bool anyFailedStandardChecks() const
Whether or not any checks failed at the Standard level.
Definition SatfuncConsistencyCheckManager.cpp:107
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::run
void run(const GridView &gv, GetCellIndex &&getCellIndex)
Execute collection of saturation function consistency checks for all cells in simulation model.
Definition SatfuncConsistencyCheckManager.hpp:128
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::ReportRecordOutput
typename SatfuncConsistencyChecks< Scalar >::ReportRecordOutput ReportRecordOutput
Call-back function type for outputting a single record of a consistency condition violation report.
Definition SatfuncConsistencyCheckManager.hpp:66
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::LocalToGlobal
std::function< std::size_t(int)> LocalToGlobal
Callback for translating active cell index to globally unique point ID.
Definition SatfuncConsistencyCheckManager.hpp:62
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::SatfuncConsistencyCheckManager
SatfuncConsistencyCheckManager(const std::size_t numSamplePoints, const EclipseState &eclipseState, const LocalToGlobal &localToGlobal)
Constructor.
Definition SatfuncConsistencyCheckManager.cpp:88
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::ViolationLevel
typename SatfuncConsistencyChecks< Scalar >::ViolationLevel ViolationLevel
Severity level for consistency condition violation.
Definition SatfuncConsistencyCheckManager.hpp:70
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::anyFailedCriticalChecks
bool anyFailedCriticalChecks() const
Whether or not any checks failed at the Critical level.
Definition SatfuncConsistencyCheckManager.cpp:116
Opm::Satfunc::PhaseChecks::SatfuncConsistencyCheckManager::reportFailures
void reportFailures(const ViolationLevel level, const ReportRecordOutput &emitReportRecord) const
Generate textual summary output of all failed consistency checks at specific level.
Definition SatfuncConsistencyCheckManager.cpp:125
Opm::Satfunc::PhaseChecks::UnscaledSatfuncCheckPoint
Callbacks for defining the consistency check point of a single region.
Definition UnscaledSatfuncCheckPoint.hpp:47
Opm::Satfunc::PhaseChecks::SatfuncCheckPointInterface
Callback protocol for single saturation function consistency check point.
Definition SatfuncCheckPointInterface.hpp:40