10#include "gtest/gtest.h"
12#include "libmesh/face_tri3.h"
13#include "libmesh/edge_edge2.h"
14#include "libmesh/int_range.h"
16#include <libmesh/serial_mesh.h>
25addNodes(MeshBase & mesh,
const std::vector<Point> & points)
27 std::vector<Node *> node_ptrs;
29 node_ptrs.push_back(
mesh.add_point(points[i], i));
35isWatertight(MeshBase & mesh)
37 mesh.prepare_for_use(
false);
39 std::vector<const Elem *> raw_ptrs;
40 for (
const auto * el :
mesh.active_local_element_ptr_range())
41 raw_ptrs.push_back(el);
48edgeLoopIsWatertight(
const Parallel::Communicator & comm,
49 const std::vector<Point> & points,
50 const std::vector<std::pair<unsigned int, unsigned int>> & edges)
53 const auto nodes = addNodes(mesh, points);
54 for (
const auto & [id0, id1] : edges)
56 auto edge =
new Edge2();
57 edge->set_node(0, nodes[id0]);
58 edge->set_node(1, nodes[id1]);
61 return isWatertight(mesh);
66triSurfaceIsWatertight(
const Parallel::Communicator & comm,
67 const std::vector<Point> & points,
68 const std::vector<std::array<unsigned int, 3>> & faces)
71 const auto nodes = addNodes(mesh, points);
72 for (
const auto &
f : faces)
74 auto tri =
new Tri3();
75 tri->set_node(0, nodes[
f[0]]);
76 tri->set_node(1, nodes[
f[1]]);
77 tri->set_node(2, nodes[
f[2]]);
80 return isWatertight(mesh);
86TEST(WaterTightTest, TwoDGeoOpenAndClose)
89 const std::vector<Point> points = {
90 Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(1.0, 1.0, 0.0), Point(0.0, 1.0, 0.0)};
92 EXPECT_FALSE(edgeLoopIsWatertight(comm, points, {{0, 1}, {1, 2}, {2, 3}}));
93 EXPECT_TRUE(edgeLoopIsWatertight(comm, points, {{0, 1}, {1, 2}, {2, 3}, {3, 0}}));
98TEST(WaterTightTest, ThreeDGeoOpenAndClose)
101 const std::vector<Point> points = {
102 Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(1.0, 1.0, 0.0), Point(0.0, 1.0, 0.0)};
104 EXPECT_FALSE(triSurfaceIsWatertight(comm, points, {{{0, 1, 2}}, {{0, 1, 3}}, {{1, 2, 3}}}));
106 triSurfaceIsWatertight(comm, points, {{{0, 1, 2}}, {{0, 1, 3}}, {{1, 2, 3}}, {{0, 2, 3}}}));
Real f(Real x)
Test function for Brents method.
TEST(WaterTightTest, TwoDGeoOpenAndClose)
bool checkWatertightnessFromRawElems(const std::vector< const Elem * > &bd_elements)
auto index_range(const T &sizable)