FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
partition_set.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9#include <kernel/adjacency/dynamic_graph.hpp>
10#include <kernel/adjacency/graph.hpp>
11#include <kernel/adjacency/permutation.hpp>
12#include <kernel/util/string.hpp>
13
14#include <deque>
15
16namespace FEAT
17{
18 namespace Geometry
19 {
30 {
31 protected:
35 int _prio;
37 int _level;
38
41
42 public:
45 _prio(0),
46 _level(0)
47 {
48 }
49
65 explicit Partition(Adjacency::Graph&& graph_, const String& name_, int prio_ = 0, int level_ = 0) :
66 _name(name_),
67 _prio(prio_),
68 _level(level_),
69 _patches(std::forward<Adjacency::Graph>(graph_))
70 {
71 }
72
73
89 explicit Partition(const Adjacency::DynamicGraph& graph_, const String& name_, int prio_ = 0, int level_ = 0) :
90 _name(name_),
91 _prio(prio_),
92 _level(level_),
93 _patches(Adjacency::RenderType::as_is, graph_)
94 {
95 }
96
102 _patches(std::forward<Adjacency::Graph>(other._patches))
103 {
104 }
105
108 {
109 if(this == &other)
110 return *this;
111 _name = other._name;
112 _prio = other._prio;
113 _level = other._level;
114 _patches = std::forward<Adjacency::Graph>(other._patches);
115 return *this;
116 }
117
119 virtual ~Partition()
120 {
121 }
122
124 Index size() const
125 {
126 return Index(_patches.get_num_nodes_domain());
127 }
128
131 {
132 return Index(_patches.get_num_nodes_domain());
133 }
134
137 {
138 return Index(_patches.get_num_nodes_image());
139 }
140
143 {
144 return _name;
145 }
146
148 int get_priority() const
149 {
150 return _prio;
151 }
152
154 int get_level() const
155 {
156 return _level;
157 }
158
161 {
162 return _patches;
163 }
164
171 void permute(const Adjacency::Permutation& inv_perm)
172 {
173 _patches.permute_indices(inv_perm);
174 }
175 }; // class Partition
176
186 {
187 protected:
189 std::deque<Partition> _parts;
190
191 public:
193 {
194 }
195
197 _parts(std::move(other._parts))
198 {
199 }
200
201 virtual ~PartitionSet()
202 {
203 }
204
205 void clear()
206 {
207 _parts.clear();
208 }
209
210 std::deque<Partition>& get_partitions()
211 {
212 return _parts;
213 }
214
215 const std::deque<Partition>& get_partitions() const
216 {
217 return _parts;
218 }
219
220 void add_partition(Partition&& part)
221 {
222 _parts.emplace_back(std::forward<Partition>(part));
223 }
224
243 const Partition* find_partition(int size, const String& name = "", int prio = 0) const
244 {
245 std::deque<String> names;
246 if(!name.empty())
247 names.push_back(name);
248 return find_partition(size, names, prio);
249 }
250
251 const Partition* find_partition(int size, const std::deque<String>& names, int prio = 0) const
252 {
253 const Partition* part(nullptr);
254
255 // loop over all partitions
256 for(auto it = _parts.begin(); it != _parts.end(); ++it)
257 {
258 // check size
259 if(int(it->size()) != size)
260 continue;
261
262 // check name
263 if(!names.empty())
264 {
265 bool match = false;
266 for(const auto& name : names)
267 {
268 match = match || (name == it->get_name());
269 }
270 if(!match)
271 continue;
272 }
273
274 // check priority
275 if((it->get_priority() <= 0) || (it->get_priority() < prio))
276 continue;
277
278 // okay, that's a candidate
279 // does it have a greater or equal priority to the previously found one?
280 if((part != nullptr) && (part->get_priority() > it->get_priority()))
281 continue;
282
283 // we have found a matching partition
284 part = &(*it);
285 }
286
287 return part;
288 }
289 }; // class PartitionSet
290 } // namespace Geometry
291} // namespace FEAT
FEAT Kernel base header.
Dynamic Adjacency Graph implementation.
Adjacency Graph implementation.
Definition: graph.hpp:34
void permute_indices(const Adjacency::Permutation &inv_perm)
Permutes the image indices.
Definition: graph.cpp:221
Partition & operator=(Partition &&other)
move-assign operator
int _prio
the priority for automatic choice
Adjacency::Graph _patches
our actual partitioning
int _level
the level that this partitioning refers to
Partition(Partition &&other)
move constructor
Partition()
default construcotr
Partition(const Adjacency::DynamicGraph &graph_, const String &name_, int prio_=0, int level_=0)
Constructor.
void permute(const Adjacency::Permutation &inv_perm)
Permutes the element indices.
virtual ~Partition()
destructor
String _name
the name of this partitioning
Partition(Adjacency::Graph &&graph_, const String &name_, int prio_=0, int level_=0)
Constructor.
const Adjacency::Graph & get_patches() const
std::deque< Partition > _parts
the actual partitions in the set
const Partition * find_partition(int size, const String &name="", int prio=0) const
Tries to find a suitable partition in the set.
String class implementation.
Definition: string.hpp:47
@ other
generic/other permutation strategy
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.