Loading...
Searching...
No Matches
adaption.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_ADAPTION_HPP__
26#define __BITPIT_ADAPTION_HPP__
27
28#include <vector>
29#include <unordered_map>
30#include <unordered_set>
31
32namespace bitpit {
33
34namespace adaption
35{
36 enum Marker {
37 MARKER_REFINE,
38 MARKER_NONE,
39 MARKER_COARSEN,
40 MARKER_UNDEFINED
41 };
42
43 enum Type {
44 TYPE_UNKNOWN = -2,
45 TYPE_NONE = -1,
46 TYPE_CREATION = 0,
47 TYPE_DELETION,
48 TYPE_REFINEMENT,
49 TYPE_COARSENING,
50 TYPE_RENUMBERING,
51 TYPE_PARTITION_SEND,
52 TYPE_PARTITION_RECV,
53 TYPE_PARTITION_NOTICE
54 };
55
56 enum Entity {
57 ENTITY_UNKNOWN = -1,
58 ENTITY_CELL,
59 ENTITY_INTERFACE
60 };
61
62 struct Info
63 {
64 Info()
65 : type(TYPE_UNKNOWN), entity(ENTITY_UNKNOWN), rank(-1)
66 {
67 }
68
69 Info(Type user_type, Entity user_entity, int user_rank = -1)
70 : type(user_type), entity(user_entity), rank(user_rank)
71 {
72 }
73
74 Type type;
75 Entity entity;
76 int rank;
77 std::vector<long> previous;
78 std::vector<long> current;
79 };
80
82 {
83
84 public:
85 typedef std::vector<Info>::iterator iterator;
86 typedef std::vector<Info>::const_iterator const_iterator;
87
88 static void appendIds(std::vector<long> src, bool unique, std::vector<long> *dst);
89 static std::size_t removeIds(std::unordered_set<long> src, std::vector<long> *dst);
90
92
93 std::size_t size() const;
94
95 iterator begin() noexcept;
96 iterator end() noexcept;
97
98 const_iterator begin() const noexcept;
99 const_iterator end() const noexcept;
100
101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
103
104 std::size_t insert();
105 std::size_t insert(Type type, Entity entity, int rank = -1);
106 std::size_t insert(const Info &other);
107 std::size_t insert(Info &&other);
108
109 bool erase(std::size_t id);
110 std::size_t erase(Type type);
111
112 Info & at(std::size_t id);
113 const Info & at(std::size_t id) const;
114
115 const std::vector<Info> & data() const noexcept;
116 std::vector<Info> & data() noexcept;
117
118 Info & operator[](std::size_t id);
119 const Info & operator[](std::size_t id) const;
120
121 std::vector<Info> dump();
122
123 private:
124 typedef std::tuple<int, int, int> infoData_t;
125
126 std::unordered_map<infoData_t, std::size_t, utils::hashing::hash<infoData_t>> m_cache;
127 std::unordered_set<int> m_cachedTypes;
128 std::vector<Info> m_collection;
129 };
130}
131
132class PatchKernel;
133
135{
136
137public:
138 FlatMapping();
140
141 virtual ~FlatMapping() = default;
142
143 virtual void update(const std::vector<adaption::Info> &adaptionData) = 0;
144
145 const std::vector<long> & getNumbering() const;
146 const std::vector<long> & getMapping() const;
147
148protected:
149 PatchKernel *m_patch;
150 std::vector<long> m_numbering;
151 std::vector<long> m_mapping;
152
153};
154
155
157{
158
159public:
162
163 void update(const std::vector<adaption::Info> &adaptionData) override;
164
165};
166
167}
168
169#endif
void update(const std::vector< adaption::Info > &adaptionData) override
Definition adaption.cpp:578
const std::vector< long > & getMapping() const
Definition adaption.cpp:526
const std::vector< long > & getNumbering() const
Definition adaption.cpp:516
The PatchKernel class provides an interface for defining patches.
const std::vector< Info > & data() const noexcept
Definition adaption.cpp:165
const_iterator cbegin() const noexcept
Definition adaption.cpp:143
Info & operator[](std::size_t id)
Definition adaption.cpp:374
bool erase(std::size_t id)
Definition adaption.cpp:291
static std::size_t removeIds(std::unordered_set< long > src, std::vector< long > *dst)
Definition adaption.cpp:452
const_iterator cend() const noexcept
Definition adaption.cpp:153
static void appendIds(std::vector< long > src, bool unique, std::vector< long > *dst)
Definition adaption.cpp:419
std::vector< Info > dump()
Definition adaption.cpp:398
Info & at(std::size_t id)
Definition adaption.cpp:343
The namespace 'adaption' contains the routines and the data structures for handling patch adaption.
Definition adaption.cpp:38
The namespace 'patch' contains routines for interacting with the patch manager.
The Info struct defines the infomation associated to an adaption.
Definition adaption.hpp:63