mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-26 19:46:24 -06:00
ParallelPAvgDynamicSourceData: template Scalar type
This commit is contained in:
parent
b9ad890ea5
commit
b68a854909
@ -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<double>::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<double>
|
||||
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,7 +42,6 @@
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
@ -97,7 +96,7 @@ Opm::ParallelWBPCalculation::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<double>>
|
||||
(this->comm_, sourceLocations, this->localIdx_);
|
||||
}
|
||||
else {
|
||||
|
@ -51,10 +51,10 @@ class ParallelWBPCalculation
|
||||
public:
|
||||
/// Callback for inferring the source locations which are active on the
|
||||
/// current MPI rank.
|
||||
using GlobalToLocal = ParallelPAvgDynamicSourceData::GlobalToLocal;
|
||||
using GlobalToLocal = ParallelPAvgDynamicSourceData<double>::GlobalToLocal;
|
||||
|
||||
/// Callback for evaluating WBPn source terms on the current MPI rank.
|
||||
using Evaluator = ParallelPAvgDynamicSourceData::Evaluator;
|
||||
using Evaluator = ParallelPAvgDynamicSourceData<double>::Evaluator;
|
||||
|
||||
/// Callback for constructing a source term evaluation function on the
|
||||
/// current MPI rank. Needed for deferred construction of per-well
|
||||
@ -213,7 +213,7 @@ private:
|
||||
///
|
||||
/// Enables transparent usage of this object as an argument to \code
|
||||
/// PAvgCalculator::inferBlockAveragePressures() \endcode.
|
||||
operator const ParallelPAvgDynamicSourceData&() const
|
||||
operator const ParallelPAvgDynamicSourceData<double>&() const
|
||||
{
|
||||
return *this->srcData_;
|
||||
}
|
||||
@ -294,7 +294,7 @@ private:
|
||||
|
||||
private:
|
||||
/// Type of wrapped object.
|
||||
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData>;
|
||||
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData<double>>;
|
||||
|
||||
/// MPI communicator for this source data object.
|
||||
std::reference_wrapper<const Parallel::Communication> comm_;
|
||||
|
@ -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