4 #ifdef LIBMESH_HAVE_NETGEN 6 #include "netgen/nglib/nglib.h" 18 #ifdef LIBMESH_HAVE_NETGEN 19 CPPUNIT_TEST( testLibMeshNetgen );
20 CPPUNIT_TEST( testBadHole );
26 CPPUNIT_TEST_SUITE_END();
38 #ifdef LIBMESH_HAVE_NETGEN 43 auto ngmesh = Ng_NewMesh();
44 Ng_DeleteMesh(ngmesh);
49 auto ngmesh = Ng_NewMesh();
51 Ng_Meshing_Parameters params;
52 params.elementsperedge = 1;
53 params.elementspercurve = 1;
55 std::vector<std::array<double, 3>> point_coords =
74 auto n_input_points = point_coords.size();
76 CPPUNIT_ASSERT_EQUAL(permutation.size(), n_input_points);
78 std::vector<std::size_t> inverse_permutation (n_input_points);
80 for (std::size_t i=0; i != n_input_points; ++i)
82 inverse_permutation[permutation[i]] = i;
83 Ng_AddPoint(ngmesh, point_coords[permutation[i]].data());
86 std::vector<std::array<int, 3>> tri_nodes =
113 for (
auto & nodes : tri_nodes)
115 std::array<int, 3> permuted_nodes = nodes;
116 for (
auto & node_i : permuted_nodes)
117 node_i = inverse_permutation[node_i-1]+1;
118 Ng_AddSurfaceElement(ngmesh, NG_TRIG, permuted_nodes.data());
121 Ng_GenerateVolumeMesh(ngmesh, ¶ms);
122 const std::size_t
n_elem = Ng_GetNE(ngmesh);
123 const std::size_t n_points = Ng_GetNP(ngmesh);
124 CPPUNIT_ASSERT_GREATEREQUAL(n_input_points, n_points);
126 std::set<int> nodes_seen;
127 for (std::size_t i = 0; i !=
n_elem; ++i)
131 Ng_Volume_Element_Type ngtype =
132 Ng_GetVolumeElement(ngmesh, i+1, ngnodes);
133 CPPUNIT_ASSERT(ngtype == NG_TET);
134 for (
int n = 0; n != 4; ++n)
135 if (ngnodes[n] <=
int(n_input_points) && ngnodes[n] > 0)
136 nodes_seen.insert(ngnodes[n]);
139 Ng_DeleteMesh(ngmesh);
141 return nodes_seen.size();
148 std::vector<std::size_t> permutation (16);
149 std::iota(permutation.begin(), permutation.end(), 0);
151 int n_original_nodes = testPermutedHole(permutation);
153 CPPUNIT_ASSERT_EQUAL(n_original_nodes, 16);
160 const std::size_t n_input_points = 16;
162 std::vector<std::size_t> permutation (n_input_points);
163 std::iota(permutation.begin(), permutation.end(), 0);
165 int fails=0, successes = 0;
167 auto run_test = [
this, &fails, &successes, &permutation]()
169 int n_original_nodes = testPermutedHole(permutation);
170 fails += (n_original_nodes != n_input_points);
171 successes += (n_original_nodes == n_input_points);
172 std::cout <<
"Found " << n_original_nodes <<
"/" << n_input_points <<
" original nodes\n";
173 std::cout <<
"Fails = " << fails <<
", successes = " << successes << std::endl;
179 std::vector<std::size_t> c(permutation.size());
181 for (std::size_t i = 1; i != n_input_points ; ++i)
186 std::swap(permutation[c[i]], permutation[i]);
188 std::swap(permutation[0], permutation[i]);
void iota(ForwardIter first, ForwardIter last, T value)
Utility::iota was created back when std::iota was just an SGI STL extension.
std::size_t testPermutedHole(const std::vector< std::size_t > &permutation)
void testAllPermutations()
CPPUNIT_TEST_SUITE_REGISTRATION(LibMeshNetgenTest)