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>
30#include <opm/simulators/linalg/WellOperators.hpp>
36 template <
class Communication>
37 void extendCommunicatorWithWells(
const Communication& comm,
38 std::shared_ptr<Communication>&
commRW,
43 using IndexSet =
typename Communication::ParallelIndexSet;
44 using LocalIndex =
typename IndexSet::LocalIndex;
45 const IndexSet&
indset = comm.indexSet();
47 const int max_nw = comm.communicator().max(
nw);
48 const int rank = comm.communicator().rank();
53 indset_rw.add(
ind->global(), LocalIndex(
ind->local(),
ind->local().attribute(),
true));
54 const int glo =
ind->global();
55 const std::size_t
loc =
ind->local().local();
63 for (
int i = 0; i <
nw; ++i) {
73 commRW->remoteIndices().setNeighbours(comm.remoteIndices().getNeighbours());
80 template<
class Scalar>
using PressureMatrixType = Dune::BCRSMatrix<MatrixBlock<Scalar, 1, 1>>;
81 template<
class Scalar>
using PressureVectorType = Dune::BlockVector<Dune::FieldVector<Scalar, 1>>;
82 template<
class Scalar>
using SeqCoarseOperatorType = Dune::MatrixAdapter<PressureMatrixType<Scalar>,
85 template<
class Scalar,
class Comm>
86 using ParCoarseOperatorType
91 template<
class Scalar,
class Comm>
92 using CoarseOperatorType = std::conditional_t<std::is_same<Comm, Dune::Amg::SequentialInformation>::value,
97 template<
class FineOperator,
class Communication,
class Scalar,
bool transpose = false>
101 using CoarseOperator =
typename Details::CoarseOperatorType<Scalar,Communication>;
103 using ParallelInformation = Communication;
104 using FineVectorType=
typename FineOperator::domain_type;
108 const FineVectorType& weights,
110 const std::size_t pressureIndex)
111 : communication_(&
const_cast<Communication&
>(comm))
114 , pressure_var_index_(pressureIndex)
121 using CoarseMatrix =
typename CoarseOperator::matrix_type;
124 if (prm_.
get<
bool>(
"add_wells")) {
132 CoarseMatrix::implicit));
136 coarseLevelMatrix_->entry(
rownum,
col.index()) = 0.0;
141 coarseLevelMatrix_.reset(
143 auto createIter = coarseLevelMatrix_->createbegin();
151 if constexpr (std::is_same_v<Communication, Dune::Amg::SequentialInformation>) {
152 coarseLevelCommunication_ = std::make_shared<Communication>();
154 coarseLevelCommunication_ = std::make_shared<Communication>(
155 communication_->communicator(), communication_->category(),
false);
157 if (prm_.
get<
bool>(
"add_wells")) {
158 fineOperator.addWellPressureEquationsStruct(*coarseLevelMatrix_);
159 coarseLevelMatrix_->compress();
160 if constexpr (!std::is_same_v<Communication, Dune::Amg::SequentialInformation>) {
161 extendCommunicatorWithWells(*communication_, coarseLevelCommunication_,
nw);
166 this->
lhs_.resize(this->coarseLevelMatrix_->M());
167 this->
rhs_.resize(this->coarseLevelMatrix_->N());
168 using OperatorArgs =
typename Dune::Amg::ConstructionTraits<CoarseOperator>::Arguments;
170 this->
operator_ = Dune::Amg::ConstructionTraits<CoarseOperator>::construct(
oargs);
177 *coarseLevelMatrix_ = 0;
178 auto rowCoarse = coarseLevelMatrix_->begin();
186 const auto&
bw = weights_[
entry.index()];
187 for (std::size_t i = 0; i <
bw.size(); ++i) {
188 matrix_el += (*entry)[pressure_var_index_][i] *
bw[i];
191 const auto&
bw = weights_[
row.index()];
192 for (std::size_t i = 0; i <
bw.size(); ++i) {
193 matrix_el += (*entry)[i][pressure_var_index_] *
bw[i];
199 if (prm_.
get<
bool>(
"add_wells")) {
219 auto end =
fine.end(), begin =
fine.begin();
221 for (
auto block = begin; block != end; ++block) {
222 const auto&
bw = weights_[block.index()];
225 rhs_el = (*block)[pressure_var_index_];
227 for (std::size_t i = 0; i < block->size(); ++i) {
241 auto end =
fine.end(), begin =
fine.begin();
243 for (
auto block = begin; block != end; ++block) {
245 const auto&
bw = weights_[block.index()];
246 for (std::size_t i = 0; i < block->size(); ++i) {
247 (*block)[i] = this->
lhs_[block - begin] *
bw[i];
250 (*block)[pressure_var_index_] = this->
lhs_[block - begin];
260 const Communication& getCoarseLevelCommunication()
const
262 return *coarseLevelCommunication_;
266 Communication* communication_;
267 const FineVectorType& weights_;
269 const int pressure_var_index_;
270 std::shared_ptr<Communication> coarseLevelCommunication_;
271 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:49
FineOperatorType::range_type FineRangeType
The type of the range of the fine level operator.
Definition twolevelmethodcpr.hh:59
CoarseDomainType lhs_
The coarse level lhs.
Definition twolevelmethodcpr.hh:146
CoarseRangeType rhs_
The coarse level rhs.
Definition twolevelmethodcpr.hh:144
FineOperatorType::domain_type FineDomainType
The type of the domain of the fine level operator.
Definition twolevelmethodcpr.hh:63
std::shared_ptr< CoarseOperatorType > operator_
the coarse level linear operator.
Definition twolevelmethodcpr.hh:148
Dune linear operator that assumes ghost rows are ordered after interior rows.
Definition WellOperators.hpp:402
Definition PressureBhpTransferPolicy.hpp:99
PressureBhpTransferPolicy * clone() const override
Clone the current object.
Definition PressureBhpTransferPolicy.hpp:255
void moveToFineLevel(typename ParentType::FineDomainType &fine) override
Updates the fine level linear system after the correction of the coarse levels system.
Definition PressureBhpTransferPolicy.hpp:237
void createCoarseLevelSystem(const FineOperator &fineOperator) override
Algebraically creates the coarse level system.
Definition PressureBhpTransferPolicy.hpp:118
void calculateCoarseEntries(const FineOperator &fineOperator) override
???.
Definition PressureBhpTransferPolicy.hpp:173
Hierarchical collection of key/value pairs.
Definition PropertyTree.hpp:39
T get(const std::string &key) const
Retrieve property value given hierarchical property key.
Definition PropertyTree.cpp:59
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Algebraic twolevel methods.