OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
edge.hpp
Go to the documentation of this file.
1// OpenBEM - Copyright (C) 2026 Shashwat Sharma
2
3// This file is part of OpenBEM.
4
5// OpenBEM is free software: you can redistribute it and/or modify it under the terms of the
6// GNU General Public License as published by the Free Software Foundation, either version 3
7// of the License, or (at your option) any later version.
8
9// You should have received a copy of the GNU General Public License along with OpenBEM.
10// If not, see <https://www.gnu.org/licenses/>.
11
12
18#ifndef EDGE_H
19#define EDGE_H
20
21#include <stdexcept>
22
23#include "types.hpp"
24
25
26namespace bem
27{
28
29const Float EDGE_DEFAULT_TOL = 1.0e-6;
30
40template <uint8_t dim>
41class Edge
42{
43
44 static_assert((dim == 1 || dim == 2 || dim == 3), "Edge must be defined in one, two, or three dimensions.");
45
46public:
47
53 {
54 set_v(v);
55 return;
56 };
57
58
71
72
78 {
79 return v_;
80 };
81
82
89 {
90 if (idx >= 2)
91 throw std::out_of_range("Edge::v(): vertex index out of bounds.");
92 return v_.col(idx);
93 };
94
95
101
102
107 Float length() const
108 { return length_; };
109
110
116 { return edge_vec_; };
117
118
124 { return unit_vec_; };
125
126
132 { return centroid_; };
133
134
139 static Edge<dim> reference_edge();
140
141
148 Edge<2> to_2d() const;
149
150
156 Edge<3> to_3d() const;
157
158
165 bool point_on_edge(ConstEigRef<EigColVecN<Float, dim>> r, const Float tol = EDGE_DEFAULT_TOL) const;
166
167
168private:
169
174 EigColVecN<Float, dim> compute_edge_vec() const { return v_.col(1) - v_.col(0); };
175
176
181 Float compute_length() const { return edge_vec().norm(); };
182
183
188 EigColVecN<Float, dim> compute_unit_vec() const { return edge_vec() / length(); };
189
190
195 EigColVecN<Float, dim> compute_centroid() const { return v_.rowwise().sum() / 2.0; };
196
197
199 Float length_;
200 EigColVecN<Float, dim> edge_vec_, unit_vec_, centroid_;
201
202};
203
208}
209
210#ifndef BEM_LINKED
212#endif
213
214#endif
Edge primitive class.
Definition edge.hpp:42
Edge< 2 > to_2d() const
Returns an equivalent edge with coordinates in a local 2D system, and with the local origin at this e...
Definition edge.cpp:51
Edge(ConstEigRef< EigMatMN< Float, dim, 2 > > v)
Constructs an Edge with given vertices.
Definition edge.hpp:52
void set_v(ConstEigRef< EigMatMN< Float, dim, 2 > > v)
Sets the vertices of this Edge.
Definition edge.cpp:28
Edge(ConstEigRef< EigColVecN< Float, dim > > v1, ConstEigRef< EigColVecN< Float, dim > > v2)
Constructs an Edge with given vertices.
Definition edge.hpp:64
EigColVecN< Float, dim > v(const uint8_t idx) const
Returns the vertex of this Edge at a given index.
Definition edge.hpp:88
EigColVecN< Float, dim > edge_vec() const
Returns the vector from the first to the second vertex of this Edge.
Definition edge.hpp:115
static Edge< dim > reference_edge()
Returns a reference edge in the specified dimension from 0 to 1 along the first axis.
Definition edge.cpp:40
EigColVecN< Float, dim > unit_vec() const
Returns the unit vector along this Edge from its first to its second vertex.
Definition edge.hpp:123
const EigMatMN< Float, dim, 2 > & v() const
Returns the vertices of this Edge.
Definition edge.hpp:77
bool point_on_edge(ConstEigRef< EigColVecN< Float, dim > > r, const Float tol=EDGE_DEFAULT_TOL) const
Returns true if the given point is on the edge, inclusive of vertices.
Definition edge.cpp:81
EigColVecN< Float, dim > centroid() const
Returns the centroid of this Edge.
Definition edge.hpp:131
Float length() const
Returns the length of this Edge.
Definition edge.hpp:107
Edge< 3 > to_3d() const
Adds a 0-valued third dimension if this Edge is in 2D, adds a 0-valued second and third dimension if ...
Definition edge.cpp:71
const Eigen::Ref< const EigObj > ConstEigRef
Read-only reference to an Eigen object.
Definition types.hpp:98
double Float
Floating point number.
Definition types.hpp:47
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Definition types.hpp:86
Primary namespace for the OpenBEM library.
Definition constants.hpp:31