LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
check_entity_indexing.cc
1#include <gtest/gtest.h>
2#include <lf/mesh/mesh.h>
3
4#include <iostream>
5
7
8void checkEntityIndexing(const Mesh& mesh) {
9 using size_type = lf::base::size_type; // type for indices
10 const auto dim_mesh = mesh.DimMesh(); // dimension of meshed manifold
11 // Now run over all co-dimensions to check indexing
12 for (size_type co_dim = 0; co_dim <= dim_mesh; ++co_dim) {
13 // Number of entities of current co-dimension
14 const auto no_of_entities = mesh.NumEntities(co_dim);
15 // counting array for occurrences of an index
16 std::vector<int> idx_use(no_of_entities, 0);
17 // Traverse all entities of a given co-dimension
18 for (const Entity* e : mesh.Entities(co_dim)) {
19 // Fetch index of current entity
20 const lf::base::glb_idx_t current_idx = mesh.Index(*e);
21 // Check whether index is in range and, if so, count it
22 EXPECT_LT(current_idx, no_of_entities)
23 << "Index " << current_idx << " out of range";
24 idx_use[current_idx]++;
25
26 // Check consistency of indexing
27 const lf::mesh::Entity* e_ptr = mesh.EntityByIndex(co_dim, current_idx);
28 EXPECT_TRUE(e_ptr) << "Invalid pointer to entity "
29 << static_cast<int>(current_idx);
30 if (e_ptr != nullptr) {
31 EXPECT_EQ(current_idx, mesh.Index(*e_ptr))
32 << "Index mismatch for codim " << co_dim << ", index "
33 << current_idx;
34 }
35 } // end loop over entities
36
37 // Indices should occur only once. This means that the counting array
38 // should contain 1 in every component.
39 for (size_type idx_cnt = 0; idx_cnt < no_of_entities; ++idx_cnt) {
40 // NOLINTNEXTLINE
41 EXPECT_EQ(idx_use[idx_cnt], 1)
42 << "Index " << idx_cnt << " occurs " << idx_use[idx_cnt] << " times!";
43 }
44 } // end for
45} // end checkEntityIndexing()
46} // namespace lf::mesh::test_utils
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
Abstract interface for objects representing a single mesh.
virtual const mesh::Entity * EntityByIndex(dim_t codim, base::glb_idx_t index) const =0
Method for accessing an entity through its index.
virtual std::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
virtual size_type NumEntities(unsigned codim) const =0
The number of Entities that have the given codimension.
virtual unsigned DimMesh() const =0
The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the ref...
virtual size_type Index(const Entity &e) const =0
Acess to the index of a mesh entity of any co-dimension.
unsigned int size_type
general type for variables related to size of arrays
Definition types.h:20
unsigned int glb_idx_t
type for global index of mesh entities (nodes, edges, cells)
Definition types.h:24
Utilities for testing sanity of mesh data structures and tests involving meshes.
void checkEntityIndexing(const Mesh &mesh)
Function for testing mesh indexing (should be called from google test)