4238 |
18 Sep 22 |
peter |
// $Id$ |
4238 |
18 Sep 22 |
peter |
2 |
|
4238 |
18 Sep 22 |
peter |
3 |
/* |
4238 |
18 Sep 22 |
peter |
Copyright (C) 2022 Peter Johansson |
4238 |
18 Sep 22 |
peter |
5 |
|
4238 |
18 Sep 22 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4238 |
18 Sep 22 |
peter |
7 |
|
4238 |
18 Sep 22 |
peter |
The yat library is free software; you can redistribute it and/or |
4238 |
18 Sep 22 |
peter |
modify it under the terms of the GNU General Public License as |
4238 |
18 Sep 22 |
peter |
published by the Free Software Foundation; either version 3 of the |
4238 |
18 Sep 22 |
peter |
License, or (at your option) any later version. |
4238 |
18 Sep 22 |
peter |
12 |
|
4238 |
18 Sep 22 |
peter |
The yat library is distributed in the hope that it will be useful, |
4238 |
18 Sep 22 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4238 |
18 Sep 22 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4238 |
18 Sep 22 |
peter |
General Public License for more details. |
4238 |
18 Sep 22 |
peter |
17 |
|
4238 |
18 Sep 22 |
peter |
You should have received a copy of the GNU General Public License |
4238 |
18 Sep 22 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4238 |
18 Sep 22 |
peter |
20 |
*/ |
4238 |
18 Sep 22 |
peter |
21 |
|
4238 |
18 Sep 22 |
peter |
22 |
#include <config.h> |
4238 |
18 Sep 22 |
peter |
23 |
|
4238 |
18 Sep 22 |
peter |
24 |
#include "RootFinderDerivative.h" |
4238 |
18 Sep 22 |
peter |
25 |
|
4238 |
18 Sep 22 |
peter |
26 |
#include <gsl/gsl_errno.h> |
4238 |
18 Sep 22 |
peter |
27 |
|
4238 |
18 Sep 22 |
peter |
28 |
#include <cassert> |
4238 |
18 Sep 22 |
peter |
29 |
#include <memory> |
4238 |
18 Sep 22 |
peter |
30 |
|
4238 |
18 Sep 22 |
peter |
31 |
namespace theplu { |
4238 |
18 Sep 22 |
peter |
32 |
namespace yat { |
4238 |
18 Sep 22 |
peter |
33 |
namespace utility { |
4238 |
18 Sep 22 |
peter |
34 |
|
4238 |
18 Sep 22 |
peter |
35 |
RootFinderDerivative::RootFinderDerivative(const gsl_root_fdfsolver_type* t) |
4238 |
18 Sep 22 |
peter |
36 |
: type_(t), solver_(gsl_root_fdfsolver_alloc(t)) |
4238 |
18 Sep 22 |
peter |
37 |
{} |
4238 |
18 Sep 22 |
peter |
38 |
|
4238 |
18 Sep 22 |
peter |
39 |
|
4238 |
18 Sep 22 |
peter |
40 |
const char* RootFinderDerivative::name(void) const |
4238 |
18 Sep 22 |
peter |
41 |
{ |
4238 |
18 Sep 22 |
peter |
42 |
assert(solver_.get()); |
4238 |
18 Sep 22 |
peter |
43 |
return gsl_root_fdfsolver_name(solver_.get()); |
4238 |
18 Sep 22 |
peter |
44 |
} |
4238 |
18 Sep 22 |
peter |
45 |
|
4238 |
18 Sep 22 |
peter |
46 |
|
4238 |
18 Sep 22 |
peter |
47 |
RootFinderDerivative::Delta::Delta(double epsabs, double epsrel) |
4238 |
18 Sep 22 |
peter |
48 |
: epsabs_(epsabs), epsrel_(epsrel) |
4238 |
18 Sep 22 |
peter |
49 |
{} |
4238 |
18 Sep 22 |
peter |
50 |
|
4238 |
18 Sep 22 |
peter |
51 |
|
4238 |
18 Sep 22 |
peter |
52 |
bool RootFinderDerivative::Delta::operator()(const gsl_root_fdfsolver* s) |
4238 |
18 Sep 22 |
peter |
53 |
{ |
4238 |
18 Sep 22 |
peter |
54 |
double x = gsl_root_fdfsolver_root(s); |
4238 |
18 Sep 22 |
peter |
55 |
if (!prev_) { |
4238 |
18 Sep 22 |
peter |
56 |
prev_.reset(new double(x)); |
4238 |
18 Sep 22 |
peter |
57 |
return false; |
4238 |
18 Sep 22 |
peter |
58 |
} |
4238 |
18 Sep 22 |
peter |
59 |
|
4238 |
18 Sep 22 |
peter |
60 |
int status = gsl_root_test_delta(*prev_, x, epsabs_, epsrel_); |
4238 |
18 Sep 22 |
peter |
61 |
*prev_ = x; |
4238 |
18 Sep 22 |
peter |
62 |
return status == GSL_SUCCESS; |
4238 |
18 Sep 22 |
peter |
63 |
} |
4238 |
18 Sep 22 |
peter |
64 |
|
4238 |
18 Sep 22 |
peter |
65 |
|
4238 |
18 Sep 22 |
peter |
66 |
void |
4238 |
18 Sep 22 |
peter |
67 |
RootFinderDerivative::GslFree::operator()(gsl_root_fdfsolver* solver) const |
4238 |
18 Sep 22 |
peter |
68 |
{ |
4238 |
18 Sep 22 |
peter |
69 |
gsl_root_fdfsolver_free(solver); |
4238 |
18 Sep 22 |
peter |
70 |
} |
4238 |
18 Sep 22 |
peter |
71 |
|
4238 |
18 Sep 22 |
peter |
72 |
}}} |