Mercurial > hg > kwantix
annotate src/func.cpp @ 30:d22bce6382d7
Finalise removal of all namespaces, one namespace to rule them all.
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Wed, 03 Feb 2010 19:30:20 -0600 |
parents | 0af772242000 |
children | 7f31f9e2d196 |
rev | line source |
---|---|
0 | 1 #include "include/func.hpp" |
2 #include "include/error.hpp" | |
3 #include <gsl/gsl_deriv.h> | |
4 #include <cmath> | |
4
9d4fda54a41d
Buggy, must check why interpolator assignment destroys precomputed
Jordi Guitérrez Hermoso <jordigh@gmail.com>
parents:
0
diff
changeset
|
5 #include <limits> |
0 | 6 |
30
d22bce6382d7
Finalise removal of all namespaces, one namespace to rule them all.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
28
diff
changeset
|
7 namespace kwantxi{ |
0 | 8 |
9 //The static variables... | |
10 double realfunc::eps = 0; | |
11 double realfunc::sqrteps = 0; | |
12 double realfunc::root3eps = 0; | |
13 bool realfunc::initialised = false; | |
14 | |
15 //Static variables | |
16 point gsl_function_wrapper::x; | |
17 size_t gsl_function_wrapper::index = 1; | |
18 realfunc gsl_function_wrapper::myfunc(0); | |
19 gsl_function* gsl_function_wrapper::f = 0; | |
20 | |
21 //******************* Wrapper functions ***************************** | |
22 gsl_function_wrapper::gsl_function_wrapper( const realfunc &thefunc, | |
23 point p, size_t idx){ | |
24 myfunc = thefunc; | |
25 x = p; | |
26 index = idx; | |
27 f -> function = &takemyaddress; | |
28 f -> params = 0; | |
29 | |
30 } | |
31 | |
32 void gsl_function_wrapper::set_params(const realfunc &thefunc, | |
33 point p, size_t idx){ | |
34 myfunc = thefunc; | |
35 x = p; | |
36 index = idx; | |
37 f -> function = &takemyaddress; | |
38 f -> params = 0; | |
39 } | |
40 | |
41 gsl_function* gsl_function_wrapper::get_gsl_function() const{ | |
42 return f; | |
43 } | |
44 | |
45 double gsl_function_wrapper::takemyaddress(double xi, void* nothing){ | |
46 x(index) = xi; | |
47 nothing = 0; | |
48 return myfunc(x); | |
49 } | |
50 | |
51 // **************** realfunc functions ********************************* | |
52 realfunc::realfunc() : myfunc(0){ | |
53 if(!initialised){ | |
54 eps = std::numeric_limits<double>::epsilon(); | |
55 sqrteps = sqrt(eps); | |
56 root3eps = pow(eps,1/3.0); | |
57 initialised = true; | |
58 } | |
59 } | |
60 | |
61 realfunc::realfunc( double(*f)(const point&)) : myfunc(f) { | |
62 if(!initialised){ | |
63 eps = std::numeric_limits<double>::epsilon(); | |
64 sqrteps = sqrt(eps); | |
65 root3eps = pow(eps,1/3.0); | |
66 initialised = true; | |
67 } | |
68 } | |
69 | |
70 void realfunc::set_function_ptr(double (f_in)(const point &p)){ | |
71 myfunc = f_in; | |
72 } | |
73 | |
74 double realfunc::operator()(const point& p) const{ | |
75 return at(p); | |
76 } | |
77 double realfunc::at(const point& p) const{ | |
78 if(myfunc == 0){ | |
15
5144dd3c5468
Almost completed adding all Doxygen docstrings.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
79 throw no_init(__LINE__,__FILE__); |
0 | 80 } |
81 | |
82 return myfunc(p); | |
83 } | |
84 | |
85 double realfunc::d(const point& p, size_t k) const{ | |
86 gsl_function_wrapper gfw(*this,p,k); | |
87 double result, abserror; | |
88 double x = p(1); | |
89 double typx = (1 > log(x) ? 1 : log(x)); | |
90 double h = sqrteps*( fabs(x) > typx ? fabs(x) : typx); | |
91 | |
92 gsl_deriv_central(gfw.get_gsl_function(), x, h, &result, &abserror); | |
93 return result; | |
94 } | |
95 | |
96 double realfunc::d2(const point& p, size_t k1, size_t k2) const{ | |
97 //FIXME | |
98 //Figure this out later. | |
99 k1 = k2; | |
100 p.size(); | |
101 return 0; | |
102 } | |
103 | |
30
d22bce6382d7
Finalise removal of all namespaces, one namespace to rule them all.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
28
diff
changeset
|
104 kwantxi::badArgument |
15
5144dd3c5468
Almost completed adding all Doxygen docstrings.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
105 realfunc::no_init(int line, string file) const{ |
30
d22bce6382d7
Finalise removal of all namespaces, one namespace to rule them all.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
28
diff
changeset
|
106 kwantxi::badArgument exc; |
0 | 107 exc.line = line; |
108 exc.file = file; | |
109 exc.reason = "Did not assign a function pointer to a realfunc object."; | |
15
5144dd3c5468
Almost completed adding all Doxygen docstrings.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
4
diff
changeset
|
110 return exc; |
0 | 111 } |
112 } |