Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
testPolyhedralMeshDimensions.cpp
Go to the documentation of this file.
1#include <PolyhedralMesh.h>
2#include <iostream>
3#include <stdexcept>
4#include <type_traits>
5
6namespace
7{
8 void require(bool condition, const char *message)
9 {
10 if (!condition)
11 {
12 throw std::runtime_error(message);
13 }
14 }
15 void interval()
16 {
18 std::map<size_t, Mesh::Vector> positions;
19 for (size_t k = 0; k < 3; ++k)
20 {
21 positions[k][0] = double(k);
22 }
23 Mesh mesh(positions, {{10, {0}, {{{0}}}}, {11, {0, 1}, {{{1}}}}, {12, {1}, {{{2}}}}});
24 mesh.validate();
25 require(mesh.face(10).isExternal() && !mesh.face(11).isExternal(), "1D external face classification incorrect");
26 require(mesh.face(11).parents.size() == 2, "1D shared vertex lost its regions");
27 require(mesh.region(0).children.at({11}) == mesh.region(1).children.at({11}), "1D vertex not shared");
28 require(mesh.face(12).position[0] == 2, "1D face position incorrect");
29 }
30 void polygons()
31 {
33 static_assert(
34 std::is_same_v<decltype(std::declval<const Mesh &>().face(0)), const model::Polyhedron<2, 1> &>);
35 const std::map<size_t, Mesh::Vector> positions{{0, {0, 0}}, {1, {1, 0}}, {2, {2, 0}}, {3, {0, 1}},
36 {4, {1, 1}}, {5, {2, 1}}, {6, {1, 0.5}}};
37 const std::vector<Mesh::FaceInput> faces{
38 {10, {0}, {{{0, 1}}}}, {11, {1}, {{{1, 2}}}}, {12, {0}, {{{0, 3}}}}, {13, {0, 1}, {{{1, 6}}, {{6, 4}}}},
39 {14, {1}, {{{2, 5}}}}, {15, {0}, {{{3, 4}}}}, {16, {1}, {{{4, 5}}}}};
40 std::weak_ptr<model::Polyhedron<2, 0>> weak;
41 {
42 Mesh mesh(positions, faces);
43 mesh.validate();
44 require(mesh.factory<2>().size() == 2 && mesh.factory<1>().size() == 7 &&
45 mesh.template factory<0>().size() == 6,
46 "2D factory counts incorrect");
47 require(mesh.face(10).isExternal() && !mesh.face(13).isExternal(),
48 "2D external face classification incorrect");
49 require(mesh.face(13).children.count({1}) && mesh.face(13).children.count({4}),
50 "2D face endpoints incorrect");
51 require(mesh.region(0).children.at({13}) == mesh.region(1).children.at({13}), "2D face not shared");
52 require(mesh.template factory<0>().at({1})->parents.size() == 3, "Triple edge incidence lost");
53 for (const auto &region : mesh.factory<2>())
54 {
55 require(region.second->perimeter.size() == 4, "2D region perimeter missing");
56 for (const auto &incidence : region.second->perimeter)
57 {
58 require(incidence.sink() == incidence.next().source(), "2D perimeter disconnected");
59 }
60 }
61 weak = mesh.template factory<0>().at({1});
62 }
63 require(weak.expired(), "2D ownership cycle");
64 auto broken = faces;
65 broken.pop_back();
66 bool rejected = false;
67 try
68 {
69 Mesh mesh(positions, broken);
70 }
71 catch (const std::runtime_error &)
72 {
73 rejected = true;
74 }
75 require(rejected, "Open polygon accepted");
76 }
77 template <int dim> void simplexBoundary()
78 {
80 std::map<size_t, typename Mesh::Vector> positions;
81 positions[0] = Mesh::Vector::Zero();
82 for (int k = 0; k < dim; ++k)
83 {
84 positions[k + 1] = Mesh::Vector::Unit(k);
85 }
86 std::vector<typename Mesh::FaceInput> faces;
87 for (int excluded = 0; excluded <= dim; ++excluded)
88 {
89 typename Mesh::FaceInput face;
90 face.id = 100 + excluded;
91 face.regions = {0};
92 std::array<size_t, dim> simplex;
93 size_t index = 0;
94 for (int k = 0; k <= dim; ++k)
95 {
96 if (k != excluded)
97 {
98 simplex[index++] = k;
99 }
100 }
101 face.simplices.push_back(simplex);
102 faces.push_back(face);
103 }
104 Mesh mesh(positions, faces);
105 mesh.validate();
106 require(mesh.template factory<0>().size() == dim + 1, "Simplex vertices not shared");
107 require(mesh.region(0).children.size() == dim + 1, "Simplex facets incorrect");
108 if constexpr (dim >= 3)
109 {
110 for (const auto &face : mesh.template factory<2>())
111 {
112 for (const auto &incidence : face.second->perimeter)
113 {
114 require(incidence.sink() == incidence.next().source(), "Polygon connectivity incorrect");
115 require(incidence.next().prev().edge == incidence.edge, "Polygon next/prev incorrect");
116 }
117 }
118 }
119 }
120} // namespace
121int main()
122{
123 interval();
124 polygons();
125 simplexBoundary<3>();
126 simplexBoundary<4>();
127 simplexBoundary<5>();
128 std::cout << "Dimension-generic polyhedral topology passed (1D through 5D)\n";
129}
void require(bool value, const char *message)
SimplicialMesh< 3 > Mesh
int index
int k