initializeWBPCalculationService: move to BlackoilWellModelGeneric

This commit is contained in:
Arne Morten Kvarving 2024-11-18 11:41:52 +01:00
parent a67e8c44b4
commit 4d998545eb
4 changed files with 79 additions and 88 deletions

View File

@ -500,14 +500,9 @@ template<class Scalar> class WellContributions;
// setting the well_solutions_ based on well_state.
void updatePrimaryVariables(DeferredLogger& deferred_logger);
void initializeWBPCalculationService();
data::WellBlockAveragePressures
computeWellBlockAveragePressures() const;
typename ParallelWBPCalculation<Scalar>::EvaluatorFactory
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const;
void updateAverageFormationFactor();
void computePotentials(const std::size_t widx,

View File

@ -2101,6 +2101,80 @@ registerOpenWellsForWBPCalculation()
}
}
template<class Scalar>
typename ParallelWBPCalculation<Scalar>::EvaluatorFactory
BlackoilWellModelGeneric<Scalar>::
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]() -> typename ParallelWBPCalculation<Scalar>::Evaluator
{
if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
// Well is stopped/shut. Return evaluator for stopped wells.
return []([[maybe_unused]] const int connIdx, Span sourceTerm)
{
// Well/connection is stopped/shut. Set all items to
// zero.
sourceTerm
.set(Item::Pressure , 0.0)
.set(Item::PoreVol , 0.0)
.set(Item::MixtureDensity, 0.0)
.set(Item::Depth , 0.0)
;
};
}
// Well is open. Return an evaluator for open wells/open connections.
return [this, wellPtr = this->well_container_generic_[*this->wbpCalcMap_[wellIdx].openWellIdx_]]
(const int connIdx, Span sourceTerm)
{
// Note: The only item which actually matters for the WBP
// calculation at the well reservoir connection level is the
// mixture density. Set other items to zero.
const auto& connIdxMap =
this->conn_idx_map_[wellPtr->indexOfWell()];
const auto rho = wellPtr->
connectionDensity(connIdxMap.global(connIdx),
connIdxMap.open(connIdx));
sourceTerm
.set(Item::Pressure , 0.0)
.set(Item::PoreVol , 0.0)
.set(Item::MixtureDensity, rho)
.set(Item::Depth , 0.0)
;
};
};
}
template<class Scalar>
void BlackoilWellModelGeneric<Scalar>::
initializeWBPCalculationService()
{
this->wbpCalcMap_.clear();
this->wbpCalcMap_.resize(this->wells_ecl_.size());
this->registerOpenWellsForWBPCalculation();
auto wellID = std::size_t{0};
for (const auto& well : this->wells_ecl_) {
this->wbpCalcMap_[wellID].wbpCalcIdx_ = this->wbpCalculationService_
.createCalculator(well,
this->local_parallel_well_info_[wellID],
this->conn_idx_map_[wellID].local(),
this->makeWellSourceEvaluatorFactory(wellID));
++wellID;
}
this->wbpCalculationService_.defineCommunication();
}
template class BlackoilWellModelGeneric<double>;
#if FLOW_INSTANTIATE_FLOAT

View File

@ -460,6 +460,11 @@ protected:
void registerOpenWellsForWBPCalculation();
typename ParallelWBPCalculation<Scalar>::EvaluatorFactory
makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const;
void initializeWBPCalculationService();
Schedule& schedule_;
const SummaryState& summaryState_;
const EclipseState& eclState_;

View File

@ -2357,34 +2357,6 @@ namespace Opm {
template <typename TypeTag>
void
BlackoilWellModel<TypeTag>::
initializeWBPCalculationService()
{
this->wbpCalcMap_.clear();
this->wbpCalcMap_.resize(this->wells_ecl_.size());
this->registerOpenWellsForWBPCalculation();
auto wellID = std::size_t{0};
for (const auto& well : this->wells_ecl_) {
this->wbpCalcMap_[wellID].wbpCalcIdx_ = this->wbpCalculationService_
.createCalculator(well,
this->local_parallel_well_info_[wellID],
this->conn_idx_map_[wellID].local(),
this->makeWellSourceEvaluatorFactory(wellID));
++wellID;
}
this->wbpCalculationService_.defineCommunication();
}
template <typename TypeTag>
data::WellBlockAveragePressures
BlackoilWellModel<TypeTag>::
@ -2431,61 +2403,6 @@ namespace Opm {
template <typename TypeTag>
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]() -> typename ParallelWBPCalculation<Scalar>::Evaluator
{
if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
// Well is stopped/shut. Return evaluator for stopped wells.
return []([[maybe_unused]] const int connIdx, Span sourceTerm)
{
// Well/connection is stopped/shut. Set all items to
// zero.
sourceTerm
.set(Item::Pressure , 0.0)
.set(Item::PoreVol , 0.0)
.set(Item::MixtureDensity, 0.0)
.set(Item::Depth , 0.0)
;
};
}
// Well is open. Return an evaluator for open wells/open connections.
return [this, wellPtr = this->well_container_[*this->wbpCalcMap_[wellIdx].openWellIdx_].get()]
(const int connIdx, Span sourceTerm)
{
// Note: The only item which actually matters for the WBP
// calculation at the well reservoir connection level is the
// mixture density. Set other items to zero.
const auto& connIdxMap =
this->conn_idx_map_[wellPtr->indexOfWell()];
const auto rho = wellPtr->
connectionDensity(connIdxMap.global(connIdx),
connIdxMap.open(connIdx));
sourceTerm
.set(Item::Pressure , 0.0)
.set(Item::PoreVol , 0.0)
.set(Item::MixtureDensity, rho)
.set(Item::Depth , 0.0)
;
};
};
}
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::