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/cuistl/CuVector.hpp>
25#include <opm/simulators/linalg/cuistl/PreconditionerHolder.hpp>
26#include <opm/simulators/linalg/cuistl/detail/preconditioner_should_call_post_pre.hpp>
39template <
class X,
class Y,
class CudaPreconditionerType>
59 : m_underlyingPreconditioner(preconditioner)
67 virtual void pre([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
override
69 static_assert(!detail::shouldCallPreconditionerPre<CudaPreconditionerType>(),
70 "We currently do not support Preconditioner::pre().");
77 virtual void apply(X& v,
const Y& d)
override
80 m_inputBuffer.reset(
new CuVector<field_type>(v.dim()));
81 m_outputBuffer.reset(
new CuVector<field_type>(v.dim()));
83 m_inputBuffer->copyFromHost(d);
84 m_underlyingPreconditioner->apply(*m_outputBuffer, *m_inputBuffer);
85 m_outputBuffer->copyToHost(v);
92 virtual void post([[maybe_unused]] X& x)
override
94 static_assert(!detail::shouldCallPreconditionerPost<CudaPreconditionerType>(),
95 "We currently do not support Preconditioner::post().");
100 Dune::SolverCategory::Category
category()
const override
102 return m_underlyingPreconditioner->category();
108 m_underlyingPreconditioner->update();
111 static constexpr bool shouldCallPre()
113 return detail::shouldCallPreconditionerPost<CudaPreconditionerType>();
115 static constexpr bool shouldCallPost()
117 return detail::shouldCallPreconditionerPre<CudaPreconditionerType>();
120 virtual std::shared_ptr<Dune::PreconditionerWithUpdate<CuVector<field_type>, CuVector<field_type>>>
123 return m_underlyingPreconditioner;
128 std::shared_ptr<CudaPreconditionerType> m_underlyingPreconditioner;
130 std::unique_ptr<CuVector<field_type>> m_inputBuffer;
131 std::unique_ptr<CuVector<field_type>> m_outputBuffer;
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
Makes a CUDA preconditioner available to a CPU simulator.
Definition PreconditionerAdapter.hpp:43
Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
Definition PreconditionerAdapter.hpp:100
virtual void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition PreconditionerAdapter.hpp:67
virtual void apply(X &v, const Y &d) override
Apply the preconditoner.
Definition PreconditionerAdapter.hpp:77
virtual void post(X &x) override
Clean up.
Definition PreconditionerAdapter.hpp:92
PreconditionerAdapter(std::shared_ptr< CudaPreconditionerType > preconditioner)
Constructor.
Definition PreconditionerAdapter.hpp:58
X domain_type
The domain type of the preconditioner.
Definition PreconditionerAdapter.hpp:46
virtual std::shared_ptr< Dune::PreconditionerWithUpdate< CuVector< field_type >, CuVector< field_type > > > getUnderlyingPreconditioner() override
getUnderlyingPreconditioner gets the underlying preconditioner (preconditioner being held)
Definition PreconditionerAdapter.hpp:121
typename X::field_type field_type
The field type of the preconditioner.
Definition PreconditionerAdapter.hpp:50
virtual void update() override
Calls update on the underlying CUDA preconditioner.
Definition PreconditionerAdapter.hpp:106
Y range_type
The range type of the preconditioner.
Definition PreconditionerAdapter.hpp:48
Common interface for adapters that hold preconditioners.
Definition PreconditionerHolder.hpp:34