Skip to content

Commit

Permalink
PressureBhpTransferPolicy: workaround dune bug
Browse files Browse the repository at this point in the history
calling compress() on an empty matrix causes a nullptr dereference.
use random build mode to avoid the call to compress() if matrix is
empty.
  • Loading branch information
akva2 committed Dec 7, 2022
1 parent 56559ac commit a468efb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions opm/simulators/linalg/PressureBhpTransferPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,17 @@ namespace Opm
= static_cast<size_t>(std::ceil(fineLevelMatrix.nonzeroes() /
std::max(1ul,fineLevelMatrix.N())));
const double overflow_fraction = 1.2;
coarseLevelMatrix_.reset(new CoarseMatrix(fineLevelMatrix.N() + nw,
fineLevelMatrix.M() + nw,
average_elements_per_row,
overflow_fraction,
CoarseMatrix::implicit));
if (fineLevelMatrix.N() + nw > 0) {
coarseLevelMatrix_ = std::make_unique<CoarseMatrix>(fineLevelMatrix.N() + nw,
fineLevelMatrix.M() + nw,
average_elements_per_row,
overflow_fraction,
CoarseMatrix::implicit);
} else { // workaround bcrsmatrix bug with implicit build mode + empty matrix
coarseLevelMatrix_ = std::make_unique<CoarseMatrix>(fineLevelMatrix.N() + nw,
fineLevelMatrix.M() + nw,
CoarseMatrix::random);
}
int rownum = 0;
for (const auto& row : fineLevelMatrix) {
for (auto col = row.begin(), cend = row.end(); col != cend; ++col) {
Expand Down Expand Up @@ -151,7 +157,12 @@ namespace Opm
#endif
if (prm_.get<bool>("add_wells")) {
fineOperator.addWellPressureEquationsStruct(*coarseLevelMatrix_);
coarseLevelMatrix_->compress(); // all elemenst should be set
if (coarseLevelMatrix_->N() > 0) {
coarseLevelMatrix_->compress(); // all elements should be set
} else { // workaround for bug in compress()
coarseLevelMatrix_->endrowsizes();
coarseLevelMatrix_->endindices();
}
if constexpr (!std::is_same_v<Communication, Dune::Amg::SequentialInformation>) {
extendCommunicatorWithWells(*communication_, coarseLevelCommunication_, nw);
}
Expand Down

0 comments on commit a468efb

Please sign in to comment.