Extract Existence Predicate for Well BHP Reference Depth

This commit adds a new member function,

    bool Well::hasRefDepth() const

that allows the caller to query whether or not a particular well has
an active value for the well BHP reference depth.  The most common
cause of this value being missing is that the depth item of WELSPECS
is defaulted while the well is not connected to any active cells.

This predicate allows client code, e.g., the restart output module,
to safely access reference depth values in the case of potentially
missing reference depths.
This commit is contained in:
Bård Skaflestad 2021-12-17 12:45:55 +01:00
parent 25ea975171
commit 8306b7039f
3 changed files with 82 additions and 2 deletions

View File

@ -526,6 +526,7 @@ public:
int getHeadI() const;
int getHeadJ() const;
double getWPaveRefDepth() const;
bool hasRefDepth() const;
double getRefDepth() const;
double getDrainageRadius() const;
double getEfficiencyFactor() const;

View File

@ -847,8 +847,13 @@ bool Well::getAllowCrossFlow() const {
return this->allow_cross_flow;
}
bool Well::hasRefDepth() const
{
return this->ref_depth.has_value();
}
double Well::getRefDepth() const {
if (!this->ref_depth.has_value())
if (!this->hasRefDepth())
throw std::logic_error(fmt::format("Well: {} - tried to access not initialized well reference depth", this->name()));
return *this->ref_depth;
}
@ -1637,7 +1642,8 @@ bool Well::cmp_structure(const Well& other) const {
&& (this->seqIndex() == other.seqIndex())
&& (this->getHeadI() == other.getHeadI())
&& (this->getHeadJ() == other.getHeadJ())
&& (this->getRefDepth() == other.getRefDepth())
&& (this->hasRefDepth() == other.hasRefDepth())
&& (!this->hasRefDepth() || (this->getRefDepth() == other.getRefDepth()))
&& (this->getPreferredPhase() == other.getPreferredPhase())
&& (this->unit_system == other.unit_system)
&& (this->udq_undefined == other.udq_undefined)

View File

@ -1578,3 +1578,76 @@ END
BOOST_CHECK_EQUAL(w5.getRefDepth(), grid.getCellDepth(0,0,0));
BOOST_CHECK_EQUAL(w5.getWPaveRefDepth(), 0);
}
BOOST_AUTO_TEST_CASE(Missing_RefDepth) {
const auto deck = Parser{}.parseString(R"(RUNSPEC
START
17 DEC 2021 /
DIMENS
10 10 4 /
GRID
DXV
10*100.0 /
DYV
10*100.0 /
DZV
4*10.0 /
DEPTHZ
121*2000.0 /
PERMX
400*100.0 /
PERMY
400*100.0 /
PERMZ
400*10.0 /
PORO
400*0.3 /
-- Deactivate Cells (1,1,3) And (1,1,4)
ACTNUM
1 99*1
1 99*1
0 99*1
0 99*1
/
SCHEDULE
WELSPECS
'W1' 'G' 1 1 1* 'OIL' 2* 'STOP' 4* /
/
COMPDAT
'W1' 1 1 4 4 'OPEN' 1* 34.720 0.216 3095.832 2* 'Y' 12.828 /
'W1' 1 1 3 3 'OPEN' 1* 34.720 0.216 3095.832 2* 'Y' 12.828 /
/
TSTEP
1 /
COMPDAT
'W1' 1 1 2 2 'OPEN' 1* 25.620 0.216 2086.842 2* 'Y' 8.486 /
/
TSTEP
1 /
END
)");
const auto es = EclipseState{ deck };
const auto sched = Schedule{ deck, es };
const auto& w0 = sched[0].wells("W1");
BOOST_CHECK_MESSAGE(! w0.hasRefDepth(),
R"(Well "W1" must NOT have a BHP reference depth at report=1)");
BOOST_CHECK_THROW(w0.getRefDepth(), std::logic_error);
const auto& w1 = sched[1].wells("W1");
BOOST_CHECK_MESSAGE(w1.hasRefDepth(),
R"(Well "W1" must have a BHP reference depth at report=2)");
BOOST_CHECK_CLOSE(w1.getRefDepth(), es.getInputGrid().getCellDepth(0, 0, 1), 1.0e-8);
}