OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
function_space.cpp
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
19
20#include <functional>
21#include <stdexcept>
22
23#include <external/Eigen/Dense>
24
25#include "types.hpp"
26#include "matrix/base.hpp"
27
31
32
33namespace bem::rwg
34{
35
37 const Triangle<3>& tri,
40 const bool rotated
41 )
42{
43 if (!rotated)
44 return (points.colwise() - tri.v((edge + 2) % 3)) * normalization(tri)[edge];
45 else
46 return -(
47 points.colwise() - tri.v((edge + 2) % 3)
48 ).colwise().cross(tri.normal()) * normalization(tri)[edge];
49};
50
51
53 const Triangle<3>& tri,
56 const bool rotated
57 )
58{
59 tri_quad.compute_points_weights(tri);
61
63 for (uint8_t edge = 0; edge < 3; ++edge)
64 {
65 result[edge] =
66 ((
67 value(tri, edge, tri_quad.points(), rotated).array() * field.array()
68 ).colwise().sum().matrix() * tri_quad.weights().transpose())[0];
69 }
70 return result;
71};
72
73
75 const TriangleMesh<3>& mesh,
78 const bool rotated
79 )
80{
81 if (coeffs.num_cols() > 1)
82 throw std::runtime_error("Rwg::reconstruct_field(): `coeffs` should be a column vector."
83 );
84
86
87 for (Index point = 0; point < points.cols(); ++point)
88 {
89 for (Index face = 0; face < mesh.num_elems(); ++face)
90 {
92
93 if (!tri.point_in_triangle(points.col(point)))
94 continue;
95
96 for (uint8_t edge = 0; edge < 3; ++edge)
97 {
98 Index idx = mesh.elem_edges(edge, face);
99 field.col(point) += Rwg::value(tri, edge, points.col(point), rotated) * coeffs.value(idx, 0);
100 }
101 }
102 }
103
104 return field;
105
106};
107
108
110 const Triangle<3>& tri,
113 )
114{
115 tri_quad.compute_points_weights(tri);
117 field_eval(tri_quad.points()).array() *
118 value(tri, tri_quad.points()).array();
119 return (field * tri_quad.weights().transpose())[0];
120};
121
122
124 const TriangleMesh<3>& mesh,
127 )
128{
129
130 if (coeffs.num_cols() > 1)
131 throw std::runtime_error("Pulse::reconstruct_field(): `coeffs` should be a column vector."
132 );
133
135
136 for (Index point = 0; point < points.cols(); ++point)
137 {
138 for (Index face = 0; face < mesh.num_elems(); ++face)
139 {
141
142 if (!tri.point_in_triangle(points.col(point)))
143 continue;
144
145 field[point] = Pulse::value(tri, points.col(point))[0] * coeffs.value(face, 0);
146 }
147 }
148
149 return field;
150
151};
152
153}
Index num_elems() const
Returns the number of elements in the mesh.
Definition base.hpp:127
Triangle< dim > elem_primitive(Index elem) const
Returns a Triangle primitive object representing a specific element of the mesh.
const EigMatNX< Index, 3 > & elem_edges() const
Returns the edge indices of each element in the mesh.
static EigRowVec< Complex > reconstruct_field(const TriangleMesh< 3 > &mesh, const MatrixBase< Complex > &coeffs, ConstEigRef< EigMatNX< Float, 3 > > points)
Reconstructs a scalar field expressed with pulse functions on a given triangle mesh.
static EigRowVec< Float > value(const Triangle< 3 > &tri, ConstEigRef< EigMatNX< Float, 3 > > points)
Evaluates the value of the pulse function associated with a given triangle at a given set of points i...
static Complex test_field(const Triangle< 3 > &tri, std::function< EigRowVec< Complex >(ConstEigRef< EigMatNX< Float, 3 > >)> field_eval, TriangleQuadratureBase< 3 > &tri_quad)
Tests a field on the pulse function associated with a given triangle.
static EigMatNX< Complex, 3 > reconstruct_field(const TriangleMesh< 3 > &mesh, const MatrixBase< Complex > &coeffs, ConstEigRef< EigMatNX< Float, 3 > > points, const bool rotated=false)
Reconstructs a vector field expressed with RWG functions on a given triangle mesh.
static EigMatNX< Float, 3 > value(const Triangle< 3 > &tri, uint8_t edge, ConstEigRef< EigMatNX< Float, 3 > > points, const bool rotated=false)
Evaluates the value of the RWG function associated with a given edge of a given triangle at a given s...
static EigColVecN< Complex, 3 > test_field(const Triangle< 3 > &tri, std::function< EigMatNX< Complex, 3 >(ConstEigRef< EigMatNX< Float, 3 > >)> field_eval, TriangleQuadratureBase< 3 > &tri_quad, const bool rotated=false)
Tests a field on the RWG functions associated with the edges of a given triangle.
static EigRowVecN< Float, 3 > normalization(const Triangle< 3 > &tri)
Defines the normalization factor for each RWG function associated with a given triangle.
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.