OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
base.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_MESH_BASE_H
19#define GEOM_MESH_BASE_H
20
21#include <string>
22
23#include "types.hpp"
24
25
26namespace bem
27{
28
39template <uint8_t dim, uint8_t verts_per_elem>
41{
42
43 static_assert((dim == 1 || dim == 2 || dim == 3), "MeshBase: `dim` must be 1, 2, or 3.");
44
45public:
46
52 { return verts_; };
53
54
61 { return verts_.col(vert); };
62
63
69 { return elems_; };
70
71
78 { return elems_.col(elem); };
79
80
88 { return elems_(vert, elem); };
89
90
100 { return elem_tags_; };
101
102
112 { return elem_tags_[elem]; };
113
114
120 { return verts_.cols(); };
121
122
128 { return elems_.cols(); };
129
130
136 virtual void partition_by_elems(
139 ) const = 0;
140
141
147 {
149 for (Index ii = 0; ii < elems_.cols(); ++ii)
150 {
152 Eigen::placeholders::all, elems_.col(ii)
153 );
154 centroids(Eigen::placeholders::all, ii) = coords.rowwise().mean();
155 }
156 return centroids;
157 };
158
159
163 virtual void reverse_orientation()
164 {
165 elems_ = elems_.colwise().reverse().eval();
166 return;
167 };
168
169
173 virtual ~MeshBase() = default;
174
175
176protected:
177
180 EigRowVec<Index> elem_tags_;
181
182};
183
184
189template <typename MeshType>
191{
192public:
193
201 const MeshType& mesh,
203 const std::string name = "view"
204 ): mesh_(mesh), elem_inds_(elem_inds), name_(name) {};
205
206
213 const MeshType& mesh,
214 const std::string name = "view"
215 ): mesh_(mesh), name_(name)
216 {
217 elem_inds_ = EigRowVec<Index>::LinSpaced(mesh_.num_elems(), 0, mesh_.num_elems() - 1);
218 return;
219 };
220
221
227 {
229 mesh_.partition_by_elems(submesh, elem_inds_);
230 return submesh;
231 };
232
233
238 const EigRowVec<Index>& elem_inds() const { return elem_inds_; };
239
240
245 const std::string& name() const { return name_; };
246
247
248protected:
249
250 const MeshType& mesh_;
251 const EigRowVec<Index> elem_inds_;
252 const std::string name_ = "view";
253
254};
255
260}
261
262#endif
Mesh base class.
Definition base.hpp:41
virtual ~MeshBase()=default
Virtual destructor.
virtual void partition_by_elems(MeshBase< dim, verts_per_elem > &partition, ConstEigRef< EigRowVec< Index > > elem_inds) const =0
Returns a sub-mesh that contains only specified elements of this mesh.
virtual void reverse_orientation()
Reverses the orientation of each element.
Definition base.hpp:163
Index num_verts() const
Returns the number of vertices in the mesh.
Definition base.hpp:119
Index elem_tags(Index elem) const
Returns the tag associated with a specified element.
Definition base.hpp:111
Index num_elems() const
Returns the number of elements in the mesh.
Definition base.hpp:127
EigColVecN< Float, dim > verts(Index vert) const
Returns the coordinates of a specific vertex.
Definition base.hpp:60
const EigRowVec< Index > & elem_tags() const
Returns the element tags.
Definition base.hpp:99
EigColVecN< Index, 3 > elems(Index elem) const
Returns the vertex indices of a specific element.
Definition base.hpp:77
EigMatNX< Float, dim > elem_centroids() const
Computes and returns the centroid of each element.
Definition base.hpp:146
Index elems(uint8_t vert, Index elem) const
Returns the index of a specific vertex of a specific element.
Definition base.hpp:87
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 that provides a lightweight view into a MeshBase object.
Definition base.hpp:191
MeshView(const MeshType &mesh, ConstEigRef< EigRowVec< Index > > elem_inds, const std::string name="view")
Constructs a MeshView from a mesh and specified element indices.
Definition base.hpp:200
const EigRowVec< Index > & elem_inds() const
Returns the parent mesh's element indices associated with this view.
Definition base.hpp:238
const std::string & name() const
Returns the name of the view.
Definition base.hpp:245
MeshType mesh() const
Creates and returns a new mesh containing the elements of the parent mesh associated with this view.
Definition base.hpp:226
MeshView(const MeshType &mesh, const std::string name="view")
Constructs a MeshView from a mesh, containing all its elements.
Definition base.hpp:212
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
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Definition types.hpp:86
Eigen::Matrix< T, N, Eigen::Dynamic > EigMatNX
Fixed-height matrix with N rows containing type T.
Definition types.hpp:78
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