dune-assembler 2.12
Loading...
Searching...
No Matches
localpattern.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_LOCALPATTERN_HH
5#define DUNE_ASSEMBLER_BACKENDS_LOCALPATTERN_HH
6
7#include <cstdint>
8
11
12namespace Dune::Assembler {
13
15 : public FlatMatrix<char>
16{
17 using Base = FlatMatrix<char>;
18
19public:
20 using Base::Base;
22
23 void add (size_type row, size_type col)
24 {
25 (*this)[row][col] = true;
26 }
27
28 void addAll ()
29 {
30 containsAll_ = true;
31 }
32
33 [[nodiscard]] bool contains (size_type row, size_type col) const
34 {
35 return (*this)[row][col];
36 }
37
38 [[nodiscard]] bool containsAll () const
39 {
40 return containsAll_;
41 }
42
43 void clear ()
44 {
46 containsAll_ = false;
47 }
48
49 template <class RowIndices, class ColIndices, class F>
50 void visitEntries (const RowIndices& rowIndices, const ColIndices& colIndices, F&& f) const
51 {
52 if (containsAll())
53 for (auto i : rowIndices)
54 for (auto j : colIndices)
55 f(i, j);
56 else
57 for (auto i : rowIndices)
58 for (auto j : colIndices)
59 if (contains(i,j))
60 f(i, j);
61 }
62
63private:
64 bool containsAll_ = false;
65};
66
67
69 : public FlatSet<std::pair<std::uint16_t,std::uint16_t>>
70{
72
73public:
76
77public:
78 template <class Extents>
79 explicit LocalPatternSet (const Extents& extents)
80 : LocalPatternSet{extents.extent(0), extents.extent(1)}
81 {}
82
84 : rowSize_(rows)
85 , colSize_(cols)
86 {}
87
88 LocalPatternSet () = default;
89
90 void add (size_type row, size_type col)
91 {
93 }
94
95 void addAll ()
96 {
97 containsAll_ = true;
98 }
99
100 void clear ()
101 {
102 Base::clear();
103 containsAll_ = false;
104 }
105
107 {
108 rowSize_ = rowSize;
109 colSize_ = colSize;
110 }
111
112 [[nodiscard]] bool contains (size_type row, size_type col) const
113 {
114 return Base::contains(value_type{row,col});
115 }
116
117 [[nodiscard]] bool containsAll () const
118 {
119 return containsAll_;
120 }
121
122 template <class RowIndices, class ColIndices, class F>
124 {
125 if (containsAll())
126 for (auto i : rowIndices)
127 for (auto j : colIndices)
128 f(i, j);
129 else
130 for (auto&& [i,j] : *this)
131 f(i, j);
132 }
133
134private:
135 std::size_t rowSize_ = 0;
136 std::size_t colSize_ = 0;
137
138 bool containsAll_ = false;
139};
140
141} // end namespace Dune::Assembler
142
143#endif // DUNE_ASSEMBLER_BACKENDS_LOCALPATTERN_HH
Definition localboundaryintersectionmatrixassembler.hh:9
Col col
Definition flatmatrix.hh:17
constexpr FlatMatrix & operator=(const value_type &value)
Definition flatmatrix.hh:38
Definition flatset.hh:15
void insert(const value_type &value)
Definition flatset.hh:26
bool contains(const value_type &value) const
Definition flatset.hh:33
Definition localpattern.hh:16
void clear()
Definition localpattern.hh:43
void visitEntries(const RowIndices &rowIndices, const ColIndices &colIndices, F &&f) const
Definition localpattern.hh:50
void addAll()
Definition localpattern.hh:28
bool containsAll() const
Definition localpattern.hh:38
bool contains(size_type row, size_type col) const
Definition localpattern.hh:33
void add(size_type row, size_type col)
Definition localpattern.hh:23
Definition localpattern.hh:70
LocalPatternSet(std::size_t rows, std::size_t cols)
Definition localpattern.hh:83
void add(size_type row, size_type col)
Definition localpattern.hh:90
bool contains(size_type row, size_type col) const
Definition localpattern.hh:112
void addAll()
Definition localpattern.hh:95
void clear()
Definition localpattern.hh:100
bool containsAll() const
Definition localpattern.hh:117
LocalPatternSet(const Extents &extents)
Definition localpattern.hh:79
void visitEntries(const RowIndices &rowIndices, const ColIndices &colIndices, F &&f) const
Definition localpattern.hh:123
void resize(std::size_t rowSize, std::size_t colSize)
Definition localpattern.hh:106
T clear(T... args)