preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
18{
20 using Eigen::Vector3d;
21 Vector3d coords1(0.0, 0.0, 0.0);
22 Vector3d coords2(1.0, 0.0, 0.0);
23 Vector3d coords3(0.0, 1.0, 0.0);
24 Vector3d coords4(0.0, 0.0, 1.0);
25
26 Vertex v1(coords1, 0);
27 Vertex v2(coords2, 1);
28 Vertex v3(coords3, 2);
29 Vertex v4(coords4, 3);
30
31 Tetrahedron tetra(v1, v2, v3, v4);
32
33 Vertex &v1ref = tetra.vertex(0);
34 BOOST_TEST(v1ref.getID() == v1.getID());
35
36 Vertex &v2ref = tetra.vertex(1);
37 BOOST_TEST(v2ref.getID() == v2.getID());
38
39 Vertex &v3ref = tetra.vertex(2);
40 BOOST_TEST(v3ref.getID() == v3.getID());
41
42 Vertex &v4ref = tetra.vertex(3);
43 BOOST_TEST(v4ref.getID() == v4.getID());
44
45 Vector3d center = tetra.getCenter();
46 BOOST_TEST(testing::equals(center, (coords1 + coords2 + coords3 + coords4) / 4));
47
48 // sqrt(11)/4
49 constexpr double expectedRadius = 0.82915619758;
50 BOOST_TEST(tetra.getEnclosingRadius() == expectedRadius);
51
52 constexpr double expectedVolume = 1.0 / 6.0;
53 BOOST_TEST(tetra.getVolume() == expectedVolume);
54}
55
58{
60 // Same as above, but with a vertex whose projection
61 // on the opposing tetra is out ouf the tetrahedron.
62 // Also, we give it a negative z-coordinate
63 using Eigen::Vector3d;
64 Vector3d coords1(0.0, 0.0, 0.0);
65 Vector3d coords2(1.0, 0.0, 0.0);
66 Vector3d coords3(0.0, 1.0, 0.0);
67 Vector3d coords4(-5.0, 10.0, -1.0);
68
69 Vertex v1(coords1, 0);
70 Vertex v2(coords2, 1);
71 Vertex v3(coords3, 2);
72 Vertex v4(coords4, 3);
73
74 Tetrahedron tetra(v1, v2, v3, v4);
75
76 Vertex &v1ref = tetra.vertex(0);
77 BOOST_TEST(v1ref.getID() == v1.getID());
78
79 Vertex &v2ref = tetra.vertex(1);
80 BOOST_TEST(v2ref.getID() == v2.getID());
81
82 Vertex &v3ref = tetra.vertex(2);
83 BOOST_TEST(v3ref.getID() == v3.getID());
84
85 Vertex &v4ref = tetra.vertex(3);
86 BOOST_TEST(v4ref.getID() == v4.getID());
87
88 Vector3d center = tetra.getCenter();
89 BOOST_TEST(testing::equals(center, (coords1 + coords2 + coords3 + coords4) / 4));
90
91 // sqrt(11)/4
92 constexpr double expectedRadius = 8.314144574157945;
93 BOOST_TEST(tetra.getEnclosingRadius() == expectedRadius);
94
95 constexpr double expectedVolume = 1.0 / 6.0;
96 BOOST_TEST(tetra.getVolume() == expectedVolume);
97}
98
100BOOST_AUTO_TEST_CASE(TetrahedronEquality)
101{
102 PRECICE_TEST();
103 using Eigen::Vector3d;
104 Vector3d coords1(0.0, 0.0, 0.0);
105 Vector3d coords2(1.0, 0.0, 0.0);
106 Vector3d coords3(0.0, 1.0, 0.0);
107 Vector3d coords4(0.0, 0.0, 1.0);
108 Vector3d coords5(0.0, 0.0, -1.0);
109
110 Vertex v1(coords1, 0);
111 Vertex v2(coords2, 1);
112 Vertex v3(coords3, 2);
113 Vertex v4(coords4, 3);
114 Vertex v5(coords5, 4);
115
116 Tetrahedron tetra1(v1, v2, v3, v4);
117 Tetrahedron tetra2(v3, v1, v2, v4);
118 Tetrahedron tetra3(v1, v2, v3, v5);
119
120 BOOST_TEST(tetra1 == tetra2);
121 BOOST_TEST(tetra1 != tetra3);
122 BOOST_TEST(tetra2 != tetra3);
123}
124
125PRECICE_TEST_SETUP(1_rank)
126BOOST_AUTO_TEST_CASE(TetrahedronWKTPrint)
127{
128 PRECICE_TEST();
129 Vertex v1(Eigen::Vector3d(0., 0., 0.), 0);
130 Vertex v2(Eigen::Vector3d(1., 0., 0.), 1);
131 Vertex v3(Eigen::Vector3d(0., 1., 0.), 2);
132 Vertex v4(Eigen::Vector3d(0., 0., 1.), 3);
133
134 Tetrahedron t1(v1, v2, v3, v4);
135 std::stringstream stream;
136 stream << t1;
137 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))");
138 BOOST_TEST(t1string == stream.str());
139}
140
141BOOST_AUTO_TEST_SUITE_END() // Tetrahedron
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#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
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:109
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:93
Main namespace of the precice library.
T str(T... args)