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 <functional>
21
22#include "types.hpp"
23#include "constants.hpp"
26
27
28namespace bem
29{
30
31template <uint8_t dim>
33 const Triangle<dim>& tri,
35 )
36{
37 if (!eval)
38 throw std::invalid_argument(
39 "IterativeGaussTriangleQuadrature::compute_points_weights(): invalid or missing eval."
40 );
41
42 uint8_t order = starting_order_;
43 gauss_quad_.set_order(order);
44 gauss_quad_.compute_points_weights(tri);
45
46 EigRowVec<Complex> vals = eval(gauss_quad_.points());
47 Complex val_ref = gauss_quad_.weights().dot(vals);
48
49 if (max_iters_ > TRI_MAX_ORDER)
50 throw std::runtime_error(
51 "IterativeGaussTriangleQuadrature::compute_points_weights(): max iterations must not exceed " + std::to_string(TRI_MAX_ORDER));
52
53 for (order = starting_order_ + 1; order <= max_iters_; ++order)
54 {
55 // Order 3 and order 4 have the same rule
56 if (order == 4 && starting_order_ != 4)
57 continue;
58
59 gauss_quad_.set_order(order);
60 gauss_quad_.compute_points_weights(tri);
61 vals = eval(gauss_quad_.points());
62 Complex val = gauss_quad_.weights().dot(vals);
63
64 bool equal = val_ref == val;
65 bool converged = compare_with_tol(val, val_ref, tol_, 1);
66
67 assert((equal || val_ref != zero) &&
68 "IterativeGaussTriangleQuadrature::compute_points_weights(): divide by zero.");
69
70 if (equal || converged)
71 {
72 base::points_ = gauss_quad_.points();
73 base::weights_ = gauss_quad_.weights();
74 base::points_weights_computed_ = true;
75 converged_order_ = order;
76 converged_ = true;
77 return;
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
93
94}
void compute_points_weights(const Triangle< dim > &tri, 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
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