preCICE v3.1.1
Loading...
Searching...
No Matches
TetrahedronTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <sstream>
3#include <string>
4#include "logging/Logger.hpp"
6#include "mesh/Vertex.hpp"
8#include "testing/Testing.hpp"
9
10using namespace precice;
11using namespace precice::mesh;
12
13BOOST_AUTO_TEST_SUITE(MeshTests)
14BOOST_AUTO_TEST_SUITE(TetrahedronTests)
15
17{
18 PRECICE_TEST(1_rank);
19 using Eigen::Vector3d;
20 Vector3d coords1(0.0, 0.0, 0.0);
21 Vector3d coords2(1.0, 0.0, 0.0);
22 Vector3d coords3(0.0, 1.0, 0.0);
23 Vector3d coords4(0.0, 0.0, 1.0);
24
25 Vertex v1(coords1, 0);
26 Vertex v2(coords2, 1);
27 Vertex v3(coords3, 2);
28 Vertex v4(coords4, 3);
29
30 Tetrahedron tetra(v1, v2, v3, v4);
31
32 Vertex &v1ref = tetra.vertex(0);
33 BOOST_TEST(v1ref.getID() == v1.getID());
34
35 Vertex &v2ref = tetra.vertex(1);
36 BOOST_TEST(v2ref.getID() == v2.getID());
37
38 Vertex &v3ref = tetra.vertex(2);
39 BOOST_TEST(v3ref.getID() == v3.getID());
40
41 Vertex &v4ref = tetra.vertex(3);
42 BOOST_TEST(v4ref.getID() == v4.getID());
43
44 Vector3d center = tetra.getCenter();
45 BOOST_TEST(testing::equals(center, (coords1 + coords2 + coords3 + coords4) / 4));
46
47 // sqrt(11)/4
48 constexpr double expectedRadius = 0.82915619758;
49 BOOST_TEST(tetra.getEnclosingRadius() == expectedRadius);
50
51 constexpr double expectedVolume = 1.0 / 6.0;
52 BOOST_TEST(tetra.getVolume() == expectedVolume);
53}
54
56{
57
58 // Same as above, but with a vertex whose projection
59 // on the opposing tetra is out ouf the tetrahedron.
60 // Also, we give it a negative z-coordinate
61 PRECICE_TEST(1_rank);
62 using Eigen::Vector3d;
63 Vector3d coords1(0.0, 0.0, 0.0);
64 Vector3d coords2(1.0, 0.0, 0.0);
65 Vector3d coords3(0.0, 1.0, 0.0);
66 Vector3d coords4(-5.0, 10.0, -1.0);
67
68 Vertex v1(coords1, 0);
69 Vertex v2(coords2, 1);
70 Vertex v3(coords3, 2);
71 Vertex v4(coords4, 3);
72
73 Tetrahedron tetra(v1, v2, v3, v4);
74
75 Vertex &v1ref = tetra.vertex(0);
76 BOOST_TEST(v1ref.getID() == v1.getID());
77
78 Vertex &v2ref = tetra.vertex(1);
79 BOOST_TEST(v2ref.getID() == v2.getID());
80
81 Vertex &v3ref = tetra.vertex(2);
82 BOOST_TEST(v3ref.getID() == v3.getID());
83
84 Vertex &v4ref = tetra.vertex(3);
85 BOOST_TEST(v4ref.getID() == v4.getID());
86
87 Vector3d center = tetra.getCenter();
88 BOOST_TEST(testing::equals(center, (coords1 + coords2 + coords3 + coords4) / 4));
89
90 // sqrt(11)/4
91 constexpr double expectedRadius = 8.314144574157945;
92 BOOST_TEST(tetra.getEnclosingRadius() == expectedRadius);
93
94 constexpr double expectedVolume = 1.0 / 6.0;
95 BOOST_TEST(tetra.getVolume() == expectedVolume);
96}
97
98BOOST_AUTO_TEST_CASE(TetrahedronEquality)
99{
100 PRECICE_TEST(1_rank);
101 using Eigen::Vector3d;
102 Vector3d coords1(0.0, 0.0, 0.0);
103 Vector3d coords2(1.0, 0.0, 0.0);
104 Vector3d coords3(0.0, 1.0, 0.0);
105 Vector3d coords4(0.0, 0.0, 1.0);
106 Vector3d coords5(0.0, 0.0, -1.0);
107
108 Vertex v1(coords1, 0);
109 Vertex v2(coords2, 1);
110 Vertex v3(coords3, 2);
111 Vertex v4(coords4, 3);
112 Vertex v5(coords5, 4);
113
114 Tetrahedron tetra1(v1, v2, v3, v4);
115 Tetrahedron tetra2(v3, v1, v2, v4);
116 Tetrahedron tetra3(v1, v2, v3, v5);
117
118 BOOST_TEST(tetra1 == tetra2);
119 BOOST_TEST(tetra1 != tetra3);
120 BOOST_TEST(tetra2 != tetra3);
121}
122
123BOOST_AUTO_TEST_CASE(TetrahedronWKTPrint)
124{
125 PRECICE_TEST(1_rank);
126 Vertex v1(Eigen::Vector3d(0., 0., 0.), 0);
127 Vertex v2(Eigen::Vector3d(1., 0., 0.), 1);
128 Vertex v3(Eigen::Vector3d(0., 1., 0.), 2);
129 Vertex v4(Eigen::Vector3d(0., 0., 1.), 3);
130
131 Tetrahedron t1(v1, v2, v3, v4);
132 std::stringstream stream;
133 stream << t1;
134 std::string t1string("MULTILINESTRING ((0 0 0, 1 0 0), (0 0 0, 0 1 0), (0 0 0, 0 0 1), (1 0 0, 0 1 0), (1 0 0, 0 0 1), (0 1 0, 0 0 1))");
135 BOOST_TEST(t1string == stream.str());
136}
137
138BOOST_AUTO_TEST_SUITE_END() // Tetrahedron
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
BOOST_AUTO_TEST_CASE(BasicTetra)
Tetrahedron of a mesh, defined by 4 vertices.
Vertex & vertex(int i)
Returns tetrahedron vertex with index 0, 1, 2 or 3.
const Eigen::VectorXd getCenter() const
Returns the barycenter of the tetrahedron.
double getEnclosingRadius() const
Returns the radius of the sphere enclosing the tetrahedron.
double getVolume() const
Returns the unsigned volume of the tetrahedron.
Vertex of a mesh.
Definition Vertex.hpp:16
VertexID getID() const
Returns the unique (among vertices of one mesh on one processor) ID of the vertex.
Definition Vertex.hpp:111
provides Mesh, Data and primitives.
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
Main namespace of the precice library.
T str(T... args)