From 6cfe647c816dcf36554722b54450bc5908ef4626 Mon Sep 17 00:00:00 2001 From: Tobias Meyer Andersen Date: Wed, 20 Dec 2023 09:31:40 +0100 Subject: [PATCH] clean up and fix multiprocess RebuildOnUpdate wrapper --- .../linalg/PreconditionerFactory_impl.hpp | 2 +- .../linalg/PreconditionerWithUpdate.hpp | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/opm/simulators/linalg/PreconditionerFactory_impl.hpp b/opm/simulators/linalg/PreconditionerFactory_impl.hpp index f6527ded7..73f5a1755 100644 --- a/opm/simulators/linalg/PreconditionerFactory_impl.hpp +++ b/opm/simulators/linalg/PreconditionerFactory_impl.hpp @@ -180,7 +180,7 @@ struct StandardPreconditioners const int n = prm.get("ilulevel", 0); const double w = prm.get("relaxation", 1.0); const bool resort = prm.get("resort", false); - return wrapBlockPreconditioner, M>>(comm, op.getmat(), n, w, resort); + return wrapBlockPreconditioner, const M*>>(comm, &op.getmat(), n, w, resort); }); F::addCreator("DILU", [](const O& op, const P& prm, const std::function&, std::size_t, const C& comm) { DUNE_UNUSED_PARAMETER(prm); diff --git a/opm/simulators/linalg/PreconditionerWithUpdate.hpp b/opm/simulators/linalg/PreconditionerWithUpdate.hpp index 96be78499..5abcbab26 100644 --- a/opm/simulators/linalg/PreconditionerWithUpdate.hpp +++ b/opm/simulators/linalg/PreconditionerWithUpdate.hpp @@ -85,13 +85,13 @@ wrapPreconditioner(Args&&... args) return std::make_shared>(std::forward(args)...); } -template +template class RebuildOnUpdatePreconditioner : public PreconditionerWithUpdate { public: - RebuildOnUpdatePreconditioner(Matrix op_mat, const int n, const double w, const bool resort) - : orig_precond_(std::make_unique(op_mat, n, w, resort)), op_mat_(op_mat), n_(n), w_(w), resort_(resort) + RebuildOnUpdatePreconditioner(MatrixPtr mat_ptr, const int n, const double w, const bool resort) + : orig_precond_(std::make_unique(*mat_ptr, n, w, resort)), mat_ptr_(mat_ptr), n_(n), w_(w), resort_(resort) { } @@ -118,19 +118,18 @@ public: return orig_precond_->category(); } - // The update() function does nothing for a wrapped preconditioner. - virtual void update() override + // Rebuild the preconditioner on update + void update() override { - orig_precond_ = std::make_unique(op_mat_, n_, w_, resort_); + orig_precond_ = std::make_unique(*mat_ptr_, n_, w_, resort_); } private: std::unique_ptr orig_precond_; - //TODO: replace excess copy of matrix with pointer - Matrix op_mat_; - int n_; - double w_; - bool resort_; + const MatrixPtr mat_ptr_; + const int n_; + const double w_; + const bool resort_; }; } // namespace Dune