20#ifndef OPM_GPUISTL_DETAIL_GPU_PRECONDITIONER_UTILS_HEADER
21#define OPM_GPUISTL_DETAIL_GPU_PRECONDITIONER_UTILS_HEADER
25#include <dune/istl/bcrsmatrix.hh>
48template<
class Operator,
class BlockType>
49Dune::BCRSMatrix<BlockType>
makeCPUMatrix(
const Operator& op,
bool copyValues =
true) {
53 const auto& gpuMatrix = op.getmat();
55 const auto rowIndices = gpuMatrix.getRowIndices().asStdVector();
56 const auto columnIndices = gpuMatrix.getColumnIndices().asStdVector();
58 const auto numberOfNonZeroes = gpuMatrix.nonzeroes();
59 const auto N = gpuMatrix.N();
61 Dune::BCRSMatrix<BlockType> matrix(N, N, numberOfNonZeroes, Dune::BCRSMatrix<BlockType>::row_wise);
62 for (
auto row = matrix.createbegin(); row != matrix.createend(); ++row) {
63 for (
auto j = rowIndices[row.index()]; j != rowIndices[row.index() + 1]; ++j) {
64 const auto columnIndex = columnIndices[j];
65 row.insert(columnIndex);
73 const auto nonZeros = gpuMatrix.getNonZeroValues().asStdVector();
74 for (std::size_t i = 0; i < N; ++i) {
75 for (
auto j = rowIndices[i]; j != rowIndices[i + 1]; ++j) {
76 const auto columnIndex = columnIndices[j];
78 BlockType blockMatrix;
79 constexpr static auto rows = BlockType::rows;
81 for (std::size_t k = 0; k < rows; ++k) {
82 for (std::size_t l = 0; l < rows; ++l) {
83 blockMatrix[k][l] = nonZeros[j * rows * rows + k * rows + l];
86 matrix[i][columnIndex] = blockMatrix;
Definition: autotuner.hpp:30
Dune::BCRSMatrix< BlockType > makeCPUMatrix(const Operator &op, bool copyValues=true)
Utility functions for GPU preconditioner creation.
Definition: gpu_preconditioner_utils.hpp:49