OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
hgf.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
18#include "kernels/hgf.hpp"
19
20#include <cassert>
21#include <limits>
22#include <cmath>
23
24#include "types.hpp"
25#include "constants.hpp"
26
27
28namespace bem
29{
30
34 const Complex k
35 ) const
36{
37 Float r = (r_obs - r_src).norm();
38 assert(r > 0 && "HGF::kernel(): Distance must be greater than 0.");
39 return std::exp(-J * k * r) / r / four_pi;
40}
41
45 const Complex k
46 ) const
47{
49 Float r = r_diff.norm();
50 assert(r > 0 && "HGF::grad_kernel(): Distance must be greater than 0.");
51
52 const Complex jkr = J * k * r;
53 const Complex scalar_term = -std::exp(-jkr) * (one + jkr) / (Float)std::pow(r, 3) / four_pi;
54
55 return r_diff * scalar_term;
56}
57
58
62 const Complex k
63 ) const
64{
65 Float r = (r_obs - r_src).norm();
66 assert(r > 0 && "HGF::kernel(): Distance must be greater than 0.");
67 return (std::exp(-J * k * r) - one) / r / four_pi;
68}
69
73 const Complex k
74 ) const
75{
77 Float r = r_diff.norm();
78 assert(r > 0 && "HGF::grad_kernel(): Distance must be greater than 0.");
79
80 const Complex jkr = J * k * r;
81 const Float r_sq = std::pow(r, 2);
82 const Float r_cu = r_sq * r;
83
85 std::exp(-jkr) * (one + jkr) - (one + half * k * k * r_sq)
86 ) / r_cu / four_pi;
87 return r_diff * scalar_term;
88}
89
90
94 const Complex k
95 ) const
96{
97 Float r = (r_obs - r_src).norm();
98
99 if (std::abs(k) == 0.0)
100 return (Complex)0.0;
101
102 const Float tol = KERNEL_DEFAULT_TOL;
103 const Complex jk = J * k;
104 const Complex jkr = jk * r;
105
108
109 for (uint32_t jj = 2; true; jj++)
110 {
111 multiplier *= -jkr / (Float)jj;
112 val += multiplier;
113 if (std::abs(multiplier) <= tol * std::abs(val))
114 break;
115 }
116 val /= four_pi;
117
118 return val;
119}
120
124 const Complex k
125 ) const
126{
128 Float r = r_diff.norm();
129
130 if (std::abs(k) == 0.0)
131 return EigColVecN<Complex, 3>::Zero(3, 1);
132
133 const Float tol = KERNEL_DEFAULT_TOL;
134 const Complex jk = J * k;
135 const Complex jkc = jk * k * k;
136 const Complex jkr = jk * r;
137
138 Complex multiplier = jkc * (one + jkr) / (Float)6.0;
140 for (uint32_t jj = 4; true; jj++)
141 {
142 multiplier *= -jkr / (Float)jj;
144 if (std::abs(multiplier) <= tol * std::abs(scalar_term))
145 break;
146 }
147 scalar_term *= -1.0 / four_pi;
148
149 return r_diff * scalar_term;
150}
151
152}
Complex kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the kernel for given observation and source points.
Definition hgf.cpp:31
EigColVecN< Complex, 3 > grad_kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the gradient of the kernel for given observation and source points.
Definition hgf.cpp:42
Complex kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the kernel for given observation and source points.
Definition hgf.cpp:59
EigColVecN< Complex, 3 > grad_kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the gradient of the kernel for given observation and source points.
Definition hgf.cpp:70
EigColVecN< Complex, 3 > grad_kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the gradient of the kernel for given observation and source points.
Definition hgf.cpp:121
Complex kernel(ConstEigRef< EigColVecN< Float, 3 > > r_obs, ConstEigRef< EigColVecN< Float, 3 > > r_src, const Complex k) const
Computes the kernel for given observation and source points.
Definition hgf.cpp:91
const Complex J
Imaginary unit.
Definition constants.hpp:40
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
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
Primary namespace for the OpenBEM library.
Definition constants.hpp:31