OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
iterative_gauss.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 <stdexcept>
21#include <functional>
22
23#include "types.hpp"
24#include "constants.hpp"
26
27
28namespace bem
29{
30
31template <uint8_t dim>
36 )
37{
38 if (!eval)
39 throw std::invalid_argument(
40 "IterativeGaussLineQuadrature::compute_points_weights(): invalid or missing eval."
41 );
42
43 if ((p2 - p1).norm() == 0.0)
44 {
45 base::points_ = p1;
46 base::weights_ = EigRowVec<Float>::Zero(1, 1);
47 base::points_weights_computed_ = true;
48 converged_ = true;
49 return;
50 }
51
52 uint8_t order = starting_order_;
53 gauss_quad_.compute_points_weights(p1, p2);
54
55 EigRowVec<Complex> vals = eval(gauss_quad_.points());
56 Complex val_ref = gauss_quad_.weights().dot(vals);
57
58 if (max_iters_ > LINE_MAX_ORDER)
59 throw std::domain_error(
60 "IterativeGaussLineQuadrature::compute_points_weights(): max iterations must not exceed " + std::to_string(LINE_MAX_ORDER));
61
62 for (order = starting_order_ + 1; order <= max_iters_; order++)
63 {
64 gauss_quad_.set_order(order);
65 gauss_quad_.compute_points_weights(p1, p2);
66 vals = eval(gauss_quad_.points());
67 Complex val = gauss_quad_.weights().dot(vals);
68
69 if (compare_with_tol(val, val_ref, tol_, 1) == true)
70 {
71 base::points_ = gauss_quad_.points();
72 base::weights_ = gauss_quad_.weights();
73 base::points_weights_computed_ = true;
74 converged_ = true;
75 converged_order_ = order;
76 return;
77 }
78
79 val_ref = val;
80 }
81
82 base::points_ = gauss_quad_.points();
83 base::weights_ = gauss_quad_.weights();
84 base::points_weights_computed_ = true;
85 converged_ = false;
86
87 return;
88};
89
90
94
95}
void compute_points_weights(ConstEigRef< EigColVecN< Float, dim > > p1, ConstEigRef< EigColVecN< Float, dim > > p2, std::function< EigRowVec< Complex >(ConstEigRef< EigMatNX< Float, dim > >)> eval={}) override
Computes and stores the points on which to evaluate the integrand, and the corresponding weights.
bool compare_with_tol(const Complex val, const Complex val_ref, const Float tol, const uint8_t mode)
Compares two complex numbers within a given tolerance based on a given rule.
Definition utility.cpp:36
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
Primary namespace for the OpenBEM library.
Definition constants.hpp:31