preCICE
Toggle main menu visibility
Loading...
Searching...
No Matches
src
mesh
Tetrahedron.cpp
Go to the documentation of this file.
1
#include "
Tetrahedron.hpp
"
2
#include <Eigen/Core>
3
#include <algorithm>
4
#include <boost/concept/assert.hpp>
5
#include "
math/differences.hpp
"
6
#include "
math/geometry.hpp
"
7
#include "
mesh/Vertex.hpp
"
8
#include "
utils/EigenIO.hpp
"
9
10
namespace
precice::mesh
{
11
12
Tetrahedron::Tetrahedron
(
13
Vertex
&vertexOne,
14
Vertex
&vertexTwo,
15
Vertex
&vertexThree,
16
Vertex
&vertexFour)
17
:
_vertices
({&vertexOne, &vertexTwo, &vertexThree, &vertexFour})
18
{
19
PRECICE_ASSERT
(vertexOne.getDimensions() == vertexTwo.getDimensions(),
20
vertexOne.getDimensions(), vertexTwo.getDimensions());
21
PRECICE_ASSERT
(vertexOne.getDimensions() == vertexThree.getDimensions(),
22
vertexOne.getDimensions(), vertexThree.getDimensions());
23
PRECICE_ASSERT
(vertexOne.getDimensions() == vertexFour.getDimensions(),
24
vertexOne.getDimensions(), vertexFour.getDimensions());
25
PRECICE_ASSERT
(getDimensions() == 3, getDimensions());
26
27
PRECICE_ASSERT
(
28
(&vertexOne != &vertexTwo) &&
29
(&vertexOne != &vertexThree) &&
30
(&vertexOne != &vertexFour) &&
31
(&vertexTwo != &vertexThree) &&
32
(&vertexTwo != &vertexFour) &&
33
(&vertexThree != &vertexFour),
34
"Tetrahedron vertices are not unique!"
);
35
36
std::sort(_vertices.begin(), _vertices.end(),
37
[](
const
Vertex
*lhs,
const
Vertex
*rhs) { return *lhs < *rhs; });
38
}
39
40
double
Tetrahedron::getVolume
()
const
41
{
42
return
math::geometry::tetraVolume
(
vertex
(0).getCoords(),
vertex
(1).getCoords(),
vertex
(2).getCoords(),
vertex
(3).getCoords());
43
}
44
45
int
Tetrahedron::getDimensions
()
const
46
{
47
return
_vertices
[0]->getDimensions();
48
}
49
50
const
Eigen::VectorXd
Tetrahedron::getCenter
()
const
51
{
52
return
(
vertex
(0).getCoords() +
vertex
(1).getCoords() +
vertex
(2).getCoords() +
vertex
(3).getCoords()) / 4.0;
53
}
54
55
double
Tetrahedron::getEnclosingRadius
()
const
56
{
57
auto
center =
getCenter
();
58
return
std::max({(center -
vertex
(0).
getCoords
()).norm(),
59
(center -
vertex
(1).
getCoords
()).norm(),
60
(center -
vertex
(2).
getCoords
()).norm(),
61
(center -
vertex
(3).
getCoords
()).norm()});
62
}
63
64
bool
Tetrahedron::operator==
(
const
Tetrahedron
&other)
const
65
{
66
return
std::is_permutation(
_vertices
.begin(),
_vertices
.end(), other.
_vertices
.begin(),
67
[](
const
Vertex
*v1,
const
Vertex
*v2) { return *v1 == *v2; });
68
}
69
70
bool
Tetrahedron::operator!=
(
const
Tetrahedron
&other)
const
71
{
72
return
!(*
this
== other);
73
}
74
75
std::ostream &
operator<<
(std::ostream &os,
const
Tetrahedron
&t)
76
{
77
// Show 6 edges: 0-1, 0-2, 0-3, 1-2, 1-3, 2_3
78
using
utils::eigenio::wkt
;
79
const
auto
&v0 = t.
vertex
(0);
80
const
auto
&v1 = t.
vertex
(1);
81
const
auto
&v2 = t.
vertex
(2);
82
const
auto
&v3 = t.
vertex
(3);
83
84
return
os <<
"MULTILINESTRING ("
85
<<
"("
<< v0.getCoords().transpose().format(wkt()) <<
", "
<< v1.getCoords().transpose().format(wkt()) <<
"), "
86
<<
"("
<< v0.getCoords().transpose().format(wkt()) <<
", "
<< v2.getCoords().transpose().format(wkt()) <<
"), "
87
<<
"("
<< v0.getCoords().transpose().format(wkt()) <<
", "
<< v3.getCoords().transpose().format(wkt()) <<
"), "
88
<<
"("
<< v1.getCoords().transpose().format(wkt()) <<
", "
<< v2.getCoords().transpose().format(wkt()) <<
"), "
89
<<
"("
<< v1.getCoords().transpose().format(wkt()) <<
", "
<< v3.getCoords().transpose().format(wkt()) <<
"), "
90
<<
"("
<< v2.getCoords().transpose().format(wkt()) <<
", "
<< v3.getCoords().transpose().format(wkt()) <<
")"
91
<<
")"
;
92
}
93
94
}
// namespace precice::mesh
EigenIO.hpp
Tetrahedron.hpp
Vertex.hpp
PRECICE_ASSERT
#define PRECICE_ASSERT(...)
Definition
assertion.hpp:85
precice::mesh::Tetrahedron
Tetrahedron of a mesh, defined by 4 vertices.
Definition
Tetrahedron.hpp:16
precice::mesh::Tetrahedron::vertex
Vertex & vertex(int i)
Returns tetrahedron vertex with index 0, 1, 2 or 3.
Definition
Tetrahedron.hpp:78
precice::mesh::Tetrahedron::_vertices
std::array< Vertex *, 4 > _vertices
Vertices defining the Tetrahedron.
Definition
Tetrahedron.hpp:73
precice::mesh::Tetrahedron::getCenter
const Eigen::VectorXd getCenter() const
Returns the barycenter of the tetrahedron.
Definition
Tetrahedron.cpp:50
precice::mesh::Tetrahedron::getEnclosingRadius
double getEnclosingRadius() const
Returns the radius of the sphere enclosing the tetrahedron.
Definition
Tetrahedron.cpp:55
precice::mesh::Tetrahedron::getVolume
double getVolume() const
Returns the unsigned volume of the tetrahedron.
Definition
Tetrahedron.cpp:40
precice::mesh::Tetrahedron::operator!=
bool operator!=(const Tetrahedron &other) const
Not equal, implemented in terms of equal.
Definition
Tetrahedron.cpp:70
precice::mesh::Tetrahedron::operator==
bool operator==(const Tetrahedron &other) const
Compares two Tetrahedrons for equality.
Definition
Tetrahedron.cpp:64
precice::mesh::Tetrahedron::getDimensions
int getDimensions() const
Returns dimensionalty of space the Tetrahedron is embedded in.
Definition
Tetrahedron.cpp:45
precice::mesh::Tetrahedron::Tetrahedron
Tetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Definition
Tetrahedron.cpp:12
precice::mesh::Vertex
Vertex of a mesh.
Definition
Vertex.hpp:16
precice::mesh::Vertex::getCoords
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition
Vertex.hpp:116
differences.hpp
geometry.hpp
precice::math::geometry::tetraVolume
double tetraVolume(const Eigen::Vector3d &a, const Eigen::Vector3d &b, const Eigen::Vector3d &c, const Eigen::Vector3d &d)
Computes the (unsigned) area of a triangle in 3D.
Definition
geometry.cpp:116
precice::mesh
provides Mesh, Data and primitives.
Definition
ScaleActionTest.cpp:20
precice::mesh::operator<<
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Definition
BoundingBox.cpp:192
precice::utils::eigenio::wkt
Eigen::IOFormat wkt()
Definition
EigenIO.hpp:7