preCICE v3.1.2
Loading...
Searching...
No Matches
EdgeTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <Eigen/src/Core/Matrix.h>
3#include <iosfwd>
4#include <string>
5#include "logging/Logger.hpp"
6#include "mesh/Edge.hpp"
7#include "mesh/Vertex.hpp"
9#include "testing/Testing.hpp"
10
11using namespace precice;
12using namespace precice::mesh;
13using namespace Eigen;
14
15BOOST_AUTO_TEST_SUITE(MeshTests)
16BOOST_AUTO_TEST_SUITE(EdgeTests)
17
19{
20 PRECICE_TEST(1_rank);
21 Vertex v1(Vector3d::Constant(0.0), 0);
22 Vertex v2(Vector3d::Constant(1.0), 1);
23 Edge edge(v1, v2);
24
25 BOOST_TEST(edge.getDimensions() == 3);
26 VectorXd coords1 = edge.vertex(0).getCoords();
27 VectorXd coords2 = edge.vertex(1).getCoords();
28 BOOST_TEST(coords1 == Vector3d::Constant(0.0));
29 BOOST_TEST(coords2 == Vector3d::Constant(1.0));
30
31 double expectedLenght = std::sqrt(3.0);
32 double expectedRadius = expectedLenght / 2.0;
33 BOOST_TEST(edge.getLength() == expectedLenght);
34 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
35 BOOST_TEST(testing::equals(edge.getCenter(), (coords1 + coords2) / 2));
36}
37
39{
40 PRECICE_TEST(1_rank);
41 Vertex v1(Vector2d::Constant(0.0), 0);
42 Vertex v2(Vector2d::Constant(1.0), 1);
43 Edge edge(v1, v2);
44 BOOST_TEST(edge.getDimensions() == 2);
45
46 double expectedLenght = std::sqrt(2.0);
47 double expectedRadius = expectedLenght / 2.0;
48 BOOST_TEST(edge.getLength() == expectedLenght);
49 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
50 BOOST_TEST(testing::equals(edge.getCenter(), Vector2d{0.5, 0.5}));
51}
52
54{
55 PRECICE_TEST(1_rank);
56 Vertex v1(Vector2d::Constant(0.0), 0);
57 Vertex v2(Vector2d{1, 0}, 1);
58 Edge edge(v1, v2);
59 BOOST_TEST(edge.getDimensions() == 2);
60
61 double expectedLenght = std::sqrt(1.0);
62 double expectedRadius = expectedLenght / 2.0;
63 BOOST_TEST(edge.getLength() == expectedLenght);
64 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
65 BOOST_TEST(testing::equals(edge.getCenter(), Vector2d{0.5, 0}));
66}
67
69{
70 PRECICE_TEST(1_rank);
71 Vertex v1(Vector2d::Constant(0.0), 0);
72 Vertex v2(Vector2d{0, 1}, 1);
73 Edge edge(v1, v2);
74 BOOST_TEST(edge.getDimensions() == 2);
75
76 double expectedLenght = std::sqrt(1.0);
77 double expectedRadius = expectedLenght / 2.0;
78 BOOST_TEST(edge.getLength() == expectedLenght);
79 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
80 BOOST_TEST(testing::equals(edge.getCenter(), Vector2d{0, 0.5}));
81}
82
84{
85 PRECICE_TEST(1_rank);
86 Vertex v1(Vector3d::Constant(0.0), 0);
87 Vertex v2(Vector3d{1, 0, 0}, 1);
88 Edge edge(v1, v2);
89 BOOST_TEST(edge.getDimensions() == 3);
90
91 double expectedLenght = std::sqrt(1.0);
92 double expectedRadius = expectedLenght / 2.0;
93 BOOST_TEST(edge.getLength() == expectedLenght);
94 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
95 BOOST_TEST(testing::equals(edge.getCenter(), Vector3d{0.5, 0, 0}));
96}
97
99{
100 PRECICE_TEST(1_rank);
101 Vertex v1(Vector3d::Constant(0.0), 0);
102 Vertex v2(Vector3d{0, 1, 0}, 1);
103 Edge edge(v1, v2);
104 BOOST_TEST(edge.getDimensions() == 3);
105
106 double expectedLenght = std::sqrt(1.0);
107 double expectedRadius = expectedLenght / 2.0;
108 BOOST_TEST(edge.getLength() == expectedLenght);
109 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
110 BOOST_TEST(testing::equals(edge.getCenter(), Vector3d{0, 0.5, 0}));
111}
112
114{
115 PRECICE_TEST(1_rank);
116 Vertex v1(Vector3d::Constant(0.0), 0);
117 Vertex v2(Vector3d{0, 0, 1}, 1);
118 Edge edge(v1, v2);
119 BOOST_TEST(edge.getDimensions() == 3);
120
121 double expectedLenght = std::sqrt(1.0);
122 double expectedRadius = expectedLenght / 2.0;
123 BOOST_TEST(edge.getLength() == expectedLenght);
124 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
125 BOOST_TEST(testing::equals(edge.getCenter(), Vector3d{0, 0, 0.5}));
126}
127
129{
130 PRECICE_TEST(1_rank);
131 Vertex v1(Vector3d::Constant(0.0), 0);
132 Vertex v2(Vector3d::Constant(1.0), 1);
133 Edge edge(v1, v2);
134 BOOST_TEST(edge.getDimensions() == 3);
135
136 double expectedLenght = std::sqrt(3.0);
137 double expectedRadius = expectedLenght / 2.0;
138 BOOST_TEST(edge.getLength() == expectedLenght);
139 BOOST_TEST(edge.getEnclosingRadius() == expectedRadius);
140 BOOST_TEST(testing::equals(edge.getCenter(), Vector3d::Constant(0.5)));
141}
142
144{
145 PRECICE_TEST(1_rank);
146 Vertex v1(Vector3d(0, 0, 0), 0);
147 Vertex v2(Vector3d(0, 0, 1), 0);
148 Vertex v3(Vector3d(0, 0, 2), 0);
149 Edge edge1(v1, v2);
150 Edge edge2(v2, v1);
151 Edge edge3(v1, v3);
152 Edge edge4(v1, v3);
153 BOOST_TEST(edge1 == edge2);
154 BOOST_TEST(edge1 != edge3);
155 BOOST_TEST(edge3 == edge4);
156}
157
159{
160 PRECICE_TEST(1_rank);
161 Vertex v1(Vector2d(1., 2.), 0);
162 Vertex v2(Vector2d(2., 3.), 0);
163 Edge e1(v1, v2);
164 std::stringstream e1stream;
165 e1stream << e1;
166 std::string e1str("LINESTRING (1 2, 2 3)");
167 BOOST_TEST(e1str == e1stream.str());
168 Vertex v3(Vector3d(1., 2., 3.), 0);
169 Vertex v4(Vector3d(3., 2., 1.), 0);
170 Edge e2(v3, v4);
171 std::stringstream e2stream;
172 e2stream << e2;
173 std::string e2str("LINESTRING (1 2 3, 3 2 1)");
174 BOOST_TEST(e2str == e2stream.str());
175}
176
177BOOST_AUTO_TEST_CASE(EdgeConnectedTo)
178{
179 PRECICE_TEST(1_rank);
180 Vertex v1(Vector3d(0, 0, 1), 0);
181 Vertex v2(Vector3d(0, 0, 2), 0);
182 Vertex v3(Vector3d(0, 0, 3), 0);
183 Vertex v4(Vector3d(0, 0, 4), 0);
184
185 Edge edge1(v1, v2);
186 Edge edge2(v2, v3);
187 BOOST_TEST(edge1.connectedTo(edge2));
188 BOOST_TEST(edge2.connectedTo(edge1));
189
190 Edge edge3(v3, v4);
191 BOOST_TEST(!edge1.connectedTo(edge3));
192 BOOST_TEST(!edge3.connectedTo(edge1));
193 BOOST_TEST(edge2.connectedTo(edge3));
194 BOOST_TEST(edge3.connectedTo(edge2));
195}
196
BOOST_AUTO_TEST_CASE(Edges)
Definition EdgeTest.cpp:18
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
double getEnclosingRadius() const
Returns the radius of the enclosing circle of the edge.
Definition Edge.cpp:34
double getLength() const
Returns the length of the edge.
Definition Edge.cpp:23
int getDimensions() const
Returns number of spatial dimensions (2 or 3) the edge is embedded to.
Definition Edge.hpp:91
const Eigen::VectorXd getCenter() const
Returns the center of the edge.
Definition Edge.cpp:29
Vertex & vertex(int i)
Returns the edge's vertex with index 0 or 1.
Definition Edge.hpp:77
bool connectedTo(const Edge &other) const
Checks whether both edges share a vertex.
Definition Edge.cpp:39
Vertex of a mesh.
Definition Vertex.hpp:16
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition Vertex.hpp:116
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 sqrt(T... args)
T str(T... args)