diff --git a/opm/simulators/linalg/PreconditionerFactory_impl.hpp b/opm/simulators/linalg/PreconditionerFactory_impl.hpp index 919e409d8..f6527ded7 100644 --- a/opm/simulators/linalg/PreconditionerFactory_impl.hpp +++ b/opm/simulators/linalg/PreconditionerFactory_impl.hpp @@ -177,10 +177,10 @@ struct StandardPreconditioners return createParILU(op, prm, comm, prm.get("ilulevel", 0)); }); F::addCreator("DuneILU", [](const O& op, const P& prm, const std::function&, std::size_t, const C& comm) { - const double w = prm.get("relaxation", 1.0); const int n = prm.get("ilulevel", 0); + const double w = prm.get("relaxation", 1.0); const bool resort = prm.get("resort", false); - return wrapBlockPreconditioner>>(comm, op.getmat(), n, w, resort); + return wrapBlockPreconditioner, 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 ba9111dfd..96be78499 100644 --- a/opm/simulators/linalg/PreconditionerWithUpdate.hpp +++ b/opm/simulators/linalg/PreconditionerWithUpdate.hpp @@ -77,7 +77,7 @@ private: OriginalPreconditioner orig_precond_; }; - +//TODO: extend this functionality to support RebuildOnUpdatePreconditioner template std::shared_ptr> wrapPreconditioner(Args&&... args) @@ -85,6 +85,53 @@ wrapPreconditioner(Args&&... args) return std::make_shared>(std::forward(args)...); } +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) + { + } + + using X = typename OriginalPreconditioner::domain_type; + using Y = typename OriginalPreconditioner::range_type; + + virtual void pre(X& x, Y& b) override + { + orig_precond_->pre(x, b); + } + + virtual void apply(X& v, const Y& d) override + { + orig_precond_->apply(v, d); + } + + virtual void post(X& x) override + { + orig_precond_->post(x); + } + + virtual SolverCategory::Category category() const override + { + return orig_precond_->category(); + } + + // The update() function does nothing for a wrapped preconditioner. + virtual void update() override + { + orig_precond_ = std::make_unique(op_mat_, 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_; +}; } // namespace Dune