FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
facet_neighbors.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
11#include <kernel/util/string.hpp>
12
13namespace FEAT
14{
15 namespace Geometry
16 {
18 namespace Intern
19 {
23 struct FacetNeighbors
24 {
25 // \brief Descriptive String
26 static String name()
27 {
28 return "FacetNeighbors";
29 }
30
42 template<typename NeighborIndexSetType_, typename FacetIndexSetType_>
43 static void compute(NeighborIndexSetType_& neighbors, const FacetIndexSetType_& facet_idx)
44 {
45 Index num_cells(facet_idx.get_num_entities());
46 Index num_facets(facet_idx.get_index_bound());
47
48 XASSERT(neighbors.get_num_entities() == num_cells);
49
50 // A facet is shared by exactly 2 cells if it is interiour, and is present in exactly one cell if it is at
51 // the boundary
52 typedef Index SharedBy[2];
53 std::vector<Index> shared_by_vec(size_t(2)*num_facets);
54 auto shared_by = reinterpret_cast<SharedBy*>(shared_by_vec.data());
55
56 // ~Index(0) is the marker for "no neighbor"
57 FEAT_PRAGMA_OMP(parallel for)
58 for(Index l = 0; l < num_facets; ++l)
59 {
60 shared_by[l][0] = ~Index(0);
61 shared_by[l][1] = ~Index(0);
62 }
63
64 // For each facet, find the cells sharing it
65 for(Index k = 0; k < num_cells; ++k)
66 {
67 for(int j = 0; j < facet_idx.num_indices; ++j)
68 {
69 // Index of the facet
70 Index l(facet_idx[k][j]);
71
72 if(shared_by[l][0] == ~Index(0))
73 shared_by[l][0] = k;
74 else if(shared_by[l][1] == ~Index(0))
75 shared_by[l][1] = k;
76 else
77 XABORTM("Facet "+stringify(l)+" is shared by cells "+stringify(shared_by[l][0])+", "+stringify(shared_by[l][1])+" and again by "+stringify(k));
78 }
79 }
80
81 // For every cell and for every facet of that cell, the neighbor at a face is the OTHER cell sharing it
82 // (if any)
83 FEAT_PRAGMA_OMP(parallel for)
84 for(Index k = 0; k < num_cells; ++k)
85 {
86 for(int j = 0; j < facet_idx.num_indices; ++j)
87 {
88 // Index of the facet
89 Index l(facet_idx[k][j]);
90
91 if(shared_by[l][0] == k)
92 neighbors[k][j] = shared_by[l][1];
93 else if(shared_by[l][1] == k)
94 neighbors[k][j] = shared_by[l][0];
95 else
96 XABORTM("Facet "+stringify(l)+" found at cell "+stringify(k)+" but is shared by cells "+stringify(shared_by[l][0])+", "+stringify(shared_by[l][1]));
97 }
98 }
99
100 } // compute()
101
102 }; // struct FacetNeighbors
103
104 } // namespace Intern
106 } // namespace Geometry
107} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
std::uint64_t Index
Index data type.