preCICE
Loading...
Searching...
No Matches
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
19 using RawCoords = std::array<double, 3>;
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 setTagged(bool tagged);
55
56 void tag();
57
59 inline double coord(int index) const;
60
61 inline bool operator==(const Vertex &rhs) const;
62
63 inline bool operator!=(const Vertex &rhs) const;
64
66 inline bool operator<(const Vertex &rhs) const;
67
68private:
70 std::array<double, 3> _coords;
71
73 short _dim;
74
77
79 int _globalIndex = -1;
80
82 bool _owner = true;
83
85 bool _tagged = false;
86};
87
88// ------------------------------------------------------ HEADER IMPLEMENTATION
89
90template <typename VECTOR_T>
92 const VECTOR_T &coordinates,
93 int id)
94 : _dim(coordinates.size()),
95 _id(id)
96{
97 PRECICE_ASSERT(_dim == 2 || _dim == 3, _dim);
98 _coords.fill(0.0);
99 std::copy_n(coordinates.begin(), _dim, _coords.data());
100}
101
102template <typename VECTOR_T>
104 const VECTOR_T &coordinates)
105{
106 PRECICE_ASSERT(coordinates.size() == _dim, coordinates.size(), _dim);
107 _coords.fill(0.0);
108 std::copy_n(coordinates.begin(), _dim, _coords.data());
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{
130 PRECICE_ASSERT(0 <= index && index < _dim, index, _dim);
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
150std::ostream &operator<<(std::ostream &os, const Vertex &v);
151
152} // namespace precice::mesh
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Vertex of a mesh.
Definition Vertex.hpp:16
bool operator<(const Vertex &rhs) const
Implements partial ordering by ID.
Definition Vertex.hpp:144
std::array< double, 3 > RawCoords
Definition Vertex.hpp:19
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:73
void setTagged(bool tagged)
Definition Vertex.cpp:37
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:85
void setCoords(const VECTOR_T &coordinates)
Sets the coordinates of the vertex.
Definition Vertex.hpp:103
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:70
bool _owner
true if this processors is the owner of the vertex (for parallel simulations)
Definition Vertex.hpp:82
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:79
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:91
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:76
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
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