preCICE v3.1.2
Loading...
Searching...
No Matches
PartitionOfUnityClusteringTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <memory>
4#include <ostream>
5#include <string>
6#include <utility>
7#include <vector>
8#include "logging/Logger.hpp"
10#include "mesh/Data.hpp"
11#include "mesh/Mesh.hpp"
13#include "mesh/Utils.hpp"
14#include "mesh/Vertex.hpp"
16#include "testing/Testing.hpp"
17
18using namespace precice;
19using namespace precice::mesh;
20using namespace precice::mapping;
21using namespace precice::testing;
23
24BOOST_AUTO_TEST_SUITE(MappingTests)
25BOOST_AUTO_TEST_SUITE(PartitionOfUnityClustering)
26
28
29BOOST_AUTO_TEST_CASE(createClustering2D)
30{
31 PRECICE_TEST(1_rank);
32
33 int meshDimension = 2;
34 // Generate the meshes
35 mesh::PtrMesh inMesh = std::make_shared<Mesh>("inMesh", meshDimension, testing::nextMeshID());
36 mesh::PtrMesh outMesh = std::make_shared<Mesh>("outMesh", meshDimension, testing::nextMeshID());
37
38 // Create triangular shaped matching meshes
39 for (unsigned int i = 0; i < 10; ++i) {
40 for (unsigned int j = i; j < 10; ++j) {
41 inMesh->createVertex(Eigen::Vector2d(static_cast<double>(i), static_cast<double>(j)));
42 outMesh->createVertex(Eigen::Vector2d(static_cast<double>(i), static_cast<double>(j)));
43 }
44 }
45 double relativeOverlap = 0.3;
46 unsigned int verticesPerPartition = 10;
47 bool projectToInput = false;
48 {
49 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
50 BOOST_TEST(averagePartitionRadius == 2.2360679774997898);
51 BOOST_TEST(centerCandidates.size() == 19);
52 }
53
54 {
55 projectToInput = true;
56 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
57 BOOST_TEST(averagePartitionRadius == 2.2360679774997898);
58 BOOST_TEST(centerCandidates.size() == 25);
59 }
60}
61
62BOOST_AUTO_TEST_CASE(createClustering3D)
63{
64 PRECICE_TEST(1_rank);
65
66 int meshDimension = 3;
67 // Generate the meshes
68 mesh::PtrMesh inMesh = std::make_shared<Mesh>("inMesh", meshDimension, testing::nextMeshID());
69 mesh::PtrMesh outMesh = std::make_shared<Mesh>("outMesh", meshDimension, testing::nextMeshID());
70
71 // Create triangular shaped matching meshes
72 for (unsigned int i = 0; i < 10; ++i) {
73 for (unsigned int j = i; j < 10; ++j) {
74 for (unsigned int k = i; k < 10; ++k) {
75 inMesh->createVertex(Eigen::Vector3d(static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)));
76 outMesh->createVertex(Eigen::Vector3d(static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)));
77 }
78 }
79 }
80 double relativeOverlap = 0.15;
81 unsigned int verticesPerPartition = 10;
82 bool projectToInput = false;
83 {
84 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
85 BOOST_TEST(averagePartitionRadius == 1.4142135623730951);
86 BOOST_TEST(centerCandidates.size() == 188);
87 }
88
89 {
90 projectToInput = true;
91 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
92 BOOST_TEST(averagePartitionRadius == 1.4142135623730951);
93 BOOST_TEST(centerCandidates.size() == 222);
94 }
95}
96
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(createClustering2D)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Vertex & createVertex(const Eigen::VectorXd &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:103
contains data mapping from points to meshes.
provides Mesh, Data and primitives.
contains the testing framework.
Definition helper.hpp:9
Main namespace of the precice library.