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 BEM_RWG_ASSEMBLER_BASE_H
19#define BEM_RWG_ASSEMBLER_BASE_H
20
21#include "types.hpp"
25#include "matrix/base.hpp"
29
30
31namespace bem::rwg
32{
33
44template <uint8_t obs_num_dof, uint8_t src_num_dof>
46{
47
48 static_assert((obs_num_dof > 0), "OperatorAssemblerBase: `obs_num_dof` must be greater than 0.");
49 static_assert((src_num_dof > 0), "OperatorAssemblerBase: `src_num_dof` must be greater than 0.");
50
51public:
52
64 ):
65 obs_mesh_(obs_mesh),
66 src_mesh_(src_mesh),
67 elem_pairs_(elem_pairs) {};
68
69
78 ):
79 obs_mesh_(obs_mesh),
80 src_mesh_(src_mesh),
81 elem_pairs_(make_pairs(obs_mesh, src_mesh)) {};
82
83
91 obs_mesh_(mesh),
92 src_mesh_(mesh),
93 elem_pairs_(elem_pairs) {};
94
95
101 obs_mesh_(mesh),
102 src_mesh_(mesh),
103 elem_pairs_(make_pairs(mesh, mesh)) {};
104
105
114 template <typename OperatorType>
118 const Complex k
119 )
120 {
121
122 static_assert(
123 std::is_base_of<OperatorBase<obs_num_dof, src_num_dof>, OperatorType>::value,
124 "OperatorAssemblerBase::assemble(): `OperatorType` must derive from `OperatorBase<obs_num_dof, src_num_dof>`"
125 );
126
128
129#pragma omp parallel for firstprivate(op)
130 for (Index ii = 0; ii < elem_pairs_.cols(); ++ii)
131 {
132 Triangle<3> obs_tri = obs_mesh_.elem_primitive(elem_pairs_(0, ii));
133 Triangle<3> src_tri = src_mesh_.elem_primitive(elem_pairs_(1, ii));
134
136
137#pragma omp critical
138 fill_matrix(mat, elem_pairs_.col(ii), values);
139 }
140
141 mat.assemble();
142 return;
143 };
144
145
152
153
161 virtual void fill_matrix(
165 ) = 0;
166
167
178 )
179 {
180 Index num_pairs = obs_mesh.num_elems() * src_mesh.num_elems();
182
183 for (Index ii = 0; ii < num_pairs; ++ii)
184 {
185 pairs(0, ii) = ii / src_mesh.num_elems();
186 pairs(1, ii) = ii % src_mesh.num_elems();
187 }
188
189 return pairs;
190 };
191
192
203 )
204 {
205 Index num_pairs = obs_elems.size() * src_elems.size();
207
208 for (Index ii = 0; ii < obs_elems.size(); ++ii)
209 {
210 for (Index jj = 0; jj < src_elems.size(); ++jj)
211 {
212 pairs(0, jj + ii * src_elems.size()) = obs_elems[ii];
213 pairs(1, jj + ii * src_elems.size()) = src_elems[jj];
214 }
215 }
216
217 return pairs;
218 };
219
220
221protected:
222
223 const TriangleMesh<3>& obs_mesh_;
224 const TriangleMesh<3>& src_mesh_;
225 const EigMatNX<Index, 2> elem_pairs_;
226
227};
228
229
234template <uint8_t obs_num_dof>
236{
237
238 static_assert((obs_num_dof > 0), "ExcitationAssemblerBase: `obs_num_dof` must be greater than 0.");
239
240public:
241
247 obs_mesh_(mesh),
248 elems_(EigRowVec<Index>::LinSpaced(obs_mesh_.num_elems(), 0, obs_mesh_.num_elems() - 1)) {};
249
250
257 obs_mesh_(mesh),
258 elems_(elems) {};
259
260
268 virtual void assemble(
271 const Complex k
272 ) = 0;
273
274
275protected:
276
277 const TriangleMesh<3>& obs_mesh_;
278 const EigRowVec<Index> elems_;
279
280};
281
282
288template <uint8_t obs_dim, uint8_t src_num_dof>
290{
291
292 static_assert((obs_dim > 0), "`obs_dim` must be greater than 0.");
293 static_assert((src_num_dof > 0), "`src_num_dof` must be greater than 0.");
294
295public:
296
307 ):
308 obs_cloud_(obs_cloud),
309 src_mesh_(src_mesh),
310 elems_(elems) {};
311
312
321 ):
322 obs_cloud_(obs_cloud),
323 src_mesh_(src_mesh),
324 elems_(EigRowVec<Index>::LinSpaced(src_mesh.num_elems(), 0, src_mesh.num_elems() - 1)) {};
325
326
334 virtual void assemble(
337 const Complex k
338 ) = 0;
339
340
341protected:
342
343 const PointCloud<3>& obs_cloud_;
344 const TriangleMesh<3>& src_mesh_;
345 const EigRowVec<Index> elems_;
346
347};
348
353}
354
355#endif
Triangle< dim > elem_primitive(Index elem) const
Returns a Triangle primitive object representing a specific element of the mesh.
Base class for generating excitation matrices for RWG-based BEM systems.
Definition base.hpp:236
ExcitationAssemblerBase(const TriangleMesh< 3 > &mesh)
Constructs an ExcitationAssemblerBase for a given mesh.
Definition base.hpp:246
ExcitationAssemblerBase(const TriangleMesh< 3 > &mesh, ConstEigRef< EigRowVec< Index > > elems)
Constructs an ExcitationAssemblerBase for a given mesh on given test elements.
Definition base.hpp:256
virtual void assemble(MatrixBase< Complex > &mat, ExcitationBase< obs_num_dof > &exc, const Complex k)=0
Assembles the excitation matrix for a given excitation object and observation triangle mesh.
Base class for generating RWG-based BEM operator matrices.
Definition base.hpp:46
static EigMatNX< Index, 2 > make_pairs(const TriangleMesh< 3 > &obs_mesh, const TriangleMesh< 3 > &src_mesh)
Generates all possible pairs of triangle indices for given observation and source triangle meshes.
Definition base.hpp:175
virtual void fill_matrix(MatrixBase< Complex > &mat, ConstEigRef< EigColVecN< Index, 2 > > elem_pair, ConstEigRef< EigMatMN< Complex, obs_num_dof, src_num_dof > > values)=0
Fills operator values in the matrix based on source and observation meshes and degrees of freedom.
OperatorAssemblerBase(const TriangleMesh< 3 > &obs_mesh, const TriangleMesh< 3 > &src_mesh)
Constructs an OperatorAssemblerBase for given observation and source meshes.
Definition base.hpp:75
void assemble(MatrixBase< Complex > &mat, OperatorType op, const Complex k)
Assembles the operator matrix for a given operator object and source and observation meshes.
Definition base.hpp:115
static EigMatNX< Index, 2 > make_pairs(ConstEigRef< EigRowVec< Index > > obs_elems, ConstEigRef< EigRowVec< Index > > src_elems)
Makes all possible pairs of triangle indices for given observation and source triangle indices.
Definition base.hpp:200
OperatorAssemblerBase(const TriangleMesh< 3 > &obs_mesh, const TriangleMesh< 3 > &src_mesh, ConstEigRef< EigMatNX< Index, 2 > > elem_pairs)
Constructs an OperatorAssemblerBase for given observation and source meshes.
Definition base.hpp:60
virtual void prep_matrix(MatrixBase< Complex > &mat)=0
Prepares the matrix for assembly (e.g., resizing and preallocation).
OperatorAssemblerBase(const TriangleMesh< 3 > &mesh, ConstEigRef< EigMatNX< Index, 2 > > elem_pairs)
Constructs an OperatorAssemblerBase for a given mesh.
Definition base.hpp:90
OperatorAssemblerBase(const TriangleMesh< 3 > &mesh)
Constructs an OperatorAssemblerBase for a given mesh.
Definition base.hpp:100
Base class for generating RWG-based BEM projector matrices.
Definition base.hpp:290
virtual void assemble(MatrixBase< Complex > &mat, ProjectorBase< src_num_dof > &op, const Complex k)=0
Assembles the projector matrix for a given projector object, source mesh, and observation points.
ProjectorAssemblerBase(const PointCloud< 3 > &obs_cloud, const TriangleMesh< 3 > &src_mesh, ConstEigRef< EigRowVec< Index > > elems)
Constructs a ProjectorAssemblerBase for given observation points and source mesh.
Definition base.hpp:303
ProjectorAssemblerBase(const PointCloud< 3 > &obs_cloud, const TriangleMesh< 3 > &src_mesh)
Constructs a ProjectorAssemblerBase for given observation points and source mesh.
Definition base.hpp:318
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
std::complex< Float > Complex
Complex floating point number.
Definition types.hpp:51
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
Namespace for RWG-based BEM functionality.