Dune Core Modules (2.9.0)

bccsmatrix.hh
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ISTL_BCCSMATRIX_HH
6#define DUNE_ISTL_BCCSMATRIX_HH
7
11
12namespace Dune::ISTL::Impl
13{
27 template<class B, class I = typename std::allocator<B>::size_type>
28 class BCCSMatrix
29 {
30 public:
31 using Index = I;
32 using size_type = std::size_t;
33
36 BCCSMatrix()
37 : N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
38 {}
39
41 ~BCCSMatrix()
42 {
43 if(N_+M_+Nnz_!=0)
44 free();
45 }
46
48 void setSize(size_type rows, size_type columns)
49 {
50 N_ = rows;
51 M_ = columns;
52 }
53
58 size_type N() const
59 {
60 return N_;
61 }
62
64 size_type nonzeroes() const
65 {
66 return Nnz_;
67 }
68
73 size_type M() const
74 {
75 return M_;
76 }
77
84 B* getValues() const
85 {
86 return values;
87 }
88
95 Index* getRowIndex() const
96 {
97 return rowindex;
98 }
99
106 Index* getColStart() const
107 {
108 return colstart;
109 }
110
112 BCCSMatrix& operator=(const BCCSMatrix& mat)
113 {
114 if(N_+M_+Nnz_!=0)
115 free();
116 N_=mat.N_;
117 M_=mat.M_;
118 Nnz_= mat.Nnz_;
119 if(M_>0) {
120 colstart=new size_type[M_+1];
121 for(size_type i=0; i<=M_; ++i)
122 colstart[i]=mat.colstart[i];
123 }
124
125 if(Nnz_>0) {
126 values = new B[Nnz_];
127 rowindex = new size_type[Nnz_];
128
129 for(size_type i=0; i<Nnz_; ++i)
130 values[i]=mat.values[i];
131
132 for(size_type i=0; i<Nnz_; ++i)
133 rowindex[i]=mat.rowindex[i];
134 }
135 return *this;
136 }
137
139 virtual void free()
140 {
141 delete[] values;
142 delete[] rowindex;
143 delete[] colstart;
144 N_ = 0;
145 M_ = 0;
146 Nnz_ = 0;
147 }
148
149 public:
150 size_type N_, M_, Nnz_;
151 B* values;
152 Index* rowindex;
153 Index* colstart;
154 };
155
156}
157#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 (Dec 21, 23:30, 2024)