Loading...
Searching...
No Matches
BlockedMatrix.hpp
/*
Copyright 2019 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_BLOCKED_MATRIX_HPP
#define OPM_BLOCKED_MATRIX_HPP
namespace Opm::Accelerator {
template<class Scalar>
class BlockedMatrix
{
public:
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_)
: nnzValues(new Scalar[nnzbs_*block_size_*block_size_])
, colIndices(new int[nnzbs_*block_size_*block_size_])
, rowPointers(new int[Nb_+1])
, Nb(Nb_)
, nnzbs(nnzbs_)
, block_size(block_size_)
, deleteNnzs(true)
, deleteSparsity(true)
{}
BlockedMatrix(const BlockedMatrix& M)
: nnzValues(new Scalar[M.nnzbs*M.block_size*M.block_size])
, colIndices(M.colIndices)
, rowPointers(M.rowPointers)
, Nb(M.Nb)
, nnzbs(M.nnzbs)
, block_size(M.block_size)
, deleteNnzs(true)
, deleteSparsity(false)
{}
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_,
Scalar* nnzValues_, int *colIndices_, int *rowPointers_)
: nnzValues(nnzValues_)
, colIndices(colIndices_)
, rowPointers(rowPointers_)
, Nb(Nb_)
, nnzbs(nnzbs_)
, block_size(block_size_)
, deleteNnzs(false)
, deleteSparsity(false)
{}
~BlockedMatrix()
{
if (deleteNnzs) {
delete[] nnzValues;
}
if (deleteSparsity) {
delete[] colIndices;
delete[] rowPointers;
}
}
Scalar* nnzValues;
int *colIndices;
int *rowPointers;
int Nb;
int nnzbs;
unsigned int block_size;
bool deleteNnzs;
bool deleteSparsity;
};
void sortRow(int* colIndices, int* data, int left, int right);
template<class Scalar>
void blockMultSub(Scalar* a, const Scalar* b,
const Scalar* c, unsigned int block_size);
template<class Scalar>
void blockMult(Scalar* mat1, Scalar* mat2, Scalar* resMat, unsigned int block_size);
} // namespace Opm::Accelerator
#endif
Opm::Accelerator::BlockedMatrix
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Opm::Accelerator::BlockedMatrix::BlockedMatrix
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_)
Allocate BlockedMatrix and data arrays with given sizes.
Definition BlockedMatrix.hpp:35
Opm::Accelerator::BlockedMatrix::BlockedMatrix
BlockedMatrix(const BlockedMatrix &M)
Allocate BlockedMatrix, but copy sparsity pattern instead of allocating new memory.
Definition BlockedMatrix.hpp:48
Opm::Accelerator::BlockedMatrix::BlockedMatrix
BlockedMatrix(int Nb_, int nnzbs_, unsigned int block_size_, Scalar *nnzValues_, int *colIndices_, int *rowPointers_)
Allocate BlockedMatrix, but let data arrays point to existing arrays.
Definition BlockedMatrix.hpp:66