Files Classes Functions Hierarchy
#include <desys.h>
Public Member Functions | |
| T & | yiGet (uintc i, uintc k) |
| Write to the yi state matrix. | |
| T const | yiGet (uintc i, uintc k) const |
| Access the yi state matrix. | |
| desys (uintc dim_, uintc order_) | |
| Allocate memory yi uninitialized. | |
| ~desys () | |
| Cleanup. | |
| void | eval () |
| Increment the system. | |
| ostream & | print (ostream &os) const |
| Output the state of the de system. | |
Public Attributes | |
| uint | dim |
| The dimension of the system. | |
| uint | order |
| The highest order of the derivatives. | |
| T * | dy |
| The infinitessimal - small change added to y for the next step. | |
| T | xval |
| The independent variable x. | |
| T * | yi |
| A 2D matrix of yi[0], yi[1],. | |
| NINT | integrator |
| Numerical Integrator. | |
| T | hstep |
| The step sizes. | |
void integrator.eval
(
T & dy, // Infitesimal or change in y.
T & h, // The step size
T const y, // dependent variable
T const x // independent variable
);
integrator(&xval,yi);
++integrator.yDorder;
The DE solver has a 2D matrix yi. The first row is yi[0], yi[1], ..., yi[order-1] correspond with y, y', y'', .... y^(order-1). The rows correspond to the dimension, the columns the order.
The numerical integrator is passed the locations to xval and yi[] when it is constructed. This coupling lets the equations see all the variables.
Since there is only one integrator, when the dimension is >1 it needs to behave as the current equation. Since this design eliminated virtual functions it is the clients responsibility to define a ++ operator on D of NINT<D,T> to move to the next equation in the system of equations.
Whether this helps for efficiency I do not know. For when dim>1 the client can use an array of function pointers or a case statement.
class desystestf1
{
public:
double * xval;
// yi[0] is y, yi[1] is y'
double * yi;
desystestf1(double * xval_, double * yi_)
: xval(xval_), yi(yi_) {}
void operator ++ () {}
// y''=-y
void operator () (double & Dz, double const z, double const x) const
{ Dz = -yi[0]; }
};
...
typedef nintegrationEuler< desystestf1, double > integrator;
desys< integrator ,double > de(1,2);
de.yiGet(0,0)=1.0;
de.yiGet(0,1)=0.0;
de.hstep=0.001;
cout << de << endl;
for (; de.xval < 0.3; de.eval() )
{}
cout << de << endl;
Definition at line 93 of file desys.h.
Allocate memory yi uninitialized.
Definition at line 181 of file desys.h.
References desys< NINT, T >::dim, desys< NINT, T >::order, and desys< NINT, T >::xval.
00182 : dim(dim_), order(order_), dy(new T[dim]), 00183 yi(new T[order*dim]), integrator(&xval,yi) 00184 { 00185 assert(dim>0); 00186 assert(order>0); 00187 xval=0.0; 00188 }
Cleanup.
Definition at line 174 of file desys.h.
References desys< NINT, T >::dy, and desys< NINT, T >::yi.
Increment the system.
cout << SHOW(yi[order+c]) << endl;
Definition at line 192 of file desys.h.
References desys< NINT, T >::dim, desys< NINT, T >::dy, desys< NINT, T >::hstep, desys< NINT, T >::integrator, desys< NINT, T >::order, desys< NINT, T >::xval, and desys< NINT, T >::yi.
Referenced by helixtestscope::helixtest::idle03(), desystest::test01(), desystest::test02(), desystest::test03(), desystest::test04(), and desystest::test05().
00193 { 00194 uint c; 00195 assert(hstep!=0); 00196 for (uint i=0; i<dim; ++i ) 00197 { 00198 c = i*order+order-1; 00199 00200 //cout << SHOW(xval) << endl; 00201 00202 //cout << SHOW(order) << endl; 00203 //cout << SHOW(c) << endl; 00204 //cout << SHOW(order+c) << endl; 00205 //cout << SHOW(i*(order+1)) << endl; 00206 //cout << SHOW(yi[c]) << endl; 00207 integrator.eval(dy[i],hstep,yi[c],xval); 00208 //print(cout); cout << endl; 00210 yi[c] += dy[i]; 00211 //cout << SHOW(yi[c]) << endl; 00212 //cout << SHOW(yi[order-1+c]) << endl; 00213 //cout << "*"; 00214 //print(cout); cout << endl; 00215 00216 ++integrator.yDorder; 00217 } 00218 xval += hstep; 00219 00220 if (order<=1) 00221 return; 00222 00223 for (uint i=0; i<dim; ++i ) 00224 { 00225 c = i*order + order; 00226 00227 for (uint k=2; k<=order; ++k ) 00228 yi[c-k] += yi[c-k+1]*hstep; 00229 } 00230 }
| ostream & desys< NINT, T >::print | ( | ostream & | os | ) | const [inline] |
Output the state of the de system.
Definition at line 150 of file desys.h.
References desys< NINT, T >::dim, desys< NINT, T >::hstep, desys< NINT, T >::order, desys< NINT, T >::xval, and desys< NINT, T >::yi.
00151 { 00152 os << "dim=" << dim << endl; 00153 os << "order=" << order << endl; 00154 os << "hstep=" << hstep << endl; 00155 os << "xval=" << xval << endl; 00156 os << "(y0, y0', ...)" << endl; 00157 os << "(y1, y1', ...)" << endl; 00158 os << "=" << endl; 00159 00160 os << "yi" << endl; 00161 for (uint i=0; i<dim; ++i) 00162 { 00163 os << "[" << i << "]: "; 00164 for (uint k=0; k<order; ++k) 00165 os << yi[i*order+k] << " "; 00166 os << endl; 00167 } 00168 00169 return os; 00170 }
| T const desys< NINT, T >::yiGet | ( | uintc | i, | |
| uintc | k | |||
| ) | const [inline] |
Access the yi state matrix.
Definition at line 118 of file desys.h.
References desys< NINT, T >::dim, desys< NINT, T >::order, and desys< NINT, T >::yi.
Write to the yi state matrix.
Definition at line 114 of file desys.h.
References desys< NINT, T >::dim, desys< NINT, T >::order, and desys< NINT, T >::yi.
Referenced by helixtestscope::helixtest::idle03(), desystest::test02(), helixtestscope::helixtest::test03(), desystest::test03(), desystest::test04(), and desystest::test05().
The dimension of the system.
Definition at line 101 of file desys.h.
Referenced by desys< NINT, T >::desys(), desys< NINT, T >::eval(), desys< NINT, T >::print(), and desys< NINT, T >::yiGet().
The infinitessimal - small change added to y for the next step.
Definition at line 106 of file desys.h.
Referenced by desys< NINT, T >::eval(), and desys< NINT, T >::~desys().
The step sizes.
Definition at line 125 of file desys.h.
Referenced by desys< NINT, T >::eval(), desys< NINT, T >::print(), desystest::test01(), desystest::test02(), helixtestscope::helixtest::test03(), desystest::test03(), desystest::test04(), and desystest::test05().
| NINT desys< NINT, T >::integrator |
Numerical Integrator.
Definition at line 122 of file desys.h.
Referenced by desys< NINT, T >::eval(), helixtestscope::helixtest::test03(), and desystest::test05().
The highest order of the derivatives.
Definition at line 103 of file desys.h.
Referenced by desys< NINT, T >::desys(), desys< NINT, T >::eval(), desys< NINT, T >::print(), and desys< NINT, T >::yiGet().
The independent variable x.
Definition at line 109 of file desys.h.
Referenced by desys< NINT, T >::desys(), desys< NINT, T >::eval(), desys< NINT, T >::print(), desystest::test01(), desystest::test02(), desystest::test03(), desystest::test04(), and desystest::test05().
A 2D matrix of yi[0], yi[1],.
..,yi[Order] variable rows for each dimension.
Definition at line 111 of file desys.h.
Referenced by desys< NINT, T >::eval(), desys< NINT, T >::print(), desys< NINT, T >::yiGet(), and desys< NINT, T >::~desys().
1.5.8