mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
ParallelWBPCalculation: template Scalar type
This commit is contained in:
parent
66a08b9c1a
commit
27d99f78ec
@ -488,7 +488,7 @@ class WellContributions;
|
||||
data::WellBlockAveragePressures
|
||||
computeWellBlockAveragePressures() const;
|
||||
|
||||
ParallelWBPCalculation::EvaluatorFactory
|
||||
typename ParallelWBPCalculation<Scalar>::EvaluatorFactory
|
||||
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const;
|
||||
|
||||
void registerOpenWellsForWBPCalculation();
|
||||
|
@ -550,7 +550,7 @@ protected:
|
||||
std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>> local_parallel_well_info_;
|
||||
|
||||
std::vector<WellProdIndexCalculator> prod_index_calc_;
|
||||
mutable ParallelWBPCalculation wbpCalculationService_;
|
||||
mutable ParallelWBPCalculation<Scalar> wbpCalculationService_;
|
||||
|
||||
std::vector<int> pvt_region_idx_;
|
||||
|
||||
|
@ -2075,14 +2075,14 @@ namespace Opm {
|
||||
|
||||
|
||||
template <typename TypeTag>
|
||||
ParallelWBPCalculation::EvaluatorFactory
|
||||
typename ParallelWBPCalculation<typename BlackoilWellModel<TypeTag>::Scalar>::EvaluatorFactory
|
||||
BlackoilWellModel<TypeTag>::
|
||||
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const
|
||||
{
|
||||
using Span = typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
|
||||
using Item = typename Span::Item;
|
||||
|
||||
return [wellIdx, this]() -> ParallelWBPCalculation::Evaluator
|
||||
return [wellIdx, this]() -> typename ParallelWBPCalculation<Scalar>::Evaluator
|
||||
{
|
||||
if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
|
||||
// Well is stopped/shut. Return evaluator for stopped wells.
|
||||
|
@ -47,13 +47,14 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
Opm::ParallelWBPCalculation::
|
||||
template<class Scalar>
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
LocalConnSet::LocalConnSet(const std::vector<int>& localConnIdx)
|
||||
: localConnIdx_ { localConnIdx }
|
||||
{}
|
||||
|
||||
int
|
||||
Opm::ParallelWBPCalculation::
|
||||
template<class Scalar>
|
||||
int Opm::ParallelWBPCalculation<Scalar>::
|
||||
LocalConnSet::localIndex(const std::size_t connIdx) const
|
||||
{
|
||||
return (connIdx >= this->localConnIdx_.size())
|
||||
@ -63,40 +64,45 @@ LocalConnSet::localIndex(const std::size_t connIdx) const
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Opm::ParallelWBPCalculation::SourceData::SourceData(const Parallel::Communication& comm)
|
||||
template<class Scalar>
|
||||
Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
SourceData(const Parallel::Communication& comm)
|
||||
: comm_ { comm }
|
||||
{}
|
||||
|
||||
Opm::ParallelWBPCalculation::SourceData&
|
||||
Opm::ParallelWBPCalculation::SourceData::
|
||||
template<class Scalar>
|
||||
typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
|
||||
Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
localIndex(GlobalToLocal localIdx)
|
||||
{
|
||||
this->localIdx_ = std::move(localIdx);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::SourceData&
|
||||
Opm::ParallelWBPCalculation::SourceData::
|
||||
template<class Scalar>
|
||||
typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
|
||||
Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
evaluator(Evaluator eval)
|
||||
{
|
||||
this->eval_ = std::move(eval);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::SourceData&
|
||||
Opm::ParallelWBPCalculation::SourceData::
|
||||
template<class Scalar>
|
||||
typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
|
||||
Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
evaluatorFactory(EvaluatorFactory evalFactory)
|
||||
{
|
||||
this->evalFactory_ = std::move(evalFactory);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
Opm::ParallelWBPCalculation::SourceData::
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
buildStructure(const std::vector<std::size_t>& sourceLocations)
|
||||
{
|
||||
if (this->srcData_ == nullptr) {
|
||||
this->srcData_ = std::make_unique<ParallelPAvgDynamicSourceData<double>>
|
||||
this->srcData_ = std::make_unique<ParallelPAvgDynamicSourceData<Scalar>>
|
||||
(this->comm_, sourceLocations, this->localIdx_);
|
||||
}
|
||||
else {
|
||||
@ -104,7 +110,9 @@ buildStructure(const std::vector<std::size_t>& sourceLocations)
|
||||
}
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::SourceData::collectDynamicValues()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
collectDynamicValues()
|
||||
{
|
||||
if (this->srcData_ == nullptr) {
|
||||
throw std::logic_error {
|
||||
@ -132,8 +140,9 @@ void Opm::ParallelWBPCalculation::SourceData::collectDynamicValues()
|
||||
this->srcData_->synchroniseSources();
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
std::vector<int>
|
||||
Opm::ParallelWBPCalculation::SourceData::
|
||||
Opm::ParallelWBPCalculation<Scalar>::SourceData::
|
||||
getLocalIndex(const std::vector<std::size_t>& globalIndex) const
|
||||
{
|
||||
auto localIdx = std::vector<int>(globalIndex.size());
|
||||
@ -149,37 +158,43 @@ getLocalIndex(const std::vector<std::size_t>& globalIndex) const
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
Opm::ParallelWBPCalculation::ParallelWBPCalculation(const GridDims& cellIndexMap,
|
||||
const Parallel::Communication& gridComm)
|
||||
template<class Scalar>
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
ParallelWBPCalculation(const GridDims& cellIndexMap,
|
||||
const Parallel::Communication& gridComm)
|
||||
: cellIndexMap_{ cellIndexMap }
|
||||
, reservoirSrc_{ gridComm }
|
||||
{}
|
||||
|
||||
Opm::ParallelWBPCalculation&
|
||||
Opm::ParallelWBPCalculation::localCellIndex(GlobalToLocal localCellIdx)
|
||||
template<class Scalar>
|
||||
Opm::ParallelWBPCalculation<Scalar>&
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
localCellIndex(GlobalToLocal localCellIdx)
|
||||
{
|
||||
this->reservoirSrc_.localIndex(std::move(localCellIdx));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation&
|
||||
Opm::ParallelWBPCalculation::evalCellSource(Evaluator evalCellSrc)
|
||||
template<class Scalar>
|
||||
Opm::ParallelWBPCalculation<Scalar>&
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
evalCellSource(Evaluator evalCellSrc)
|
||||
{
|
||||
this->reservoirSrc_.evaluator(std::move(evalCellSrc));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Opm::ParallelWBPCalculation::
|
||||
template<class Scalar>
|
||||
std::size_t Opm::ParallelWBPCalculation<Scalar>::
|
||||
createCalculator(const Well& well,
|
||||
const ParallelWellInfo<double>& parallelWellInfo,
|
||||
const ParallelWellInfo<Scalar>& parallelWellInfo,
|
||||
const std::vector<int>& localConnIdx,
|
||||
EvaluatorFactory makeWellSourceEvaluator)
|
||||
{
|
||||
assert (this->wellConnSrc_.size() == this->localConnSet_.size());
|
||||
|
||||
const auto ix = this->calculators_
|
||||
.setCalculator(well.seqIndex(), std::make_unique<ParallelPAvgCalculator<double>>
|
||||
.setCalculator(well.seqIndex(), std::make_unique<ParallelPAvgCalculator<Scalar>>
|
||||
(parallelWellInfo.communication(),
|
||||
this->cellIndexMap_, well.getConnections()));
|
||||
|
||||
@ -204,7 +219,9 @@ createCalculator(const Well& well,
|
||||
return ix;
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::defineCommunication()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
defineCommunication()
|
||||
{
|
||||
assert (this->calculators_.numCalculators() == this->wellConnSrc_.size());
|
||||
|
||||
@ -218,7 +235,9 @@ void Opm::ParallelWBPCalculation::defineCommunication()
|
||||
}
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::collectDynamicValues()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
collectDynamicValues()
|
||||
{
|
||||
this->reservoirSrc_.collectDynamicValues();
|
||||
|
||||
@ -227,25 +246,29 @@ void Opm::ParallelWBPCalculation::collectDynamicValues()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Opm::ParallelWBPCalculation::
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
inferBlockAveragePressures(const std::size_t calcIndex,
|
||||
const PAvg& controls,
|
||||
const double gravity,
|
||||
const double refDepth)
|
||||
const Scalar gravity,
|
||||
const Scalar refDepth)
|
||||
{
|
||||
this->calculators_[calcIndex]
|
||||
.inferBlockAveragePressures(this->makeEvaluationSources(calcIndex),
|
||||
controls, gravity, refDepth);
|
||||
}
|
||||
|
||||
const Opm::PAvgCalculator<double>::Result&
|
||||
Opm::ParallelWBPCalculation::averagePressures(const std::size_t calcIndex) const
|
||||
template<class Scalar>
|
||||
const typename Opm::PAvgCalculator<Scalar>::Result&
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
averagePressures(const std::size_t calcIndex) const
|
||||
{
|
||||
return this->calculators_[calcIndex].averagePressures();
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::pruneInactiveWBPCells()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
pruneInactiveWBPCells()
|
||||
{
|
||||
if (this->reservoirSrc_.comm().size() == 1) {
|
||||
this->pruneInactiveWBPCellsSerial();
|
||||
@ -255,7 +278,9 @@ void Opm::ParallelWBPCalculation::pruneInactiveWBPCells()
|
||||
}
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsSerial()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
pruneInactiveWBPCellsSerial()
|
||||
{
|
||||
this->calculators_.pruneInactiveWBPCells
|
||||
([this](const std::vector<std::size_t>& globalWBPCellIdx)
|
||||
@ -275,7 +300,9 @@ void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsSerial()
|
||||
});
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsParallel()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
pruneInactiveWBPCellsParallel()
|
||||
{
|
||||
this->calculators_.pruneInactiveWBPCells(
|
||||
[this](const std::vector<std::size_t>& globalWBPCellIdx)
|
||||
@ -314,7 +341,9 @@ void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsParallel()
|
||||
});
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::defineReservoirCommunication()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
defineReservoirCommunication()
|
||||
{
|
||||
auto sourceCells = std::vector<std::size_t>{};
|
||||
|
||||
@ -327,16 +356,22 @@ void Opm::ParallelWBPCalculation::defineReservoirCommunication()
|
||||
this->reservoirSrc_.buildStructure({sourceCells.begin(), u});
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::defineWellCommunication(const std::size_t well)
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
defineWellCommunication(const std::size_t well)
|
||||
{
|
||||
this->wellConnSrc_[well]
|
||||
.buildStructure(this->calculators_[well].allWellConnections());
|
||||
}
|
||||
|
||||
Opm::PAvgCalculator<double>::Sources
|
||||
Opm::ParallelWBPCalculation::makeEvaluationSources(const WellID well) const
|
||||
template<class Scalar>
|
||||
typename Opm::PAvgCalculator<Scalar>::Sources
|
||||
Opm::ParallelWBPCalculation<Scalar>::
|
||||
makeEvaluationSources(const WellID well) const
|
||||
{
|
||||
return PAvgCalculator<double>::Sources{}
|
||||
return typename PAvgCalculator<Scalar>::Sources{}
|
||||
.wellBlocks(this->reservoirSrc_)
|
||||
.wellConns (this->wellConnSrc_[well]);
|
||||
}
|
||||
|
||||
template class Opm::ParallelWBPCalculation<double>;
|
||||
|
@ -46,15 +46,16 @@ namespace Opm {
|
||||
/// Parallel facility for managing the on-rank collection and global
|
||||
/// distribution of WBPn source values as well as local calculation and
|
||||
/// distributed reduction of the inferred WBPn report values.
|
||||
template<class Scalar>
|
||||
class ParallelWBPCalculation
|
||||
{
|
||||
public:
|
||||
/// Callback for inferring the source locations which are active on the
|
||||
/// current MPI rank.
|
||||
using GlobalToLocal = ParallelPAvgDynamicSourceData<double>::GlobalToLocal;
|
||||
using GlobalToLocal = typename ParallelPAvgDynamicSourceData<Scalar>::GlobalToLocal;
|
||||
|
||||
/// Callback for evaluating WBPn source terms on the current MPI rank.
|
||||
using Evaluator = ParallelPAvgDynamicSourceData<double>::Evaluator;
|
||||
using Evaluator = typename ParallelPAvgDynamicSourceData<Scalar>::Evaluator;
|
||||
|
||||
/// Callback for constructing a source term evaluation function on the
|
||||
/// current MPI rank. Needed for deferred construction of per-well
|
||||
@ -112,7 +113,7 @@ public:
|
||||
/// well.
|
||||
std::size_t
|
||||
createCalculator(const Well& well,
|
||||
const ParallelWellInfo<double>& parallelWellInfo,
|
||||
const ParallelWellInfo<Scalar>& parallelWellInfo,
|
||||
const std::vector<int>& localConnIdx,
|
||||
EvaluatorFactory makeWellSourceEvaluator);
|
||||
|
||||
@ -152,8 +153,8 @@ public:
|
||||
/// Well::getWPaveRefDepth() \endcode.
|
||||
void inferBlockAveragePressures(const std::size_t calcIndex,
|
||||
const PAvg& controls,
|
||||
const double gravity,
|
||||
const double refDepth);
|
||||
const Scalar gravity,
|
||||
const Scalar refDepth);
|
||||
|
||||
/// Retrieve results from most recent WBPn value calculation for
|
||||
/// specified well.
|
||||
@ -163,7 +164,7 @@ public:
|
||||
///
|
||||
/// \return Result set from most recent call to member function \c
|
||||
/// inferBlockAveragePressures() for \c calcIndex.
|
||||
const PAvgCalculator<double>::Result&
|
||||
const typename PAvgCalculator<Scalar>::Result&
|
||||
averagePressures(const std::size_t calcIndex) const;
|
||||
|
||||
private:
|
||||
@ -213,7 +214,7 @@ private:
|
||||
///
|
||||
/// Enables transparent usage of this object as an argument to \code
|
||||
/// PAvgCalculator::inferBlockAveragePressures() \endcode.
|
||||
operator const ParallelPAvgDynamicSourceData<double>&() const
|
||||
operator const ParallelPAvgDynamicSourceData<Scalar>&() const
|
||||
{
|
||||
return *this->srcData_;
|
||||
}
|
||||
@ -294,7 +295,7 @@ private:
|
||||
|
||||
private:
|
||||
/// Type of wrapped object.
|
||||
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData<double>>;
|
||||
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData<Scalar>>;
|
||||
|
||||
/// MPI communicator for this source data object.
|
||||
std::reference_wrapper<const Parallel::Communication> comm_;
|
||||
@ -316,7 +317,7 @@ private:
|
||||
};
|
||||
|
||||
/// Calculation object IDs.
|
||||
using WellID = std::vector<SourceData>::size_type;
|
||||
using WellID = typename std::vector<SourceData>::size_type;
|
||||
|
||||
/// Cell index triple map ((I,J,K) <-> global).
|
||||
std::reference_wrapper<const GridDims> cellIndexMap_;
|
||||
@ -326,7 +327,7 @@ private:
|
||||
|
||||
/// Collection of WBPn calculation objects. One object for each well on
|
||||
/// rank.
|
||||
PAvgCalculatorCollection<double> calculators_{};
|
||||
PAvgCalculatorCollection<Scalar> calculators_{};
|
||||
|
||||
/// Source term objects for each well on rank.
|
||||
std::vector<SourceData> wellConnSrc_{};
|
||||
@ -360,7 +361,8 @@ private:
|
||||
/// terms.
|
||||
///
|
||||
/// \return WBPn source terms aggregated for \p well.
|
||||
PAvgCalculator<double>::Sources makeEvaluationSources(const WellID well) const;
|
||||
typename PAvgCalculator<Scalar>::Sources
|
||||
makeEvaluationSources(const WellID well) const;
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -233,7 +233,7 @@ namespace {
|
||||
return localIdx;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::EvaluatorFactory connSource()
|
||||
Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
|
||||
{
|
||||
return []() {
|
||||
auto rho = std::vector { 0.1, 0.12, 0.14, };
|
||||
@ -373,7 +373,7 @@ namespace {
|
||||
return localIdx;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::EvaluatorFactory connSource()
|
||||
Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
|
||||
{
|
||||
return []() {
|
||||
auto rho = std::vector { 0.16, 0.18, 0.2, };
|
||||
@ -483,22 +483,22 @@ namespace {
|
||||
return pwi;
|
||||
}
|
||||
|
||||
void setCallbacksTop(Opm::ParallelWBPCalculation& wbpCalcService)
|
||||
void setCallbacksTop(Opm::ParallelWBPCalculation<double>& wbpCalcService)
|
||||
{
|
||||
wbpCalcService
|
||||
.localCellIndex(&Rank::Top::globalToLocal)
|
||||
.evalCellSource(&Rank::Top::cellSource);
|
||||
}
|
||||
|
||||
void setCallbacksBottom(Opm::ParallelWBPCalculation& wbpCalcService)
|
||||
void setCallbacksBottom(Opm::ParallelWBPCalculation<double>& wbpCalcService)
|
||||
{
|
||||
wbpCalcService
|
||||
.localCellIndex(&Rank::Bottom::globalToLocal)
|
||||
.evalCellSource(&Rank::Bottom::cellSource);
|
||||
}
|
||||
|
||||
void setCallbacks(const int rank,
|
||||
Opm::ParallelWBPCalculation& wbpCalcService)
|
||||
void setCallbacks(const int rank,
|
||||
Opm::ParallelWBPCalculation<double>& wbpCalcService)
|
||||
{
|
||||
if (rank == 0) {
|
||||
setCallbacksTop(wbpCalcService);
|
||||
@ -508,7 +508,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::EvaluatorFactory connSource(const int rank)
|
||||
Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource(const int rank)
|
||||
{
|
||||
if (rank == 0) {
|
||||
return Rank::Top::connSource();
|
||||
@ -551,7 +551,7 @@ namespace {
|
||||
|
||||
Opm::Parallel::Communication comm;
|
||||
Opm::GridDims cellIndexMap;
|
||||
Opm::ParallelWBPCalculation wbpCalcService;
|
||||
Opm::ParallelWBPCalculation<double> wbpCalcService;
|
||||
Opm::ParallelWellInfo<double> pwi;
|
||||
};
|
||||
|
||||
@ -566,7 +566,7 @@ BOOST_AUTO_TEST_CASE(Create)
|
||||
BOOST_REQUIRE_EQUAL(comm.size(), 2);
|
||||
|
||||
const Opm::GridDims dims{5, 5, 10};
|
||||
auto wbpCalcService = Opm::ParallelWBPCalculation {
|
||||
auto wbpCalcService = Opm::ParallelWBPCalculation<double> {
|
||||
dims, comm
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user