Merge pull request #5374 from akva2/pavg_template_scalar

PAvgCalculator: template Scalar type
This commit is contained in:
Bård Skaflestad 2024-05-22 13:21:36 +02:00 committed by GitHub
commit f249a64d6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 175 additions and 118 deletions

View File

@ -488,7 +488,7 @@ class WellContributions;
data::WellBlockAveragePressures data::WellBlockAveragePressures
computeWellBlockAveragePressures() const; computeWellBlockAveragePressures() const;
ParallelWBPCalculation::EvaluatorFactory typename ParallelWBPCalculation<Scalar>::EvaluatorFactory
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const; makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const;
void registerOpenWellsForWBPCalculation(); void registerOpenWellsForWBPCalculation();

View File

@ -550,7 +550,7 @@ protected:
std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>> local_parallel_well_info_; std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>> local_parallel_well_info_;
std::vector<WellProdIndexCalculator> prod_index_calc_; std::vector<WellProdIndexCalculator> prod_index_calc_;
mutable ParallelWBPCalculation wbpCalculationService_; mutable ParallelWBPCalculation<Scalar> wbpCalculationService_;
std::vector<int> pvt_region_idx_; std::vector<int> pvt_region_idx_;

View File

@ -89,13 +89,15 @@ namespace Opm {
this->alternative_well_rate_init_ = this->alternative_well_rate_init_ =
Parameters::get<TypeTag, Properties::AlternativeWellRateInit>(); Parameters::get<TypeTag, Properties::AlternativeWellRateInit>();
using SourceDataSpan =
typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
this->wbpCalculationService_ this->wbpCalculationService_
.localCellIndex([this](const std::size_t globalIndex) .localCellIndex([this](const std::size_t globalIndex)
{ return this->compressedIndexForInterior(globalIndex); }) { return this->compressedIndexForInterior(globalIndex); })
.evalCellSource([this](const int localCell, .evalCellSource([this](const int localCell,
PAvgDynamicSourceData::SourceDataSpan<Scalar> sourceTerms) SourceDataSpan sourceTerms)
{ {
using Item = typename PAvgDynamicSourceData::SourceDataSpan<Scalar>::Item; using Item = typename SourceDataSpan::Item;
const auto* intQuants = this->simulator_.model() const auto* intQuants = this->simulator_.model()
.cachedIntensiveQuantities(localCell, /*timeIndex = */0); .cachedIntensiveQuantities(localCell, /*timeIndex = */0);
@ -2033,7 +2035,7 @@ namespace Opm {
{ {
auto wbpResult = data::WellBlockAveragePressures{}; auto wbpResult = data::WellBlockAveragePressures{};
using Calculated = PAvgCalculator::Result::WBPMode; using Calculated = typename PAvgCalculator<Scalar>::Result::WBPMode;
using Output = data::WellBlockAvgPress::Quantity; using Output = data::WellBlockAvgPress::Quantity;
this->wbpCalculationService_.collectDynamicValues(); this->wbpCalculationService_.collectDynamicValues();
@ -2073,14 +2075,14 @@ namespace Opm {
template <typename TypeTag> template <typename TypeTag>
ParallelWBPCalculation::EvaluatorFactory typename ParallelWBPCalculation<typename BlackoilWellModel<TypeTag>::Scalar>::EvaluatorFactory
BlackoilWellModel<TypeTag>:: BlackoilWellModel<TypeTag>::
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const
{ {
using Span = PAvgDynamicSourceData::SourceDataSpan<Scalar>; using Span = typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
using Item = typename Span::Item; using Item = typename Span::Item;
return [wellIdx, this]() -> ParallelWBPCalculation::Evaluator return [wellIdx, this]() -> typename ParallelWBPCalculation<Scalar>::Evaluator
{ {
if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) { if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
// Well is stopped/shut. Return evaluator for stopped wells. // Well is stopped/shut. Return evaluator for stopped wells.

View File

@ -32,15 +32,18 @@
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
Opm::ParallelPAvgCalculator:: template<class Scalar>
Opm::ParallelPAvgCalculator<Scalar>::
ParallelPAvgCalculator(const Parallel::Communication& comm, ParallelPAvgCalculator(const Parallel::Communication& comm,
const GridDims& cellIndexMap, const GridDims& cellIndexMap,
const WellConnections& connections) const WellConnections& connections)
: PAvgCalculator { cellIndexMap, connections } : PAvgCalculator<Scalar> { cellIndexMap, connections }
, comm_ { comm } , comm_ { comm }
{} {}
void Opm::ParallelPAvgCalculator::collectGlobalContributions() template<class Scalar>
void Opm::ParallelPAvgCalculator<Scalar>::
collectGlobalContributions()
{ {
auto collect = [this](Accumulator& accumulator) auto collect = [this](Accumulator& accumulator)
{ {
@ -54,3 +57,5 @@ void Opm::ParallelPAvgCalculator::collectGlobalContributions()
collect(this->accumCTF_); collect(this->accumCTF_);
collect(this->accumPV_); collect(this->accumPV_);
} }
template class Opm::ParallelPAvgCalculator<double>;

View File

@ -38,7 +38,8 @@ namespace Opm {
/// have a flowing bottom-hole pressure. Mainly useful for reporting. /// have a flowing bottom-hole pressure. Mainly useful for reporting.
/// ///
/// Parallel edition. Handles distributed wells. /// Parallel edition. Handles distributed wells.
class ParallelPAvgCalculator : public PAvgCalculator template<class Scalar>
class ParallelPAvgCalculator : public PAvgCalculator<Scalar>
{ {
public: public:
/// Constructor /// Constructor
@ -55,6 +56,8 @@ public:
const WellConnections& connections); const WellConnections& connections);
private: private:
using Accumulator = typename PAvgCalculator<Scalar>::Accumulator;
/// MPI communication object. /// MPI communication object.
std::reference_wrapper<const Parallel::Communication> comm_; std::reference_wrapper<const Parallel::Communication> comm_;

View File

@ -33,31 +33,34 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
Opm::ParallelPAvgDynamicSourceData:: template<class Scalar>
Opm::ParallelPAvgDynamicSourceData<Scalar>::
ParallelPAvgDynamicSourceData(const Parallel::Communication& comm, ParallelPAvgDynamicSourceData(const Parallel::Communication& comm,
const std::vector<std::size_t>& sourceLocations, const std::vector<std::size_t>& sourceLocations,
GlobalToLocal localCellIdx) GlobalToLocal localCellIdx)
: PAvgDynamicSourceData { sourceLocations } : PAvgDynamicSourceData<Scalar> { sourceLocations }
, comm_ { comm } , comm_ { comm }
{ {
this->finaliseConstruction(sourceLocations, std::move(localCellIdx)); this->finaliseConstruction(sourceLocations, std::move(localCellIdx));
} }
void Opm::ParallelPAvgDynamicSourceData::setToZero() template<class Scalar>
void Opm::ParallelPAvgDynamicSourceData<Scalar>::setToZero()
{ {
std::fill_n(this->localSrc_.begin(), this->localSrc_.size(), 0.0); std::fill_n(this->localSrc_.begin(), this->localSrc_.size(), 0.0);
} }
void template<class Scalar>
Opm::ParallelPAvgDynamicSourceData:: void Opm::ParallelPAvgDynamicSourceData<Scalar>::
reconstruct(const std::vector<std::size_t>& sourceLocations, reconstruct(const std::vector<std::size_t>& sourceLocations,
GlobalToLocal localCellIdx) GlobalToLocal localCellIdx)
{ {
PAvgDynamicSourceData::reconstruct(sourceLocations); // Reconstruct base PAvgDynamicSourceData<Scalar>::reconstruct(sourceLocations); // Reconstruct base
this->finaliseConstruction(sourceLocations, std::move(localCellIdx)); this->finaliseConstruction(sourceLocations, std::move(localCellIdx));
} }
void Opm::ParallelPAvgDynamicSourceData::collectLocalSources(Evaluator eval) template<class Scalar>
void Opm::ParallelPAvgDynamicSourceData<Scalar>::collectLocalSources(Evaluator eval)
{ {
auto localIx = std::size_t{0}; auto localIx = std::size_t{0};
@ -66,7 +69,8 @@ void Opm::ParallelPAvgDynamicSourceData::collectLocalSources(Evaluator eval)
} }
} }
void Opm::ParallelPAvgDynamicSourceData::synchroniseSources() template<class Scalar>
void Opm::ParallelPAvgDynamicSourceData<Scalar>::synchroniseSources()
{ {
this->comm_.get() this->comm_.get()
.allgatherv(this->localSrc_.data(), // Input (from) .allgatherv(this->localSrc_.data(), // Input (from)
@ -76,15 +80,16 @@ void Opm::ParallelPAvgDynamicSourceData::synchroniseSources()
this->startPointers_.data()); // Output offsets this->startPointers_.data()); // Output offsets
} }
std::vector<double>::size_type template<class Scalar>
Opm::ParallelPAvgDynamicSourceData:: typename std::vector<Scalar>::size_type
storageIndex(const std::vector<double>::size_type elemIndex) const Opm::ParallelPAvgDynamicSourceData<Scalar>::
storageIndex(const typename std::vector<Scalar>::size_type elemIndex) const
{ {
return this->storageIndex_[elemIndex]; return this->storageIndex_[elemIndex];
} }
void template<class Scalar>
Opm::ParallelPAvgDynamicSourceData:: void Opm::ParallelPAvgDynamicSourceData<Scalar>::
finaliseConstruction(const std::vector<std::size_t>& sourceLocations, finaliseConstruction(const std::vector<std::size_t>& sourceLocations,
GlobalToLocal localCellIdx) GlobalToLocal localCellIdx)
{ {
@ -100,18 +105,20 @@ finaliseConstruction(const std::vector<std::size_t>& sourceLocations,
ix += 1; ix += 1;
} }
this->localSrc_.assign(numSpanItems() * this->locations_.size(), 0.0); this->localSrc_.assign(this->numSpanItems() * this->locations_.size(), 0.0);
this->defineCommunication(); this->defineCommunication();
} }
Opm::PAvgDynamicSourceData::SourceDataSpan<double> template<class Scalar>
Opm::ParallelPAvgDynamicSourceData::localSourceTerm(const std::size_t localIx) typename Opm::PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>
Opm::ParallelPAvgDynamicSourceData<Scalar>::localSourceTerm(const std::size_t localIx)
{ {
return this->sourceTerm(localIx, this->localSrc_); return this->sourceTerm(localIx, this->localSrc_);
} }
void Opm::ParallelPAvgDynamicSourceData::defineCommunication() template<class Scalar>
void Opm::ParallelPAvgDynamicSourceData<Scalar>::defineCommunication()
{ {
// 1) Determine origins/owning ranks for all source terms. // 1) Determine origins/owning ranks for all source terms.
auto ixVec = std::vector<std::size_t>(this->locations_.size()); auto ixVec = std::vector<std::size_t>(this->locations_.size());
@ -119,7 +126,7 @@ void Opm::ParallelPAvgDynamicSourceData::defineCommunication()
ixVec.begin(), ixVec.begin(),
[](const auto& location) { return location.ix; }); [](const auto& location) { return location.ix; });
constexpr auto numItems = numSpanItems(); constexpr auto numItems = ParallelPAvgDynamicSourceData<Scalar>::numSpanItems();
const auto& [allIndices, allIxStart] = allGatherv(ixVec, this->comm_.get()); const auto& [allIndices, allIxStart] = allGatherv(ixVec, this->comm_.get());
@ -166,3 +173,5 @@ void Opm::ParallelPAvgDynamicSourceData::defineCommunication()
this->storageIndex_[elemIndex] = storageIx++; this->storageIndex_[elemIndex] = storageIx++;
} }
} }
template class Opm::ParallelPAvgDynamicSourceData<double>;

View File

@ -32,13 +32,15 @@ namespace Opm {
/// Dynamic source data for block-average pressure calculations. /// Dynamic source data for block-average pressure calculations.
/// Specialisation for parallel runs. /// Specialisation for parallel runs.
class ParallelPAvgDynamicSourceData : public PAvgDynamicSourceData template<class Scalar>
class ParallelPAvgDynamicSourceData : public PAvgDynamicSourceData<Scalar>
{ {
public: public:
/// Translate globally unique, linearised Cartesian cell indices to /// Translate globally unique, linearised Cartesian cell indices to
/// local, on-rank, cell indices. Assumed to return a negative value /// local, on-rank, cell indices. Assumed to return a negative value
/// result if the input cell index is not owned by the current rank. /// result if the input cell index is not owned by the current rank.
using GlobalToLocal = std::function<int(const std::size_t)>; using GlobalToLocal = std::function<int(const std::size_t)>;
template<class T> using SourceDataSpan = typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<T>;
/// Collect source term contributions from local, on-rank, cell. /// Collect source term contributions from local, on-rank, cell.
/// ///
@ -49,7 +51,7 @@ public:
/// in which \c cellIndex is the local, on-rank, cell index in the range /// in which \c cellIndex is the local, on-rank, cell index in the range
/// 0 to #active cells on rank - 1. Function \c eval is expected to /// 0 to #active cells on rank - 1. Function \c eval is expected to
/// fill in/assign all \c sourceTerm items for this cell. /// fill in/assign all \c sourceTerm items for this cell.
using Evaluator = std::function<void(int, SourceDataSpan<double>)>; using Evaluator = std::function<void(int, SourceDataSpan<Scalar>)>;
/// Constructor /// Constructor
/// ///
@ -117,11 +119,11 @@ private:
std::vector<LocalLocation> locations_{}; std::vector<LocalLocation> locations_{};
/// Source data values owned by current rank. /// Source data values owned by current rank.
std::vector<double> localSrc_{}; std::vector<Scalar> localSrc_{};
/// Translation map from element index to storage index in /// Translation map from element index to storage index in
/// PAvgDynamicSourceData::src_. /// PAvgDynamicSourceData::src_.
std::vector<std::vector<double>::size_type> storageIndex_{}; std::vector<typename std::vector<Scalar>::size_type> storageIndex_{};
/// Receive size from all ranks (allgatherv()). /// Receive size from all ranks (allgatherv()).
std::vector<int> allSizes_{}; // Type int to meet API requirements. std::vector<int> allSizes_{}; // Type int to meet API requirements.
@ -136,8 +138,8 @@ private:
/// \param[in] elemIndex Source element index. /// \param[in] elemIndex Source element index.
/// ///
/// \return Storage (starting) index in PAvgDynamicSourceData::src_. /// \return Storage (starting) index in PAvgDynamicSourceData::src_.
[[nodiscard]] std::vector<double>::size_type [[nodiscard]] typename std::vector<Scalar>::size_type
storageIndex(std::vector<double>::size_type elemIndex) const override; storageIndex(typename std::vector<Scalar>::size_type elemIndex) const override;
/// Identify local source term elements on rank and build communication /// Identify local source term elements on rank and build communication
/// pattern for all source terms. /// pattern for all source terms.
@ -159,7 +161,7 @@ private:
/// \param[in] localIx Logical element index into \c localSrc_. /// \param[in] localIx Logical element index into \c localSrc_.
/// ///
/// \return Mutable view into \c localSrc_. /// \return Mutable view into \c localSrc_.
[[nodiscard]] SourceDataSpan<double> [[nodiscard]] SourceDataSpan<Scalar>
localSourceTerm(const std::size_t localIx); localSourceTerm(const std::size_t localIx);
/// Build communication pattern for all source terms. /// Build communication pattern for all source terms.

View File

@ -42,19 +42,19 @@
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
#include <numeric>
#include <stdexcept> #include <stdexcept>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include <vector> #include <vector>
Opm::ParallelWBPCalculation:: template<class Scalar>
Opm::ParallelWBPCalculation<Scalar>::
LocalConnSet::LocalConnSet(const std::vector<int>& localConnIdx) LocalConnSet::LocalConnSet(const std::vector<int>& localConnIdx)
: localConnIdx_ { localConnIdx } : localConnIdx_ { localConnIdx }
{} {}
int template<class Scalar>
Opm::ParallelWBPCalculation:: int Opm::ParallelWBPCalculation<Scalar>::
LocalConnSet::localIndex(const std::size_t connIdx) const LocalConnSet::localIndex(const std::size_t connIdx) const
{ {
return (connIdx >= this->localConnIdx_.size()) return (connIdx >= this->localConnIdx_.size())
@ -64,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 } : comm_ { comm }
{} {}
Opm::ParallelWBPCalculation::SourceData& template<class Scalar>
Opm::ParallelWBPCalculation::SourceData:: typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
Opm::ParallelWBPCalculation<Scalar>::SourceData::
localIndex(GlobalToLocal localIdx) localIndex(GlobalToLocal localIdx)
{ {
this->localIdx_ = std::move(localIdx); this->localIdx_ = std::move(localIdx);
return *this; return *this;
} }
Opm::ParallelWBPCalculation::SourceData& template<class Scalar>
Opm::ParallelWBPCalculation::SourceData:: typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
Opm::ParallelWBPCalculation<Scalar>::SourceData::
evaluator(Evaluator eval) evaluator(Evaluator eval)
{ {
this->eval_ = std::move(eval); this->eval_ = std::move(eval);
return *this; return *this;
} }
Opm::ParallelWBPCalculation::SourceData& template<class Scalar>
Opm::ParallelWBPCalculation::SourceData:: typename Opm::ParallelWBPCalculation<Scalar>::SourceData&
Opm::ParallelWBPCalculation<Scalar>::SourceData::
evaluatorFactory(EvaluatorFactory evalFactory) evaluatorFactory(EvaluatorFactory evalFactory)
{ {
this->evalFactory_ = std::move(evalFactory); this->evalFactory_ = std::move(evalFactory);
return *this; return *this;
} }
void template<class Scalar>
Opm::ParallelWBPCalculation::SourceData:: void Opm::ParallelWBPCalculation<Scalar>::SourceData::
buildStructure(const std::vector<std::size_t>& sourceLocations) buildStructure(const std::vector<std::size_t>& sourceLocations)
{ {
if (this->srcData_ == nullptr) { if (this->srcData_ == nullptr) {
this->srcData_ = std::make_unique<ParallelPAvgDynamicSourceData> this->srcData_ = std::make_unique<ParallelPAvgDynamicSourceData<Scalar>>
(this->comm_, sourceLocations, this->localIdx_); (this->comm_, sourceLocations, this->localIdx_);
} }
else { else {
@ -105,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) { if (this->srcData_ == nullptr) {
throw std::logic_error { throw std::logic_error {
@ -133,8 +140,9 @@ void Opm::ParallelWBPCalculation::SourceData::collectDynamicValues()
this->srcData_->synchroniseSources(); this->srcData_->synchroniseSources();
} }
template<class Scalar>
std::vector<int> std::vector<int>
Opm::ParallelWBPCalculation::SourceData:: Opm::ParallelWBPCalculation<Scalar>::SourceData::
getLocalIndex(const std::vector<std::size_t>& globalIndex) const getLocalIndex(const std::vector<std::size_t>& globalIndex) const
{ {
auto localIdx = std::vector<int>(globalIndex.size()); auto localIdx = std::vector<int>(globalIndex.size());
@ -150,37 +158,43 @@ getLocalIndex(const std::vector<std::size_t>& globalIndex) const
// =========================================================================== // ===========================================================================
Opm::ParallelWBPCalculation::ParallelWBPCalculation(const GridDims& cellIndexMap, template<class Scalar>
const Parallel::Communication& gridComm) Opm::ParallelWBPCalculation<Scalar>::
ParallelWBPCalculation(const GridDims& cellIndexMap,
const Parallel::Communication& gridComm)
: cellIndexMap_{ cellIndexMap } : cellIndexMap_{ cellIndexMap }
, reservoirSrc_{ gridComm } , reservoirSrc_{ gridComm }
{} {}
Opm::ParallelWBPCalculation& template<class Scalar>
Opm::ParallelWBPCalculation::localCellIndex(GlobalToLocal localCellIdx) Opm::ParallelWBPCalculation<Scalar>&
Opm::ParallelWBPCalculation<Scalar>::
localCellIndex(GlobalToLocal localCellIdx)
{ {
this->reservoirSrc_.localIndex(std::move(localCellIdx)); this->reservoirSrc_.localIndex(std::move(localCellIdx));
return *this; return *this;
} }
Opm::ParallelWBPCalculation& template<class Scalar>
Opm::ParallelWBPCalculation::evalCellSource(Evaluator evalCellSrc) Opm::ParallelWBPCalculation<Scalar>&
Opm::ParallelWBPCalculation<Scalar>::
evalCellSource(Evaluator evalCellSrc)
{ {
this->reservoirSrc_.evaluator(std::move(evalCellSrc)); this->reservoirSrc_.evaluator(std::move(evalCellSrc));
return *this; return *this;
} }
std::size_t template<class Scalar>
Opm::ParallelWBPCalculation:: std::size_t Opm::ParallelWBPCalculation<Scalar>::
createCalculator(const Well& well, createCalculator(const Well& well,
const ParallelWellInfo<double>& parallelWellInfo, const ParallelWellInfo<Scalar>& parallelWellInfo,
const std::vector<int>& localConnIdx, const std::vector<int>& localConnIdx,
EvaluatorFactory makeWellSourceEvaluator) EvaluatorFactory makeWellSourceEvaluator)
{ {
assert (this->wellConnSrc_.size() == this->localConnSet_.size()); assert (this->wellConnSrc_.size() == this->localConnSet_.size());
const auto ix = this->calculators_ const auto ix = this->calculators_
.setCalculator(well.seqIndex(), std::make_unique<ParallelPAvgCalculator> .setCalculator(well.seqIndex(), std::make_unique<ParallelPAvgCalculator<Scalar>>
(parallelWellInfo.communication(), (parallelWellInfo.communication(),
this->cellIndexMap_, well.getConnections())); this->cellIndexMap_, well.getConnections()));
@ -205,7 +219,9 @@ createCalculator(const Well& well,
return ix; return ix;
} }
void Opm::ParallelWBPCalculation::defineCommunication() template<class Scalar>
void Opm::ParallelWBPCalculation<Scalar>::
defineCommunication()
{ {
assert (this->calculators_.numCalculators() == this->wellConnSrc_.size()); assert (this->calculators_.numCalculators() == this->wellConnSrc_.size());
@ -219,7 +235,9 @@ void Opm::ParallelWBPCalculation::defineCommunication()
} }
} }
void Opm::ParallelWBPCalculation::collectDynamicValues() template<class Scalar>
void Opm::ParallelWBPCalculation<Scalar>::
collectDynamicValues()
{ {
this->reservoirSrc_.collectDynamicValues(); this->reservoirSrc_.collectDynamicValues();
@ -228,25 +246,29 @@ void Opm::ParallelWBPCalculation::collectDynamicValues()
} }
} }
void template<class Scalar>
Opm::ParallelWBPCalculation:: void Opm::ParallelWBPCalculation<Scalar>::
inferBlockAveragePressures(const std::size_t calcIndex, inferBlockAveragePressures(const std::size_t calcIndex,
const PAvg& controls, const PAvg& controls,
const double gravity, const Scalar gravity,
const double refDepth) const Scalar refDepth)
{ {
this->calculators_[calcIndex] this->calculators_[calcIndex]
.inferBlockAveragePressures(this->makeEvaluationSources(calcIndex), .inferBlockAveragePressures(this->makeEvaluationSources(calcIndex),
controls, gravity, refDepth); controls, gravity, refDepth);
} }
const Opm::PAvgCalculator::Result& template<class Scalar>
Opm::ParallelWBPCalculation::averagePressures(const std::size_t calcIndex) const const typename Opm::PAvgCalculator<Scalar>::Result&
Opm::ParallelWBPCalculation<Scalar>::
averagePressures(const std::size_t calcIndex) const
{ {
return this->calculators_[calcIndex].averagePressures(); return this->calculators_[calcIndex].averagePressures();
} }
void Opm::ParallelWBPCalculation::pruneInactiveWBPCells() template<class Scalar>
void Opm::ParallelWBPCalculation<Scalar>::
pruneInactiveWBPCells()
{ {
if (this->reservoirSrc_.comm().size() == 1) { if (this->reservoirSrc_.comm().size() == 1) {
this->pruneInactiveWBPCellsSerial(); this->pruneInactiveWBPCellsSerial();
@ -256,7 +278,9 @@ void Opm::ParallelWBPCalculation::pruneInactiveWBPCells()
} }
} }
void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsSerial() template<class Scalar>
void Opm::ParallelWBPCalculation<Scalar>::
pruneInactiveWBPCellsSerial()
{ {
this->calculators_.pruneInactiveWBPCells this->calculators_.pruneInactiveWBPCells
([this](const std::vector<std::size_t>& globalWBPCellIdx) ([this](const std::vector<std::size_t>& globalWBPCellIdx)
@ -276,7 +300,9 @@ void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsSerial()
}); });
} }
void Opm::ParallelWBPCalculation::pruneInactiveWBPCellsParallel() template<class Scalar>
void Opm::ParallelWBPCalculation<Scalar>::
pruneInactiveWBPCellsParallel()
{ {
this->calculators_.pruneInactiveWBPCells( this->calculators_.pruneInactiveWBPCells(
[this](const std::vector<std::size_t>& globalWBPCellIdx) [this](const std::vector<std::size_t>& globalWBPCellIdx)
@ -315,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>{}; auto sourceCells = std::vector<std::size_t>{};
@ -328,16 +356,22 @@ void Opm::ParallelWBPCalculation::defineReservoirCommunication()
this->reservoirSrc_.buildStructure({sourceCells.begin(), u}); 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] this->wellConnSrc_[well]
.buildStructure(this->calculators_[well].allWellConnections()); .buildStructure(this->calculators_[well].allWellConnections());
} }
Opm::PAvgCalculator::Sources template<class Scalar>
Opm::ParallelWBPCalculation::makeEvaluationSources(const WellID well) const typename Opm::PAvgCalculator<Scalar>::Sources
Opm::ParallelWBPCalculation<Scalar>::
makeEvaluationSources(const WellID well) const
{ {
return PAvgCalculator::Sources{} return typename PAvgCalculator<Scalar>::Sources{}
.wellBlocks(this->reservoirSrc_) .wellBlocks(this->reservoirSrc_)
.wellConns (this->wellConnSrc_[well]); .wellConns (this->wellConnSrc_[well]);
} }
template class Opm::ParallelWBPCalculation<double>;

View File

@ -46,15 +46,16 @@ namespace Opm {
/// Parallel facility for managing the on-rank collection and global /// Parallel facility for managing the on-rank collection and global
/// distribution of WBPn source values as well as local calculation and /// distribution of WBPn source values as well as local calculation and
/// distributed reduction of the inferred WBPn report values. /// distributed reduction of the inferred WBPn report values.
template<class Scalar>
class ParallelWBPCalculation class ParallelWBPCalculation
{ {
public: public:
/// Callback for inferring the source locations which are active on the /// Callback for inferring the source locations which are active on the
/// current MPI rank. /// current MPI rank.
using GlobalToLocal = ParallelPAvgDynamicSourceData::GlobalToLocal; using GlobalToLocal = typename ParallelPAvgDynamicSourceData<Scalar>::GlobalToLocal;
/// Callback for evaluating WBPn source terms on the current MPI rank. /// Callback for evaluating WBPn source terms on the current MPI rank.
using Evaluator = ParallelPAvgDynamicSourceData::Evaluator; using Evaluator = typename ParallelPAvgDynamicSourceData<Scalar>::Evaluator;
/// Callback for constructing a source term evaluation function on the /// Callback for constructing a source term evaluation function on the
/// current MPI rank. Needed for deferred construction of per-well /// current MPI rank. Needed for deferred construction of per-well
@ -112,7 +113,7 @@ public:
/// well. /// well.
std::size_t std::size_t
createCalculator(const Well& well, createCalculator(const Well& well,
const ParallelWellInfo<double>& parallelWellInfo, const ParallelWellInfo<Scalar>& parallelWellInfo,
const std::vector<int>& localConnIdx, const std::vector<int>& localConnIdx,
EvaluatorFactory makeWellSourceEvaluator); EvaluatorFactory makeWellSourceEvaluator);
@ -152,8 +153,8 @@ public:
/// Well::getWPaveRefDepth() \endcode. /// Well::getWPaveRefDepth() \endcode.
void inferBlockAveragePressures(const std::size_t calcIndex, void inferBlockAveragePressures(const std::size_t calcIndex,
const PAvg& controls, const PAvg& controls,
const double gravity, const Scalar gravity,
const double refDepth); const Scalar refDepth);
/// Retrieve results from most recent WBPn value calculation for /// Retrieve results from most recent WBPn value calculation for
/// specified well. /// specified well.
@ -163,7 +164,7 @@ public:
/// ///
/// \return Result set from most recent call to member function \c /// \return Result set from most recent call to member function \c
/// inferBlockAveragePressures() for \c calcIndex. /// inferBlockAveragePressures() for \c calcIndex.
const PAvgCalculator::Result& const typename PAvgCalculator<Scalar>::Result&
averagePressures(const std::size_t calcIndex) const; averagePressures(const std::size_t calcIndex) const;
private: private:
@ -213,7 +214,7 @@ private:
/// ///
/// Enables transparent usage of this object as an argument to \code /// Enables transparent usage of this object as an argument to \code
/// PAvgCalculator::inferBlockAveragePressures() \endcode. /// PAvgCalculator::inferBlockAveragePressures() \endcode.
operator const ParallelPAvgDynamicSourceData&() const operator const ParallelPAvgDynamicSourceData<Scalar>&() const
{ {
return *this->srcData_; return *this->srcData_;
} }
@ -294,7 +295,7 @@ private:
private: private:
/// Type of wrapped object. /// Type of wrapped object.
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData>; using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData<Scalar>>;
/// MPI communicator for this source data object. /// MPI communicator for this source data object.
std::reference_wrapper<const Parallel::Communication> comm_; std::reference_wrapper<const Parallel::Communication> comm_;
@ -316,7 +317,7 @@ private:
}; };
/// Calculation object IDs. /// 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). /// Cell index triple map ((I,J,K) <-> global).
std::reference_wrapper<const GridDims> cellIndexMap_; std::reference_wrapper<const GridDims> cellIndexMap_;
@ -326,7 +327,7 @@ private:
/// Collection of WBPn calculation objects. One object for each well on /// Collection of WBPn calculation objects. One object for each well on
/// rank. /// rank.
PAvgCalculatorCollection calculators_{}; PAvgCalculatorCollection<Scalar> calculators_{};
/// Source term objects for each well on rank. /// Source term objects for each well on rank.
std::vector<SourceData> wellConnSrc_{}; std::vector<SourceData> wellConnSrc_{};
@ -360,7 +361,8 @@ private:
/// terms. /// terms.
/// ///
/// \return WBPn source terms aggregated for \p well. /// \return WBPn source terms aggregated for \p well.
PAvgCalculator::Sources makeEvaluationSources(const WellID well) const; typename PAvgCalculator<Scalar>::Sources
makeEvaluationSources(const WellID well) const;
}; };
} // namespace Opm } // namespace Opm

View File

@ -214,9 +214,9 @@ namespace {
} }
void cellSource(const int cell, void cellSource(const int cell,
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src) Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double> src)
{ {
using Item = Opm::PAvgDynamicSourceData::SourceDataSpan<double>::Item; using Item = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>::Item;
src .set(Item::Pressure , pressure(cell)) src .set(Item::Pressure , pressure(cell))
.set(Item::PoreVol , porevol (cell)) .set(Item::PoreVol , porevol (cell))
@ -233,16 +233,16 @@ namespace {
return localIdx; return localIdx;
} }
Opm::ParallelWBPCalculation::EvaluatorFactory connSource() Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
{ {
return []() { return []() {
auto rho = std::vector { 0.1, 0.12, 0.14, }; auto rho = std::vector { 0.1, 0.12, 0.14, };
return [rho = std::move(rho)] return [rho = std::move(rho)]
(const int connIx, (const int connIx,
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src) Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double> src)
{ {
using Item = Opm::PAvgDynamicSourceData::SourceDataSpan<double>::Item; using Item = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>::Item;
src .set(Item::Pressure , 1222.0) src .set(Item::Pressure , 1222.0)
.set(Item::PoreVol , 1.25) .set(Item::PoreVol , 1.25)
@ -353,10 +353,10 @@ namespace {
}); });
} }
void cellSource(const int cell, void cellSource(const int cell,
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src) Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double> src)
{ {
using Item = Opm::PAvgDynamicSourceData::SourceDataSpan<double>::Item; using Item = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>::Item;
src .set(Item::Pressure , pressure(cell)) src .set(Item::Pressure , pressure(cell))
.set(Item::PoreVol , porevol (cell)) .set(Item::PoreVol , porevol (cell))
@ -373,16 +373,16 @@ namespace {
return localIdx; return localIdx;
} }
Opm::ParallelWBPCalculation::EvaluatorFactory connSource() Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
{ {
return []() { return []() {
auto rho = std::vector { 0.16, 0.18, 0.2, }; auto rho = std::vector { 0.16, 0.18, 0.2, };
return [rho = std::move(rho)] return [rho = std::move(rho)]
(const int connIx, (const int connIx,
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src) Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double> src)
{ {
using Item = Opm::PAvgDynamicSourceData::SourceDataSpan<double>::Item; using Item = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>::Item;
src .set(Item::Pressure , 1222.0) src .set(Item::Pressure , 1222.0)
.set(Item::PoreVol , 1.25) .set(Item::PoreVol , 1.25)
@ -483,22 +483,22 @@ namespace {
return pwi; return pwi;
} }
void setCallbacksTop(Opm::ParallelWBPCalculation& wbpCalcService) void setCallbacksTop(Opm::ParallelWBPCalculation<double>& wbpCalcService)
{ {
wbpCalcService wbpCalcService
.localCellIndex(&Rank::Top::globalToLocal) .localCellIndex(&Rank::Top::globalToLocal)
.evalCellSource(&Rank::Top::cellSource); .evalCellSource(&Rank::Top::cellSource);
} }
void setCallbacksBottom(Opm::ParallelWBPCalculation& wbpCalcService) void setCallbacksBottom(Opm::ParallelWBPCalculation<double>& wbpCalcService)
{ {
wbpCalcService wbpCalcService
.localCellIndex(&Rank::Bottom::globalToLocal) .localCellIndex(&Rank::Bottom::globalToLocal)
.evalCellSource(&Rank::Bottom::cellSource); .evalCellSource(&Rank::Bottom::cellSource);
} }
void setCallbacks(const int rank, void setCallbacks(const int rank,
Opm::ParallelWBPCalculation& wbpCalcService) Opm::ParallelWBPCalculation<double>& wbpCalcService)
{ {
if (rank == 0) { if (rank == 0) {
setCallbacksTop(wbpCalcService); 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) { if (rank == 0) {
return Rank::Top::connSource(); return Rank::Top::connSource();
@ -551,7 +551,7 @@ namespace {
Opm::Parallel::Communication comm; Opm::Parallel::Communication comm;
Opm::GridDims cellIndexMap; Opm::GridDims cellIndexMap;
Opm::ParallelWBPCalculation wbpCalcService; Opm::ParallelWBPCalculation<double> wbpCalcService;
Opm::ParallelWellInfo<double> pwi; Opm::ParallelWellInfo<double> pwi;
}; };
@ -566,7 +566,7 @@ BOOST_AUTO_TEST_CASE(Create)
BOOST_REQUIRE_EQUAL(comm.size(), 2); BOOST_REQUIRE_EQUAL(comm.size(), 2);
const Opm::GridDims dims{5, 5, 10}; const Opm::GridDims dims{5, 5, 10};
auto wbpCalcService = Opm::ParallelWBPCalculation { auto wbpCalcService = Opm::ParallelWBPCalculation<double> {
dims, comm dims, comm
}; };
@ -599,7 +599,7 @@ BOOST_AUTO_TEST_CASE(TopOfFormation_Well_OpenConns)
cse.wbpCalcService.inferBlockAveragePressures(calcIndex, controls, gravity, refDepth); cse.wbpCalcService.inferBlockAveragePressures(calcIndex, controls, gravity, refDepth);
const auto avgPress = cse.wbpCalcService.averagePressures(calcIndex); const auto avgPress = cse.wbpCalcService.averagePressures(calcIndex);
using WBPMode = Opm::PAvgCalculator::Result::WBPMode; using WBPMode = Opm::PAvgCalculator<double>::Result::WBPMode;
BOOST_CHECK_CLOSE(avgPress.value(WBPMode::WBP) , 1254.806625666667, 1.0e-8); BOOST_CHECK_CLOSE(avgPress.value(WBPMode::WBP) , 1254.806625666667, 1.0e-8);
BOOST_CHECK_CLOSE(avgPress.value(WBPMode::WBP4), 1295.348292333333, 1.0e-8); BOOST_CHECK_CLOSE(avgPress.value(WBPMode::WBP4), 1295.348292333333, 1.0e-8);

View File

@ -108,7 +108,7 @@ private:
class CalculateSourceTerm class CalculateSourceTerm
{ {
public: public:
using SrcTerm = Opm::PAvgDynamicSourceData::SourceDataSpan<double>; using SrcTerm = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>;
explicit CalculateSourceTerm(const std::size_t rank) explicit CalculateSourceTerm(const std::size_t rank)
: rank_ { rank } : rank_ { rank }
@ -129,11 +129,11 @@ private:
}; };
std::size_t std::size_t
sourceTermsAreCorrect(const std::size_t comm_size, sourceTermsAreCorrect(const std::size_t comm_size,
const std::size_t num_src, const std::size_t num_src,
const Opm::PAvgDynamicSourceData& source_data) const Opm::PAvgDynamicSourceData<double>& source_data)
{ {
using Item = Opm::PAvgDynamicSourceData::SourceDataSpan<const double>::Item; using Item = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<const double>::Item;
auto num_correct = 0*num_src; auto num_correct = 0*num_src;
@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(Eval_and_collect)
const auto num_src_loc = std::size_t{50}; const auto num_src_loc = std::size_t{50};
auto source_data = Opm::ParallelPAvgDynamicSourceData { auto source_data = Opm::ParallelPAvgDynamicSourceData<double> {
comm, sourceLocations(num_src_loc), comm, sourceLocations(num_src_loc),
LocalCellIndex { comm_rank, comm_size } LocalCellIndex { comm_rank, comm_size }
}; };