Loading...
Searching...
No Matches
bccsmatrix.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_BCCSMATRIX_HH
#define DUNE_ISTL_BCCSMATRIX_HH
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/common/typetraits.hh>
namespace Dune::ISTL::Impl
{
template<class B, class I = typename std::allocator<B>::size_type>
class BCCSMatrix
{
public:
using Index = I;
using size_type = std::size_t;
BCCSMatrix()
: N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
{}
~BCCSMatrix()
{
if(N_+M_+Nnz_!=0)
free();
}
void setSize(size_type rows, size_type columns)
{
N_ = rows;
M_ = columns;
}
size_type N() const
{
return N_;
}
size_type nonzeroes() const
{
return Nnz_;
}
size_type M() const
{
return M_;
}
B* getValues() const
{
return values;
}
Index* getRowIndex() const
{
return rowindex;
}
Index* getColStart() const
{
return colstart;
}
BCCSMatrix& operator=(const BCCSMatrix& mat)
{
if(N_+M_+Nnz_!=0)
free();
N_=mat.N_;
M_=mat.M_;
Nnz_= mat.Nnz_;
if(M_>0) {
colstart=new size_type[M_+1];
for(size_type i=0; i<=M_; ++i)
colstart[i]=mat.colstart[i];
}
if(Nnz_>0) {
values = new B[Nnz_];
rowindex = new size_type[Nnz_];
for(size_type i=0; i<Nnz_; ++i)
values[i]=mat.values[i];
for(size_type i=0; i<Nnz_; ++i)
rowindex[i]=mat.rowindex[i];
}
return *this;
}
virtual void free()
{
delete[] values;
delete[] rowindex;
delete[] colstart;
N_ = 0;
M_ = 0;
Nnz_ = 0;
}
public:
size_type N_, M_, Nnz_;
B* values;
Index* rowindex;
Index* colstart;
};
}
#endif
Dune::size_type