/*
Copyright 2020 Equinor 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 .
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace {
template
void checkSizeCompatibility(const Opm::WellProdIndexCalculator& wellPICalc,
const std::vector& connMobility)
{
if (connMobility.size() != wellPICalc.numConnections()) {
throw std::logic_error {
"Mobility vector size does not match expected number of connections"
};
}
}
template
Scalar logRescale(const Scalar r0, const Scalar rw, const Scalar rd, const Scalar S)
{
const auto numerator = std::log(r0 / rw) + S;
const auto denom = std::log(rd / rw) + S;
return numerator / denom;
}
template
void standardConnFactorsExplicitDrainRadius(const Opm::Well& well,
std::vector& stdConnFact)
{
const auto& connections = well.getConnections();
const auto rdrain = well.getDrainageRadius();
std::transform(connections.begin(), connections.end(), stdConnFact.begin(),
[rdrain](const Opm::Connection& conn)
{
return conn.CF() * logRescale(conn.r0(), conn.rw(), rdrain, conn.skinFactor());
});
}
template
void standardConnFactorsDrainIsEquivalent(const Opm::Well& well,
std::vector& stdConnFact)
{
const auto& connections = well.getConnections();
std::transform(connections.begin(), connections.end(), stdConnFact.begin(),
[](const Opm::Connection& conn)
{
return conn.CF();
});
}
template
std::vector calculateStandardConnFactors(const Opm::Well& well)
{
std::vector stdConnFact(well.getConnections().size());
if (well.getDrainageRadius() > 0.0) {
// Well has an explicit drainage radius. Apply logarithmic
// scaling to the CTFs.
standardConnFactorsExplicitDrainRadius(well, stdConnFact);
}
else {
// Unspecified drainage radius. Standard mobility connection
// scaling factors are just the regular CTFs.
standardConnFactorsDrainIsEquivalent(well, stdConnFact);
}
return stdConnFact;
}
} // namespace Anonymous
template
Opm::WellProdIndexCalculator::
WellProdIndexCalculator(const Well& well)
: standardConnFactors_{ calculateStandardConnFactors(well) }
{}
template
void Opm::WellProdIndexCalculator::
reInit(const Well& well)
{
this->standardConnFactors_ = calculateStandardConnFactors(well);
}
template
Scalar Opm::WellProdIndexCalculator::
connectionProdIndStandard(const std::size_t connIdx,
const Scalar connMobility) const
{
return this->standardConnFactors_[connIdx] * connMobility;
}
// ===========================================================================
template
std::vector
Opm::connectionProdIndStandard(const WellProdIndexCalculator& wellPICalc,
const std::vector& connMobility)
{
checkSizeCompatibility(wellPICalc, connMobility);
const auto nConn = wellPICalc.numConnections();
auto connPI = connMobility;
for (auto connIx = 0*nConn; connIx < nConn; ++connIx) {
connPI[connIx] = wellPICalc
.connectionProdIndStandard(connIx, connMobility[connIx]);
}
return connPI;
}
template
Scalar Opm::wellProdIndStandard(const WellProdIndexCalculator& wellPICalc,
const std::vector& connMobility)
{
const auto connPI = connectionProdIndStandard(wellPICalc, connMobility);
return std::accumulate(connPI.begin(), connPI.end(), 0.0);
}
#define INSTANTIATE_TYPE(T) \
template class Opm::WellProdIndexCalculator; \
template std::vector \
Opm::connectionProdIndStandard(const WellProdIndexCalculator&, \
const std::vector&); \
template T \
Opm::wellProdIndStandard(const WellProdIndexCalculator&, \
const std::vector&);
INSTANTIATE_TYPE(double)
#if FLOW_INSTANTIATE_FLOAT
INSTANTIATE_TYPE(float)
#endif