Dune Core Modules (unstable)

bdmatrix.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © 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_BDMATRIX_HH
6#define DUNE_ISTL_BDMATRIX_HH
7
8#include <memory>
9
12
15
21namespace Dune {
31 template <class B, class A=std::allocator<B> >
32 class BDMatrix : public BCRSMatrix<B,A>
33 {
34 public:
35
36 //===== type definitions and constants
37
39 using field_type = typename Imp::BlockTraits<B>::field_type;
40
42 typedef B block_type;
43
45 typedef A allocator_type;
46
48 //typedef BCRSMatrix<B,A>::row_type row_type;
49
51 typedef typename A::size_type size_type;
52
54 BDMatrix() : BCRSMatrix<B,A>() {}
55
56 explicit BDMatrix(int size)
57 : BCRSMatrix<B,A>(size, size, BCRSMatrix<B,A>::random) {
58
59 for (int i=0; i<size; i++)
61
63
64 for (int i=0; i<size; i++)
65 this->BCRSMatrix<B,A>::addindex(i, i);
66
68
69 }
70
72 BDMatrix (std::initializer_list<B> const &list)
73 : BDMatrix(list.size())
74 {
75 size_t i=0;
76 for (auto it = list.begin(); it != list.end(); ++it, ++i)
77 (*this)[i][i] = *it;
78 }
79
82 {
83 this->BCRSMatrix<B,A>::setSize(size, // rows
84 size, // columns
85 size); // nonzeros
86
87 for (auto i : range(size))
89
91
92 for (auto i : range(size))
93 this->BCRSMatrix<B,A>::addindex(i, i);
94
96 }
97
99 BDMatrix& operator= (const BDMatrix& other) {
100 this->BCRSMatrix<B,A>::operator=(other);
101 return *this;
102 }
103
107 return *this;
108 }
109
115 template <class V>
116 void solve (V& x, const V& rhs) const {
117 for (size_type i=0; i<this->N(); i++)
118 {
119 auto&& xv = Impl::asVector(x[i]);
120 auto&& rhsv = Impl::asVector(rhs[i]);
121 Impl::asMatrix((*this)[i][i]).solve(xv,rhsv);
122 }
123 }
124
126 void invert() {
127 for (size_type i=0; i<this->N(); i++)
128 Impl::asMatrix((*this)[i][i]).invert();
129 }
130
131 private:
132
133 // ////////////////////////////////////////////////////////////////////////////
134 // The following methods from the base class should now actually be called
135 // ////////////////////////////////////////////////////////////////////////////
136
137 // createbegin and createend should be in there, too, but I can't get it to compile
138 // BCRSMatrix<B,A>::CreateIterator createbegin () {}
139 // BCRSMatrix<B,A>::CreateIterator createend () {}
140 void setrowsize (size_type i, size_type s) {}
141 void incrementrowsize (size_type i) {}
142 void endrowsizes () {}
143 void addindex (size_type row, size_type col) {}
144 void endindices () {}
145 };
146
147 template<typename B, typename A>
148 struct FieldTraits< BDMatrix<B, A> >
149 {
150 using field_type = typename BDMatrix<B, A>::field_type;
151 using real_type = typename FieldTraits<field_type>::real_type;
152 };
155} // end namespace Dune
156
157#endif
Implementation of the BCRSMatrix class.
Helper functions for determining the vector/matrix block level.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:466
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1146
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition: bcrsmatrix.hh:1114
@ random
Build entries randomly.
Definition: bcrsmatrix.hh:526
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1188
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1269
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:2001
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:858
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:908
A block-diagonal matrix.
Definition: bdmatrix.hh:33
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bdmatrix.hh:39
A::size_type size_type
implement row_type with compressed vector
Definition: bdmatrix.hh:51
BDMatrix()
Default constructor.
Definition: bdmatrix.hh:54
BDMatrix(std::initializer_list< B > const &list)
Construct from a std::initializer_list.
Definition: bdmatrix.hh:72
B block_type
export the type representing the components
Definition: bdmatrix.hh:42
void solve(V &x, const V &rhs) const
Solve the system Ax=b in O(n) time.
Definition: bdmatrix.hh:116
A allocator_type
export the allocator type
Definition: bdmatrix.hh:45
BDMatrix & operator=(const BDMatrix &other)
assignment
Definition: bdmatrix.hh:99
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition: bdmatrix.hh:81
void invert()
Inverts the matrix.
Definition: bdmatrix.hh:126
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Utilities for reduction like operations on ranges.
Implements a scalar matrix view wrapper around an existing scalar.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)