23#include <opm/common/TimingMacros.hpp>
25#include <opm/simulators/linalg/matrixblock.hh>
26#include <opm/simulators/linalg/PropertyTree.hpp>
29#include <dune/istl/paamg/pinfo.hh>
35 template <
class Communication>
36 void extendCommunicatorWithWells(
const Communication& comm,
37 std::shared_ptr<Communication>& commRW,
40 OPM_TIMEBLOCK(extendCommunicatorWithWells);
42 using IndexSet =
typename Communication::ParallelIndexSet;
43 using LocalIndex =
typename IndexSet::LocalIndex;
44 const IndexSet& indset = comm.indexSet();
45 IndexSet& indset_rw = commRW->indexSet();
46 const int max_nw = comm.communicator().max(nw);
47 const int rank = comm.communicator().rank();
49 std::size_t loc_max = 0;
50 indset_rw.beginResize();
51 for (
auto ind = indset.begin(), indend = indset.end(); ind != indend; ++ind) {
52 indset_rw.add(ind->global(), LocalIndex(ind->local(), ind->local().attribute(),
true));
53 const int glo = ind->global();
54 const std::size_t loc = ind->local().local();
55 glo_max = std::max(glo_max, glo);
56 loc_max = std::max(loc_max, loc);
58 const int global_max = comm.communicator().max(glo_max);
60 assert(loc_max + 1 == indset.size());
61 std::size_t local_ind = loc_max + 1;
62 for (
int i = 0; i < nw; ++i) {
64 const std::size_t v = global_max + max_nw * rank + i + 1;
66 indset_rw.add(v, LocalIndex(local_ind, Dune::OwnerOverlapCopyAttributeSet::owner,
true));
69 indset_rw.endResize();
70 assert(indset_rw.size() == indset.size() + nw);
72 commRW->remoteIndices().setNeighbours(comm.remoteIndices().getNeighbours());
73 commRW->remoteIndices().template rebuild<true>();
79 using PressureMatrixType = Dune::BCRSMatrix<Opm::MatrixBlock<double, 1, 1>>;
80 using PressureVectorType = Dune::BlockVector<Dune::FieldVector<double, 1>>;
81 using SeqCoarseOperatorType = Dune::MatrixAdapter<PressureMatrixType, PressureVectorType, PressureVectorType>;
83 using ParCoarseOperatorType
84 = Dune::OverlappingSchwarzOperator<PressureMatrixType, PressureVectorType, PressureVectorType, Comm>;
86 using CoarseOperatorType = std::conditional_t<std::is_same<Comm, Dune::Amg::SequentialInformation>::value,
87 SeqCoarseOperatorType,
88 ParCoarseOperatorType<Comm>>;
91 template <
class FineOperator,
class Communication,
bool transpose = false>
95 typedef typename Details::CoarseOperatorType<Communication> CoarseOperator;
97 typedef Communication ParallelInformation;
98 typedef typename FineOperator::domain_type FineVectorType;
102 const FineVectorType& weights,
104 const std::size_t pressureIndex)
105 : communication_(&
const_cast<Communication&
>(comm))
108 , pressure_var_index_(pressureIndex)
115 using CoarseMatrix =
typename CoarseOperator::matrix_type;
118 if (prm_.get<
bool>(
"add_wells")) {
126 CoarseMatrix::implicit));
130 coarseLevelMatrix_->entry(
rownum,
col.index()) = 0.0;
135 coarseLevelMatrix_.reset(
137 auto createIter = coarseLevelMatrix_->createbegin();
145 if constexpr (std::is_same_v<Communication, Dune::Amg::SequentialInformation>) {
146 coarseLevelCommunication_ = std::make_shared<Communication>();
148 coarseLevelCommunication_ = std::make_shared<Communication>(
149 communication_->communicator(), communication_->category(),
false);
151 if (prm_.get<
bool>(
"add_wells")) {
152 fineOperator.addWellPressureEquationsStruct(*coarseLevelMatrix_);
153 coarseLevelMatrix_->compress();
154 if constexpr (!std::is_same_v<Communication, Dune::Amg::SequentialInformation>) {
155 extendCommunicatorWithWells(*communication_, coarseLevelCommunication_,
nw);
160 this->
lhs_.resize(this->coarseLevelMatrix_->M());
161 this->
rhs_.resize(this->coarseLevelMatrix_->N());
162 using OperatorArgs =
typename Dune::Amg::ConstructionTraits<CoarseOperator>::Arguments;
164 this->
operator_ = Dune::Amg::ConstructionTraits<CoarseOperator>::construct(
oargs);
171 *coarseLevelMatrix_ = 0;
172 auto rowCoarse = coarseLevelMatrix_->begin();
180 const auto&
bw = weights_[
entry.index()];
181 for (std::size_t
i = 0;
i <
bw.size(); ++
i) {
185 const auto&
bw = weights_[
row.index()];
186 for (std::size_t
i = 0;
i <
bw.size(); ++
i) {
193 if (prm_.get<
bool>(
"add_wells")) {
213 auto end =
fine.end(), begin =
fine.begin();
216 const auto&
bw = weights_[
block.index()];
219 rhs_el = (*block)[pressure_var_index_];
221 for (std::size_t i = 0; i < block->size(); ++i) {
222 rhs_el += (*block)[i] * bw[i];
225 this->
rhs_[block - begin] = rhs_el;
235 auto end =
fine.end(), begin =
fine.begin();
239 const auto&
bw = weights_[
block.index()];
240 for (std::size_t
i = 0;
i <
block->size(); ++
i) {
244 (*block)[pressure_var_index_] = this->
lhs_[
block - begin];
254 const Communication& getCoarseLevelCommunication()
const
256 return *coarseLevelCommunication_;
260 Communication* communication_;
261 const FineVectorType& weights_;
263 const int pressure_var_index_;
264 std::shared_ptr<Communication> coarseLevelCommunication_;
265 std::shared_ptr<typename CoarseOperator::matrix_type> coarseLevelMatrix_;
Abstract base class for transfer between levels and creation of the coarse level system.
Definition twolevelmethodcpr.hh:44
FineOperatorType::range_type FineRangeType
The type of the range of the fine level operator.
Definition twolevelmethodcpr.hh:54
CoarseDomainType lhs_
The coarse level lhs.
Definition twolevelmethodcpr.hh:141
CoarseRangeType rhs_
The coarse level rhs.
Definition twolevelmethodcpr.hh:139
FineOperatorType::domain_type FineDomainType
The type of the domain of the fine level operator.
Definition twolevelmethodcpr.hh:58
std::shared_ptr< CoarseOperatorType > operator_
the coarse level linear operator.
Definition twolevelmethodcpr.hh:143
Definition AquiferInterface.hpp:35
Definition PressureBhpTransferPolicy.hpp:93
virtual void moveToFineLevel(typename ParentType::FineDomainType &fine) override
Updates the fine level linear system after the correction of the coarse levels system.
Definition PressureBhpTransferPolicy.hpp:231
virtual void calculateCoarseEntries(const FineOperator &fineOperator) override
???.
Definition PressureBhpTransferPolicy.hpp:167
virtual PressureBhpTransferPolicy * clone() const override
Clone the current object.
Definition PressureBhpTransferPolicy.hpp:249
virtual void createCoarseLevelSystem(const FineOperator &fineOperator) override
Algebraically creates the coarse level system.
Definition PressureBhpTransferPolicy.hpp:112
Definition PropertyTree.hpp:37
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27
Algebraic twolevel methods.