Skip to content

Commit

Permalink
New unit test
Browse files Browse the repository at this point in the history
This fails for me on master, and works for me with the new patch, so
hopefully it'll be a reliable way of making sure that any improved code
doesn't revert the fix.
  • Loading branch information
roystgnr authored and miaoyinb committed May 2, 2023
1 parent 3767c48 commit 890d938
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion tests/mesh/mesh_triangulation.C
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public:
// This covers an old poly2tri collinearity-tolerance bug
CPPUNIT_TEST( testPoly2TriHolesExtraRefined );

// This covers a more recent tolerance bug when verifying holes
CPPUNIT_TEST( testPoly2TriHolePerturbed );

CPPUNIT_TEST( testPoly2TriNonUniformRefined );
CPPUNIT_TEST( testPoly2TriHolesNonUniformRefined );
#endif
Expand All @@ -64,6 +67,7 @@ public:
CPPUNIT_TEST( testTriangleInterp );
CPPUNIT_TEST( testTriangleInterp2 );
CPPUNIT_TEST( testTriangleHoles );
CPPUNIT_TEST( testTriangleHolePerturbed );
CPPUNIT_TEST( testTriangleMeshedHoles );
CPPUNIT_TEST( testTriangleEdges );
CPPUNIT_TEST( testTriangleSegments );
Expand All @@ -84,7 +88,7 @@ public:
triangulator.triangulation_type() = TriangulatorInterface::PSLG;

// Don't try to insert points unless we're requested to later
triangulator.desired_area() = 1000;
triangulator.desired_area() = 1e16;
triangulator.minimum_angle() = 0;
triangulator.smooth_after_generating() = false;
triangulator.set_verify_hole_boundaries(true);
Expand Down Expand Up @@ -469,6 +473,50 @@ public:
}


void testTriangulatorHolePerturbed(MeshBase & mesh,
TriangulatorInterface & triangulator)
{
// Points based on a simplification of a hole verification failure
// case
mesh.add_point(Point(100,0), 0);
mesh.add_point(Point(100,100), 1);
mesh.add_point(Point(0,100), 2);
mesh.add_point(Point(-100,100), 3);
mesh.add_point(Point(-100,0), 4);
mesh.add_point(Point(-100,-100), 5);
mesh.add_point(Point(0,-100), 6);
mesh.add_point(Point(100,-100), 7);

commonSettings(triangulator);

// Add a diamond hole in *almost* the center
TriangulatorInterface::PolygonHole
diamond(Point(0,4.e-16),
std::sqrt(2)/2, 4);
const std::vector<TriangulatorInterface::Hole*> holes { &diamond };
triangulator.attach_hole_list(&holes);

triangulator.triangulate();

CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), dof_id_type(12));

// Center coordinates for all the elements we expect
const Real r2p200o6 = (std::sqrt(Real(2))+200)/6,
r2p400o6 = (std::sqrt(Real(2))+400)/6;

std::vector <Point> expected_centers
{ {r2p400o6,100./3}, {-r2p400o6,100./3},
{r2p400o6,-100./3}, {-r2p400o6,-100./3},
{100./3,r2p400o6}, {-100./3,r2p400o6},
{100./3,-r2p400o6}, {-100./3,-r2p400o6},
{r2p200o6,r2p200o6}, {-r2p200o6,r2p200o6},
{r2p200o6,-r2p200o6}, {-r2p200o6,-r2p200o6},
};

testFoundCenters(mesh, expected_centers);
}


void testTriangulatorMeshedHoles(MeshBase & mesh,
TriangulatorInterface & triangulator)
{
Expand Down Expand Up @@ -652,6 +700,16 @@ public:
}


void testTriangleHolePerturbed()
{
LOG_UNIT_TEST;

Mesh mesh(*TestCommWorld);
TriangleInterface triangle(mesh);
testTriangulatorHolePerturbed(mesh, triangle);
}


void testTriangleMeshedHoles()
{
LOG_UNIT_TEST;
Expand Down Expand Up @@ -736,6 +794,16 @@ public:
}


void testPoly2TriHolePerturbed()
{
LOG_UNIT_TEST;

Mesh mesh(*TestCommWorld);
Poly2TriTriangulator p2t_tri(mesh);
testTriangulatorHolePerturbed(mesh, p2t_tri);
}


void testPoly2TriMeshedHoles()
{
LOG_UNIT_TEST;
Expand Down

0 comments on commit 890d938

Please sign in to comment.