25#ifndef __BITPIT_PATCH_KERNEL_TPP__
26#define __BITPIT_PATCH_KERNEL_TPP__
38template<
typename patch_t>
39std::unique_ptr<patch_t> PatchKernel::clone(
const patch_t *original)
41 static_assert(std::is_base_of<PatchKernel, patch_t>::value,
"Specified pointer is not derived from PatchKernel");
43 patch_t *
clone =
static_cast<patch_t *
>(original->clone().release());
45 return std::unique_ptr<patch_t>(clone);
53template<
typename IdStorage>
67 bool deleteLastInternalCell =
false;
68#if BITPIT_ENABLE_MPI==1
69 bool deleteFirstGhostCell =
false;
72 if (
id == m_lastInternalCellId) {
73 deleteLastInternalCell =
true;
76#if BITPIT_ENABLE_MPI==1
77 else if (
id == m_firstGhostCellId) {
78 deleteFirstGhostCell =
true;
86 if (deleteLastInternalCell) {
90#if BITPIT_ENABLE_MPI==1
91 if (deleteFirstGhostCell) {
104template<
typename IdStorage>
118 bool deleteLastInternalVertex =
false;
119#if BITPIT_ENABLE_MPI==1
120 bool deleteFirstGhostVertex =
false;
122 for (
long id : ids) {
123 if (
id == m_lastInternalVertexId) {
124 deleteLastInternalVertex =
true;
127#if BITPIT_ENABLE_MPI==1
128 else if (
id == m_firstGhostVertexId) {
129 deleteFirstGhostVertex =
true;
137 if (deleteLastInternalVertex) {
141#if BITPIT_ENABLE_MPI==1
142 if (deleteFirstGhostVertex) {
155template<
typename IdStorage>
169 if (!m_interfaces.empty()) {
170 lastId = m_interfaces.back().getId();
172 lastId = Interface::NULL_ID;
175 bool deleteLast =
false;
176 for (
long id : ids) {
198template<
typename item_t,
typename id_t>
202 std::unordered_map<id_t, id_t> renumberMap;
204 id_t counter = offset;
205 for(
const item_t &item : container) {
206 id_t originalId = item.getId();
207 id_t finalId = counter++;
209 renumberMap.insert({originalId, finalId});
224template<
typename item_t,
typename id_t>
226 const std::unordered_map<id_t, id_t> &renumberMap)
229 id_t unusedId = std::numeric_limits<id_t>::max();
230 while (container.
exists(unusedId)) {
238 std::unordered_map<id_t, id_t> conflictMap;
240 for(
const item_t &item : container) {
245 id_t currentId = item.getId();
248 auto conflictMapItr = conflictMap.find(currentId);
249 if (conflictMapItr != conflictMap.end()) {
250 originalId = conflictMapItr->second;
251 conflictMap.erase(conflictMapItr);
253 originalId = currentId;
257 id_t finalId = renumberMap.at(originalId);
261 if (currentId == finalId) {
276 bool conflict = container.
exists(finalId);
279 throw std::runtime_error(
"Renumbering requires an unused id, but all ids are used.");
282 oldConflictId = finalId;
283 newConflicdId = currentId;
284 tmpConflictId = unusedId;
292 container.
updateId(oldConflictId, tmpConflictId);
296 container[currentId].setId(finalId);
297 container.
updateId(currentId, finalId);
301 container.
updateId(tmpConflictId, newConflicdId);
302 container[newConflicdId].setId(newConflicdId);
305 auto conflictMapItr = conflictMap.
find(oldConflictId);
306 if (conflictMapItr == conflictMap.end()) {
307 conflictMap.insert({newConflicdId, oldConflictId});
309 conflictMap.insert({newConflicdId, conflictMapItr->second});
310 conflictMap.erase(conflictMapItr);
331template<
typename Function>
334 auto selector = [](
long neighId) {
365template<
typename Selector,
typename Function>
371 std::vector<long> neighIds;
373 for (
long neighId : neighIds) {
374 if (!selector(neighId)) {
378 bool stop = function(neighId, 0);
407template<
typename Function,
typename SeedContainer>
410 auto selector = [](
long neighId) {
440template<
typename Selector,
typename Function,
typename SeedContainer>
442 Selector selector, Function function)
const
446 std::unordered_set<long> previousSeedIds;
447 std::unordered_set<long> currentSeedIds;
448 std::unordered_set<long> futureSeeds(seedIds.begin(), seedIds.end());
450 std::vector<long> neighIds;
451 for (
int layer = 0; layer < nLayers; ++layer) {
452 previousSeedIds.swap(currentSeedIds);
453 currentSeedIds.swap(futureSeeds);
456 for (
long seedId : currentSeedIds) {
459 for (
long neighId : neighIds) {
460 if (previousSeedIds.count(neighId) > 0) {
462 }
else if (currentSeedIds.count(neighId) > 0) {
464 }
else if (futureSeeds.count(neighId) > 0) {
466 }
else if (!selector(neighId)) {
470 bool stop = function(neighId, layer);
475 futureSeeds.insert(neighId);
496template<
typename Function>
499 auto selector = [](
long neighId) {
529template<
typename Selector,
typename Function>
534 if (cellAdjacenciesAvailable) {
535 cellAdjacenciesAvailable = !m_cells.empty();
538 std::unique_ptr<std::vector<long>> neighStorage;
539 if (!cellAdjacenciesAvailable) {
540 neighStorage = std::unique_ptr<std::vector<long>>(
new std::vector<long>());
545 if (cellAdjacenciesAvailable) {
551 neighs = neighStorage->data();
552 nNeighs = neighStorage->size();
555 for(std::size_t n = 0; n < nNeighs; ++n){
556 long neighId = neighs[n];
557 if (!selector(neighId)) {
561 bool stop = function(neighId, 0);
586template<
typename Function,
typename SeedContainer>
589 auto selector = [](
long neighId) {
619template<
typename Selector,
typename Function,
typename SeedContainer>
621 Selector selector, Function function)
const
631 std::unique_ptr<std::vector<long>> neighStorage;
632 if (!cellAdjacenciesAvailable) {
633 neighStorage = std::unique_ptr<std::vector<long>>(
new std::vector<long>());
637 std::unordered_set<long> previousSeedIds;
638 std::unordered_set<long> currentSeedIds;
639 std::unordered_set<long> futureSeeds(seedIds.begin(), seedIds.end());
641 for (
int layer = 0; layer < nLayers; ++layer) {
642 previousSeedIds.swap(currentSeedIds);
643 currentSeedIds.swap(futureSeeds);
646 for (
long seedId : currentSeedIds) {
649 if (cellAdjacenciesAvailable) {
655 neighs = neighStorage->data();
656 nNeighs = neighStorage->size();
659 for(std::size_t n = 0; n < nNeighs; ++n){
660 long neighId = neighs[n];
661 if (previousSeedIds.count(neighId) > 0) {
663 }
else if (currentSeedIds.count(neighId) > 0) {
665 }
else if (futureSeeds.count(neighId) > 0) {
667 }
else if (!selector(neighId)) {
671 bool stop = function(neighId, layer);
676 futureSeeds.insert(neighId);
The Cell class defines the cells.
const long * getAdjacencies() const
int getAdjacencyCount() const
void processCellNeighbours(long seedId, int nLayers, Function function) const
void mappedItemRenumbering(PiercedVector< item_t, id_t > &container, const std::unordered_map< id_t, id_t > &renumberMap)
AdjacenciesBuildStrategy getAdjacenciesBuildStrategy() const
std::unordered_map< id_t, id_t > consecutiveItemRenumbering(PiercedVector< item_t, id_t > &container, long offset)
AdaptionMode getAdaptionMode() const
std::vector< long > findCellNeighs(long id) const
bool deleteVertex(long id)
void processCellsNeighbours(const SeedContainer &seedIds, int nLayers, Function function) const
std::vector< long > findCellFaceNeighs(long id) const
bool deleteVertices(const IdStorage &ids)
void processCellFaceNeighbours(long seedId, int nLayers, Function function) const
bool deleteInterface(long id)
static std::unique_ptr< patch_t > clone(const patch_t *original)
bool deleteCells(const IdStorage &ids)
void processCellsFaceNeighbours(const SeedContainer &seedIds, int nLayers, Function function) const
bool deleteInterfaces(const IdStorage &ids)
void updateId(const id_t ¤tId, const id_t &updatedId)
const_iterator find(const id_t &id) const noexcept
bool exists(id_t id) const
Metafunction for generating a pierced vector.
#define BITPIT_UNUSED(variable)