19#ifndef OPM_PRECONDITIONERADAPTER_HPP
20#define OPM_PRECONDITIONERADAPTER_HPP
22#include <dune/istl/preconditioner.hh>
23#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
24#include <opm/simulators/linalg/gpuistl/GpuVector.hpp>
25#include <opm/simulators/linalg/gpuistl/PreconditionerHolder.hpp>
26#include <opm/simulators/linalg/gpuistl/detail/preconditioner_should_call_post_pre.hpp>
39template <
class X,
class Y,
class CudaPreconditionerType>
42 public PreconditionerHolder<GpuVector<typename X::field_type>, GpuVector<typename Y::field_type>>
58 : m_underlyingPreconditioner(preconditioner)
66 virtual void pre([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
override
69 "We currently do not support Preconditioner::pre().");
76 virtual void apply(X& v,
const Y& d)
override
82 m_inputBuffer->copyFromHost(d);
83 m_underlyingPreconditioner->apply(*m_outputBuffer, *m_inputBuffer);
84 m_outputBuffer->copyToHost(v);
91 virtual void post([[maybe_unused]] X& x)
override
94 "We currently do not support Preconditioner::post().");
99 Dune::SolverCategory::Category
category()
const override
101 return m_underlyingPreconditioner->category();
107 m_underlyingPreconditioner->update();
110 static constexpr bool shouldCallPre()
114 static constexpr bool shouldCallPost()
119 virtual std::shared_ptr<Dune::PreconditionerWithUpdate<GpuVector<field_type>, GpuVector<field_type>>>
122 return m_underlyingPreconditioner;
125 virtual bool hasPerfectUpdate()
const override {
126 return m_underlyingPreconditioner->hasPerfectUpdate();
131 std::shared_ptr<CudaPreconditionerType> m_underlyingPreconditioner;
133 std::unique_ptr<GpuVector<field_type>> m_inputBuffer;
134 std::unique_ptr<GpuVector<field_type>> m_outputBuffer;
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
Definition gpu_type_detection.hpp:30
Y range_type
The range type of the preconditioner.
Definition PreconditionerAdapter.hpp:48
virtual void apply(X &v, const Y &d) override
Apply the preconditoner.
Definition PreconditionerAdapter.hpp:76
virtual void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition PreconditionerAdapter.hpp:66
virtual void update() override
Calls update on the underlying CUDA preconditioner.
Definition PreconditionerAdapter.hpp:105
virtual std::shared_ptr< Dune::PreconditionerWithUpdate< GpuVector< field_type >, GpuVector< field_type > > > getUnderlyingPreconditioner() override
getUnderlyingPreconditioner gets the underlying preconditioner (preconditioner being held)
Definition PreconditionerAdapter.hpp:120
typename X::field_type field_type
The field type of the preconditioner.
Definition PreconditionerAdapter.hpp:50
virtual void post(X &x) override
Clean up.
Definition PreconditionerAdapter.hpp:91
X domain_type
The domain type of the preconditioner.
Definition PreconditionerAdapter.hpp:46
Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category).
Definition PreconditionerAdapter.hpp:99
PreconditionerAdapter(std::shared_ptr< CudaPreconditionerType > preconditioner)
Constructor.
Definition PreconditionerAdapter.hpp:57
Common interface for adapters that hold preconditioners.
Definition PreconditionerHolder.hpp:34
constexpr bool shouldCallPreconditionerPost()
Tests (compile time) if the preconditioner type needs to call post() after a call to apply(....
Definition preconditioner_should_call_post_pre.hpp:52
constexpr bool shouldCallPreconditionerPre()
Tests (compile time) if the preconditioner type needs to call pre() before a call to apply().
Definition preconditioner_should_call_post_pre.hpp:34