mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #5374 from akva2/pavg_template_scalar
PAvgCalculator: template Scalar type
This commit is contained in:
commit
f249a64d6c
@ -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_;
|
||||
|
||||
|
@ -89,13 +89,15 @@ namespace Opm {
|
||||
this->alternative_well_rate_init_ =
|
||||
Parameters::get<TypeTag, Properties::AlternativeWellRateInit>();
|
||||
|
||||
using SourceDataSpan =
|
||||
typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
|
||||
this->wbpCalculationService_
|
||||
.localCellIndex([this](const std::size_t globalIndex)
|
||||
{ return this->compressedIndexForInterior(globalIndex); })
|
||||
.evalCellSource([this](const int localCell,
|
||||
PAvgDynamicSourceData::SourceDataSpan<Scalar> sourceTerms)
|
||||
.evalCellSource([this](const int localCell,
|
||||
SourceDataSpan sourceTerms)
|
||||
{
|
||||
using Item = typename PAvgDynamicSourceData::SourceDataSpan<Scalar>::Item;
|
||||
using Item = typename SourceDataSpan::Item;
|
||||
|
||||
const auto* intQuants = this->simulator_.model()
|
||||
.cachedIntensiveQuantities(localCell, /*timeIndex = */0);
|
||||
@ -2033,7 +2035,7 @@ namespace Opm {
|
||||
{
|
||||
auto wbpResult = data::WellBlockAveragePressures{};
|
||||
|
||||
using Calculated = PAvgCalculator::Result::WBPMode;
|
||||
using Calculated = typename PAvgCalculator<Scalar>::Result::WBPMode;
|
||||
using Output = data::WellBlockAvgPress::Quantity;
|
||||
|
||||
this->wbpCalculationService_.collectDynamicValues();
|
||||
@ -2073,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 = PAvgDynamicSourceData::SourceDataSpan<Scalar>;
|
||||
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.
|
||||
|
@ -32,15 +32,18 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
Opm::ParallelPAvgCalculator::
|
||||
template<class Scalar>
|
||||
Opm::ParallelPAvgCalculator<Scalar>::
|
||||
ParallelPAvgCalculator(const Parallel::Communication& comm,
|
||||
const GridDims& cellIndexMap,
|
||||
const WellConnections& connections)
|
||||
: PAvgCalculator { cellIndexMap, connections }
|
||||
: PAvgCalculator<Scalar> { cellIndexMap, connections }
|
||||
, comm_ { comm }
|
||||
{}
|
||||
|
||||
void Opm::ParallelPAvgCalculator::collectGlobalContributions()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelPAvgCalculator<Scalar>::
|
||||
collectGlobalContributions()
|
||||
{
|
||||
auto collect = [this](Accumulator& accumulator)
|
||||
{
|
||||
@ -54,3 +57,5 @@ void Opm::ParallelPAvgCalculator::collectGlobalContributions()
|
||||
collect(this->accumCTF_);
|
||||
collect(this->accumPV_);
|
||||
}
|
||||
|
||||
template class Opm::ParallelPAvgCalculator<double>;
|
||||
|
@ -38,7 +38,8 @@ namespace Opm {
|
||||
/// have a flowing bottom-hole pressure. Mainly useful for reporting.
|
||||
///
|
||||
/// Parallel edition. Handles distributed wells.
|
||||
class ParallelPAvgCalculator : public PAvgCalculator
|
||||
template<class Scalar>
|
||||
class ParallelPAvgCalculator : public PAvgCalculator<Scalar>
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
@ -55,6 +56,8 @@ public:
|
||||
const WellConnections& connections);
|
||||
|
||||
private:
|
||||
using Accumulator = typename PAvgCalculator<Scalar>::Accumulator;
|
||||
|
||||
/// MPI communication object.
|
||||
std::reference_wrapper<const Parallel::Communication> comm_;
|
||||
|
||||
|
@ -33,31 +33,34 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
Opm::ParallelPAvgDynamicSourceData::
|
||||
template<class Scalar>
|
||||
Opm::ParallelPAvgDynamicSourceData<Scalar>::
|
||||
ParallelPAvgDynamicSourceData(const Parallel::Communication& comm,
|
||||
const std::vector<std::size_t>& sourceLocations,
|
||||
GlobalToLocal localCellIdx)
|
||||
: PAvgDynamicSourceData { sourceLocations }
|
||||
: PAvgDynamicSourceData<Scalar> { sourceLocations }
|
||||
, comm_ { comm }
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
Opm::ParallelPAvgDynamicSourceData::
|
||||
template<class Scalar>
|
||||
void Opm::ParallelPAvgDynamicSourceData<Scalar>::
|
||||
reconstruct(const std::vector<std::size_t>& sourceLocations,
|
||||
GlobalToLocal localCellIdx)
|
||||
{
|
||||
PAvgDynamicSourceData::reconstruct(sourceLocations); // Reconstruct base
|
||||
PAvgDynamicSourceData<Scalar>::reconstruct(sourceLocations); // Reconstruct base
|
||||
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};
|
||||
|
||||
@ -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()
|
||||
.allgatherv(this->localSrc_.data(), // Input (from)
|
||||
@ -76,15 +80,16 @@ void Opm::ParallelPAvgDynamicSourceData::synchroniseSources()
|
||||
this->startPointers_.data()); // Output offsets
|
||||
}
|
||||
|
||||
std::vector<double>::size_type
|
||||
Opm::ParallelPAvgDynamicSourceData::
|
||||
storageIndex(const std::vector<double>::size_type elemIndex) const
|
||||
template<class Scalar>
|
||||
typename std::vector<Scalar>::size_type
|
||||
Opm::ParallelPAvgDynamicSourceData<Scalar>::
|
||||
storageIndex(const typename std::vector<Scalar>::size_type elemIndex) const
|
||||
{
|
||||
return this->storageIndex_[elemIndex];
|
||||
}
|
||||
|
||||
void
|
||||
Opm::ParallelPAvgDynamicSourceData::
|
||||
template<class Scalar>
|
||||
void Opm::ParallelPAvgDynamicSourceData<Scalar>::
|
||||
finaliseConstruction(const std::vector<std::size_t>& sourceLocations,
|
||||
GlobalToLocal localCellIdx)
|
||||
{
|
||||
@ -100,18 +105,20 @@ finaliseConstruction(const std::vector<std::size_t>& sourceLocations,
|
||||
ix += 1;
|
||||
}
|
||||
|
||||
this->localSrc_.assign(numSpanItems() * this->locations_.size(), 0.0);
|
||||
this->localSrc_.assign(this->numSpanItems() * this->locations_.size(), 0.0);
|
||||
|
||||
this->defineCommunication();
|
||||
}
|
||||
|
||||
Opm::PAvgDynamicSourceData::SourceDataSpan<double>
|
||||
Opm::ParallelPAvgDynamicSourceData::localSourceTerm(const std::size_t localIx)
|
||||
template<class Scalar>
|
||||
typename Opm::PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>
|
||||
Opm::ParallelPAvgDynamicSourceData<Scalar>::localSourceTerm(const std::size_t localIx)
|
||||
{
|
||||
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.
|
||||
auto ixVec = std::vector<std::size_t>(this->locations_.size());
|
||||
@ -119,7 +126,7 @@ void Opm::ParallelPAvgDynamicSourceData::defineCommunication()
|
||||
ixVec.begin(),
|
||||
[](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());
|
||||
|
||||
@ -166,3 +173,5 @@ void Opm::ParallelPAvgDynamicSourceData::defineCommunication()
|
||||
this->storageIndex_[elemIndex] = storageIx++;
|
||||
}
|
||||
}
|
||||
|
||||
template class Opm::ParallelPAvgDynamicSourceData<double>;
|
||||
|
@ -32,13 +32,15 @@ namespace Opm {
|
||||
|
||||
/// Dynamic source data for block-average pressure calculations.
|
||||
/// Specialisation for parallel runs.
|
||||
class ParallelPAvgDynamicSourceData : public PAvgDynamicSourceData
|
||||
template<class Scalar>
|
||||
class ParallelPAvgDynamicSourceData : public PAvgDynamicSourceData<Scalar>
|
||||
{
|
||||
public:
|
||||
/// Translate globally unique, linearised Cartesian cell indices to
|
||||
/// local, on-rank, cell indices. Assumed to return a negative value
|
||||
/// result if the input cell index is not owned by the current rank.
|
||||
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.
|
||||
///
|
||||
@ -49,7 +51,7 @@ public:
|
||||
/// 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
|
||||
/// 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
|
||||
///
|
||||
@ -117,11 +119,11 @@ private:
|
||||
std::vector<LocalLocation> locations_{};
|
||||
|
||||
/// Source data values owned by current rank.
|
||||
std::vector<double> localSrc_{};
|
||||
std::vector<Scalar> localSrc_{};
|
||||
|
||||
/// Translation map from element index to storage index in
|
||||
/// 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()).
|
||||
std::vector<int> allSizes_{}; // Type int to meet API requirements.
|
||||
@ -136,8 +138,8 @@ private:
|
||||
/// \param[in] elemIndex Source element index.
|
||||
///
|
||||
/// \return Storage (starting) index in PAvgDynamicSourceData::src_.
|
||||
[[nodiscard]] std::vector<double>::size_type
|
||||
storageIndex(std::vector<double>::size_type elemIndex) const override;
|
||||
[[nodiscard]] typename std::vector<Scalar>::size_type
|
||||
storageIndex(typename std::vector<Scalar>::size_type elemIndex) const override;
|
||||
|
||||
/// Identify local source term elements on rank and build communication
|
||||
/// pattern for all source terms.
|
||||
@ -159,7 +161,7 @@ private:
|
||||
/// \param[in] localIx Logical element index into \c localSrc_.
|
||||
///
|
||||
/// \return Mutable view into \c localSrc_.
|
||||
[[nodiscard]] SourceDataSpan<double>
|
||||
[[nodiscard]] SourceDataSpan<Scalar>
|
||||
localSourceTerm(const std::size_t localIx);
|
||||
|
||||
/// Build communication pattern for all source terms.
|
||||
|
@ -42,19 +42,19 @@
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#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())
|
||||
@ -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 }
|
||||
{}
|
||||
|
||||
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>
|
||||
this->srcData_ = std::make_unique<ParallelPAvgDynamicSourceData<Scalar>>
|
||||
(this->comm_, sourceLocations, this->localIdx_);
|
||||
}
|
||||
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) {
|
||||
throw std::logic_error {
|
||||
@ -133,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());
|
||||
@ -150,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>
|
||||
.setCalculator(well.seqIndex(), std::make_unique<ParallelPAvgCalculator<Scalar>>
|
||||
(parallelWellInfo.communication(),
|
||||
this->cellIndexMap_, well.getConnections()));
|
||||
|
||||
@ -205,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());
|
||||
|
||||
@ -219,7 +235,9 @@ void Opm::ParallelWBPCalculation::defineCommunication()
|
||||
}
|
||||
}
|
||||
|
||||
void Opm::ParallelWBPCalculation::collectDynamicValues()
|
||||
template<class Scalar>
|
||||
void Opm::ParallelWBPCalculation<Scalar>::
|
||||
collectDynamicValues()
|
||||
{
|
||||
this->reservoirSrc_.collectDynamicValues();
|
||||
|
||||
@ -228,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::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();
|
||||
@ -256,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)
|
||||
@ -276,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)
|
||||
@ -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>{};
|
||||
|
||||
@ -328,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::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::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::GlobalToLocal;
|
||||
using GlobalToLocal = typename ParallelPAvgDynamicSourceData<Scalar>::GlobalToLocal;
|
||||
|
||||
/// 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
|
||||
/// 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::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&() 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>;
|
||||
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 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::Sources makeEvaluationSources(const WellID well) const;
|
||||
typename PAvgCalculator<Scalar>::Sources
|
||||
makeEvaluationSources(const WellID well) const;
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -214,9 +214,9 @@ namespace {
|
||||
}
|
||||
|
||||
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))
|
||||
.set(Item::PoreVol , porevol (cell))
|
||||
@ -233,16 +233,16 @@ namespace {
|
||||
return localIdx;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::EvaluatorFactory connSource()
|
||||
Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
|
||||
{
|
||||
return []() {
|
||||
auto rho = std::vector { 0.1, 0.12, 0.14, };
|
||||
|
||||
return [rho = std::move(rho)]
|
||||
(const int connIx,
|
||||
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src)
|
||||
(const int connIx,
|
||||
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)
|
||||
.set(Item::PoreVol , 1.25)
|
||||
@ -353,10 +353,10 @@ namespace {
|
||||
});
|
||||
}
|
||||
|
||||
void cellSource(const int cell,
|
||||
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src)
|
||||
void cellSource(const int cell,
|
||||
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))
|
||||
.set(Item::PoreVol , porevol (cell))
|
||||
@ -373,16 +373,16 @@ namespace {
|
||||
return localIdx;
|
||||
}
|
||||
|
||||
Opm::ParallelWBPCalculation::EvaluatorFactory connSource()
|
||||
Opm::ParallelWBPCalculation<double>::EvaluatorFactory connSource()
|
||||
{
|
||||
return []() {
|
||||
auto rho = std::vector { 0.16, 0.18, 0.2, };
|
||||
|
||||
return [rho = std::move(rho)]
|
||||
(const int connIx,
|
||||
Opm::PAvgDynamicSourceData::SourceDataSpan<double> src)
|
||||
(const int connIx,
|
||||
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)
|
||||
.set(Item::PoreVol , 1.25)
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -599,7 +599,7 @@ BOOST_AUTO_TEST_CASE(TopOfFormation_Well_OpenConns)
|
||||
cse.wbpCalcService.inferBlockAveragePressures(calcIndex, controls, gravity, refDepth);
|
||||
|
||||
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::WBP4), 1295.348292333333, 1.0e-8);
|
||||
|
@ -108,7 +108,7 @@ private:
|
||||
class CalculateSourceTerm
|
||||
{
|
||||
public:
|
||||
using SrcTerm = Opm::PAvgDynamicSourceData::SourceDataSpan<double>;
|
||||
using SrcTerm = Opm::PAvgDynamicSourceData<double>::SourceDataSpan<double>;
|
||||
|
||||
explicit CalculateSourceTerm(const std::size_t rank)
|
||||
: rank_ { rank }
|
||||
@ -129,11 +129,11 @@ private:
|
||||
};
|
||||
|
||||
std::size_t
|
||||
sourceTermsAreCorrect(const std::size_t comm_size,
|
||||
const std::size_t num_src,
|
||||
const Opm::PAvgDynamicSourceData& source_data)
|
||||
sourceTermsAreCorrect(const std::size_t comm_size,
|
||||
const std::size_t num_src,
|
||||
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;
|
||||
|
||||
@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(Eval_and_collect)
|
||||
|
||||
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),
|
||||
LocalCellIndex { comm_rank, comm_size }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user