| 1 |
#include "stk_middle_mesh/create_mesh.hpp" |
| 2 |
#include "stk_middle_mesh/mesh_io.hpp" |
| 3 |
#include "stk_middle_mesh/predicates/point_classifier_normal_wrapper.hpp" |
| 4 |
#include "stk_middle_mesh/utils.hpp" |
| 5 |
#include "gtest/gtest.h" |
| 6 |
|
| 7 |
namespace { |
| 8 |
|
| 9 |
using namespace stk::middle_mesh::mesh; |
| 10 |
using namespace stk::middle_mesh::mesh::impl; |
| 11 |
using namespace stk::middle_mesh::predicates::impl; |
| 12 |
|
| 13 |
void check_all_entities_same(const std::vector<PointRecord>& records) |
| 14 |
{ |
| 15 |
assert(records.size() > 0); |
| 16 |
EXPECT_NE(records[0].type, PointClassification::Interior); |
| 17 |
EXPECT_NE(records[0].type, PointClassification::Exterior); |
| 18 |
|
| 19 |
MeshEntityPtr entity = get_entity(records[0]); |
| 20 |
|
| 21 |
for (auto& r : records) |
| 22 |
{ |
| 23 |
MeshEntityPtr entity2 = get_entity(r); |
| 24 |
EXPECT_EQ(entity->get_id(), entity2->get_id()); |
| 25 |
EXPECT_EQ(entity->get_type(), entity2->get_type()); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
void check_records_uniqueness(const std::vector<PointRecord>& records) |
| 30 |
{ |
| 31 |
EXPECT_GE(records.size(), 1u); |
| 32 |
|
| 33 |
// test all records types are the same |
| 34 |
PointClassification type = records[0].type; |
| 35 |
for (auto& r : records) |
| 36 |
EXPECT_EQ(r.type, type); |
| 37 |
|
| 38 |
if (type == PointClassification::Interior) |
| 39 |
{ |
| 40 |
EXPECT_EQ(records.size(), 1u); |
| 41 |
} else if (type == PointClassification::Edge) |
| 42 |
{ |
| 43 |
MeshEntityPtr edge = get_entity(records[0]); |
| 44 |
int numelExpected = std::min(edge->count_up(), int(2)); |
| 45 |
EXPECT_EQ((int)records.size(), numelExpected); |
| 46 |
check_all_entities_same(records); |
| 47 |
} else if (type == PointClassification::Vert) |
| 48 |
{ |
| 49 |
MeshEntityPtr vert = get_entity(records[0]); |
| 50 |
std::vector<MeshEntityPtr> els; |
| 51 |
get_upward(vert, 2, els); |
| 52 |
int numelExpected = std::min(els.size(), size_t(4)); |
| 53 |
EXPECT_EQ((int)records.size(), numelExpected); |
| 54 |
check_all_entities_same(records); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
} // namespace |
| 59 |
|
| 60 |
TEST(PointClassifierNormalWrapper, EigthSphere) |
| 61 |
{ |
| 62 |
if (stk::middle_mesh::utils::impl::comm_size(MPI_COMM_WORLD) != 1) |
| 63 |
GTEST_SKIP(); |
| 64 |
|
| 65 |
// when projecting from a sphere to another sphere with larger |
| 66 |
// radius, each point should project onto exactly 1 point on |
| 67 |
// the larger sphere |
| 68 |
std::shared_ptr<Mesh> mesh1 = create_eigth_sphere(5, 5, 0.5, 1.5); |
| 69 |
|
| 70 |
std::shared_ptr<Mesh> mesh2 = create_eigth_sphere(5, 5, 0.5, 2); |
| 71 |
|
| 72 |
PointClassifierNormalWrapper c(mesh1); |
| 73 |
|
| 74 |
std::vector<MeshEntityPtr> elements; |
| 75 |
for (auto& v : mesh1->get_vertices()) |
| 76 |
if (v) |
| 77 |
{ |
| 78 |
get_upward(v, 2, elements); |
| 79 |
MeshEntityPtr el1 = elements[0]; |
| 80 |
|
| 81 |
std::vector<PointRecord> records; |
| 82 |
for (auto& el2 : mesh2->get_elements()) |
| 83 |
if (el2) |
| 84 |
{ |
| 85 |
PointRecord r = c.classify(el2, el1, v->get_point_orig(0)); |
| 86 |
if (r.type != PointClassification::Exterior) |
| 87 |
{ |
| 88 |
records.push_back(r); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
check_records_uniqueness(records); |
| 93 |
} |
| 94 |
} |