OpenBEM
Open-source framework for electromagnetic simulation with the boundary element method.
Loading...
Searching...
No Matches
iterative_trapz.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 ITER_TRAPZ_LINE_QUAD_H
19#define ITER_TRAPZ_LINE_QUAD_H
20
21#include <functional>
22#include <stdexcept>
23
24#include "types.hpp"
27
28
29namespace bem
30{
31
32const Float ITER_TRAPZ_LINE_DEFAULT_TOL = 1e-3;
33
43template <uint8_t dim>
45{
46
47 using base = LineQuadratureBase<dim>;
48
49public:
50
56 {
57 if (starting_num_segments > TRAPZ_LINE_MAX_NUM_SEGMENTS)
58 throw std::domain_error(
59 std::string("IterativeTrapzLineQuadrature::set_starting_num_segments(): number of ") +
60 std::string("segments must be less than ") +
61 std::to_string(TRAPZ_LINE_MAX_NUM_SEGMENTS) + ".");
62
63 starting_num_segments_ = starting_num_segments;
64 base::points_weights_computed_ = false;
65 converged_ = false;
66 return;
67 };
68
69
74 uint16_t starting_num_segments() const { return starting_num_segments_; };
75
76
81 void set_tol(const Float tol)
82 {
83 tol_ = tol;
84 base::points_weights_computed_ = false;
85 converged_ = false;
86 return;
87 };
88
89
94 Float tol() const { return tol_; };
95
96
102 {
103 max_iters_ = max_iters;
104 base::points_weights_computed_ = false;
105 converged_ = false;
106 return;
107 };
108
109
114 uint16_t max_iters() const { return max_iters_; };
115
116
126 std::function<EigRowVec<Complex> (ConstEigRef<EigMatNX<Float, dim>>)> eval = {}
127 ) override;
128
129
134 bool converged() const
135 {
136 if (!base::points_weights_computed_)
137 throw std::runtime_error(
138 "IterativeTrapzLineQuadrature::converged(): must call `compute_points_weights()` first.");
139 return converged_;
140 };
141
142
147 uint16_t converged_num_segments() const { return converged_num_segments_; };
148
149
150private:
151
152 bool converged_ = false;
153 uint16_t starting_num_segments_ = 1;
154 uint16_t converged_num_segments_ = 0;
155 uint16_t max_iters_ = LINE_MAX_ORDER;
156 Float tol_ = ITER_TRAPZ_LINE_DEFAULT_TOL;
157
158};
159
164}
165
166#ifndef BEM_LINKED
168#endif
169
170#endif
Class for iterative trapezoidal integration over a line segment.
void set_max_iters(const uint16_t max_iters)
Sets the maximum number of iterations allowed even if not converged.
bool converged() const
Checks whether the iterations converged.
void set_starting_num_segments(const uint16_t starting_num_segments)
Sets the initial number of sub-segments into which the given line segment is divided.
uint16_t starting_num_segments() const
Returns the initial number of sub-segments into which the given line segment is divided.
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.
Float tol() const
Returns the relative convergence tolerance defining when iterations should stop.
uint16_t max_iters() const
Returns the maximum number of iterations allowed even if not converged.
void set_tol(const Float tol)
Sets the relative convergence tolerance defining when iterations should stop.
uint16_t converged_num_segments() const
Returns the number of sub-segments for which the iterations converged.
Base class for quadrature over a line segment.
Definition base.hpp:46
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
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