dune-assembler 2.11
Loading...
Searching...
No Matches
flatmatrix.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_ASSEMBLER_BACKENDS_FLATMATRIX_HH
5#define DUNE_ASSEMBLER_BACKENDS_FLATMATRIX_HH
6
7#include <vector>
8
11
12namespace Dune::Assembler {
13
14template <class T>
16 : public Std::mdarray<T, Std::dextents<std::size_t,2>, Std::layout_right, std::vector<T>>
17{
19 using index_type = typename Base::index_type;
20 using value_type = typename Base::value_type;
21 using extents_type = typename Base::extents_type;
22 using mapping_type = typename Base::mapping_type;
23
24 template <class Self>
25 struct BracketProxy
26 {
27 constexpr auto& operator[] (index_type j) const { return (*self_)(i_,j); }
28 Self* self_;
29 index_type i_;
30 };
31
32public:
33 using Base::Base;
34
35 constexpr FlatMatrix& operator= (const value_type& value)
36 {
37 for (index_type i = 0; i < rows(); ++i)
38 for (index_type j = 0; j < cols(); ++j)
39 (*this)[i][j] = value;
40 return *this;
41 }
42
43 constexpr BracketProxy<const FlatMatrix> operator[] (index_type i) const { return {this,i}; }
44 constexpr BracketProxy<FlatMatrix> operator[] (index_type i) { return {this,i}; }
45
46 constexpr index_type rows () const noexcept { return Base::extent(0); }
47 constexpr index_type cols () const noexcept { return Base::extent(1); }
48
51
53 void resize (index_type rows, index_type cols, const value_type& value)
54 {
55 if (rows != this->rows() || cols != this->cols())
56 {
57 auto container = std::move(*this).extract_container();
58 auto m = mapping_type{extents_type{rows,cols}};
59 container.resize(m.required_span_size(), value);
60 static_cast<Base&>(*this) = Base{m, std::move(container)};
61 }
62 }
63
65 void resize (index_type rows, index_type cols)
66 {
67 if (rows != this->rows() || cols != this->cols())
68 {
69 auto container = std::move(*this).extract_container();
70 auto m = mapping_type{extents_type{rows,cols}};
71 container.resize(m.required_span_size());
72 static_cast<Base&>(*this) = Base{m, std::move(container)};
73 }
74 }
75
77};
78
79} // end namespace Dune::Assembler
80
81#endif // DUNE_ASSEMBLER_BACKENDS_FLATMATRIX_HH
Definition localboundaryintersectionmatrixassembler.hh:9
Definition flatmatrix.hh:17
void resize(index_type rows, index_type cols)
Change the shape of the matrix and resize the underlying container.
Definition flatmatrix.hh:65
constexpr index_type rows() const noexcept
Definition flatmatrix.hh:46
constexpr FlatMatrix & operator=(const value_type &value)
Definition flatmatrix.hh:35
void resize(index_type rows, index_type cols, const value_type &value)
Change the shape of the matrix and resize the underlying container with given default value.
Definition flatmatrix.hh:53
constexpr BracketProxy< const FlatMatrix > operator[](index_type i) const
Definition flatmatrix.hh:43
constexpr index_type cols() const noexcept
Definition flatmatrix.hh:47