FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
validate_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
9#include <kernel/geometry/boundary_factory.hpp>
10#include <kernel/geometry/mesh_part.hpp>
11
12namespace FEAT
13{
14 namespace Geometry
15 {
17 namespace TestAux
18 {
33 template<typename MeshType>
34 void validate_neighbors(const MeshType& mesh)
35 {
36 static constexpr int facet_dim = MeshType::shape_dim-1;
37 const auto& neigh = mesh.get_neighbors();
38 const auto& facet_idx = mesh.template get_index_set<MeshType::shape_dim, facet_dim>();
39
40 Geometry::BoundaryFactory<MeshType> boundary_factory(mesh);
41 Geometry::MeshPart<MeshType> boundary(boundary_factory);
42
43 Index num_facets(mesh.get_num_entities(MeshType::shape_dim-1));
44
45 bool* at_boundary(new bool[num_facets]);
46
47 for(Index l(0); l < num_facets; ++l)
48 at_boundary[l] = false;
49
50 // Mark all boundary facets
51 const auto& facet_trg = boundary.template get_target_set<MeshType::shape_dim-1>();
52 for(Index l(0); l < facet_trg.get_num_entities(); ++l)
53 {
54 at_boundary[facet_trg[l]] = true;
55 }
56
57 // Check the mesh
58 for(Index k(0); k < mesh.get_num_entities(MeshType::shape_dim); ++k)
59 {
60 for(int j(0); j < facet_idx.num_indices; ++j)
61 {
62 Index other_cell(neigh(k,j));
63 // If we have a neighbor...
64 if(other_cell != ~Index(0))
65 {
66 bool ok(false);
67 // ... then this should NOT be the boundary
68 if(at_boundary[facet_idx(k,j)])
69 throw String("Facet "+stringify(facet_idx(k,j))+
70 " is at the boundary, but the _neighborinformation says it is not!");
71
72 // Check for vice versa neighbor relationship
73 for(int i(0); i < facet_idx.num_indices; ++i)
74 {
75 if(neigh(other_cell,i) == k)
76 {
77 ok = true;
78 break;
79 }
80 }
81 if(!ok)
82 throw String("Cell "+stringify(k)+" has neighbor "+stringify(other_cell)+" but not vice versa!");
83 }
84 else
85 {
87 if(!at_boundary[facet_idx(k,j)])
88 throw String("Facet "+stringify(facet_idx(k,j))+
89 " is not at the boundary, but the _neighbor information says it is!");
90 }
91 }
92
93 }
94
95 // Clean up
96 delete[] at_boundary;
97
98 }
99 } // namespace TestAux
101 } // namespace Geometry
102} // namespace FEAT
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.