Loading...
Searching...
No Matches
ParallelWBPCalculation.hpp
/*
Copyright 2023 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARALLEL_WBP_CALCULATION_HPP
#define PARALLEL_WBP_CALCULATION_HPP
#include <opm/simulators/wells/ParallelPAvgDynamicSourceData.hpp>
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <opm/simulators/wells/PerforationData.hpp>
#include <opm/input/eclipse/Schedule/Well/PAvgCalculator.hpp>
#include <opm/input/eclipse/Schedule/Well/PAvgCalculatorCollection.hpp>
#include <cstddef>
#include <functional>
#include <memory>
#include <vector>
namespace Opm {
class GridDims;
template<class Scalar> class ParallelWellInfo;
class PAvg;
class Well;
}
namespace Opm {
template<class Scalar>
class ParallelWBPCalculation
{
public:
using GlobalToLocal = typename ParallelPAvgDynamicSourceData<Scalar>::GlobalToLocal;
using Evaluator = typename ParallelPAvgDynamicSourceData<Scalar>::Evaluator;
using EvaluatorFactory = std::function<Evaluator()>;
explicit ParallelWBPCalculation(const GridDims& cellIndexMap,
const Parallel::Communication& gridComm);
ParallelWBPCalculation& localCellIndex(GlobalToLocal localCellIdx);
ParallelWBPCalculation& evalCellSource(Evaluator evalCellSrc);
std::size_t
createCalculator(const Well& well,
const ParallelWellInfo<Scalar>& parallelWellInfo,
const std::vector<int>& localConnIdx,
EvaluatorFactory makeWellSourceEvaluator);
void defineCommunication();
void collectDynamicValues();
void inferBlockAveragePressures(const std::size_t calcIndex,
const PAvg& controls,
const Scalar gravity,
const Scalar refDepth);
const PAvgCalculatorResult<Scalar>&
averagePressures(const std::size_t calcIndex) const;
private:
class LocalConnSet
{
public:
explicit LocalConnSet(const std::vector<int>& localConnIdx);
int localIndex(const std::size_t connIdx) const;
private:
std::vector<int> localConnIdx_{};
};
class SourceData
{
public:
operator const ParallelPAvgDynamicSourceData<Scalar>&() const
{
return *this->srcData_;
}
explicit SourceData(const Parallel::Communication& comm);
SourceData& localIndex(GlobalToLocal localIdx);
SourceData& evaluator(Evaluator eval);
SourceData& evaluatorFactory(EvaluatorFactory evalFactory);
void buildStructure(const std::vector<std::size_t>& sourceLocations);
void collectDynamicValues();
const Parallel::Communication& comm() const
{
return this->comm_.get();
}
std::vector<int>
getLocalIndex(const std::vector<std::size_t>& globalIndex) const;
private:
using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData<Scalar>>;
std::reference_wrapper<const Parallel::Communication> comm_;
GlobalToLocal localIdx_{};
Evaluator eval_{};
EvaluatorFactory evalFactory_{};
DataPtr srcData_{};
};
using WellID = typename std::vector<SourceData>::size_type;
std::reference_wrapper<const GridDims> cellIndexMap_;
SourceData reservoirSrc_;
PAvgCalculatorCollection<Scalar> calculators_{};
std::vector<SourceData> wellConnSrc_{};
std::vector<LocalConnSet> localConnSet_{};
void pruneInactiveWBPCells();
void pruneInactiveWBPCellsSerial();
void pruneInactiveWBPCellsParallel();
void defineReservoirCommunication();
void defineWellCommunication(const std::size_t well);
typename PAvgCalculator<Scalar>::Sources
makeEvaluationSources(const WellID well) const;
};
} // namespace Opm
#endif // PARALLEL_WBP_CALCULATION_HPP
Opm::ParallelPAvgDynamicSourceData::Evaluator
std::function< void(int, SourceDataSpan< Scalar >)> Evaluator
Collect source term contributions from local, on-rank, cell.
Definition ParallelPAvgDynamicSourceData.hpp:64
Opm::ParallelPAvgDynamicSourceData::GlobalToLocal
std::function< int(const std::size_t)> GlobalToLocal
Translate globally unique, linearised Cartesian cell indices to local, on-rank, cell indices.
Definition ParallelPAvgDynamicSourceData.hpp:42
Opm::ParallelWBPCalculation::inferBlockAveragePressures
void inferBlockAveragePressures(const std::size_t calcIndex, const PAvg &controls, const Scalar gravity, const Scalar refDepth)
Compute WBPn report values for a single well.
Definition ParallelWBPCalculation.cpp:251
Opm::ParallelWBPCalculation::averagePressures
const PAvgCalculatorResult< Scalar > & averagePressures(const std::size_t calcIndex) const
Retrieve results from most recent WBPn value calculation for specified well.
Definition ParallelWBPCalculation.cpp:264
Opm::ParallelWBPCalculation::createCalculator
std::size_t createCalculator(const Well &well, const ParallelWellInfo< Scalar > &parallelWellInfo, const std::vector< int > &localConnIdx, EvaluatorFactory makeWellSourceEvaluator)
Create, or reassign, a WBPn calculation object for a particular well.
Definition ParallelWBPCalculation.cpp:189
Opm::ParallelWBPCalculation::ParallelWBPCalculation
ParallelWBPCalculation(const GridDims &cellIndexMap, const Parallel::Communication &gridComm)
Constructor.
Definition ParallelWBPCalculation.cpp:163
Opm::ParallelWBPCalculation::defineCommunication
void defineCommunication()
Set up communication patterns for both cell and connection level source terms and partial/intermediat...
Definition ParallelWBPCalculation.cpp:224
Opm::ParallelWBPCalculation::GlobalToLocal
typename ParallelPAvgDynamicSourceData< Scalar >::GlobalToLocal GlobalToLocal
Callback for inferring the source locations which are active on the current MPI rank.
Definition ParallelWBPCalculation.hpp:55
Opm::ParallelWBPCalculation::evalCellSource
ParallelWBPCalculation & evalCellSource(Evaluator evalCellSrc)
Assign evaluation function for computing the on-rank, cell level WBPn source terms.
Definition ParallelWBPCalculation.cpp:181
Opm::ParallelWBPCalculation::Evaluator
typename ParallelPAvgDynamicSourceData< Scalar >::Evaluator Evaluator
Callback for evaluating WBPn source terms on the current MPI rank.
Definition ParallelWBPCalculation.hpp:58
Opm::ParallelWBPCalculation::EvaluatorFactory
std::function< Evaluator()> EvaluatorFactory
Callback for constructing a source term evaluation function on the current MPI rank.
Definition ParallelWBPCalculation.hpp:63
Opm::ParallelWBPCalculation::localCellIndex
ParallelWBPCalculation & localCellIndex(GlobalToLocal localCellIdx)
Assign translation function for inferring the on-rank IDs of the known source locations.
Definition ParallelWBPCalculation.cpp:172
Opm::ParallelWBPCalculation::collectDynamicValues
void collectDynamicValues()
Collect all on-rank source term value and distribute those on-rank values to all other MPI ranks.
Definition ParallelWBPCalculation.cpp:240
Opm::ParallelWellInfo
Class encapsulating some information about parallel wells.
Definition ParallelWellInfo.hpp:198
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43