OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
triangle_mesh.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 GEOM_TRIANGLE_MESH_H
19#define GEOM_TRIANGLE_MESH_H
20
21#include "types.hpp"
24
25
26namespace bem
27{
28
38template <uint8_t dim>
39class TriangleMesh: public MeshBase<dim, 3>
40{
41
42 using base = MeshBase<dim, 3>;
43
44 static_assert((dim == 2 || dim == 3), "TriangleMesh: `dim` must be 2 or 3.");
45
46public:
47
52
53
70
71
93
94
106 void set_data(
110 const bool decoupled_edges = false
111 );
112
113
119 { return edges_; };
120
121
128 { return edges_.col(idx); };
129
130
138 { return edges_(vert, edge); };
139
140
146 { return elem_edges_; };
147
148
155 { return elem_edges_.col(idx); };
156
157
165 { return elem_edges_(edge, elem); };
166
167
173 { return elem_edge_polarities_; };
174
175
182 { return elem_edge_polarities_.col(idx); };
183
184
192 { return elem_edge_polarities_(edge, elem); };
193
194
200 { return boundary_elems_; };
201
202
208 { return junction_elems_; };
209
210
216 { return internal_elems_; };
217
218
224 { return boundary_edges_; };
225
226
232 { return junction_edges_; };
233
234
240 { return internal_edges_; };
241
242
248 { return edges_.cols(); };
249
250
259 ) const;
260
261
271 const bool strict = true
272 ) const;
273
274
281 {
282 return Triangle<dim> (
283 base::verts()(Eigen::placeholders::all, base::elems(elem)),
285 );
286 };
287
288
292 virtual void reverse_orientation()
293 {
294 base::elems_ = base::elems_.colwise().reverse().eval();
296 return;
297 };
298
299
300protected:
301
310 void generate_edges();
311
312
313 bool decoupled_edges_ = false;
314
315 EigMatNX<Index, 2> edges_;
316 EigMatNX<Index, 3> elem_edges_;
317 EigMatNX<Float, 3> elem_edge_polarities_;
318
319 EigRowVec<Index> boundary_elems_;
320 EigRowVec<Index> junction_elems_;
321 EigRowVec<Index> internal_elems_;
322
323 EigRowVec<Index> boundary_edges_;
324 EigRowVec<Index> junction_edges_;
325 EigRowVec<Index> internal_edges_;
326
327};
328
333}
334
335#ifndef BEM_LINKED
337#endif
338
339#endif
Mesh base class.
Definition base.hpp:41
const EigRowVec< Index > & elem_tags() const
Returns the element tags.
Definition base.hpp:99
const EigMatNX< Index, verts_per_elem > & elems() const
Returns the vertex indices of each element.
Definition base.hpp:68
const EigMatNX< Float, dim > & verts() const
Returns the coordinates of the mesh vertices.
Definition base.hpp:51
Class defining a mesh with triangle elements.
Triangle< dim > elem_primitive(Index elem) const
Returns a Triangle primitive object representing a specific element of the mesh.
Index elem_edges(uint8_t edge, Index elem) const
Returns the index of a specific edge of a specific element.
const EigRowVec< Index > & boundary_elems() const
Returns the indices of boundary elements in the mesh.
EigColVecN< Float, 3 > elem_edge_polarities(Index idx) const
Returns the polarities of the edges of a specific element.
const EigMatNX< Index, 3 > & elem_edges() const
Returns the edge indices of each element in the mesh.
void generate_edges()
Generates edges for the mesh based on element vertices.
const EigRowVec< Index > & junction_edges() const
Returns the indices of junction edges in the mesh.
const EigRowVec< Index > & internal_elems() const
Returns the indices of internal elements in the mesh.
void partition_by_elems(MeshBase< dim, 3 > &partition, ConstEigRef< EigRowVec< Index > > elem_inds) const
Returns a sub-mesh that contains only specified elements of this mesh.
TriangleMesh(ConstEigRef< EigMatNX< Float, dim > > verts, ConstEigRef< EigMatNX< Index, 3 > > elems, const bool decoupled_edges=false)
Constructs a TriangleMesh with given vertex and element data.
Index num_edges() const
Returns the number of edges in the mesh.
const EigMatNX< Float, 3 > & elem_edge_polarities() const
Returns the polarities of the edges of each element.
const EigRowVec< Index > & boundary_edges() const
Returns the indices of boundary edges in the mesh.
const EigMatNX< Index, 2 > & edges() const
Returns index pairs of vertices of each edge in the mesh.
void partition_by_bbox(MeshBase< dim, 3 > &partition, ConstEigRef< EigMatMN< Float, dim, 2 > > bbox, const bool strict=true) const
Returns a sub-mesh that contains only elements of this mesh that lie within a given bounding box.
TriangleMesh()
Constructs an empty TriangleMesh.
EigColVecN< Index, 3 > elem_edges(Index idx) const
Returns the edge indices of a specific element.
virtual void reverse_orientation()
Reverses the orientation of each element.
TriangleMesh(ConstEigRef< EigMatNX< Float, dim > > verts, ConstEigRef< EigMatNX< Index, 3 > > elems, ConstEigRef< EigRowVec< Index > > elem_tags, const bool decoupled_edges=false)
Constructs a TriangleMesh with given vertex and element data, and element tags.
Float elem_edge_polarities(uint8_t edge, Index elem) const
Returns the polarity of a specific edge of a specific element.
void set_data(ConstEigRef< EigMatNX< Float, dim > > verts, ConstEigRef< EigMatNX< Index, 3 > > elems, ConstEigRef< EigRowVec< Index > > elem_tags, const bool decoupled_edges=false)
Sets the mesh data.
const EigRowVec< Index > & junction_elems() const
Returns the indices of junction elements in the mesh.
EigColVecN< Index, 2 > edges(Index idx) const
Returns the vertex indices of a specific edge.
Index edges(uint8_t vert, Index edge) const
Returns the index of a specific vertex of a specific edge.
const EigRowVec< Index > & internal_edges() const
Returns the indices of internal edges in the mesh.
const Eigen::Ref< const EigObj > ConstEigRef
Read-only reference to an Eigen object.
Definition types.hpp:98
Eigen::Matrix< T, 1, Eigen::Dynamic > EigRowVec
Dynamic-size row vector containing type T.
Definition types.hpp:90
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
std::size_t Index
Unsigned integer type for indices and container sizes.
Definition types.hpp:54
Primary namespace for the OpenBEM library.
Definition constants.hpp:31