preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vertex.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <array>
6#include <iostream>
7#include <utility>
8
11#include "utils/assertion.hpp"
12
13namespace precice::mesh {
14
16class Vertex {
17public:
18 //( Used as the raw representation of the coordinates
20
22 template <typename VECTOR_T>
23 Vertex(
24 const VECTOR_T &coordinates,
25 VertexID id);
26
28 int getDimensions() const;
29
31 template <typename VECTOR_T>
32 void setCoords(const VECTOR_T &coordinates);
33
35 VertexID getID() const;
36
38 Eigen::VectorXd getCoords() const;
39
41 const RawCoords &rawCoords() const;
42
44 int getGlobalIndex() const;
45
46 void setGlobalIndex(int globalIndex);
47
48 bool isOwner() const;
49
50 void setOwner(bool owner);
51
52 bool isTagged() const;
53
54 void tag();
55
57 inline double coord(int index) const;
58
59 inline bool operator==(const Vertex &rhs) const;
60
61 inline bool operator!=(const Vertex &rhs) const;
62
64 inline bool operator<(const Vertex &rhs) const;
65
66private:
69
71 short _dim;
72
75
77 int _globalIndex = -1;
78
80 bool _owner = true;
81
83 bool _tagged = false;
84};
85
86// ------------------------------------------------------ HEADER IMPLEMENTATION
87
88template <typename VECTOR_T>
90 const VECTOR_T &coordinates,
91 int id)
92 : _dim(coordinates.size()),
93 _id(id)
94{
95 PRECICE_ASSERT(_dim == 2 || _dim == 3, _dim);
96 _coords.fill(0.0);
97 std::copy_n(coordinates.begin(), _dim, _coords.data());
98}
99
100template <typename VECTOR_T>
102 const VECTOR_T &coordinates)
103{
104 PRECICE_ASSERT(coordinates.size() == _dim, coordinates.size(), _dim);
105 _coords.fill(0.0);
106 std::copy_n(coordinates.begin(), _dim, _coords.data());
107}
108
110{
111 return _id;
112}
113
114inline Eigen::VectorXd Vertex::getCoords() const
115{
116 Eigen::VectorXd v(_dim);
117 std::copy_n(_coords.data(), _dim, v.data());
118 return v;
119}
120
122{
123 return _coords;
124}
125
126inline double Vertex::coord(int index) const
127{
129 return _coords.at(index);
130}
131
132inline bool Vertex::operator==(const Vertex &rhs) const
133{
134 return math::equals(getCoords(), rhs.getCoords());
135}
136
137inline bool Vertex::operator!=(const Vertex &rhs) const
138{
139 return !(*this == rhs);
140}
141
142inline bool Vertex::operator<(const Vertex &rhs) const
143{
144 return _id < rhs._id;
145}
146
149
150} // namespace precice::mesh
unsigned int index
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
T at(T... args)
Vertex of a mesh.
Definition Vertex.hpp:16
bool operator<(const Vertex &rhs) const
Implements partial ordering by ID.
Definition Vertex.hpp:142
double coord(int index) const
Returns a coordinate of a vertex.
Definition Vertex.hpp:126
short _dim
Dimension of the coordinates. 3D or 2D.
Definition Vertex.hpp:71
VertexID getID() const
Returns the unique (among vertices of one mesh on one processor) ID of the vertex.
Definition Vertex.hpp:109
bool _tagged
true if this vertex is tagged for partition
Definition Vertex.hpp:83
void setCoords(const VECTOR_T &coordinates)
Sets the coordinates of the vertex.
Definition Vertex.hpp:101
const RawCoords & rawCoords() const
Direct access to the coordinates.
Definition Vertex.hpp:121
std::array< double, 3 > _coords
Coordinates of the vertex.
Definition Vertex.hpp:68
bool _owner
true if this processors is the owner of the vertex (for parallel simulations)
Definition Vertex.hpp:80
bool isTagged() const
Definition Vertex.cpp:32
void setGlobalIndex(int globalIndex)
Definition Vertex.cpp:17
int _globalIndex
global (unique) index for parallel simulations
Definition Vertex.hpp:77
void setOwner(bool owner)
Definition Vertex.cpp:27
int getDimensions() const
Returns spatial dimensionality of vertex.
Definition Vertex.cpp:7
Vertex(const VECTOR_T &coordinates, VertexID id)
Constructor for vertex.
Definition Vertex.hpp:89
bool isOwner() const
Definition Vertex.cpp:22
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition Vertex.hpp:114
VertexID _id
Unique (among vertices in one mesh) ID of the vertex.
Definition Vertex.hpp:74
bool operator==(const Vertex &rhs) const
Definition Vertex.hpp:132
int getGlobalIndex() const
Globally unique index.
Definition Vertex.cpp:12
bool operator!=(const Vertex &rhs) const
Definition Vertex.hpp:137
T copy_n(T... args)
T data(T... args)
T fill(T... args)
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
provides Mesh, Data and primitives.
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
int VertexID
Definition Types.hpp:13