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#include <array>
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 constexpr Index unset = ~Index(0);
53 std::vector<std::array<Index, 2>> shared_by (num_facets, {unset, unset} );
54
55 // For each facet, find the cells sharing it
56 for(Index k = 0; k < num_cells; ++k)
57 {
58 for(int j = 0; j < facet_idx.num_indices; ++j)
59 {
60 // Index of the facet
61 Index l(facet_idx[k][j]);
62
63 if(shared_by[l][0] == unset)
64 shared_by[l][0] = k;
65 else if(shared_by[l][1] == unset)
66 shared_by[l][1] = k;
67 else
68 XABORTM("Facet "+stringify(l)+" is shared by cells "+stringify(shared_by[l][0])+", "+stringify(shared_by[l][1])+" and again by "+stringify(k));
69 }
70 }
71
72 // For every cell and for every facet of that cell, the neighbor at a face is the OTHER cell sharing it
73 // (if any)
74 FEAT_PRAGMA_OMP(parallel for)
75 for(Index k = 0; k < num_cells; ++k)
76 {
77 for(int j = 0; j < facet_idx.num_indices; ++j)
78 {
79 // Index of the facet
80 Index l(facet_idx[k][j]);
81
82 if(shared_by[l][0] == k)
83 neighbors[k][j] = shared_by[l][1];
84 else if(shared_by[l][1] == k)
85 neighbors[k][j] = shared_by[l][0];
86 else
87 XABORTM("Facet "+stringify(l)+" found at cell "+stringify(k)+" but is shared by cells "+stringify(shared_by[l][0])+", "+stringify(shared_by[l][1]));
88 }
89 }
90
91 } // compute()
92
93 }; // struct FacetNeighbors
94
95 } // namespace Intern
97 } // namespace Geometry
98} // 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:993
std::uint64_t Index
Index data type.