My Project
Loading...
Searching...
No Matches
SatfuncConsistencyChecks.hpp
1/*
2 Copyright 2024 Equinor AS
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_SATFUNC_CONSISTENCY_CHECK_MODULE_HPP
21#define OPM_SATFUNC_CONSISTENCY_CHECK_MODULE_HPP
22
23#include <opm/simulators/utils/ParallelCommunication.hpp>
24
25#include <cstddef>
26#include <functional>
27#include <memory>
28#include <random>
29#include <string>
30#include <string_view>
31#include <vector>
32
33namespace Opm {
34 template <typename Scalar>
35 struct EclEpsScalingPointsInfo;
36} // namespace Opm
37
38namespace Opm {
39
44 template <typename Scalar>
46 {
47 public:
51 class Check
52 {
53 public:
55 virtual ~Check() = default;
56
65
67 virtual bool isViolated() const = 0;
68
73 virtual bool isCritical() const = 0;
74
76 virtual std::size_t numExportedCheckValues() const = 0;
77
84 virtual void exportCheckValues(Scalar* exportedCheckValues) const = 0;
85
90 virtual std::string description() const = 0;
91
93 virtual std::string condition() const = 0;
94
103 virtual void columnNames(std::string* headers) const = 0;
104 };
105
107 enum class ViolationLevel : std::size_t {
110 Standard,
111
114 Critical,
115
117 NumLevels,
118 };
119
122 using ReportRecordOutput = std::function<void(std::string_view)>;
123
125 using PointIDFormatCallback = std::function<std::string(std::size_t)>;
126
136 explicit SatfuncConsistencyChecks(std::string_view pointName,
137 const std::size_t numSamplePoints);
138
141
144
150
154
162
175 {
176 this->formatPointID_ = formatPointID;
177 return *this;
178 }
179
181 void resetCheckSet();
182
186 void addCheck(std::unique_ptr<Check> check);
187
190 void finaliseCheckSet();
191
203 void checkEndpoints(const std::size_t pointID,
205
217 void collectFailures(int root, const Parallel::Communication& comm);
218
220 bool anyFailedStandardChecks() const;
221
223 bool anyFailedCriticalChecks() const;
224
242 void reportFailures(const ViolationLevel level,
244
245 private:
251 using RandomBitGenerator = std::minstd_rand;
252
254 struct ViolationSample
255 {
259 std::vector<std::size_t> count{};
260
266 std::vector<std::size_t> pointID{};
267
275 std::vector<Scalar> checkValues{};
276
278 void clear();
279 };
280
284 using ViolationCollection = std::array
285 <ViolationSample, static_cast<std::size_t>(ViolationLevel::NumLevels)>;
286
291 std::string pointName_{};
292
294 std::size_t numSamplePoints_;
295
301 PointIDFormatCallback formatPointID_{};
302
305 std::vector<typename std::vector<Scalar>::size_type> startCheckValues_{};
306
310 ViolationCollection violations_{};
311
314 std::vector<std::unique_ptr<Check>> battery_{};
315
322 std::unique_ptr<RandomBitGenerator> urbg_{};
323
340 void collectFailures(int root,
341 const Parallel::Communication& comm,
342 ViolationSample& violation);
343
349 void buildStructure(ViolationSample& violation);
350
383 template <typename PopulateCheckValues>
384 void processViolation(ViolationSample& violation,
385 const std::size_t checkIx,
386 const std::size_t pointID,
388
403 void processViolation(const ViolationLevel level,
404 const std::size_t checkIx,
405 const std::size_t pointID);
406
420 void incorporateRankViolations(const std::size_t* count,
421 const std::size_t* pointID,
422 const Scalar* checkValues,
423 ViolationSample& violation);
424
432 std::size_t getSampleIndex(const std::size_t sampleSize);
433
436 void ensureRandomBitGeneratorIsInitialised();
437
445 std::vector<std::size_t>::size_type
446 violationPointIDStart(const std::size_t checkIx) const;
447
458 typename std::vector<Scalar>::size_type
459 violationValueStart(const std::size_t checkIx,
460 const std::size_t sampleIx) const;
461
475 void writeReportHeader(const Check* currentCheck,
476 const std::size_t violationCount,
478
494 void writeTabulatedReportSample(const std::size_t nValueChar,
495 const Check* currentCheck,
496 const ViolationSample& violation,
497 const std::size_t checkIx,
499
510 std::pair<std::vector<std::string>, std::string::size_type>
511 formatPointIDs(const ViolationSample& violation,
512 const std::size_t checkIx) const;
513
521 std::vector<std::string>
522 collectColumnHeaders(const Check* currentCheck) const;
523
534 std::vector<std::size_t>
535 sortedPointIndices(const ViolationSample& violation,
536 const std::size_t checkIx) const;
537
550 std::size_t numPoints(const ViolationSample& violation,
551 const std::size_t checkIx) const;
552
562 std::size_t numPoints(const std::size_t violationCount) const;
563
570 bool anyFailedChecks(const ViolationLevel level) const;
571
578 auto index(const ViolationLevel level) const
579 {
580 return static_cast<typename ViolationCollection::size_type>(level);
581 }
582
599 template <typename Body>
600 void checkLoop(Body&& body);
601
618 template <typename Body>
619 void checkLoop(Body&& body) const;
620 };
621
622} // namespace Opm
623
624#endif // OPM_SATFUNC_CONSISTENCY_CHECK_MODULE_HPP
Call-back interface for an individual check.
Definition SatfuncConsistencyChecks.hpp:52
virtual std::string description() const =0
Descriptive textual summary of this check.
virtual ~Check()=default
Virtual destructor since class has virtual functions.
virtual void test(const EclEpsScalingPointsInfo< Scalar > &endPoints)=0
Run specific check against a set of saturation function end-points.
virtual bool isCritical() const =0
Whether or not this check is critical to the simulator's ability to run the case.
virtual void exportCheckValues(Scalar *exportedCheckValues) const =0
Get a linearised copy of the Scalar values involved in the check.
virtual std::string condition() const =0
Textual representation of the consistency condition.
virtual bool isViolated() const =0
Whether or not last set of end-points violated this particular check.
virtual std::size_t numExportedCheckValues() const =0
Number of Scalar values involved in the check.
virtual void columnNames(std::string *headers) const =0
Retrieve names of the exported check values.
Platform for running sets of consistency checks against collection of saturation function end-points.
Definition SatfuncConsistencyChecks.hpp:46
bool anyFailedCriticalChecks() const
Whether or not any checks failed at the Critical level.
Definition SatfuncConsistencyChecks.cpp:171
ViolationLevel
Severity level for consistency condition violation.
Definition SatfuncConsistencyChecks.hpp:107
@ NumLevels
Implementation helper. Must be last enumerator.
@ Critical
Consistency condition violated and we're not able to continue the run.
@ Standard
Consistency condition violated, but we're able to continue the run.
SatfuncConsistencyChecks & operator=(const SatfuncConsistencyChecks &rhs)=delete
Deleted assignment operator.
void resetCheckSet()
Clear current set of end-point checks.
Definition SatfuncConsistencyChecks.cpp:86
void checkEndpoints(const std::size_t pointID, const EclEpsScalingPointsInfo< Scalar > &endPoints)
Run current set of checks against a specific set of end-points.
Definition SatfuncConsistencyChecks.cpp:122
void addCheck(std::unique_ptr< Check > check)
Add specific check to in-progress check set.
Definition SatfuncConsistencyChecks.cpp:100
SatfuncConsistencyChecks(const SatfuncConsistencyChecks &rhs)=delete
Deleted copy constructor.
~SatfuncConsistencyChecks()=default
Destructor.
bool anyFailedStandardChecks() const
Whether or not any checks failed at the Standard level.
Definition SatfuncConsistencyChecks.cpp:165
std::function< std::string(std::size_t)> PointIDFormatCallback
Call-back function type for formatting a numeric end-point ID.
Definition SatfuncConsistencyChecks.hpp:125
SatfuncConsistencyChecks & setPointIDFormatCallback(const PointIDFormatCallback &formatPointID)
Replace formatting function for end-point IDs.
Definition SatfuncConsistencyChecks.hpp:174
void collectFailures(int root, const Parallel::Communication &comm)
Collect consistency violations from all ranks in MPI communicator.
Definition SatfuncConsistencyChecks.cpp:150
void finaliseCheckSet()
Commit current set of checks and build requisite internal support structures.
Definition SatfuncConsistencyChecks.cpp:109
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
void reportFailures(const ViolationLevel level, const ReportRecordOutput &emitReportRecord) const
Generate textual summary output of all failed consistency checks at specific level.
Definition SatfuncConsistencyChecks.cpp:178
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Definition SatfuncCheckPointInterface.hpp:28