dune-assembler 2.12
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
20public:
21 using index_type = typename Base::index_type;
22 using value_type = typename Base::value_type;
25
26private:
27 template <class Self>
28 struct BracketProxy
29 {
30 constexpr auto& operator[] (index_type j) const { return (*self_)(i_,j); }
31 Self* self_;
32 index_type i_;
33 };
34
35public:
36 using Base::Base;
37
38 constexpr FlatMatrix& operator= (const value_type& value)
39 {
40 for (index_type i = 0; i < rows(); ++i)
41 for (index_type j = 0; j < cols(); ++j)
42 (*this)[i][j] = value;
43 return *this;
44 }
45
46 constexpr BracketProxy<const FlatMatrix> operator[] (index_type i) const { return {this,i}; }
47 constexpr BracketProxy<FlatMatrix> operator[] (index_type i) { return {this,i}; }
48
49 constexpr index_type rows () const noexcept { return Base::extent(0); }
50 constexpr index_type cols () const noexcept { return Base::extent(1); }
51
54
57 {
58 if (rows != this->rows() || cols != this->cols())
59 {
60 auto container = std::move(*this).extract_container();
62 container.resize(m.required_span_size(), value);
63 static_cast<Base&>(*this) = Base{m, std::move(container)};
64 }
65 }
66
69 {
70 if (rows != this->rows() || cols != this->cols())
71 {
72 auto container = std::move(*this).extract_container();
74 container.resize(m.required_span_size());
75 static_cast<Base&>(*this) = Base{m, std::move(container)};
76 }
77 }
78
80};
81
82} // end namespace Dune::Assembler
83
84#endif // DUNE_ASSEMBLER_BACKENDS_FLATMATRIX_HH
Definition localboundaryintersectionmatrixassembler.hh:9
Definition flatmatrix.hh:17
typename Base::extents_type extents_type
Definition flatmatrix.hh:23
typename Base::index_type index_type
Definition flatmatrix.hh:21
void resize(index_type rows, index_type cols)
Change the shape of the matrix and resize the underlying container.
Definition flatmatrix.hh:68
constexpr index_type rows() const noexcept
Definition flatmatrix.hh:49
constexpr FlatMatrix & operator=(const value_type &value)
Definition flatmatrix.hh:38
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:56
constexpr BracketProxy< const FlatMatrix > operator[](index_type i) const
Definition flatmatrix.hh:46
constexpr index_type cols() const noexcept
Definition flatmatrix.hh:50
typename Base::mapping_type mapping_type
Definition flatmatrix.hh:24
typename Base::value_type value_type
Definition flatmatrix.hh:22