19#ifndef OPM_PRECONDITIONERCONVERTOFLOATADAPTER_HPP
20#define OPM_PRECONDITIONERCONVERTOFLOATADAPTER_HPP
22#include <dune/istl/bcrsmatrix.hh>
23#include <dune/istl/preconditioner.hh>
24#include <opm/simulators/linalg/PreconditionerWithUpdate.hpp>
25#include <opm/simulators/linalg/gpuistl/GpuSparseMatrix.hpp>
26#include <opm/simulators/linalg/gpuistl/detail/CuMatrixDescription.hpp>
27#include <opm/simulators/linalg/gpuistl/detail/CuSparseHandle.hpp>
28#include <opm/simulators/linalg/gpuistl/detail/CuSparseResource.hpp>
29#include <opm/simulators/linalg/gpuistl/detail/cusparse_constants.hpp>
30#include <opm/simulators/linalg/gpuistl/detail/cusparse_safe_call.hpp>
31#include <opm/simulators/linalg/gpuistl/detail/preconditioner_should_call_post_pre.hpp>
84template <
class CudaPreconditionerType,
class M,
class X,
class Y,
int l = 1>
99 using domain_type_to =
typename CudaPreconditionerType::domain_type;
106 using block_type =
typename domain_type::block_type;
108 using XTo = Dune::BlockVector<Dune::FieldVector<field_type_to, block_type::dimension>>;
109 using YTo = Dune::BlockVector<Dune::FieldVector<field_type_to, block_type::dimension>>;
110 using matrix_type_to =
111 typename Dune::BCRSMatrix<Dune::FieldMatrix<field_type_to, block_type::dimension, block_type::dimension>>;
122 , m_convertedMatrix(createConvertedMatrix())
129 static_assert(!detail::shouldCallPreconditionerPre<CudaPreconditionerType>(),
130 "We currently do not support Preconditioner::pre().");
137 "You need to set the underlying preconditioner with setUnderlyingPreconditioner.");
139 for (
size_t i = 0; i <
v.N(); ++i) {
140 for (
size_t j = 0; j < block_type::dimension; ++j) {
146 for (
size_t i = 0; i <
d.N(); ++i) {
147 for (
size_t j = 0; j < block_type::dimension; ++j) {
154 for (
size_t i = 0; i <
v.N(); ++i) {
155 for (
size_t j = 0; j < block_type::dimension; ++j) {
164 static_assert(!detail::shouldCallPreconditionerPost<CudaPreconditionerType>(),
165 "We currently do not support Preconditioner::post().");
169 virtual Dune::SolverCategory::Category
category()
const override
171 return m_underlyingPreconditioner->category();
174 virtual void update()
override
177 "You need to set the underlying preconditioner with setUnderlyingPreconditioner.");
179 m_underlyingPreconditioner->update();
182 const matrix_type_to& getConvertedMatrix()
const
184 return m_convertedMatrix;
187 void setUnderlyingPreconditioner(
const std::shared_ptr<CudaPreconditionerType>&
conditioner)
192 virtual bool hasPerfectUpdate()
const override {
193 return m_underlyingPreconditioner->hasPerfectUpdate();
200 const auto nnz = m_matrix.nonzeroes() * m_matrix[0][0].N() * m_matrix[0][0].N();
204 std::vector<field_type_to>
buffer(nnz, 0);
205 for (
size_t i = 0; i < nnz; ++i) {
209 matrix_type_to createConvertedMatrix()
212 const auto N = m_matrix.N();
213 matrix_type_to
matrixBuilder(N, N, m_matrix.nonzeroes(), matrix_type_to::row_wise);
215 auto rowIn = m_matrix.begin();
224 for (
auto row = m_matrix.begin();
row != m_matrix.end(); ++
row) {
226 for (
size_t i = 0; i < block_type::dimension; ++i) {
227 for (
size_t j = 0; j < block_type::dimension; ++j) {
238 matrix_type_to m_convertedMatrix;
240 std::shared_ptr<CudaPreconditionerType> m_underlyingPreconditioner;
Interface class adding the update() method to the preconditioner interface.
Definition PreconditionerWithUpdate.hpp:32
Converts the field type (eg.
Definition PreconditionerConvertFieldTypeAdapter.hpp:86
virtual void post(X &x) override
Not used at the moment.
Definition PreconditionerConvertFieldTypeAdapter.hpp:162
typename X::field_type field_type
The field type of the preconditioner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:96
X domain_type
The domain type of the preconditioner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:92
virtual void pre(X &x, Y &b) override
Not used at the moment.
Definition PreconditionerConvertFieldTypeAdapter.hpp:127
PreconditionerConvertFieldTypeAdapter(const M &matrix)
Constructor.
Definition PreconditionerConvertFieldTypeAdapter.hpp:120
virtual void apply(X &v, const Y &d) override
Apply the preconditoner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:134
typename domain_type_to::field_type field_type_to
The field type of the preconditioner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:103
typename std::remove_const< M >::type matrix_type
The matrix type the preconditioner is for.
Definition PreconditionerConvertFieldTypeAdapter.hpp:89
typename CudaPreconditionerType::range_type range_type_to
The range type of the preconditioner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:101
virtual Dune::SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
Definition PreconditionerConvertFieldTypeAdapter.hpp:169
Y range_type
The range type of the preconditioner.
Definition PreconditionerConvertFieldTypeAdapter.hpp:94
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242