| 1 |
#include "gtest/gtest.h" |
| 2 |
|
| 3 |
#include "stk_middle_mesh/create_mesh.hpp" |
| 4 |
#include "stk_middle_mesh/element_operations_2d.hpp" |
| 5 |
#include "stk_middle_mesh/incremental_mesh_boundary_snapper.hpp" |
| 6 |
#include "util/meshes.hpp" |
| 7 |
|
| 8 |
namespace stk { |
| 9 |
namespace middle_mesh { |
| 10 |
namespace impl { |
| 11 |
|
| 12 |
using namespace mesh; |
| 13 |
using namespace mesh::impl; |
| 14 |
|
| 15 |
namespace { |
| 16 |
|
| 17 |
void test_areas_positive(std::shared_ptr<Mesh> mesh) |
| 18 |
{ |
| 19 |
mesh::impl::ElementOperations2D elemOps; |
| 20 |
for (auto& e : mesh->get_elements()) |
| 21 |
if (e) |
| 22 |
{ |
| 23 |
EXPECT_GE(elemOps.compute_area(e), 0); |
| 24 |
} |
| 25 |
} |
| 26 |
} // namespace |
| 27 |
|
| 28 |
|
| 29 |
TEST(IncrementalMeshBoundarySnapper, QuarterAnnulus) |
| 30 |
{ |
| 31 |
if (utils::impl::comm_size(MPI_COMM_WORLD) > 4) |
| 32 |
GTEST_SKIP(); |
| 33 |
|
| 34 |
double pi = std::atan(1) * 4; |
| 35 |
int nmeshes = 5; |
| 36 |
|
| 37 |
for (int i = 0; i < nmeshes; ++i) |
| 38 |
{ |
| 39 |
MeshSpec spec, spec2; |
| 40 |
spec.numelX = 5; |
| 41 |
spec.numelY = 5; |
| 42 |
spec.xmin = 0.5; |
| 43 |
spec.xmax = 1.5; |
| 44 |
spec.ymin = 0; |
| 45 |
spec.ymax = pi / 2; |
| 46 |
|
| 47 |
spec2.numelX = 5 + i; |
| 48 |
spec2.numelY = 5 + i; |
| 49 |
spec2.xmin = 0.5; |
| 50 |
spec2.xmax = 1.5; |
| 51 |
spec2.ymin = 0; |
| 52 |
spec2.ymax = pi / 2; |
| 53 |
|
| 54 |
// remap coordinates to annulus |
| 55 |
auto func = [&](const utils::Point& pt) { |
| 56 |
// interpret x and y as r and theta |
| 57 |
double r = pt.x; |
| 58 |
double theta = pt.y; |
| 59 |
|
| 60 |
double x = r * std::cos(theta); |
| 61 |
double y = r * std::sin(theta); |
| 62 |
double z = 0.0; |
| 63 |
utils::Point pt2(x, y, z); |
| 64 |
return pt2; |
| 65 |
}; |
| 66 |
|
| 67 |
std::shared_ptr<Mesh> mesh1 = create_mesh(spec, func); |
| 68 |
std::shared_ptr<Mesh> mesh2 = create_mesh(spec2, func); |
| 69 |
|
| 70 |
// printVertEdges("mesh1_initial", mesh1); |
| 71 |
// printVertEdges("mesh2_initial", mesh2); |
| 72 |
|
| 73 |
IncrementalBoundarySnapperOpts snapperOpts; |
| 74 |
snapperOpts.boundarySnapNsteps = 2; |
| 75 |
auto snapper = make_incremental_boundary_snapper(mesh1, mesh2, MPI_COMM_WORLD, snapperOpts); |
| 76 |
snapper->snap(); |
| 77 |
|
| 78 |
// printVertEdges("mesh1_final", mesh1); |
| 79 |
// printVertEdges("mesh2_final", mesh2); |
| 80 |
|
| 81 |
test_areas_positive(mesh1); |
| 82 |
test_areas_positive(mesh2); |
| 83 |
|
| 84 |
mesh::impl::ElementOperations2D elemOps; |
| 85 |
std::array<double, 2> areasLocal, areasGlobal; |
| 86 |
areasLocal[0] = elemOps.compute_area(mesh1); |
| 87 |
areasLocal[1] = elemOps.compute_area(mesh2); |
| 88 |
|
| 89 |
MPI_Allreduce(areasLocal.data(), areasGlobal.data(), 2, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); |
| 90 |
EXPECT_FLOAT_EQ(areasGlobal[0], areasGlobal[1]); |
| 91 |
} |
| 92 |
} |
| 93 |
} // namespace impl |
| 94 |
} // namespace middle_mesh |
| 95 |
} // namespace stk |