preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
30BOOST_AUTO_TEST_CASE(createClustering2D)
31{
33
34 int meshDimension = 2;
35 // Generate the meshes
36 mesh::PtrMesh inMesh = std::make_shared<Mesh>("inMesh", meshDimension, testing::nextMeshID());
37 mesh::PtrMesh outMesh = std::make_shared<Mesh>("outMesh", meshDimension, testing::nextMeshID());
38
39 // Create triangular shaped matching meshes
40 for (unsigned int i = 0; i < 10; ++i) {
41 for (unsigned int j = i; j < 10; ++j) {
42 inMesh->createVertex(Eigen::Vector2d(static_cast<double>(i), static_cast<double>(j)));
43 outMesh->createVertex(Eigen::Vector2d(static_cast<double>(i), static_cast<double>(j)));
44 }
45 }
46 double relativeOverlap = 0.3;
47 unsigned int verticesPerPartition = 10;
48 bool projectToInput = false;
49 {
50 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
51 BOOST_TEST(averagePartitionRadius == 2.2360679774997898);
52 BOOST_TEST(centerCandidates.size() == 19);
53 }
54
55 {
56 projectToInput = true;
57 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
58 BOOST_TEST(averagePartitionRadius == 2.2360679774997898);
59 BOOST_TEST(centerCandidates.size() == 25);
60 }
61}
62
64BOOST_AUTO_TEST_CASE(createClustering3D)
65{
67
68 int meshDimension = 3;
69 // Generate the meshes
70 mesh::PtrMesh inMesh = std::make_shared<Mesh>("inMesh", meshDimension, testing::nextMeshID());
71 mesh::PtrMesh outMesh = std::make_shared<Mesh>("outMesh", meshDimension, testing::nextMeshID());
72
73 // Create triangular shaped matching meshes
74 for (unsigned int i = 0; i < 10; ++i) {
75 for (unsigned int j = i; j < 10; ++j) {
76 for (unsigned int k = i; k < 10; ++k) {
77 inMesh->createVertex(Eigen::Vector3d(static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)));
78 outMesh->createVertex(Eigen::Vector3d(static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)));
79 }
80 }
81 }
82 double relativeOverlap = 0.15;
83 unsigned int verticesPerPartition = 10;
84 bool projectToInput = false;
85 {
86 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
87 BOOST_TEST(averagePartitionRadius == 1.4142135623730951);
88 BOOST_TEST(centerCandidates.size() == 188);
89 }
90
91 {
92 projectToInput = true;
93 auto [averagePartitionRadius, centerCandidates] = impl::createClustering(inMesh, outMesh, relativeOverlap, verticesPerPartition, projectToInput);
94 BOOST_TEST(averagePartitionRadius == 1.4142135623730951);
95 BOOST_TEST(centerCandidates.size() == 222);
96 }
97}
98
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(createClustering2D)
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
Vertex & createVertex(const Eigen::Ref< const Eigen::VectorXd > &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:105
T make_unique(T... args)
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.