preCICE v3.1.2
Loading...
Searching...
No Matches
Vertex.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <array>
5#include <iostream>
6#include <utility>
7
10#include "utils/assertion.hpp"
11
12namespace precice {
13namespace 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[0] = coordinates[0];
97 _coords[1] = coordinates[1];
98 _coords[2] = (_dim == 3) ? coordinates[2] : 0.0;
99}
100
101template <typename VECTOR_T>
103 const VECTOR_T &coordinates)
104{
105 PRECICE_ASSERT(coordinates.size() == _dim, coordinates.size(), _dim);
106 _coords[0] = coordinates[0];
107 _coords[1] = coordinates[1];
108 _coords[2] = (_dim == 3) ? coordinates[2] : 0.0;
109}
110
112{
113 return _id;
114}
115
116inline Eigen::VectorXd Vertex::getCoords() const
117{
118 Eigen::VectorXd v(_dim);
119 std::copy_n(_coords.data(), _dim, v.data());
120 return v;
121}
122
124{
125 return _coords;
126}
127
128inline double Vertex::coord(int index) const
129{
131 return _coords.at(index);
132}
133
134inline bool Vertex::operator==(const Vertex &rhs) const
135{
136 return math::equals(getCoords(), rhs.getCoords());
137}
138
139inline bool Vertex::operator!=(const Vertex &rhs) const
140{
141 return !(*this == rhs);
142}
143
144inline bool Vertex::operator<(const Vertex &rhs) const
145{
146 return _id < rhs._id;
147}
148
151
152} // namespace mesh
153} // namespace precice
unsigned int index
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
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:144
double coord(int index) const
Returns a coordinate of a vertex.
Definition Vertex.hpp:128
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:111
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:102
const RawCoords & rawCoords() const
Direct access to the coordinates.
Definition Vertex.hpp:123
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:116
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:134
int getGlobalIndex() const
Globally unique index.
Definition Vertex.cpp:12
bool operator!=(const Vertex &rhs) const
Definition Vertex.hpp:139
T copy_n(T... args)
T data(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.
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13