DUNE PDELab (2.8)

bccsmatrix.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ISTL_BCCSMATRIX_HH
4#define DUNE_ISTL_BCCSMATRIX_HH
5
9
10namespace Dune::ISTL::Impl
11{
25 template<class B, class I = typename std::allocator<B>::size_type>
26 class BCCSMatrix
27 {
28 public:
29 using Index = I;
30 using size_type = std::size_t;
31
34 BCCSMatrix()
35 : N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
36 {}
37
39 ~BCCSMatrix()
40 {
41 if(N_+M_+Nnz_!=0)
42 free();
43 }
44
46 void setSize(size_type rows, size_type columns)
47 {
48 N_ = rows;
49 M_ = columns;
50 }
51
56 size_type N() const
57 {
58 return N_;
59 }
60
62 size_type nonzeroes() const
63 {
64 return Nnz_;
65 }
66
71 size_type M() const
72 {
73 return M_;
74 }
75
82 B* getValues() const
83 {
84 return values;
85 }
86
93 Index* getRowIndex() const
94 {
95 return rowindex;
96 }
97
104 Index* getColStart() const
105 {
106 return colstart;
107 }
108
110 BCCSMatrix& operator=(const BCCSMatrix& mat)
111 {
112 if(N_+M_+Nnz_!=0)
113 free();
114 N_=mat.N_;
115 M_=mat.M_;
116 Nnz_= mat.Nnz_;
117 if(M_>0) {
118 colstart=new size_type[M_+1];
119 for(size_type i=0; i<=M_; ++i)
120 colstart[i]=mat.colstart[i];
121 }
122
123 if(Nnz_>0) {
124 values = new B[Nnz_];
125 rowindex = new size_type[Nnz_];
126
127 for(size_type i=0; i<Nnz_; ++i)
128 values[i]=mat.values[i];
129
130 for(size_type i=0; i<Nnz_; ++i)
131 rowindex[i]=mat.rowindex[i];
132 }
133 return *this;
134 }
135
137 virtual void free()
138 {
139 delete[] values;
140 delete[] rowindex;
141 delete[] colstart;
142 N_ = 0;
143 M_ = 0;
144 Nnz_ = 0;
145 }
146
147 public:
148 size_type N_, M_, Nnz_;
149 B* values;
150 Index* rowindex;
151 Index* colstart;
152 };
153
154}
155#endif
Traits for type conversions and type information.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 31, 22:30, 2024)