Dune Core Modules (2.6.0)

bdmatrix.hh
Go to the documentation of this file.
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_BDMATRIX_HH
4#define DUNE_ISTL_BDMATRIX_HH
5
6#include <memory>
7
9
11
17namespace Dune {
27 template <class B, class A=std::allocator<B> >
28 class BDMatrix : public BCRSMatrix<B,A>
29 {
30 public:
31
32 //===== type definitions and constants
33
35 typedef typename B::field_type field_type;
36
38 typedef B block_type;
39
41 typedef A allocator_type;
42
44 //typedef BCRSMatrix<B,A>::row_type row_type;
45
47 typedef typename A::size_type size_type;
48
50 enum {blocklevel = B::blocklevel+1};
51
53 BDMatrix() : BCRSMatrix<B,A>() {}
54
55 explicit BDMatrix(int size)
56 : BCRSMatrix<B,A>(size, size, BCRSMatrix<B,A>::random) {
57
58 for (int i=0; i<size; i++)
60
62
63 for (int i=0; i<size; i++)
64 this->BCRSMatrix<B,A>::addindex(i, i);
65
67
68 }
69
71 BDMatrix (std::initializer_list<B> const &list)
72 : BDMatrix(list.size())
73 {
74 size_t i=0;
75 for (auto it = list.begin(); it != list.end(); ++it, ++i)
76 (*this)[i][i] = *it;
77 }
78
80 void setSize(size_type size)
81 {
82 this->BCRSMatrix<B,A>::setSize(size, // rows
83 size, // columns
84 size); // nonzeros
85
86 for (auto i : range(size))
88
90
91 for (auto i : range(size))
92 this->BCRSMatrix<B,A>::addindex(i, i);
93
95 }
96
98 BDMatrix& operator= (const BDMatrix& other) {
99 this->BCRSMatrix<B,A>::operator=(other);
100 return *this;
101 }
102
106 return *this;
107 }
108
110 void invert() {
111 for (int i=0; i<this->N(); i++)
112 (*this)[i][i].invert();
113 }
114
115 private:
116
117 // ////////////////////////////////////////////////////////////////////////////
118 // The following methods from the base class should now actually be called
119 // ////////////////////////////////////////////////////////////////////////////
120
121 // createbegin and createend should be in there, too, but I can't get it to compile
122 // BCRSMatrix<B,A>::CreateIterator createbegin () {}
123 // BCRSMatrix<B,A>::CreateIterator createend () {}
124 void setrowsize (size_type i, size_type s) {}
125 void incrementrowsize (size_type i) {}
126 void endrowsizes () {}
127 void addindex (size_type row, size_type col) {}
128 void endindices () {}
129 };
132} // end namespace Dune
133
134#endif
Implementation of the BCRSMatrix class.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:423
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1108
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition: bcrsmatrix.hh:1076
@ random
Build entries randomly.
Definition: bcrsmatrix.hh:489
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1150
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1207
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1894
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:820
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:870
A block-diagonal matrix.
Definition: bdmatrix.hh:29
A::size_type size_type
implement row_type with compressed vector
Definition: bdmatrix.hh:47
BDMatrix()
Default constructor.
Definition: bdmatrix.hh:53
BDMatrix(std::initializer_list< B > const &list)
Construct from a std::initializer_list.
Definition: bdmatrix.hh:71
B block_type
export the type representing the components
Definition: bdmatrix.hh:38
A allocator_type
export the allocator type
Definition: bdmatrix.hh:41
BDMatrix & operator=(const BDMatrix &other)
assignment
Definition: bdmatrix.hh:98
B::field_type field_type
export the type representing the field
Definition: bdmatrix.hh:35
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition: bdmatrix.hh:80
void invert()
Inverts the matrix.
Definition: bdmatrix.hh:110
Dune namespace.
Definition: alignedallocator.hh:10
Utilities for reduction like operations on ranges.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)